• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga  2006-2015.
4 //
5 // Distributed under the Boost Software License, Version 1.0.
6 //    (See accompanying file LICENSE_1_0.txt or copy at
7 //          http://www.boost.org/LICENSE_1_0.txt)
8 //
9 // See http://www.boost.org/libs/intrusive for documentation.
10 //
11 /////////////////////////////////////////////////////////////////////////////
12 #include <boost/intrusive/unordered_set.hpp>
13 #include <boost/intrusive/pointer_traits.hpp>
14 #include <boost/intrusive/detail/iterator.hpp>
15 #include "itestvalue.hpp"
16 #include "smart_ptr.hpp"
17 #include "common_functors.hpp"
18 #include <vector>
19 #include <set>
20 #include <boost/detail/lightweight_test.hpp>
21 #include "test_macros.hpp"
22 #include "test_container.hpp"
23 #include "unordered_test_common.hpp"
24 #include "unordered_test.hpp"
25 
26 using namespace boost::intrusive;
27 
28 template < class ValueTraits, bool ConstantTimeSize, bool CacheBegin, bool CompareHash, bool Incremental, bool Map, bool DefaultHolder >
29 struct rebinder
30 {
31    typedef unordered_rebinder_common<ValueTraits, DefaultHolder, Map> common_t;
32    typedef typename ValueContainer< typename ValueTraits::value_type >::type value_cont_type;
33 
34    template < class Option1 =void
35             , class Option2 =void
36             >
37    struct container
38    {
39       typedef unordered_set
40          < typename common_t::value_type
41          , value_traits<ValueTraits>
42          , constant_time_size<ConstantTimeSize>
43          , cache_begin<CacheBegin>
44          , compare_hash<CompareHash>
45          , incremental<Incremental>
46          , typename common_t::holder_opt
47          , typename common_t::key_of_value_opt
48          , size_type<unsigned short>
49          , Option1
50          , Option2
51          > type;
52       BOOST_STATIC_ASSERT((key_type_tester<typename common_t::key_of_value_opt, type>::value));
53       BOOST_STATIC_ASSERT((!boost::intrusive::test::is_multikey_true<type>::value));
54    };
55 };
56 
57 enum HookType
58 {
59    Base,
60    Member,
61    NonMember
62 };
63 
64 template<class VoidPointer, bool ConstantTimeSize, bool DefaultHolder, bool Map, HookType Type>
65 class test_main_template;
66 
67 template<class VoidPointer, bool ConstantTimeSize, bool DefaultHolder, bool Map>
68 class test_main_template<VoidPointer, ConstantTimeSize, DefaultHolder, Map, Base>
69 {
70    public:
execute()71    static void execute()
72    {
73       typedef testvalue<unordered_hooks<VoidPointer> > value_type;
74       static const int random_init[6] = { 3, 2, 4, 1, 5, 2 };
75       typedef typename ValueContainer< value_type >::type value_cont_type;
76       value_cont_type data (6);
77       for (int i = 0; i < 6; ++i)
78          data[i].value_ = random_init[i];
79 
80       typedef testvalue_traits< unordered_hooks<VoidPointer> > testval_traits_t;
81       //base
82       typedef typename detail::if_c
83          < ConstantTimeSize
84          , typename testval_traits_t::base_value_traits
85          , typename testval_traits_t::auto_base_value_traits   //store_hash<true>
86          >::type base_hook_t;
87       test::test_unordered
88          < //cache_begin, compare_hash, incremental
89            rebinder<base_hook_t, ConstantTimeSize, ConstantTimeSize, !ConstantTimeSize, !!ConstantTimeSize, Map, DefaultHolder>
90          >::test_all(data);
91    }
92 };
93 
94 template<class VoidPointer, bool ConstantTimeSize, bool DefaultHolder, bool Map>
95 class test_main_template<VoidPointer, ConstantTimeSize, DefaultHolder, Map, Member>
96 {
97    public:
execute()98    static void execute()
99    {
100       typedef testvalue<unordered_hooks<VoidPointer> > value_type;
101       static const int random_init[6] = { 3, 2, 4, 1, 5, 2 };
102       typedef typename ValueContainer< value_type >::type value_cont_type;
103       value_cont_type data (6);
104       for (int i = 0; i < 6; ++i)
105          data[i].value_ = random_init[i];
106 
107       typedef testvalue_traits< unordered_hooks<VoidPointer> > testval_traits_t;
108       //member
109       typedef typename detail::if_c
110          < ConstantTimeSize
111          , typename testval_traits_t::member_value_traits      //optimize_multikey<true>
112          , typename testval_traits_t::auto_member_value_traits //store_hash<true>, optimize_multikey<true>
113          >::type member_hook_t;
114       test::test_unordered
115          < //cache_begin, compare_hash, incremental
116            rebinder<member_hook_t, ConstantTimeSize, false, !ConstantTimeSize, false, !ConstantTimeSize, DefaultHolder>
117          >::test_all(data);
118    }
119 };
120 
121 template<class VoidPointer, bool ConstantTimeSize, bool DefaultHolder, bool Map>
122 class test_main_template<VoidPointer, ConstantTimeSize, DefaultHolder, Map, NonMember>
123 
124 {
125    public:
execute()126    static void execute()
127    {
128       typedef testvalue<unordered_hooks<VoidPointer> > value_type;
129       static const int random_init[6] = { 3, 2, 4, 1, 5, 2 };
130       typedef typename ValueContainer< value_type >::type value_cont_type;
131       value_cont_type data (6);
132       for (int i = 0; i < 6; ++i)
133          data[i].value_ = random_init[i];
134 
135       typedef testvalue_traits< unordered_hooks<VoidPointer> > testval_traits_t;
136       //nonmember
137       test::test_unordered
138          < //cache_begin, compare_hash, incremental
139            rebinder<typename testval_traits_t::nonhook_value_traits, ConstantTimeSize, false, false, false, Map, DefaultHolder>
140          >::test_all(data);
141    }
142 };
143 
main()144 int main()
145 {
146    //VoidPointer x ConstantTimeSize x Map x DefaultHolder
147 
148    //void pointer
149    test_main_template<void*, false, false, false, Base>::execute();
150    test_main_template<void*, false,  true, false, Member>::execute();
151    test_main_template<void*,  true, false, false, NonMember>::execute();
152    test_main_template<void*,  true,  true, false, Base>::execute();
153 
154    //smart_ptr
155    test_main_template<smart_ptr<void>, false, false, false, Member>::execute();
156    test_main_template<smart_ptr<void>, false,  true, false, NonMember>::execute();
157    test_main_template<smart_ptr<void>,  true, false, false, Base>::execute();
158    test_main_template<smart_ptr<void>,  true,  true, false, Member>::execute();
159 
160    ////bounded_ptr (bool ConstantTimeSize, bool Map)
161    //test_main_template_bptr< false, false >::execute();
162    //test_main_template_bptr< false,  true >::execute();
163    //test_main_template_bptr<  true, false >::execute();
164    //test_main_template_bptr<  true,  true >::execute();
165 
166    return boost::report_errors();
167 }
168