46190526829dcb8a441feb2e5053acee3c7980a4
[platform/upstream/boost.git] / libs / interprocess / test / tree_test.cpp
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2004-2012. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // See http://www.boost.org/libs/interprocess for documentation.
8 //
9 //////////////////////////////////////////////////////////////////////////////
10 #include <boost/interprocess/detail/config_begin.hpp>
11 #include <set>
12 #include <boost/interprocess/managed_shared_memory.hpp>
13 #include <boost/interprocess/containers/set.hpp>
14 #include <boost/interprocess/containers/map.hpp>
15 #include <boost/interprocess/allocators/allocator.hpp>
16 #include <boost/interprocess/indexes/map_index.hpp>
17 #include <boost/interprocess/indexes/iset_index.hpp>
18 #include <boost/interprocess/mem_algo/simple_seq_fit.hpp>
19 #include "print_container.hpp"
20 #include "movable_int.hpp"
21 #include "dummy_test_allocator.hpp"
22 #include "set_test.hpp"
23 #include "map_test.hpp"
24 #include "emplace_test.hpp"
25
26 ///////////////////////////////////////////////////////////////////
27 //                                                               //
28 //  This example repeats the same operations with std::set and   //
29 //  shmem_set using the node allocator                           //
30 //  and compares the values of both containers                   //
31 //                                                               //
32 ///////////////////////////////////////////////////////////////////
33
34 using namespace boost::interprocess;
35
36 //Customize managed_shared_memory class
37 typedef basic_managed_shared_memory
38    <char,
39     simple_seq_fit<mutex_family, offset_ptr<void> >,
40     map_index
41    > my_managed_shared_memory;
42
43 //We will work with narrow characters for shared memory objects
44 //Alias an integer node allocator type
45 typedef allocator<int, my_managed_shared_memory::segment_manager>
46    shmem_allocator_t;
47 typedef allocator<std::pair<const int, int>, my_managed_shared_memory::segment_manager>
48    shmem_node_pair_allocator_t;
49 typedef allocator<test::movable_int, my_managed_shared_memory::segment_manager>
50    shmem_movable_allocator_t;
51 typedef allocator<std::pair<const test::movable_int, test::movable_int>, my_managed_shared_memory::segment_manager>
52    shmem_movable_node_pair_allocator_t;
53 typedef allocator<test::movable_and_copyable_int, my_managed_shared_memory::segment_manager>
54    shmem_move_copy_allocator_t;
55 typedef allocator<test::copyable_int, my_managed_shared_memory::segment_manager>
56    shmem_copy_allocator_t;
57 typedef allocator<std::pair<const test::movable_and_copyable_int, test::movable_and_copyable_int>, my_managed_shared_memory::segment_manager>
58    shmem_move_copy_node_pair_allocator_t;
59
60 //Alias standard types
61 typedef std::set<int>                                          MyStdSet;
62 typedef std::multiset<int>                                     MyStdMultiSet;
63 typedef std::map<int, int>                                     MyStdMap;
64 typedef std::multimap<int, int>                                MyStdMultiMap;
65
66 //Alias non-movable types
67 typedef set<int, std::less<int>, shmem_allocator_t>       MyShmSet;
68 typedef multiset<int, std::less<int>, shmem_allocator_t>  MyShmMultiSet;
69 typedef map<int, int, std::less<int>, shmem_node_pair_allocator_t>  MyShmMap;
70 typedef multimap<int, int, std::less<int>, shmem_node_pair_allocator_t>  MyShmMultiMap;
71
72 //Alias movable types
73 typedef set<test::movable_int, std::less<test::movable_int>
74             ,shmem_movable_allocator_t>                   MyMovableShmSet;
75 typedef multiset<test::movable_int,
76       std::less<test::movable_int>,
77       shmem_movable_allocator_t>                          MyMovableShmMultiSet;
78 typedef map<test::movable_int, test::movable_int,
79       std::less<test::movable_int>,
80       shmem_movable_node_pair_allocator_t>                     MyMovableShmMap;
81 typedef multimap<test::movable_int, test::movable_int,
82       std::less<test::movable_int>,
83       shmem_movable_node_pair_allocator_t>                     MyMovableShmMultiMap;
84
85 typedef set<test::movable_and_copyable_int
86            ,std::less<test::movable_and_copyable_int>
87            ,shmem_move_copy_allocator_t>                  MyMoveCopyShmSet;
88 typedef multiset<test::movable_and_copyable_int,
89       std::less<test::movable_and_copyable_int>,
90       shmem_move_copy_allocator_t>                        MyMoveCopyShmMultiSet;
91
92 typedef set<test::copyable_int
93            ,std::less<test::copyable_int>
94            ,shmem_copy_allocator_t>                  MyCopyShmSet;
95 typedef multiset<test::copyable_int,
96       std::less<test::copyable_int>,
97       shmem_copy_allocator_t>                        MyCopyShmMultiSet;
98
99
100 typedef map<test::movable_and_copyable_int
101            ,test::movable_and_copyable_int
102            ,std::less<test::movable_and_copyable_int>
103            ,shmem_move_copy_node_pair_allocator_t>             MyMoveCopyShmMap;
104 typedef multimap<test::movable_and_copyable_int
105                 ,test::movable_and_copyable_int
106                 ,std::less<test::movable_and_copyable_int>
107                 ,shmem_move_copy_node_pair_allocator_t>        MyMoveCopyShmMultiMap;
108
109 int main ()
110 {
111    using namespace boost::interprocess::ipcdetail;
112
113    if(0 != test::set_test<my_managed_shared_memory
114                         ,MyShmSet
115                         ,MyStdSet
116                         ,MyShmMultiSet
117                         ,MyStdMultiSet>()){
118       return 1;
119    }
120
121    if(0 != test::set_test_copyable<my_managed_shared_memory
122                         ,MyShmSet
123                         ,MyStdSet
124                         ,MyShmMultiSet
125                         ,MyStdMultiSet>()){
126       return 1;
127    }
128
129    if(0 != test::set_test<my_managed_shared_memory
130                         ,MyMovableShmSet
131                         ,MyStdSet
132                         ,MyMovableShmMultiSet
133                         ,MyStdMultiSet>()){
134       return 1;
135    }
136
137    if(0 != test::set_test<my_managed_shared_memory
138                         ,MyMoveCopyShmSet
139                         ,MyStdSet
140                         ,MyMoveCopyShmMultiSet
141                         ,MyStdMultiSet>()){
142       return 1;
143    }
144
145    if(0 != test::set_test<my_managed_shared_memory
146                         ,MyCopyShmSet
147                         ,MyStdSet
148                         ,MyCopyShmMultiSet
149                         ,MyStdMultiSet>()){
150       return 1;
151    }
152
153    if (0 != test::map_test<my_managed_shared_memory
154                   ,MyShmMap
155                   ,MyStdMap
156                   ,MyShmMultiMap
157                   ,MyStdMultiMap>()){
158       return 1;
159    }
160
161    if(0 != test::map_test_copyable<my_managed_shared_memory
162                         ,MyShmMap
163                         ,MyStdMap
164                         ,MyShmMultiMap
165                         ,MyStdMultiMap>()){
166       return 1;
167    }
168
169 //   if (0 != test::map_test<my_managed_shared_memory
170 //                  ,MyMovableShmMap
171 //                  ,MyStdMap
172 //                  ,MyMovableShmMultiMap
173 //                  ,MyStdMultiMap>()){
174 //      return 1;
175 //   }
176
177    if (0 != test::map_test<my_managed_shared_memory
178                   ,MyMoveCopyShmMap
179                   ,MyStdMap
180                   ,MyMoveCopyShmMultiMap
181                   ,MyStdMultiMap>()){
182       return 1;
183    }
184
185    const test::EmplaceOptions SetOptions = (test::EmplaceOptions)(test::EMPLACE_HINT | test::EMPLACE_ASSOC);
186    if(!boost::interprocess::test::test_emplace<set<test::EmplaceInt>, SetOptions>())
187       return 1;
188    if(!boost::interprocess::test::test_emplace<multiset<test::EmplaceInt>, SetOptions>())
189       return 1;
190    const test::EmplaceOptions MapOptions = (test::EmplaceOptions)(test::EMPLACE_HINT_PAIR | test::EMPLACE_ASSOC_PAIR);
191    if(!boost::interprocess::test::test_emplace<map<test::EmplaceInt, test::EmplaceInt>, MapOptions>())
192       return 1;
193    if(!boost::interprocess::test::test_emplace<multimap<test::EmplaceInt, test::EmplaceInt>, MapOptions>())
194       return 1;
195
196    return 0;
197 }
198
199 #include <boost/interprocess/detail/config_end.hpp>