1 //////////////////////////////////////////////////////////////////////////////
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)
7 // See http://www.boost.org/libs/interprocess for documentation.
9 //////////////////////////////////////////////////////////////////////////////
12 #include <boost/interprocess/managed_shared_memory.hpp>
13 #include <boost/interprocess/containers/flat_set.hpp>
14 #include <boost/interprocess/containers/flat_map.hpp>
15 #include <boost/interprocess/allocators/allocator.hpp>
16 #include <boost/interprocess/indexes/flat_map_index.hpp>
17 #include "print_container.hpp"
18 #include "dummy_test_allocator.hpp"
19 #include "movable_int.hpp"
20 #include "set_test.hpp"
21 #include "map_test.hpp"
22 #include "emplace_test.hpp"
24 /////////////////////////////////////////////////////////////////
26 // This example repeats the same operations with std::set and
27 // shmem_set using the node allocator
28 // and compares the values of both containers
30 /////////////////////////////////////////////////////////////////
32 using namespace boost::interprocess
;
34 //Customize managed_shared_memory class
35 typedef basic_managed_shared_memory
37 //simple_seq_fit<mutex_family>,
38 rbtree_best_fit
<mutex_family
>,
40 > my_managed_shared_memory
;
42 //Alias allocator type
43 typedef allocator
<int, my_managed_shared_memory::segment_manager
>
45 typedef allocator
<test::movable_int
, my_managed_shared_memory::segment_manager
>
46 shmem_movable_allocator_t
;
47 typedef allocator
<std::pair
<int, int>, my_managed_shared_memory::segment_manager
>
48 shmem_pair_allocator_t
;
49 typedef allocator
<std::pair
<test::movable_int
, test::movable_int
>, my_managed_shared_memory::segment_manager
>
50 shmem_movable_pair_allocator_t
;
52 typedef allocator
<test::movable_and_copyable_int
, my_managed_shared_memory::segment_manager
>
53 shmem_move_copy_allocator_t
;
55 typedef allocator
<test::copyable_int
, my_managed_shared_memory::segment_manager
>
56 shmem_copy_allocator_t
;
58 typedef allocator
<std::pair
<test::movable_and_copyable_int
, test::movable_and_copyable_int
>, my_managed_shared_memory::segment_manager
>
59 shmem_move_copy_pair_allocator_t
;
62 typedef std::set
<int> MyStdSet
;
63 typedef std::multiset
<int> MyStdMultiSet
;
64 typedef std::map
<int, int> MyStdMap
;
65 typedef std::multimap
<int, int> MyStdMultiMap
;
67 typedef flat_set
<int, std::less
<int>, shmem_allocator_t
> MyShmSet
;
68 typedef flat_multiset
<int, std::less
<int>, shmem_allocator_t
> MyShmMultiSet
;
69 typedef flat_map
<int, int, std::less
<int>, shmem_pair_allocator_t
> MyShmMap
;
70 typedef flat_multimap
<int, int, std::less
<int>, shmem_pair_allocator_t
> MyShmMultiMap
;
72 typedef flat_set
<test::movable_int
, std::less
<test::movable_int
>
73 ,shmem_movable_allocator_t
> MyMovableShmSet
;
74 typedef flat_multiset
<test::movable_int
,std::less
<test::movable_int
>
75 ,shmem_movable_allocator_t
> MyMovableShmMultiSet
;
76 typedef flat_map
<test::movable_int
, test::movable_int
77 ,std::less
<test::movable_int
>
78 ,shmem_movable_pair_allocator_t
> MyMovableShmMap
;
79 typedef flat_multimap
<test::movable_int
, test::movable_int
80 ,std::less
<test::movable_int
>
81 ,shmem_movable_pair_allocator_t
> MyMovableShmMultiMap
;
83 typedef flat_set
<test::movable_and_copyable_int
, std::less
<test::movable_and_copyable_int
>
84 ,shmem_move_copy_allocator_t
> MyMoveCopyShmSet
;
85 typedef flat_multiset
<test::movable_and_copyable_int
,std::less
<test::movable_and_copyable_int
>
86 ,shmem_move_copy_allocator_t
> MyMoveCopyShmMultiSet
;
88 typedef flat_set
<test::copyable_int
, std::less
<test::copyable_int
>
89 ,shmem_copy_allocator_t
> MyCopyShmSet
;
90 typedef flat_multiset
<test::copyable_int
,std::less
<test::copyable_int
>
91 ,shmem_copy_allocator_t
> MyCopyShmMultiSet
;
93 typedef flat_map
<test::movable_and_copyable_int
, test::movable_and_copyable_int
94 ,std::less
<test::movable_and_copyable_int
>
95 ,shmem_move_copy_pair_allocator_t
> MyMoveCopyShmMap
;
96 typedef flat_multimap
<test::movable_and_copyable_int
, test::movable_and_copyable_int
97 ,std::less
<test::movable_and_copyable_int
>
98 ,shmem_move_copy_pair_allocator_t
> MyMoveCopyShmMultiMap
;
102 using namespace boost::interprocess::test
;
104 if (0 != set_test
<my_managed_shared_memory
109 std::cout
<< "Error in set_test<MyShmSet>" << std::endl
;
113 if (0 != set_test_copyable
<my_managed_shared_memory
118 std::cout
<< "Error in set_test<MyShmSet>" << std::endl
;
122 if (0 != set_test
<my_managed_shared_memory
125 ,MyMovableShmMultiSet
127 std::cout
<< "Error in set_test<MyMovableShmSet>" << std::endl
;
131 if (0 != set_test
<my_managed_shared_memory
134 ,MyMoveCopyShmMultiSet
136 std::cout
<< "Error in set_test<MyMoveCopyShmSet>" << std::endl
;
140 if (0 != set_test
<my_managed_shared_memory
145 std::cout
<< "Error in set_test<MyCopyShmSet>" << std::endl
;
149 if (0 != map_test
<my_managed_shared_memory
154 std::cout
<< "Error in map_test<MyShmMap>" << std::endl
;
158 if (0 != map_test_copyable
<my_managed_shared_memory
163 std::cout
<< "Error in map_test<MyShmMap>" << std::endl
;
167 // if (0 != map_test<my_managed_shared_memory
170 // ,MyMovableShmMultiMap
171 // ,MyStdMultiMap>()){
175 if (0 != map_test
<my_managed_shared_memory
178 ,MyMoveCopyShmMultiMap
180 std::cout
<< "Error in map_test<MyMoveCopyShmMap>" << std::endl
;
184 //#if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC_MINOR__ < 3)
185 const test::EmplaceOptions SetOptions
= (test::EmplaceOptions
)(test::EMPLACE_HINT
| test::EMPLACE_ASSOC
);
186 const test::EmplaceOptions MapOptions
= (test::EmplaceOptions
)(test::EMPLACE_HINT_PAIR
| test::EMPLACE_ASSOC_PAIR
);
188 if(!boost::interprocess::test::test_emplace
<flat_map
<test::EmplaceInt
, test::EmplaceInt
>, MapOptions
>())
190 if(!boost::interprocess::test::test_emplace
<flat_multimap
<test::EmplaceInt
, test::EmplaceInt
>, MapOptions
>())
192 if(!boost::interprocess::test::test_emplace
<flat_set
<test::EmplaceInt
>, SetOptions
>())
194 if(!boost::interprocess::test::test_emplace
<flat_multiset
<test::EmplaceInt
>, SetOptions
>())
196 //#endif //!defined(__GNUC__)