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 //////////////////////////////////////////////////////////////////////////////
10 #include <boost/interprocess/detail/config_begin.hpp>
12 #include <boost/interprocess/managed_shared_memory.hpp>
13 #include <boost/interprocess/containers/set.hpp>
14 #include <boost/interprocess/containers/map.hpp>
15 #include <boost/interprocess/allocators/allocator.hpp>
16 #include <boost/interprocess/indexes/map_index.hpp>
17 #include <boost/interprocess/indexes/iset_index.hpp>
18 #include <boost/interprocess/mem_algo/simple_seq_fit.hpp>
19 #include "print_container.hpp"
20 #include "movable_int.hpp"
21 #include "dummy_test_allocator.hpp"
22 #include "set_test.hpp"
23 #include "map_test.hpp"
24 #include "emplace_test.hpp"
26 ///////////////////////////////////////////////////////////////////
28 // This example repeats the same operations with std::set and //
29 // shmem_set using the node allocator //
30 // and compares the values of both containers //
32 ///////////////////////////////////////////////////////////////////
34 using namespace boost::interprocess;
36 //Customize managed_shared_memory class
37 typedef basic_managed_shared_memory
39 simple_seq_fit<mutex_family, offset_ptr<void> >,
41 > my_managed_shared_memory;
43 //We will work with narrow characters for shared memory objects
44 //Alias an integer node allocator type
45 typedef allocator<int, my_managed_shared_memory::segment_manager>
47 typedef allocator<std::pair<const int, int>, my_managed_shared_memory::segment_manager>
48 shmem_node_pair_allocator_t;
49 typedef allocator<test::movable_int, my_managed_shared_memory::segment_manager>
50 shmem_movable_allocator_t;
51 typedef allocator<std::pair<const test::movable_int, test::movable_int>, my_managed_shared_memory::segment_manager>
52 shmem_movable_node_pair_allocator_t;
53 typedef allocator<test::movable_and_copyable_int, my_managed_shared_memory::segment_manager>
54 shmem_move_copy_allocator_t;
55 typedef allocator<test::copyable_int, my_managed_shared_memory::segment_manager>
56 shmem_copy_allocator_t;
57 typedef allocator<std::pair<const test::movable_and_copyable_int, test::movable_and_copyable_int>, my_managed_shared_memory::segment_manager>
58 shmem_move_copy_node_pair_allocator_t;
60 //Alias standard types
61 typedef std::set<int> MyStdSet;
62 typedef std::multiset<int> MyStdMultiSet;
63 typedef std::map<int, int> MyStdMap;
64 typedef std::multimap<int, int> MyStdMultiMap;
66 //Alias non-movable types
67 typedef set<int, std::less<int>, shmem_allocator_t> MyShmSet;
68 typedef multiset<int, std::less<int>, shmem_allocator_t> MyShmMultiSet;
69 typedef map<int, int, std::less<int>, shmem_node_pair_allocator_t> MyShmMap;
70 typedef multimap<int, int, std::less<int>, shmem_node_pair_allocator_t> MyShmMultiMap;
73 typedef set<test::movable_int, std::less<test::movable_int>
74 ,shmem_movable_allocator_t> MyMovableShmSet;
75 typedef multiset<test::movable_int,
76 std::less<test::movable_int>,
77 shmem_movable_allocator_t> MyMovableShmMultiSet;
78 typedef map<test::movable_int, test::movable_int,
79 std::less<test::movable_int>,
80 shmem_movable_node_pair_allocator_t> MyMovableShmMap;
81 typedef multimap<test::movable_int, test::movable_int,
82 std::less<test::movable_int>,
83 shmem_movable_node_pair_allocator_t> MyMovableShmMultiMap;
85 typedef set<test::movable_and_copyable_int
86 ,std::less<test::movable_and_copyable_int>
87 ,shmem_move_copy_allocator_t> MyMoveCopyShmSet;
88 typedef multiset<test::movable_and_copyable_int,
89 std::less<test::movable_and_copyable_int>,
90 shmem_move_copy_allocator_t> MyMoveCopyShmMultiSet;
92 typedef set<test::copyable_int
93 ,std::less<test::copyable_int>
94 ,shmem_copy_allocator_t> MyCopyShmSet;
95 typedef multiset<test::copyable_int,
96 std::less<test::copyable_int>,
97 shmem_copy_allocator_t> MyCopyShmMultiSet;
100 typedef map<test::movable_and_copyable_int
101 ,test::movable_and_copyable_int
102 ,std::less<test::movable_and_copyable_int>
103 ,shmem_move_copy_node_pair_allocator_t> MyMoveCopyShmMap;
104 typedef multimap<test::movable_and_copyable_int
105 ,test::movable_and_copyable_int
106 ,std::less<test::movable_and_copyable_int>
107 ,shmem_move_copy_node_pair_allocator_t> MyMoveCopyShmMultiMap;
111 using namespace boost::interprocess::ipcdetail;
113 if(0 != test::set_test<my_managed_shared_memory
121 if(0 != test::set_test_copyable<my_managed_shared_memory
129 if(0 != test::set_test<my_managed_shared_memory
132 ,MyMovableShmMultiSet
137 if(0 != test::set_test<my_managed_shared_memory
140 ,MyMoveCopyShmMultiSet
145 if(0 != test::set_test<my_managed_shared_memory
153 if (0 != test::map_test<my_managed_shared_memory
161 if(0 != test::map_test_copyable<my_managed_shared_memory
169 // if (0 != test::map_test<my_managed_shared_memory
172 // ,MyMovableShmMultiMap
173 // ,MyStdMultiMap>()){
177 if (0 != test::map_test<my_managed_shared_memory
180 ,MyMoveCopyShmMultiMap
185 const test::EmplaceOptions SetOptions = (test::EmplaceOptions)(test::EMPLACE_HINT | test::EMPLACE_ASSOC);
186 if(!boost::interprocess::test::test_emplace<set<test::EmplaceInt>, SetOptions>())
188 if(!boost::interprocess::test::test_emplace<multiset<test::EmplaceInt>, SetOptions>())
190 const test::EmplaceOptions MapOptions = (test::EmplaceOptions)(test::EMPLACE_HINT_PAIR | test::EMPLACE_ASSOC_PAIR);
191 if(!boost::interprocess::test::test_emplace<map<test::EmplaceInt, test::EmplaceInt>, MapOptions>())
193 if(!boost::interprocess::test::test_emplace<multimap<test::EmplaceInt, test::EmplaceInt>, MapOptions>())
199 #include <boost/interprocess/detail/config_end.hpp>