flat_tree_test.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. #include <boost/interprocess/detail/config_begin.hpp>
  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. // This example repeats the same operations with std::set and
  26. // shmem_set using the node allocator
  27. // and compares the values of both containers
  28. //
  29. /////////////////////////////////////////////////////////////////
  30. using namespace boost::interprocess;
  31. //Customize managed_shared_memory class
  32. typedef basic_managed_shared_memory
  33. <char,
  34. //simple_seq_fit<mutex_family>,
  35. rbtree_best_fit<mutex_family>,
  36. iset_index
  37. > my_managed_shared_memory;
  38. //Alias allocator type
  39. typedef allocator<int, my_managed_shared_memory::segment_manager>
  40. shmem_allocator_t;
  41. typedef allocator<test::movable_int, my_managed_shared_memory::segment_manager>
  42. shmem_movable_allocator_t;
  43. typedef allocator<std::pair<int, int>, my_managed_shared_memory::segment_manager>
  44. shmem_pair_allocator_t;
  45. typedef allocator<std::pair<test::movable_int, test::movable_int>, my_managed_shared_memory::segment_manager>
  46. shmem_movable_pair_allocator_t;
  47. typedef allocator<test::movable_and_copyable_int, my_managed_shared_memory::segment_manager>
  48. shmem_move_copy_allocator_t;
  49. typedef allocator<test::copyable_int, my_managed_shared_memory::segment_manager>
  50. shmem_copy_allocator_t;
  51. typedef allocator<std::pair<test::movable_and_copyable_int, test::movable_and_copyable_int>, my_managed_shared_memory::segment_manager>
  52. shmem_move_copy_pair_allocator_t;
  53. //Alias set types
  54. typedef std::set<int> MyStdSet;
  55. typedef std::multiset<int> MyStdMultiSet;
  56. typedef std::map<int, int> MyStdMap;
  57. typedef std::multimap<int, int> MyStdMultiMap;
  58. typedef flat_set<int, std::less<int>, shmem_allocator_t> MyShmSet;
  59. typedef flat_multiset<int, std::less<int>, shmem_allocator_t> MyShmMultiSet;
  60. typedef flat_map<int, int, std::less<int>, shmem_pair_allocator_t> MyShmMap;
  61. typedef flat_multimap<int, int, std::less<int>, shmem_pair_allocator_t> MyShmMultiMap;
  62. typedef flat_set<test::movable_int, std::less<test::movable_int>
  63. ,shmem_movable_allocator_t> MyMovableShmSet;
  64. typedef flat_multiset<test::movable_int,std::less<test::movable_int>
  65. ,shmem_movable_allocator_t> MyMovableShmMultiSet;
  66. typedef flat_map<test::movable_int, test::movable_int
  67. ,std::less<test::movable_int>
  68. ,shmem_movable_pair_allocator_t> MyMovableShmMap;
  69. typedef flat_multimap<test::movable_int, test::movable_int
  70. ,std::less<test::movable_int>
  71. ,shmem_movable_pair_allocator_t> MyMovableShmMultiMap;
  72. typedef flat_set<test::movable_and_copyable_int, std::less<test::movable_and_copyable_int>
  73. ,shmem_move_copy_allocator_t> MyMoveCopyShmSet;
  74. typedef flat_multiset<test::movable_and_copyable_int,std::less<test::movable_and_copyable_int>
  75. ,shmem_move_copy_allocator_t> MyMoveCopyShmMultiSet;
  76. typedef flat_set<test::copyable_int, std::less<test::copyable_int>
  77. ,shmem_copy_allocator_t> MyCopyShmSet;
  78. typedef flat_multiset<test::copyable_int,std::less<test::copyable_int>
  79. ,shmem_copy_allocator_t> MyCopyShmMultiSet;
  80. typedef flat_map<test::movable_and_copyable_int, test::movable_and_copyable_int
  81. ,std::less<test::movable_and_copyable_int>
  82. ,shmem_move_copy_pair_allocator_t> MyMoveCopyShmMap;
  83. typedef flat_multimap<test::movable_and_copyable_int, test::movable_and_copyable_int
  84. ,std::less<test::movable_and_copyable_int>
  85. ,shmem_move_copy_pair_allocator_t> MyMoveCopyShmMultiMap;
  86. int main()
  87. {
  88. using namespace boost::interprocess::test;
  89. if (0 != set_test<my_managed_shared_memory
  90. ,MyShmSet
  91. ,MyStdSet
  92. ,MyShmMultiSet
  93. ,MyStdMultiSet>()){
  94. std::cout << "Error in set_test<MyShmSet>" << std::endl;
  95. return 1;
  96. }
  97. if (0 != set_test_copyable<my_managed_shared_memory
  98. ,MyShmSet
  99. ,MyStdSet
  100. ,MyShmMultiSet
  101. ,MyStdMultiSet>()){
  102. std::cout << "Error in set_test<MyShmSet>" << std::endl;
  103. return 1;
  104. }
  105. if (0 != set_test<my_managed_shared_memory
  106. ,MyMovableShmSet
  107. ,MyStdSet
  108. ,MyMovableShmMultiSet
  109. ,MyStdMultiSet>()){
  110. std::cout << "Error in set_test<MyMovableShmSet>" << std::endl;
  111. return 1;
  112. }
  113. if (0 != set_test<my_managed_shared_memory
  114. ,MyMoveCopyShmSet
  115. ,MyStdSet
  116. ,MyMoveCopyShmMultiSet
  117. ,MyStdMultiSet>()){
  118. std::cout << "Error in set_test<MyMoveCopyShmSet>" << std::endl;
  119. return 1;
  120. }
  121. if (0 != set_test<my_managed_shared_memory
  122. ,MyCopyShmSet
  123. ,MyStdSet
  124. ,MyCopyShmMultiSet
  125. ,MyStdMultiSet>()){
  126. std::cout << "Error in set_test<MyCopyShmSet>" << std::endl;
  127. return 1;
  128. }
  129. if (0 != map_test<my_managed_shared_memory
  130. ,MyShmMap
  131. ,MyStdMap
  132. ,MyShmMultiMap
  133. ,MyStdMultiMap>()){
  134. std::cout << "Error in map_test<MyShmMap>" << std::endl;
  135. return 1;
  136. }
  137. if (0 != map_test_copyable<my_managed_shared_memory
  138. ,MyShmMap
  139. ,MyStdMap
  140. ,MyShmMultiMap
  141. ,MyStdMultiMap>()){
  142. std::cout << "Error in map_test<MyShmMap>" << std::endl;
  143. return 1;
  144. }
  145. // if (0 != map_test<my_managed_shared_memory
  146. // ,MyMovableShmMap
  147. // ,MyStdMap
  148. // ,MyMovableShmMultiMap
  149. // ,MyStdMultiMap>()){
  150. // return 1;
  151. // }
  152. if (0 != map_test<my_managed_shared_memory
  153. ,MyMoveCopyShmMap
  154. ,MyStdMap
  155. ,MyMoveCopyShmMultiMap
  156. ,MyStdMultiMap>()){
  157. std::cout << "Error in map_test<MyMoveCopyShmMap>" << std::endl;
  158. return 1;
  159. }
  160. //#if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC_MINOR__ < 3)
  161. const test::EmplaceOptions SetOptions = (test::EmplaceOptions)(test::EMPLACE_HINT | test::EMPLACE_ASSOC);
  162. const test::EmplaceOptions MapOptions = (test::EmplaceOptions)(test::EMPLACE_HINT_PAIR | test::EMPLACE_ASSOC_PAIR);
  163. if(!boost::interprocess::test::test_emplace<flat_map<test::EmplaceInt, test::EmplaceInt>, MapOptions>())
  164. return 1;
  165. if(!boost::interprocess::test::test_emplace<flat_multimap<test::EmplaceInt, test::EmplaceInt>, MapOptions>())
  166. return 1;
  167. if(!boost::interprocess::test::test_emplace<flat_set<test::EmplaceInt>, SetOptions>())
  168. return 1;
  169. if(!boost::interprocess::test::test_emplace<flat_multiset<test::EmplaceInt>, SetOptions>())
  170. return 1;
  171. //#endif //!defined(__GNUC__)
  172. return 0;
  173. }
  174. #include <boost/interprocess/detail/config_end.hpp>