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