tree_test.cpp 7.8 KB

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