1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
|
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2004-2009. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/interprocess for documentation.
//
//////////////////////////////////////////////////////////////////////////////
#include <boost/interprocess/detail/config_begin.hpp>
#include <set>
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/containers/flat_set.hpp>
#include <boost/interprocess/containers/flat_map.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
#include <boost/interprocess/indexes/flat_map_index.hpp>
#include "print_container.hpp"
#include "dummy_test_allocator.hpp"
#include "movable_int.hpp"
#include "set_test.hpp"
#include "map_test.hpp"
#include "emplace_test.hpp"
/////////////////////////////////////////////////////////////////
//
// This example repeats the same operations with std::set and
// shmem_set using the node allocator
// and compares the values of both containers
//
/////////////////////////////////////////////////////////////////
using namespace boost::interprocess;
/*
//Explicit instantiation to detect compilation errors
template class boost::interprocess::flat_set
<test::movable_and_copyable_int
,std::less<test::movable_and_copyable_int>
,test::dummy_test_allocator<test::movable_and_copyable_int> >;
template class boost::interprocess::flat_map
<test::movable_and_copyable_int
,test::movable_and_copyable_int
,std::less<test::movable_and_copyable_int>
,test::dummy_test_allocator<std::pair<test::movable_and_copyable_int
,test::movable_and_copyable_int> > >;
template class boost::interprocess::flat_multiset
<test::movable_and_copyable_int
,std::less<test::movable_and_copyable_int>
,test::dummy_test_allocator<test::movable_and_copyable_int> >;
template class boost::interprocess::flat_multimap
<test::movable_and_copyable_int
,test::movable_and_copyable_int
,std::less<test::movable_and_copyable_int>
,test::dummy_test_allocator<std::pair<test::movable_and_copyable_int
,test::movable_and_copyable_int> > >;
*/
//Customize managed_shared_memory class
typedef basic_managed_shared_memory
<char,
//simple_seq_fit<mutex_family>,
rbtree_best_fit<mutex_family>,
iset_index
> my_managed_shared_memory;
//Alias allocator type
typedef allocator<int, my_managed_shared_memory::segment_manager>
shmem_allocator_t;
typedef allocator<test::movable_int, my_managed_shared_memory::segment_manager>
shmem_movable_allocator_t;
typedef allocator<std::pair<int, int>, my_managed_shared_memory::segment_manager>
shmem_pair_allocator_t;
typedef allocator<std::pair<test::movable_int, test::movable_int>, my_managed_shared_memory::segment_manager>
shmem_movable_pair_allocator_t;
typedef allocator<test::movable_and_copyable_int, my_managed_shared_memory::segment_manager>
shmem_move_copy_allocator_t;
typedef allocator<test::copyable_int, my_managed_shared_memory::segment_manager>
shmem_copy_allocator_t;
typedef allocator<std::pair<test::movable_and_copyable_int, test::movable_and_copyable_int>, my_managed_shared_memory::segment_manager>
shmem_move_copy_pair_allocator_t;
//Alias set types
typedef std::set<int> MyStdSet;
typedef std::multiset<int> MyStdMultiSet;
typedef std::map<int, int> MyStdMap;
typedef std::multimap<int, int> MyStdMultiMap;
typedef flat_set<int, std::less<int>, shmem_allocator_t> MyShmSet;
typedef flat_multiset<int, std::less<int>, shmem_allocator_t> MyShmMultiSet;
typedef flat_map<int, int, std::less<int>, shmem_pair_allocator_t> MyShmMap;
typedef flat_multimap<int, int, std::less<int>, shmem_pair_allocator_t> MyShmMultiMap;
typedef flat_set<test::movable_int, std::less<test::movable_int>
,shmem_movable_allocator_t> MyMovableShmSet;
typedef flat_multiset<test::movable_int,std::less<test::movable_int>
,shmem_movable_allocator_t> MyMovableShmMultiSet;
typedef flat_map<test::movable_int, test::movable_int
,std::less<test::movable_int>
,shmem_movable_pair_allocator_t> MyMovableShmMap;
typedef flat_multimap<test::movable_int, test::movable_int
,std::less<test::movable_int>
,shmem_movable_pair_allocator_t> MyMovableShmMultiMap;
typedef flat_set<test::movable_and_copyable_int, std::less<test::movable_and_copyable_int>
,shmem_move_copy_allocator_t> MyMoveCopyShmSet;
typedef flat_multiset<test::movable_and_copyable_int,std::less<test::movable_and_copyable_int>
,shmem_move_copy_allocator_t> MyMoveCopyShmMultiSet;
typedef flat_set<test::copyable_int, std::less<test::copyable_int>
,shmem_copy_allocator_t> MyCopyShmSet;
typedef flat_multiset<test::copyable_int,std::less<test::copyable_int>
,shmem_copy_allocator_t> MyCopyShmMultiSet;
typedef flat_map<test::movable_and_copyable_int, test::movable_and_copyable_int
,std::less<test::movable_and_copyable_int>
,shmem_move_copy_pair_allocator_t> MyMoveCopyShmMap;
typedef flat_multimap<test::movable_and_copyable_int, test::movable_and_copyable_int
,std::less<test::movable_and_copyable_int>
,shmem_move_copy_pair_allocator_t> MyMoveCopyShmMultiMap;
//Test recursive structures
class recursive_flat_set
{
public:
int id_;
flat_set<recursive_flat_set> flat_set_;
friend bool operator< (const recursive_flat_set &a, const recursive_flat_set &b)
{ return a.id_ < b.id_; }
};
class recursive_flat_map
{
public:
int id_;
flat_map<recursive_flat_map, recursive_flat_map> map_;
recursive_flat_map (const recursive_flat_map&x)
:id_(x.id_), map_(x.map_)
{}
recursive_flat_map &operator=(const recursive_flat_map &x)
{ id_ = x.id_; map_ = x.map_; return *this; }
friend bool operator< (const recursive_flat_map &a, const recursive_flat_map &b)
{ return a.id_ < b.id_; }
};
//Test recursive structures
class recursive_flat_multiset
{
public:
int id_;
flat_multiset<recursive_flat_multiset> flat_set_;
friend bool operator< (const recursive_flat_multiset &a, const recursive_flat_set &b)
{ return a.id_ < b.id_; }
};
class recursive_flat_multimap
{
public:
int id_;
flat_map<recursive_flat_multimap, recursive_flat_multimap> map_;
recursive_flat_multimap (const recursive_flat_multimap&x)
:id_(x.id_), map_(x.map_)
{}
recursive_flat_multimap &operator=(const recursive_flat_multimap &x)
{ id_ = x.id_; map_ = x.map_; return *this; }
friend bool operator< (const recursive_flat_multimap &a, const recursive_flat_multimap &b)
{ return a.id_ < b.id_; }
};
template<class C>
void test_move()
{
//Now test move semantics
C original;
C move_ctor(boost::interprocess::move(original));
C move_assign;
move_assign = boost::interprocess::move(move_ctor);
move_assign.swap(original);
}
int main()
{
using namespace boost::interprocess::test;
//Now test move semantics
{
test_move<flat_set<recursive_flat_set> >();
test_move<flat_multiset<recursive_flat_multiset> >();
test_move<flat_map<recursive_flat_map, recursive_flat_map> >();
test_move<flat_multimap<recursive_flat_multimap, recursive_flat_multimap> >();
}
if (0 != set_test<my_managed_shared_memory
,MyShmSet
,MyStdSet
,MyShmMultiSet
,MyStdMultiSet>()){
std::cout << "Error in set_test<MyShmSet>" << std::endl;
return 1;
}
if (0 != set_test_copyable<my_managed_shared_memory
,MyShmSet
,MyStdSet
,MyShmMultiSet
,MyStdMultiSet>()){
std::cout << "Error in set_test<MyShmSet>" << std::endl;
return 1;
}
if (0 != set_test<my_managed_shared_memory
,MyMovableShmSet
,MyStdSet
,MyMovableShmMultiSet
,MyStdMultiSet>()){
std::cout << "Error in set_test<MyMovableShmSet>" << std::endl;
return 1;
}
if (0 != set_test<my_managed_shared_memory
,MyMoveCopyShmSet
,MyStdSet
,MyMoveCopyShmMultiSet
,MyStdMultiSet>()){
std::cout << "Error in set_test<MyMoveCopyShmSet>" << std::endl;
return 1;
}
if (0 != set_test<my_managed_shared_memory
,MyCopyShmSet
,MyStdSet
,MyCopyShmMultiSet
,MyStdMultiSet>()){
std::cout << "Error in set_test<MyCopyShmSet>" << std::endl;
return 1;
}
if (0 != map_test<my_managed_shared_memory
,MyShmMap
,MyStdMap
,MyShmMultiMap
,MyStdMultiMap>()){
std::cout << "Error in set_test<MyShmMap>" << std::endl;
return 1;
}
if (0 != map_test_copyable<my_managed_shared_memory
,MyShmMap
,MyStdMap
,MyShmMultiMap
,MyStdMultiMap>()){
std::cout << "Error in set_test<MyShmMap>" << std::endl;
return 1;
}
// if (0 != map_test<my_managed_shared_memory
// ,MyMovableShmMap
// ,MyStdMap
// ,MyMovableShmMultiMap
// ,MyStdMultiMap>()){
// return 1;
// }
if (0 != map_test<my_managed_shared_memory
,MyMoveCopyShmMap
,MyStdMap
,MyMoveCopyShmMultiMap
,MyStdMultiMap>()){
std::cout << "Error in set_test<MyMoveCopyShmMap>" << std::endl;
return 1;
}
//#if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC_MINOR__ < 3)
const test::EmplaceOptions SetOptions = (test::EmplaceOptions)(test::EMPLACE_HINT | test::EMPLACE_ASSOC);
const test::EmplaceOptions MapOptions = (test::EmplaceOptions)(test::EMPLACE_HINT_PAIR | test::EMPLACE_ASSOC_PAIR);
if(!boost::interprocess::test::test_emplace<flat_map<test::EmplaceInt, test::EmplaceInt>, MapOptions>())
return 1;
if(!boost::interprocess::test::test_emplace<flat_multimap<test::EmplaceInt, test::EmplaceInt>, MapOptions>())
return 1;
if(!boost::interprocess::test::test_emplace<flat_set<test::EmplaceInt>, SetOptions>())
return 1;
if(!boost::interprocess::test::test_emplace<flat_multiset<test::EmplaceInt>, SetOptions>())
return 1;
//#endif //!defined(__GNUC__)
return 0;
}
#include <boost/interprocess/detail/config_end.hpp>
|