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/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"
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
, offset_ptr
<void> >,
40 > my_managed_shared_memory
;
42 //We will work with narrow characters for shared memory objects
43 //Alias an integer node allocator type
44 typedef allocator
<int, my_managed_shared_memory::segment_manager
>
46 typedef allocator
<std::pair
<const int, int>, my_managed_shared_memory::segment_manager
>
47 shmem_node_pair_allocator_t
;
48 typedef allocator
<test::movable_int
, my_managed_shared_memory::segment_manager
>
49 shmem_movable_allocator_t
;
50 typedef allocator
<std::pair
<const test::movable_int
, test::movable_int
>, my_managed_shared_memory::segment_manager
>
51 shmem_movable_node_pair_allocator_t
;
52 typedef allocator
<test::movable_and_copyable_int
, my_managed_shared_memory::segment_manager
>
53 shmem_move_copy_allocator_t
;
54 typedef allocator
<test::copyable_int
, my_managed_shared_memory::segment_manager
>
55 shmem_copy_allocator_t
;
56 typedef 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
;
59 //Alias standard types
60 typedef std::set
<int> MyStdSet
;
61 typedef std::multiset
<int> MyStdMultiSet
;
62 typedef std::map
<int, int> MyStdMap
;
63 typedef std::multimap
<int, int> MyStdMultiMap
;
65 //Alias non-movable types
66 typedef set
<int, std::less
<int>, shmem_allocator_t
> MyShmSet
;
67 typedef multiset
<int, std::less
<int>, shmem_allocator_t
> MyShmMultiSet
;
68 typedef map
<int, int, std::less
<int>, shmem_node_pair_allocator_t
> MyShmMap
;
69 typedef multimap
<int, int, std::less
<int>, shmem_node_pair_allocator_t
> MyShmMultiMap
;
72 typedef set
<test::movable_int
, std::less
<test::movable_int
>
73 ,shmem_movable_allocator_t
> MyMovableShmSet
;
74 typedef multiset
<test::movable_int
,
75 std::less
<test::movable_int
>,
76 shmem_movable_allocator_t
> MyMovableShmMultiSet
;
77 typedef map
<test::movable_int
, test::movable_int
,
78 std::less
<test::movable_int
>,
79 shmem_movable_node_pair_allocator_t
> MyMovableShmMap
;
80 typedef multimap
<test::movable_int
, test::movable_int
,
81 std::less
<test::movable_int
>,
82 shmem_movable_node_pair_allocator_t
> MyMovableShmMultiMap
;
84 typedef set
<test::movable_and_copyable_int
85 ,std::less
<test::movable_and_copyable_int
>
86 ,shmem_move_copy_allocator_t
> MyMoveCopyShmSet
;
87 typedef multiset
<test::movable_and_copyable_int
,
88 std::less
<test::movable_and_copyable_int
>,
89 shmem_move_copy_allocator_t
> MyMoveCopyShmMultiSet
;
91 typedef set
<test::copyable_int
92 ,std::less
<test::copyable_int
>
93 ,shmem_copy_allocator_t
> MyCopyShmSet
;
94 typedef multiset
<test::copyable_int
,
95 std::less
<test::copyable_int
>,
96 shmem_copy_allocator_t
> MyCopyShmMultiSet
;
99 typedef 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
;
103 typedef 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
;
110 using namespace boost::interprocess::ipcdetail
;
112 if(0 != test::set_test
<my_managed_shared_memory
120 if(0 != test::set_test_copyable
<my_managed_shared_memory
128 if(0 != test::set_test
<my_managed_shared_memory
131 ,MyMovableShmMultiSet
136 if(0 != test::set_test
<my_managed_shared_memory
139 ,MyMoveCopyShmMultiSet
144 if(0 != test::set_test
<my_managed_shared_memory
152 if (0 != test::map_test
<my_managed_shared_memory
160 if(0 != test::map_test_copyable
<my_managed_shared_memory
168 // if (0 != test::map_test<my_managed_shared_memory
171 // ,MyMovableShmMultiMap
172 // ,MyStdMultiMap>()){
176 if (0 != test::map_test
<my_managed_shared_memory
179 ,MyMoveCopyShmMultiMap
184 const test::EmplaceOptions SetOptions
= (test::EmplaceOptions
)(test::EMPLACE_HINT
| test::EMPLACE_ASSOC
);
185 if(!boost::interprocess::test::test_emplace
<set
<test::EmplaceInt
>, SetOptions
>())
187 if(!boost::interprocess::test::test_emplace
<multiset
<test::EmplaceInt
>, SetOptions
>())
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
>())
192 if(!boost::interprocess::test::test_emplace
<multimap
<test::EmplaceInt
, test::EmplaceInt
>, MapOptions
>())