Removed trailing whitespaces
[libcds.git] / cds / container / details / make_lazy_kvlist.h
1 //$$CDS-header$$
2
3 #ifndef CDSLIB_CONTAINER_DETAILS_MAKE_LAZY_KVLIST_H
4 #define CDSLIB_CONTAINER_DETAILS_MAKE_LAZY_KVLIST_H
5
6 #include <cds/details/binary_functor_wrapper.h>
7
8 namespace cds { namespace container {
9
10     //@cond
11     namespace details {
12
13         template <class GC, typename K, typename T, class Traits>
14         struct make_lazy_kvlist
15         {
16             typedef Traits original_type_traits;
17
18             typedef GC      gc;
19             typedef K       key_type;
20             typedef T       mapped_type;
21             typedef std::pair<key_type const, mapped_type> value_type;
22
23             struct node_type: public intrusive::lazy_list::node<gc, typename original_type_traits::lock_type>
24             {
25                 value_type   m_Data;
26
27                 template <typename Q>
28                 node_type( Q const& key )
29                     : m_Data( key, mapped_type() )
30                 {}
31
32                 template <typename Q, typename R>
33                 explicit node_type( std::pair<Q, R> const& pair )
34                     : m_Data( pair )
35                 {}
36
37                 template <typename Q, typename R>
38                 node_type( Q const& key, R const& value )
39                     : m_Data( key, value )
40                 {}
41
42                 template <typename Ky, typename... Args>
43                 node_type( Ky&& key, Args&&... args )
44                     : m_Data( std::forward<Ky>( key ), std::move( mapped_type( std::forward<Args>( args )... ) ) )
45                 {}
46             };
47
48             typedef typename original_type_traits::allocator::template rebind<node_type>::other allocator_type;
49             typedef cds::details::Allocator< node_type, allocator_type > cxx_allocator;
50
51             struct node_deallocator
52             {
53                 void operator ()( node_type * pNode )
54                 {
55                     cxx_allocator().Delete( pNode );
56                 }
57             };
58
59             struct key_field_accessor {
60                 key_type const& operator()( node_type const& pair )
61                 {
62                     return pair.m_Data.first;
63                 }
64             };
65
66             typedef typename std::conditional< original_type_traits::sort,
67                 typename opt::details::make_comparator< value_type, original_type_traits >::type,
68                 typename opt::details::make_equal_to< value_type, original_type_traits >::type
69             >::type key_comparator;
70
71
72             template <typename Less>
73             struct less_wrapper {
74                 typedef cds::details::compare_wrapper< node_type, cds::opt::details::make_comparator_from_less<Less>, key_field_accessor >    type;
75             };
76
77             template <typename Equal>
78             struct equal_to_wrapper {
79                 typedef cds::details::predicate_wrapper< node_type, Equal, key_field_accessor >    type;
80             };
81
82             struct intrusive_traits: public original_type_traits
83             {
84                 typedef intrusive::lazy_list::base_hook< opt::gc<gc> >  hook;
85                 typedef node_deallocator disposer;
86
87                 typedef typename std::conditional< std::is_same< typename original_type_traits::equal_to, cds::opt::none >::value,
88                     cds::opt::none,
89                     typename equal_to_wrapper< typename original_type_traits::equal_to >::type
90                 >::type equal_to;
91
92                 typedef typename std::conditional<
93                     original_type_traits::sort
94                         || !std::is_same< typename original_type_traits::compare, cds::opt::none >::value
95                         || !std::is_same< typename original_type_traits::less, cds::opt::none >::value,
96                     cds::details::compare_wrapper<
97                         node_type,
98                         typename opt::details::make_comparator< value_type, original_type_traits >::type,
99                         key_field_accessor
100                     >,
101                     cds::opt::none
102                 >::type compare;
103
104                 static const opt::link_check_type link_checker = cds::intrusive::lazy_list::traits::link_checker;
105             };
106
107             typedef intrusive::LazyList<gc, node_type, intrusive_traits>  type;
108         };
109     }   // namespace details
110     //@endcond
111
112 }}  // namespace cds::container
113
114 #endif  // #ifndef CDSLIB_CONTAINER_DETAILS_MAKE_LAZY_KVLIST_H