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

source code of boost/libs/interprocess/test/tree_test.cpp