• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga  2007-2013
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 
13 #include "itestvalue.hpp"
14 #include "bptr_value.hpp"
15 #include "smart_ptr.hpp"
16 #include "bs_test_common.hpp"
17 #include "generic_multiset_test.hpp"
18 #include <boost/intrusive/treap_set.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 treap_multiset
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          , typename common_t::prio_of_value_opt
40          , Option1
41          , Option2
42          > type;
43       BOOST_STATIC_ASSERT((key_type_tester<typename common_t::key_of_value_opt, type>::value));
44    };
45 };
46 
47 enum HookType
48 {
49    Base,
50    Member,
51    NonMember
52 };
53 
54 template<class VoidPointer, bool ConstantTimeSize, bool DefaultHolder, bool Map, HookType Type>
55 class test_main_template;
56 
57 template<class VoidPointer, bool ConstantTimeSize, bool DefaultHolder, bool Map>
58 class test_main_template<VoidPointer, ConstantTimeSize, DefaultHolder, Map, Base>
59 {
60    public:
execute()61    static void execute()
62    {
63       typedef testvalue_traits< bs_hooks<VoidPointer> > testval_traits_t;
64       //base
65       typedef typename detail::if_c
66          < ConstantTimeSize
67          , typename testval_traits_t::base_value_traits
68          , typename testval_traits_t::auto_base_value_traits
69          >::type base_hook_t;
70       test::test_generic_multiset
71          < rebinder<base_hook_t, ConstantTimeSize, DefaultHolder, Map>
72          >::test_all();
73    }
74 };
75 
76 template<class VoidPointer, bool ConstantTimeSize, bool DefaultHolder, bool Map>
77 class test_main_template<VoidPointer, ConstantTimeSize, DefaultHolder, Map, Member>
78 {
79    public:
execute()80    static void execute()
81    {
82       typedef testvalue_traits< bs_hooks<VoidPointer> > testval_traits_t;
83       //member
84       typedef typename detail::if_c
85          < ConstantTimeSize
86          , typename testval_traits_t::member_value_traits
87          , typename testval_traits_t::auto_member_value_traits
88          >::type member_hook_t;
89       test::test_generic_multiset
90          < rebinder<member_hook_t, ConstantTimeSize, DefaultHolder, Map>
91          >::test_all();
92    }
93 };
94 
95 template<class VoidPointer, bool ConstantTimeSize, bool DefaultHolder, bool Map>
96 class test_main_template<VoidPointer, ConstantTimeSize, DefaultHolder, Map, NonMember>
97 {
98    public:
execute()99    static void execute()
100    {
101       typedef testvalue_traits< bs_hooks<VoidPointer> > testval_traits_t;
102       //nonmember
103       test::test_generic_multiset
104          < rebinder<typename testval_traits_t::nonhook_value_traits, ConstantTimeSize, DefaultHolder, Map>
105          >::test_all();
106    }
107 };
108 
109 template < bool ConstantTimeSize, bool Map >
110 struct test_main_template_bptr
111 {
executetest_main_template_bptr112    static void execute()
113    {
114       typedef BPtr_Value_Traits< Tree_BPtr_Node_Traits > value_traits;
115       typedef bounded_allocator< BPtr_Value >            allocator_type;
116 
117       bounded_allocator_scope<allocator_type> bounded_scope; (void)bounded_scope;
118       test::test_generic_multiset
119          < rebinder< value_traits, ConstantTimeSize, true, Map>
120          >::test_all();
121    }
122 };
123 
main()124 int main()
125 {
126    //Combinations: VoidPointer x ConstantTimeSize x DefaultHolder x Map
127    //Minimize them selecting different combinations for raw and smart pointers
128    //Start with ('false', 'false', 'false') in sets and 'false', 'false', 'true' in multisets
129 
130    //void pointer
131    test_main_template<void*, false, false, false, Base>::execute();
132    //test_main_template<void*, false, false, true>::execute();
133    test_main_template<void*, false, true, false, Member>::execute();
134    //test_main_template<void*, false, true,  true>::execute();
135    test_main_template<void*,  true, false, false, Base>::execute();
136    //test_main_template<void*,  true, false, true>::execute();
137    test_main_template<void*,  true, true, false, Member>::execute();
138    test_main_template<void*,  true, true,  true, NonMember>::execute();
139 
140    //smart_ptr
141    //test_main_template<smart_ptr<void>, false, false, false>::execute();
142    test_main_template<smart_ptr<void>, false, false,  true, Base>::execute();
143    //test_main_template<smart_ptr<void>, false,  true, false>::execute();
144    test_main_template<smart_ptr<void>, false,  true,  true, Member>::execute();
145    //test_main_template<smart_ptr<void>,  true, false, false>::execute();
146    test_main_template<smart_ptr<void>,  true, false, true, NonMember>::execute();
147    //test_main_template<smart_ptr<void>,  true,  true, false>::execute();
148    //test_main_template<smart_ptr<void>,  true,  true,  true>::execute();
149 
150    //bounded_ptr (bool ConstantTimeSize, bool Map)
151    test_main_template_bptr< false, false >::execute();
152    //test_main_template_bptr< false,  true >::execute();
153    //test_main_template_bptr<  true, false >::execute();
154    test_main_template_bptr<  true,  true >::execute();
155 
156    return boost::report_errors();
157 }
158