ba74ecff29b8f62d62dec0d40d595ea42096019a
[libcds.git] / cds / container / details / split_list_base.h
1 //$$CDS-header$$
2
3 #ifndef __CDS_CONTAINER_DETAILS_SPLIT_LIST_BASE_H
4 #define __CDS_CONTAINER_DETAILS_SPLIT_LIST_BASE_H
5
6 #include <cds/intrusive/details/split_list_base.h>
7
8 namespace cds { namespace container {
9
10     // forward declaration
11     struct michael_list_tag;
12
13     /// SplitListSet related definitions
14     /** @ingroup cds_nonintrusive_helper
15     */
16     namespace split_list {
17         /// Internal statistics, see \p cds::intrusive::split_list::stat
18         template <typename Counter = cds::intrusive::split_list::stat<>::counter_type >
19         using stat = cds::intrusive::split_list::stat<Counter>;
20
21         /// Disabled internal statistics, see \p cds::intrusive::split_list::empty_stat
22         typedef cds::intrusive::split_list::empty_stat empty_stat;
23
24         /// Selector of bucket table implementation =- typedef for \p intrusive::split_list::dynamic_bucket_table
25         template <bool Value>
26         using dynamic_bucket_table = cds::intrusive::split_list::dynamic_bucket_table<Value>;
27
28         using cds::intrusive::split_list::static_bucket_table;
29         using cds::intrusive::split_list::expandable_bucket_table;
30
31         //@cond
32         namespace details {
33
34             template <typename Key, typename Value, typename Traits, typename Opt>
35             struct wrap_map_traits_helper {
36                 typedef Opt key_accessor;
37             };
38
39             template <typename Key, typename Value, typename Traits >
40             struct wrap_map_traits_helper<Key, Value, Traits, opt::none>
41             {
42                 struct key_accessor
43                 {
44                     typedef Key     key_type;
45                     key_type const & operator()( std::pair<Key const, Value> const & val ) const
46                     {
47                         return val.first;
48                     }
49                 };
50             };
51
52             template <typename Key, typename Value, typename Traits>
53             struct wrap_map_traits: public Traits
54             {
55                 typedef typename wrap_map_traits_helper<Key, Value, Traits, typename Traits::key_accessor>::key_accessor    key_accessor;
56             };
57
58             template <typename Value, typename Traits, typename Opt>
59             struct wrap_set_traits_helper {
60                 typedef Opt key_accessor;
61             };
62
63             template <typename Value, typename Traits >
64             struct wrap_set_traits_helper<Value, Traits, opt::none>
65             {
66                 struct key_accessor
67                 {
68                     typedef Value     key_type;
69                     key_type const& operator()( Value const& val ) const
70                     {
71                         return val;
72                     }
73                 };
74             };
75
76             template <typename Value, typename Traits>
77             struct wrap_set_traits: public Traits
78             {
79                 typedef typename wrap_set_traits_helper<Value, Traits, typename Traits::key_accessor>::key_accessor key_accessor;
80             };
81         }  // namespace details
82         //@endcond
83
84
85         /// SplitListSet traits
86         struct traits: public intrusive::split_list::traits
87         {
88             // Ordered list implementation
89             /**
90                 Selects appropriate ordered-list implementation for split-list.
91                 Supported types are:
92                 - \p michael_list_tag - for MichaelList
93                 - \p lazy_list_tag - for LazyList
94             */
95             typedef michael_list_tag    ordered_list;
96
97             // Ordered list traits
98             /**
99                 Specifyes traits for selected ordered list type, default type:
100                 - for \p michael_list_tag: \p container::michael_list::traits.
101                 - for \p lazy_list_tag: \p container::lazy_list::traits.
102
103                 If this type is \p opt::none, the ordered list traits is combined with default
104                 ordered list traits above and split-list traits.
105             */
106             typedef opt::none           ordered_list_traits;
107
108             //@cond
109             typedef opt::none           key_accessor;
110             //@endcond
111         };
112
113         /// Option to select ordered list class for split-list
114         /**
115             This option selects appropriate ordered list class for containers based on split-list.
116             Template parameter \p Type may be \p michael_list_tag or \p lazy_list_tag.
117         */
118         template <class Type>
119         struct ordered_list
120         {
121             //@cond
122             template<class Base> struct pack: public Base
123             {
124                 typedef Type ordered_list;
125             };
126             //@endcond
127         };
128
129         /// Option to specify ordered list type traits
130         /**
131             The \p Type template parameter specifies ordered list type traits.
132             It depends on type of ordered list selected.
133         */
134         template <class Type>
135         struct ordered_list_traits
136         {
137             //@cond
138             template<class Base> struct pack: public Base
139             {
140                 typedef Type ordered_list_traits;
141             };
142             //@endcond
143         };
144
145         /// Metafunction converting option list to traits struct
146         /**
147             Available \p Options:
148             - \p split_list::ordered_list - a tag for ordered list implementation.
149             - \p split_list::ordered_list_traits - type traits for ordered list implementation.
150                 For \p MichaelList use \p container::michael_list::traits or derivatives,
151                 for \p LazyList use \p container::lazy_list::traits or derivatives.
152             - plus any option from \p intrusive::split_list::make_traits
153         */
154         template <typename... Options>
155         struct make_traits {
156             typedef typename cds::opt::make_options< traits, Options...>::type type  ;   ///< Result of metafunction
157         };
158     }   // namespace split_list
159
160     //@cond
161     // Forward declarations
162     template <class GC, class T, class Traits = split_list::traits>
163     class SplitListSet;
164
165     template <class GC, typename Key, typename Value, class Traits = split_list::traits>
166     class SplitListMap;
167     //@endcond
168
169     //@cond
170     // Forward declaration
171     namespace details {
172         template <typename GC, typename T, typename OrderedListTag, typename Traits>
173         struct make_split_list_set;
174
175         template <typename GC, typename Key, typename Value, typename OrderedListTag, typename Traits>
176         struct make_split_list_map;
177     }
178     //@endcond
179
180 }}  // namespace cds::container
181
182
183 #endif // #ifndef __CDS_CONTAINER_DETAILS_SPLIT_LIST_BASE_H