LCOV - code coverage report
Current view: top level - vset/memory/fsb/aspect - ad_allocate.hpp (source / functions) Hit Total Coverage
Test: v-set-coverage.info Lines: 18 19 94.7 %
Date: 2019-09-12 Functions: 25 27 92.6 %

          Line data    Source code
       1             : //
       2             : // Author: Vladimir Migashko <migashko@gmail.com>, (C) 2012
       3             : //
       4             : // Copyright: See COPYING file that comes with this distribution
       5             : //
       6             : 
       7             : #ifndef VSET_VSET_MEMORY_FSB_ASPECT_AD_ALLOCATE_HPP
       8             : #define VSET_VSET_MEMORY_FSB_ASPECT_AD_ALLOCATE_HPP
       9             : 
      10             : #include <vset/buffer/tags.hpp>
      11             : #include <vset/memory/fsb/tags.hpp>
      12             : 
      13             : #include <fas/typemanip/type2type.hpp>
      14             : #include <stdlib.h>
      15             : namespace vset { namespace memory{ namespace fsb{
      16             : 
      17          31 : struct ad_allocate
      18             : {
      19             :   template<typename T, typename Pointer>
      20       10833 :   Pointer operator()(T& t, fas::type2type<Pointer>, size_t num = 1, void *  /*hint*/ = 0 ) const
      21             :   {
      22       10833 :     for(; num > 1; --num) _<Pointer>(t);
      23       10833 :     return _<Pointer>(t);
      24             :   }
      25             : 
      26             : private:
      27             : 
      28             :   template<typename Pointer, typename T>
      29       10833 :   Pointer _(T& t) const
      30             :   {
      31             :     typedef Pointer pointer;
      32             :     typedef ::vset::buffer::_size_      _buffer_size_;
      33             :     typedef ::vset::buffer::_data_      _buffer_data_;
      34             :     typedef ::vset::buffer::_data_type_ _buffer_data_type_;
      35             : 
      36             :     typedef typename T::aspect::template advice_cast<_chain_type_>::type chain_type;
      37             :     typedef typename T::aspect::template advice_cast< _buffer_data_type_ >::type data_type;
      38             : 
      39       10833 :     if ( t.get_aspect().template get< _buffer_size_ >()(t) == 0 )
      40             :     {
      41          26 :       t.get_aspect().template get<_acquire_>()(t);
      42             :     }
      43             : 
      44       10833 :     data_type data = t.get_aspect().template get<_buffer_data_>()(t);
      45       10833 :     chain_type* chn = static_cast<chain_type*>( static_cast<void*>(data) );
      46       10833 :     pointer p( &t );
      47       10833 :     p.set_address( chn->mark() );
      48       10833 :     if (!p)
      49             :     {
      50          12 :       t.get_aspect().template get<_acquire_>()(t);
      51          12 :       data = t.get_aspect().template get<_buffer_data_>()(t);
      52          12 :       chn = static_cast<chain_type*>( static_cast<void*>(data) );
      53          12 :       p.set_address(chn->mark());
      54          12 :       if (!p)
      55             :       {
      56           0 :         abort();
      57             :       }
      58             :     }
      59       10833 :     return p;
      60             :   }
      61             : };
      62             : 
      63             : }}}
      64             : 
      65             : #endif

Generated by: LCOV version 1.10