LCOV - code coverage report
Current view: top level - vset/memory - allocator.hpp (source / functions) Hit Total Coverage
Test: v-set-coverage.info Lines: 16 16 100.0 %
Date: 2019-09-12 Functions: 34 41 82.9 %

          Line data    Source code
       1             : #ifndef MANAGED_ALLOCATOR_HPP
       2             : #define MANAGED_ALLOCATOR_HPP
       3             : 
       4             : #include <fas/system/nullptr.hpp>
       5             : #include <limits>
       6             : #include <cassert>
       7             : 
       8             : namespace vset { namespace memory{
       9             : 
      10             : template<typename Memory >
      11             : struct allocator
      12             : {
      13             :   typedef Memory memory_type;
      14             :   typedef typename memory_type::value_type value_type;
      15             :   typedef typename memory_type::pointer pointer;
      16             :   typedef typename memory_type::const_pointer const_pointer;
      17             :   
      18             :   typedef typename memory_type::reference       reference;
      19             :   typedef typename memory_type::const_reference const_reference;
      20             :   typedef typename memory_type::size_type size_type;
      21             :   typedef typename memory_type::difference_type difference_type;
      22             : 
      23           2 :   allocator()
      24           2 :     : _memory()
      25             :   {
      26           2 :   }
      27             :   
      28          26 :   explicit allocator(const memory_type& m)
      29          26 :     : _memory(m)
      30             :   {
      31          26 :   }
      32             : 
      33             :   template <typename U>
      34             :   struct rebind {
      35             :     typedef std::allocator<U> other;
      36             :   };
      37             : 
      38             :   pointer address(reference value ) const
      39             :   {
      40             :     return static_cast<char*>(&value) - _memory.data();
      41             :   }
      42             : 
      43             :   const_pointer address (const_reference value) const
      44             :   {
      45             :     return static_cast<char*>(&value) - _memory.data();
      46             :   }
      47             :   
      48             :   static size_type max_size () 
      49             :   {
      50             :     return 1;
      51             :   }
      52             : 
      53          36 :   pointer allocate (size_type num, void *  hint = fas_nullptr)
      54             :   {
      55          36 :     return this->_memory.allocate(num, hint);
      56             :   }
      57             : 
      58          23 :   static void construct (pointer p, const_reference value)
      59             :   {
      60          23 :     *p = value;
      61          23 :   }
      62             : 
      63             :   static void destroy (pointer p)
      64             :   {
      65             :     p->~T();
      66             :   }
      67             : 
      68           2 :   void deallocate (pointer p, size_type num)
      69             :   {
      70           2 :     this->_memory.deallocate(p, num);
      71           2 :   }
      72             : 
      73          11 :   memory_type memory() const
      74             :   {
      75          11 :     return this->_memory;
      76             :   }
      77             : 
      78             :   /*
      79             :   memory_type memory()
      80             :   {
      81             :     return this->_memory;
      82             :   }*/
      83             :   
      84             : private:
      85             :   memory_type _memory;
      86             : };
      87             : 
      88             : }}
      89             : 
      90             : #endif

Generated by: LCOV version 1.10