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 //////////////////////////////////////////////////////////////////////////////
11 #include <boost/interprocess/detail/config_begin.hpp>
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"
25 /////////////////////////////////////////////////////////////////
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
31 /////////////////////////////////////////////////////////////////
33 using namespace boost::interprocess
;
35 //Customize managed_shared_memory class
36 typedef basic_managed_shared_memory
38 //simple_seq_fit<mutex_family>,
39 rbtree_best_fit
<mutex_family
>,
41 > my_managed_shared_memory
;
43 //Alias allocator type
44 typedef allocator
<int, my_managed_shared_memory::segment_manager
>
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
;
53 typedef allocator
<test::movable_and_copyable_int
, my_managed_shared_memory::segment_manager
>
54 shmem_move_copy_allocator_t
;
56 typedef allocator
<test::copyable_int
, my_managed_shared_memory::segment_manager
>
57 shmem_copy_allocator_t
;
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
;
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
;
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
;
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
;
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
;
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
;
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
;
103 using namespace boost::interprocess::test
;
105 if (0 != set_test
<my_managed_shared_memory
110 std::cout
<< "Error in set_test<MyShmSet>" << std::endl
;
114 if (0 != set_test_copyable
<my_managed_shared_memory
119 std::cout
<< "Error in set_test<MyShmSet>" << std::endl
;
123 if (0 != set_test
<my_managed_shared_memory
126 ,MyMovableShmMultiSet
128 std::cout
<< "Error in set_test<MyMovableShmSet>" << std::endl
;
132 if (0 != set_test
<my_managed_shared_memory
135 ,MyMoveCopyShmMultiSet
137 std::cout
<< "Error in set_test<MyMoveCopyShmSet>" << std::endl
;
141 if (0 != set_test
<my_managed_shared_memory
146 std::cout
<< "Error in set_test<MyCopyShmSet>" << std::endl
;
150 if (0 != map_test
<my_managed_shared_memory
155 std::cout
<< "Error in set_test<MyShmMap>" << std::endl
;
159 if (0 != map_test_copyable
<my_managed_shared_memory
164 std::cout
<< "Error in set_test<MyShmMap>" << std::endl
;
168 // if (0 != map_test<my_managed_shared_memory
171 // ,MyMovableShmMultiMap
172 // ,MyStdMultiMap>()){
176 if (0 != map_test
<my_managed_shared_memory
179 ,MyMoveCopyShmMultiMap
181 std::cout
<< "Error in set_test<MyMoveCopyShmMap>" << std::endl
;
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
);
189 if(!boost::interprocess::test::test_emplace
<flat_map
<test::EmplaceInt
, test::EmplaceInt
>, MapOptions
>())
191 if(!boost::interprocess::test::test_emplace
<flat_multimap
<test::EmplaceInt
, test::EmplaceInt
>, MapOptions
>())
193 if(!boost::interprocess::test::test_emplace
<flat_set
<test::EmplaceInt
>, SetOptions
>())
195 if(!boost::interprocess::test::test_emplace
<flat_multiset
<test::EmplaceInt
>, SetOptions
>())
197 //#endif //!defined(__GNUC__)
202 #include <boost/interprocess/detail/config_end.hpp>