| 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 <set> |
| 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" |
| 23 | |
| 24 | ///////////////////////////////////////////////////////////////// |
| 25 | // |
| 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 |
| 29 | // |
| 30 | ///////////////////////////////////////////////////////////////// |
| 31 | |
| 32 | using namespace boost::interprocess; |
| 33 | |
| 34 | //Customize managed_shared_memory class |
| 35 | typedef basic_managed_shared_memory |
| 36 | <char, |
| 37 | //simple_seq_fit<mutex_family>, |
| 38 | rbtree_best_fit<mutex_family>, |
| 39 | iset_index |
| 40 | > my_managed_shared_memory; |
| 41 | |
| 42 | //Alias allocator type |
| 43 | typedef allocator<int, my_managed_shared_memory::segment_manager> |
| 44 | shmem_allocator_t; |
| 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; |
| 51 | |
| 52 | typedef allocator<test::movable_and_copyable_int, my_managed_shared_memory::segment_manager> |
| 53 | shmem_move_copy_allocator_t; |
| 54 | |
| 55 | typedef allocator<test::copyable_int, my_managed_shared_memory::segment_manager> |
| 56 | shmem_copy_allocator_t; |
| 57 | |
| 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; |
| 60 | |
| 61 | //Alias set types |
| 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; |
| 66 | |
| 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; |
| 71 | |
| 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; |
| 82 | |
| 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; |
| 87 | |
| 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; |
| 92 | |
| 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; |
| 99 | |
| 100 | int main() |
| 101 | { |
| 102 | using namespace boost::interprocess::test; |
| 103 | |
| 104 | if (0 != set_test<my_managed_shared_memory |
| 105 | ,MyShmSet |
| 106 | ,MyStdSet |
| 107 | ,MyShmMultiSet |
| 108 | ,MyStdMultiSet>()){ |
| 109 | std::cout << "Error in set_test<MyShmSet>" << std::endl; |
| 110 | return 1; |
| 111 | } |
| 112 | |
| 113 | if (0 != set_test_copyable<my_managed_shared_memory |
| 114 | ,MyShmSet |
| 115 | ,MyStdSet |
| 116 | ,MyShmMultiSet |
| 117 | ,MyStdMultiSet>()){ |
| 118 | std::cout << "Error in set_test<MyShmSet>" << std::endl; |
| 119 | return 1; |
| 120 | } |
| 121 | |
| 122 | if (0 != set_test<my_managed_shared_memory |
| 123 | ,MyMovableShmSet |
| 124 | ,MyStdSet |
| 125 | ,MyMovableShmMultiSet |
| 126 | ,MyStdMultiSet>()){ |
| 127 | std::cout << "Error in set_test<MyMovableShmSet>" << std::endl; |
| 128 | return 1; |
| 129 | } |
| 130 | |
| 131 | if (0 != set_test<my_managed_shared_memory |
| 132 | ,MyMoveCopyShmSet |
| 133 | ,MyStdSet |
| 134 | ,MyMoveCopyShmMultiSet |
| 135 | ,MyStdMultiSet>()){ |
| 136 | std::cout << "Error in set_test<MyMoveCopyShmSet>" << std::endl; |
| 137 | return 1; |
| 138 | } |
| 139 | |
| 140 | if (0 != set_test<my_managed_shared_memory |
| 141 | ,MyCopyShmSet |
| 142 | ,MyStdSet |
| 143 | ,MyCopyShmMultiSet |
| 144 | ,MyStdMultiSet>()){ |
| 145 | std::cout << "Error in set_test<MyCopyShmSet>" << std::endl; |
| 146 | return 1; |
| 147 | } |
| 148 | |
| 149 | if (0 != map_test<my_managed_shared_memory |
| 150 | ,MyShmMap |
| 151 | ,MyStdMap |
| 152 | ,MyShmMultiMap |
| 153 | ,MyStdMultiMap>()){ |
| 154 | std::cout << "Error in map_test<MyShmMap>" << std::endl; |
| 155 | return 1; |
| 156 | } |
| 157 | |
| 158 | if (0 != map_test_copyable<my_managed_shared_memory |
| 159 | ,MyShmMap |
| 160 | ,MyStdMap |
| 161 | ,MyShmMultiMap |
| 162 | ,MyStdMultiMap>()){ |
| 163 | std::cout << "Error in map_test<MyShmMap>" << std::endl; |
| 164 | return 1; |
| 165 | } |
| 166 | |
| 167 | // if (0 != map_test<my_managed_shared_memory |
| 168 | // ,MyMovableShmMap |
| 169 | // ,MyStdMap |
| 170 | // ,MyMovableShmMultiMap |
| 171 | // ,MyStdMultiMap>()){ |
| 172 | // return 1; |
| 173 | // } |
| 174 | |
| 175 | if (0 != map_test<my_managed_shared_memory |
| 176 | ,MyMoveCopyShmMap |
| 177 | ,MyStdMap |
| 178 | ,MyMoveCopyShmMultiMap |
| 179 | ,MyStdMultiMap>()){ |
| 180 | std::cout << "Error in map_test<MyMoveCopyShmMap>" << std::endl; |
| 181 | return 1; |
| 182 | } |
| 183 | |
| 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); |
| 187 | |
| 188 | if(!boost::interprocess::test::test_emplace<flat_map<test::EmplaceInt, test::EmplaceInt>, MapOptions>()) |
| 189 | return 1; |
| 190 | if(!boost::interprocess::test::test_emplace<flat_multimap<test::EmplaceInt, test::EmplaceInt>, MapOptions>()) |
| 191 | return 1; |
| 192 | if(!boost::interprocess::test::test_emplace<flat_set<test::EmplaceInt>, SetOptions>()) |
| 193 | return 1; |
| 194 | if(!boost::interprocess::test::test_emplace<flat_multiset<test::EmplaceInt>, SetOptions>()) |
| 195 | return 1; |
| 196 | //#endif //!defined(__GNUC__) |
| 197 | return 0; |
| 198 | |
| 199 | } |
| 200 | |