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 
11 #include <boost/interprocess/detail/config_begin.hpp>
12 #include <set>
13 #include <boost/interprocess/managed_shared_memory.hpp>
14 #include <boost/interprocess/containers/flat_set.hpp>
15 #include <boost/interprocess/containers/flat_map.hpp>
16 #include <boost/interprocess/allocators/allocator.hpp>
17 #include <boost/interprocess/indexes/flat_map_index.hpp>
18 #include "print_container.hpp"
19 #include "dummy_test_allocator.hpp"
20 #include "movable_int.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 
33 using namespace boost::interprocess;
34 
35 //Customize managed_shared_memory class
36 typedef basic_managed_shared_memory
37    <char,
38     //simple_seq_fit<mutex_family>,
39     rbtree_best_fit<mutex_family>,
40     iset_index
41    > my_managed_shared_memory;
42 
43 //Alias allocator type
44 typedef allocator<int, my_managed_shared_memory::segment_manager>
45    shmem_allocator_t;
46 typedef allocator<test::movable_int, my_managed_shared_memory::segment_manager>
47    shmem_movable_allocator_t;
48 typedef allocator<std::pair<int, int>, my_managed_shared_memory::segment_manager>
49    shmem_pair_allocator_t;
50 typedef allocator<std::pair<test::movable_int, test::movable_int>, my_managed_shared_memory::segment_manager>
51    shmem_movable_pair_allocator_t;
52 
53 typedef allocator<test::movable_and_copyable_int, my_managed_shared_memory::segment_manager>
54    shmem_move_copy_allocator_t;
55 
56 typedef allocator<test::copyable_int, my_managed_shared_memory::segment_manager>
57    shmem_copy_allocator_t;
58 
59 typedef allocator<std::pair<test::movable_and_copyable_int, test::movable_and_copyable_int>, my_managed_shared_memory::segment_manager>
60    shmem_move_copy_pair_allocator_t;
61 
62 //Alias set types
63 typedef std::set<int>                                                   MyStdSet;
64 typedef std::multiset<int>                                              MyStdMultiSet;
65 typedef std::map<int, int>                                              MyStdMap;
66 typedef std::multimap<int, int>                                         MyStdMultiMap;
67 
68 typedef flat_set<int, std::less<int>, shmem_allocator_t>                MyShmSet;
69 typedef flat_multiset<int, std::less<int>, shmem_allocator_t>           MyShmMultiSet;
70 typedef flat_map<int, int, std::less<int>, shmem_pair_allocator_t>      MyShmMap;
71 typedef flat_multimap<int, int, std::less<int>, shmem_pair_allocator_t> MyShmMultiMap;
72 
73 typedef flat_set<test::movable_int, std::less<test::movable_int>
74                 ,shmem_movable_allocator_t>                             MyMovableShmSet;
75 typedef flat_multiset<test::movable_int,std::less<test::movable_int>
76                      ,shmem_movable_allocator_t>                        MyMovableShmMultiSet;
77 typedef flat_map<test::movable_int, test::movable_int
78                 ,std::less<test::movable_int>
79                 ,shmem_movable_pair_allocator_t>                        MyMovableShmMap;
80 typedef flat_multimap<test::movable_int, test::movable_int
81                 ,std::less<test::movable_int>
82                 ,shmem_movable_pair_allocator_t>                        MyMovableShmMultiMap;
83 
84 typedef flat_set<test::movable_and_copyable_int, std::less<test::movable_and_copyable_int>
85                 ,shmem_move_copy_allocator_t>                             MyMoveCopyShmSet;
86 typedef flat_multiset<test::movable_and_copyable_int,std::less<test::movable_and_copyable_int>
87                      ,shmem_move_copy_allocator_t>                        MyMoveCopyShmMultiSet;
88 
89 typedef flat_set<test::copyable_int, std::less<test::copyable_int>
90                 ,shmem_copy_allocator_t>                                MyCopyShmSet;
91 typedef flat_multiset<test::copyable_int,std::less<test::copyable_int>
92                      ,shmem_copy_allocator_t>                           MyCopyShmMultiSet;
93 
94 typedef flat_map<test::movable_and_copyable_int, test::movable_and_copyable_int
95                 ,std::less<test::movable_and_copyable_int>
96                 ,shmem_move_copy_pair_allocator_t>                        MyMoveCopyShmMap;
97 typedef flat_multimap<test::movable_and_copyable_int, test::movable_and_copyable_int
98                 ,std::less<test::movable_and_copyable_int>
99                 ,shmem_move_copy_pair_allocator_t>                        MyMoveCopyShmMultiMap;
100 
main()101 int main()
102 {
103    using namespace boost::interprocess::test;
104 
105    if (0 != set_test<my_managed_shared_memory
106                   ,MyShmSet
107                   ,MyStdSet
108                   ,MyShmMultiSet
109                   ,MyStdMultiSet>()){
110       std::cout << "Error in set_test<MyShmSet>" << std::endl;
111       return 1;
112    }
113 
114    if (0 != set_test_copyable<my_managed_shared_memory
115                   ,MyShmSet
116                   ,MyStdSet
117                   ,MyShmMultiSet
118                   ,MyStdMultiSet>()){
119       std::cout << "Error in set_test<MyShmSet>" << std::endl;
120       return 1;
121    }
122 
123    if (0 != set_test<my_managed_shared_memory
124                   ,MyMovableShmSet
125                   ,MyStdSet
126                   ,MyMovableShmMultiSet
127                   ,MyStdMultiSet>()){
128       std::cout << "Error in set_test<MyMovableShmSet>" << std::endl;
129       return 1;
130    }
131 
132    if (0 != set_test<my_managed_shared_memory
133                   ,MyMoveCopyShmSet
134                   ,MyStdSet
135                   ,MyMoveCopyShmMultiSet
136                   ,MyStdMultiSet>()){
137       std::cout << "Error in set_test<MyMoveCopyShmSet>" << std::endl;
138       return 1;
139    }
140 
141    if (0 != set_test<my_managed_shared_memory
142                   ,MyCopyShmSet
143                   ,MyStdSet
144                   ,MyCopyShmMultiSet
145                   ,MyStdMultiSet>()){
146       std::cout << "Error in set_test<MyCopyShmSet>" << std::endl;
147       return 1;
148    }
149 
150    if (0 != map_test<my_managed_shared_memory
151                   ,MyShmMap
152                   ,MyStdMap
153                   ,MyShmMultiMap
154                   ,MyStdMultiMap>()){
155       std::cout << "Error in map_test<MyShmMap>" << std::endl;
156       return 1;
157    }
158 
159    if (0 != map_test_copyable<my_managed_shared_memory
160                   ,MyShmMap
161                   ,MyStdMap
162                   ,MyShmMultiMap
163                   ,MyStdMultiMap>()){
164       std::cout << "Error in map_test<MyShmMap>" << std::endl;
165       return 1;
166    }
167 
168 //   if (0 != map_test<my_managed_shared_memory
169 //                  ,MyMovableShmMap
170 //                  ,MyStdMap
171 //                  ,MyMovableShmMultiMap
172 //                  ,MyStdMultiMap>()){
173 //      return 1;
174 //   }
175 
176    if (0 != map_test<my_managed_shared_memory
177                   ,MyMoveCopyShmMap
178                   ,MyStdMap
179                   ,MyMoveCopyShmMultiMap
180                   ,MyStdMultiMap>()){
181       std::cout << "Error in map_test<MyMoveCopyShmMap>" << std::endl;
182       return 1;
183    }
184 
185    //#if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC_MINOR__ < 3)
186    const test::EmplaceOptions SetOptions = (test::EmplaceOptions)(test::EMPLACE_HINT | test::EMPLACE_ASSOC);
187    const test::EmplaceOptions MapOptions = (test::EmplaceOptions)(test::EMPLACE_HINT_PAIR | test::EMPLACE_ASSOC_PAIR);
188 
189    if(!boost::interprocess::test::test_emplace<flat_map<test::EmplaceInt, test::EmplaceInt>, MapOptions>())
190       return 1;
191    if(!boost::interprocess::test::test_emplace<flat_multimap<test::EmplaceInt, test::EmplaceInt>, MapOptions>())
192       return 1;
193    if(!boost::interprocess::test::test_emplace<flat_set<test::EmplaceInt>, SetOptions>())
194       return 1;
195    if(!boost::interprocess::test::test_emplace<flat_multiset<test::EmplaceInt>, SetOptions>())
196       return 1;
197    //#endif   //!defined(__GNUC__)
198    return 0;
199 
200 }
201 
202 #include <boost/interprocess/detail/config_end.hpp>
203