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_PRED_OFFSET_HPP
8 : #define VSET_VSET_MEMORY_FSB_ASPECT_AD_PRED_OFFSET_HPP
9 :
10 : #include <vset/buffer/tags.hpp>
11 : #include <vset/memory/fsb/tags.hpp>
12 :
13 : namespace vset { namespace memory{ namespace fsb{
14 :
15 31 : struct ad_pred_offset
16 : {
17 : template<typename T>
18 22347 : size_t operator()(T& t, size_t offset, size_t count) const
19 : {
20 : typedef ::vset::buffer::_data_ _buffer_data_;
21 : typedef ::vset::buffer::_data_type_ _buffer_data_type_;
22 :
23 : typedef typename T::aspect::template advice_cast<_chain_type_>::type chain_type;
24 : typedef typename T::aspect::template advice_cast<_value_type_>::type value_type;
25 : typedef typename T::aspect::template advice_cast<_buffer_data_type_>::type data_type;
26 :
27 22347 : data_type data = t.get_aspect().template get<_buffer_data_>()(t);
28 22347 : chain_type* chn = static_cast<chain_type*>( static_cast<void*>(data) );
29 :
30 22347 : if ( offset == static_cast<size_t>(-1) )
31 : {
32 4 : if ( value_type* current = chn->last_value() )
33 : {
34 : //offset = static_cast<size_t>( reinterpret_cast<data_type>(current) - data );
35 4 : offset = t.get_aspect().template get<_offset_by_ptr_>()(t, current);
36 : }
37 : }
38 42745 : else for (size_t i = 0 ; i < count ; ++i)
39 : {
40 :
41 : //if ( value_type* current = chn->pred_value( reinterpret_cast<value_type*>(data + offset) ) )
42 22343 : if ( value_type* current = chn->pred_value( t.get_aspect().template get<_ptr_by_offset_>()(t, offset) ) )
43 : {
44 : //offset = static_cast<size_t>( reinterpret_cast<data_type>(current) - data );
45 20402 : offset = t.get_aspect().template get<_offset_by_ptr_>()(t, current);
46 : }
47 : else
48 : {
49 1941 : return static_cast<size_t>(-1);
50 : }
51 : }
52 :
53 20406 : return offset;
54 : }
55 : };
56 :
57 : }}}
58 :
59 : #endif
|