• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Olaf Krzikalla 2004-2006.
4 // (C) Copyright Ion Gaztanaga  2006-2015.
5 //
6 // Distributed under the Boost Software License, Version 1.0.
7 //    (See accompanying file LICENSE_1_0.txt or copy at
8 //          http://www.boost.org/LICENSE_1_0.txt)
9 //
10 // See http://www.boost.org/libs/intrusive for documentation.
11 //
12 /////////////////////////////////////////////////////////////////////////////
13 #include <boost/intrusive/set.hpp>
14 #include "itestvalue.hpp"
15 #include "bptr_value.hpp"
16 #include "smart_ptr.hpp"
17 #include "rb_test_common.hpp"
18 #include "generic_set_test.hpp"
19 
20 using namespace boost::intrusive;
21 
22 template < class ValueTraits, bool ConstantTimeSize, bool DefaultHolder, bool Map >
23 struct rebinder
24 {
25    typedef tree_rebinder_common<ValueTraits, DefaultHolder, Map> common_t;
26    typedef typename ValueContainer< typename ValueTraits::value_type >::type value_cont_type;
27 
28    template < class Option1 =void
29             , class Option2 =void
30             >
31    struct container
32    {
33       typedef set
34          < typename common_t::value_type
35          , value_traits<ValueTraits>
36          , constant_time_size<ConstantTimeSize>
37          , typename common_t::holder_opt
38          , typename common_t::key_of_value_opt
39          , Option1
40          , Option2
41          > type;
42       BOOST_STATIC_ASSERT((key_type_tester<typename common_t::key_of_value_opt, type>::value));
43    };
44 };
45 
46 enum HookType
47 {
48    Base,
49    Member,
50    NonMember
51 };
52 
53 template<class VoidPointer, bool ConstantTimeSize, bool DefaultHolder, bool Map, HookType Type>
54 class test_main_template;
55 
56 template<class VoidPointer, bool ConstantTimeSize, bool DefaultHolder, bool Map>
57 class test_main_template<VoidPointer, ConstantTimeSize, DefaultHolder, Map, Base>
58 {
59    public:
execute()60    static void execute()
61    {
62       typedef testvalue_traits< rb_hooks<VoidPointer> > testval_traits_t;
63       //base
64       typedef typename detail::if_c
65          < ConstantTimeSize
66          , typename testval_traits_t::base_value_traits
67          , typename testval_traits_t::auto_base_value_traits
68          >::type base_hook_t;
69       test::test_generic_set
70          < rebinder<base_hook_t, ConstantTimeSize, DefaultHolder, Map>
71          >::test_all();
72    }
73 };
74 
75 template<class VoidPointer, bool ConstantTimeSize, bool DefaultHolder, bool Map>
76 class test_main_template<VoidPointer, ConstantTimeSize, DefaultHolder, Map, Member>
77 {
78    public:
execute()79    static void execute()
80    {
81       typedef testvalue_traits< rb_hooks<VoidPointer> > testval_traits_t;
82       //member
83       typedef typename detail::if_c
84          < ConstantTimeSize
85          , typename testval_traits_t::member_value_traits
86          , typename testval_traits_t::auto_member_value_traits
87          >::type member_hook_t;
88       test::test_generic_set
89          < rebinder<member_hook_t, ConstantTimeSize, DefaultHolder, Map>
90          >::test_all();
91    }
92 };
93 
94 template<class VoidPointer, bool ConstantTimeSize, bool DefaultHolder, bool Map>
95 class test_main_template<VoidPointer, ConstantTimeSize, DefaultHolder, Map, NonMember>
96 {
97    public:
execute()98    static void execute()
99    {
100       typedef testvalue_traits< rb_hooks<VoidPointer> > testval_traits_t;
101       //nonmember
102       test::test_generic_set
103          < rebinder<typename testval_traits_t::nonhook_value_traits, ConstantTimeSize, DefaultHolder, Map>
104          >::test_all();
105    }
106 };
107 
108 template < bool ConstantTimeSize, bool Map >
109 struct test_main_template_bptr
110 {
executetest_main_template_bptr111    static void execute()
112    {
113       typedef BPtr_Value_Traits< RBTree_BPtr_Node_Traits > value_traits;
114       typedef bounded_allocator< BPtr_Value >            allocator_type;
115 
116       bounded_allocator_scope<allocator_type> bounded_scope; (void)bounded_scope;
117       test::test_generic_set
118          < rebinder< value_traits, ConstantTimeSize, true, Map>
119          >::test_all();
120    }
121 };
122 
main()123 int main()
124 {
125    //Combinations: VoidPointer x ConstantTimeSize x DefaultHolder x Map
126    //Minimize them selecting different combinations for raw and smart pointers
127    //Start with ('false', 'false', 'false') in sets and 'false', 'false', 'true' in multisets
128 
129    //void pointer
130    test_main_template<void*, false, false, false, Base>::execute();
131    //test_main_template<void*, false, false, true>::execute();
132    test_main_template<void*, false, true, false, Member>::execute();
133    //test_main_template<void*, false, true,  true>::execute();
134    test_main_template<void*,  true, false, false, Base>::execute();
135    //test_main_template<void*,  true, false, true>::execute();
136    test_main_template<void*,  true, true, false, Member>::execute();
137    test_main_template<void*,  true, true,  true, NonMember>::execute();
138 
139    //smart_ptr
140    //test_main_template<smart_ptr<void>, false, false, false>::execute();
141    test_main_template<smart_ptr<void>, false, false,  true, Base>::execute();
142    //test_main_template<smart_ptr<void>, false,  true, false>::execute();
143    test_main_template<smart_ptr<void>, false,  true,  true, Member>::execute();
144    //test_main_template<smart_ptr<void>,  true, false, false>::execute();
145    test_main_template<smart_ptr<void>,  true, false, true, NonMember>::execute();
146    //test_main_template<smart_ptr<void>,  true,  true, false>::execute();
147    //test_main_template<smart_ptr<void>,  true,  true,  true>::execute();
148 
149    //bounded_ptr (bool ConstantTimeSize, bool Map)
150    test_main_template_bptr< false, false >::execute();
151    //test_main_template_bptr< false,  true >::execute();
152    //test_main_template_bptr<  true, false >::execute();
153    test_main_template_bptr<  true,  true >::execute();
154 
155    return boost::report_errors();
156 }
157