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_ACQUIRE_HPP
8 : #define VSET_VSET_MEMORY_FSB_ASPECT_AD_ACQUIRE_HPP
9 :
10 : #include <vset/buffer/tags.hpp>
11 : #include <vset/memory/fsb/tags.hpp>
12 : #include <fas/typemanip/type2type.hpp>
13 :
14 : namespace vset { namespace memory{ namespace fsb{
15 :
16 31 : struct ad_acquire
17 : {
18 : template<typename T>
19 38 : bool operator()(T& t) const
20 : {
21 : typedef ::vset::buffer::_size_ _buffer_size_;
22 : typedef ::vset::buffer::_resize_ _buffer_resize_;
23 : typedef ::vset::buffer::_data_type_ _buffer_data_type_;
24 : typedef ::vset::buffer::_data_ _buffer_data_;
25 :
26 : typedef typename T::aspect::template advice_cast<_chain_type_>::type chain_type;
27 : typedef typename T::aspect::template advice_cast<_chunk_type_>::type chunk_type;
28 : typedef typename T::aspect::template advice_cast<_buffer_data_type_>::type data_type;
29 :
30 38 : size_t offset = t.get_aspect().template get< _buffer_size_ >()(t);
31 :
32 : size_t new_size = (offset == 0)
33 : ? sizeof(chain_type) + sizeof(chunk_type)
34 38 : : offset + sizeof(chunk_type);
35 :
36 :
37 38 : t.get_aspect().template get< _buffer_resize_ >()(t, new_size);
38 :
39 38 : data_type data = t.get_aspect().template get<_buffer_data_>()(t);
40 :
41 : chain_type* ch = (offset == 0)
42 26 : ? new (data) chain_type
43 64 : : static_cast<chain_type*>( static_cast<void*>(data));
44 :
45 38 : ch->acquire(1);
46 :
47 38 : new ( data + (offset == 0 ? sizeof(chain_type) : offset) ) chunk_type;
48 : /*
49 : offset == 0
50 : ? new ( data + sizeof(chain_type) ) chunk_type
51 : : new ( data + offset ) chunk_type;
52 : */
53 :
54 38 : return true;
55 : }
56 : };
57 :
58 :
59 : }}}
60 :
61 : #endif
|