annotate DEPENDENCIES/generic/include/boost/property_map/property_map.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
rev   line source
Chris@16 1 // (C) Copyright Jeremy Siek 1999-2001.
Chris@16 2 // Copyright (C) 2006 Trustees of Indiana University
Chris@16 3 // Authors: Douglas Gregor and Jeremy Siek
Chris@16 4
Chris@16 5 // Distributed under the Boost Software License, Version 1.0. (See
Chris@16 6 // accompanying file LICENSE_1_0.txt or copy at
Chris@16 7 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 8
Chris@16 9 // See http://www.boost.org/libs/property_map for documentation.
Chris@16 10
Chris@16 11 #ifndef BOOST_PROPERTY_MAP_HPP
Chris@16 12 #define BOOST_PROPERTY_MAP_HPP
Chris@16 13
Chris@16 14 #include <boost/assert.hpp>
Chris@16 15 #include <boost/config.hpp>
Chris@16 16 #include <boost/static_assert.hpp>
Chris@16 17 #include <boost/pending/cstddef.hpp>
Chris@16 18 #include <boost/detail/iterator.hpp>
Chris@16 19 #include <boost/concept_check.hpp>
Chris@16 20 #include <boost/concept_archetype.hpp>
Chris@16 21 #include <boost/mpl/assert.hpp>
Chris@16 22 #include <boost/mpl/or.hpp>
Chris@16 23 #include <boost/mpl/and.hpp>
Chris@16 24 #include <boost/mpl/has_xxx.hpp>
Chris@16 25 #include <boost/type_traits/is_same.hpp>
Chris@16 26
Chris@16 27 namespace boost {
Chris@16 28
Chris@16 29 //=========================================================================
Chris@16 30 // property_traits class
Chris@16 31
Chris@16 32 BOOST_MPL_HAS_XXX_TRAIT_DEF(key_type)
Chris@16 33 BOOST_MPL_HAS_XXX_TRAIT_DEF(value_type)
Chris@16 34 BOOST_MPL_HAS_XXX_TRAIT_DEF(reference)
Chris@16 35 BOOST_MPL_HAS_XXX_TRAIT_DEF(category)
Chris@16 36
Chris@16 37 template<class PA>
Chris@16 38 struct is_property_map :
Chris@16 39 boost::mpl::and_<
Chris@16 40 has_key_type<PA>,
Chris@16 41 has_value_type<PA>,
Chris@16 42 has_reference<PA>,
Chris@16 43 has_category<PA>
Chris@16 44 >
Chris@16 45 {};
Chris@16 46
Chris@16 47 template <typename PA>
Chris@16 48 struct default_property_traits {
Chris@16 49 typedef typename PA::key_type key_type;
Chris@16 50 typedef typename PA::value_type value_type;
Chris@16 51 typedef typename PA::reference reference;
Chris@16 52 typedef typename PA::category category;
Chris@16 53 };
Chris@16 54
Chris@16 55 struct null_property_traits {};
Chris@16 56
Chris@16 57 template <typename PA>
Chris@16 58 struct property_traits :
Chris@16 59 boost::mpl::if_<is_property_map<PA>,
Chris@16 60 default_property_traits<PA>,
Chris@16 61 null_property_traits>::type
Chris@16 62 {};
Chris@16 63
Chris@16 64 #if 0
Chris@16 65 template <typename PA>
Chris@16 66 struct property_traits {
Chris@16 67 typedef typename PA::key_type key_type;
Chris@16 68 typedef typename PA::value_type value_type;
Chris@16 69 typedef typename PA::reference reference;
Chris@16 70 typedef typename PA::category category;
Chris@16 71 };
Chris@16 72 #endif
Chris@16 73
Chris@16 74 //=========================================================================
Chris@16 75 // property_traits category tags
Chris@16 76
Chris@16 77 namespace detail {
Chris@16 78 enum ePropertyMapID { READABLE_PA, WRITABLE_PA,
Chris@16 79 READ_WRITE_PA, LVALUE_PA, OP_BRACKET_PA,
Chris@16 80 RAND_ACCESS_ITER_PA, LAST_PA };
Chris@16 81 }
Chris@16 82 struct readable_property_map_tag { enum { id = detail::READABLE_PA }; };
Chris@16 83 struct writable_property_map_tag { enum { id = detail::WRITABLE_PA }; };
Chris@16 84 struct read_write_property_map_tag :
Chris@16 85 public readable_property_map_tag,
Chris@16 86 public writable_property_map_tag
Chris@16 87 { enum { id = detail::READ_WRITE_PA }; };
Chris@16 88
Chris@16 89 struct lvalue_property_map_tag : public read_write_property_map_tag
Chris@16 90 { enum { id = detail::LVALUE_PA }; };
Chris@16 91
Chris@16 92 //=========================================================================
Chris@16 93 // property_traits specialization for pointers
Chris@16 94
Chris@16 95 #ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Chris@16 96 // The user will just have to create their own specializations for
Chris@16 97 // other pointers types if the compiler does not have partial
Chris@16 98 // specializations. Sorry!
Chris@16 99 #define BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(TYPE) \
Chris@16 100 template <> \
Chris@16 101 struct property_traits<TYPE*> { \
Chris@16 102 typedef TYPE value_type; \
Chris@16 103 typedef value_type& reference; \
Chris@16 104 typedef std::ptrdiff_t key_type; \
Chris@16 105 typedef lvalue_property_map_tag category; \
Chris@16 106 }; \
Chris@16 107 template <> \
Chris@16 108 struct property_traits<const TYPE*> { \
Chris@16 109 typedef TYPE value_type; \
Chris@16 110 typedef const value_type& reference; \
Chris@16 111 typedef std::ptrdiff_t key_type; \
Chris@16 112 typedef lvalue_property_map_tag category; \
Chris@16 113 }
Chris@16 114
Chris@16 115 BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(long);
Chris@16 116 BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(unsigned long);
Chris@16 117 BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(int);
Chris@16 118 BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(unsigned int);
Chris@16 119 BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(short);
Chris@16 120 BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(unsigned short);
Chris@16 121 BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(char);
Chris@16 122 BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(unsigned char);
Chris@16 123 BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(signed char);
Chris@16 124 BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(bool);
Chris@16 125 BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(float);
Chris@16 126 BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(double);
Chris@16 127 BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(long double);
Chris@16 128
Chris@16 129 // This may need to be turned off for some older compilers that don't have
Chris@16 130 // wchar_t intrinsically.
Chris@16 131 # ifndef BOOST_NO_INTRINSIC_WCHAR_T
Chris@16 132 template <>
Chris@16 133 struct property_traits<wchar_t*> {
Chris@16 134 typedef wchar_t value_type;
Chris@16 135 typedef value_type& reference;
Chris@16 136 typedef std::ptrdiff_t key_type;
Chris@16 137 typedef lvalue_property_map_tag category;
Chris@16 138 };
Chris@16 139 template <>
Chris@16 140 struct property_traits<const wchar_t*> {
Chris@16 141 typedef wchar_t value_type;
Chris@16 142 typedef const value_type& reference;
Chris@16 143 typedef std::ptrdiff_t key_type;
Chris@16 144 typedef lvalue_property_map_tag category;
Chris@16 145 };
Chris@16 146 # endif
Chris@16 147
Chris@16 148 #else
Chris@16 149 template <class T>
Chris@16 150 struct property_traits<T*> {
Chris@16 151 // BOOST_STATIC_ASSERT(boost::is_same<T, T*>::value && !"Using pointers as property maps is deprecated");
Chris@16 152 typedef T value_type;
Chris@16 153 typedef value_type& reference;
Chris@16 154 typedef std::ptrdiff_t key_type;
Chris@16 155 typedef lvalue_property_map_tag category;
Chris@16 156 };
Chris@16 157 template <class T>
Chris@16 158 struct property_traits<const T*> {
Chris@16 159 // BOOST_STATIC_ASSERT(boost::is_same<T, T*>::value && !"Using pointers as property maps is deprecated");
Chris@16 160 typedef T value_type;
Chris@16 161 typedef const value_type& reference;
Chris@16 162 typedef std::ptrdiff_t key_type;
Chris@16 163 typedef lvalue_property_map_tag category;
Chris@16 164 };
Chris@16 165 #endif
Chris@16 166
Chris@16 167 #if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
Chris@16 168 // MSVC doesn't have Koenig lookup, so the user has to
Chris@16 169 // do boost::get() anyways, and the using clause
Chris@16 170 // doesn't really work for MSVC.
Chris@16 171 } // namespace boost
Chris@16 172 #endif
Chris@16 173
Chris@16 174 // These need to go in global namespace because Koenig
Chris@16 175 // lookup does not apply to T*.
Chris@16 176
Chris@16 177 // V must be convertible to T
Chris@16 178 template <class T, class V>
Chris@16 179 inline void put(T* pa, std::ptrdiff_t k, const V& val) { pa[k] = val; }
Chris@16 180
Chris@16 181 template <class T>
Chris@16 182 inline const T& get(const T* pa, std::ptrdiff_t k) { return pa[k]; }
Chris@16 183
Chris@16 184 #if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
Chris@16 185 namespace boost {
Chris@16 186 using ::put;
Chris@16 187 using ::get;
Chris@16 188 #endif
Chris@16 189
Chris@16 190 //=========================================================================
Chris@16 191 // concept checks for property maps
Chris@16 192
Chris@16 193 template <class PMap, class Key>
Chris@16 194 struct ReadablePropertyMapConcept
Chris@16 195 {
Chris@16 196 typedef typename property_traits<PMap>::key_type key_type;
Chris@16 197 typedef typename property_traits<PMap>::reference reference;
Chris@16 198 typedef typename property_traits<PMap>::category Category;
Chris@16 199 typedef boost::readable_property_map_tag ReadableTag;
Chris@16 200 void constraints() {
Chris@16 201 function_requires< ConvertibleConcept<Category, ReadableTag> >();
Chris@16 202
Chris@16 203 val = get(pmap, k);
Chris@16 204 }
Chris@16 205 PMap pmap;
Chris@16 206 Key k;
Chris@16 207 typename property_traits<PMap>::value_type val;
Chris@16 208 };
Chris@16 209 template <typename KeyArchetype, typename ValueArchetype>
Chris@16 210 struct readable_property_map_archetype {
Chris@16 211 typedef KeyArchetype key_type;
Chris@16 212 typedef ValueArchetype value_type;
Chris@16 213 typedef convertible_to_archetype<ValueArchetype> reference;
Chris@16 214 typedef readable_property_map_tag category;
Chris@16 215 };
Chris@16 216 template <typename K, typename V>
Chris@16 217 const typename readable_property_map_archetype<K,V>::reference&
Chris@16 218 get(const readable_property_map_archetype<K,V>&,
Chris@16 219 const typename readable_property_map_archetype<K,V>::key_type&)
Chris@16 220 {
Chris@16 221 typedef typename readable_property_map_archetype<K,V>::reference R;
Chris@16 222 return static_object<R>::get();
Chris@16 223 }
Chris@16 224
Chris@16 225
Chris@16 226 template <class PMap, class Key>
Chris@16 227 struct WritablePropertyMapConcept
Chris@16 228 {
Chris@16 229 typedef typename property_traits<PMap>::key_type key_type;
Chris@16 230 typedef typename property_traits<PMap>::category Category;
Chris@16 231 typedef boost::writable_property_map_tag WritableTag;
Chris@16 232 void constraints() {
Chris@16 233 function_requires< ConvertibleConcept<Category, WritableTag> >();
Chris@16 234 put(pmap, k, val);
Chris@16 235 }
Chris@16 236 PMap pmap;
Chris@16 237 Key k;
Chris@16 238 typename property_traits<PMap>::value_type val;
Chris@16 239 };
Chris@16 240 template <typename KeyArchetype, typename ValueArchetype>
Chris@16 241 struct writable_property_map_archetype {
Chris@16 242 typedef KeyArchetype key_type;
Chris@16 243 typedef ValueArchetype value_type;
Chris@16 244 typedef void reference;
Chris@16 245 typedef writable_property_map_tag category;
Chris@16 246 };
Chris@16 247 template <typename K, typename V>
Chris@16 248 void put(const writable_property_map_archetype<K,V>&,
Chris@16 249 const typename writable_property_map_archetype<K,V>::key_type&,
Chris@16 250 const typename writable_property_map_archetype<K,V>::value_type&) { }
Chris@16 251
Chris@16 252
Chris@16 253 template <class PMap, class Key>
Chris@16 254 struct ReadWritePropertyMapConcept
Chris@16 255 {
Chris@16 256 typedef typename property_traits<PMap>::category Category;
Chris@16 257 typedef boost::read_write_property_map_tag ReadWriteTag;
Chris@16 258 void constraints() {
Chris@16 259 function_requires< ReadablePropertyMapConcept<PMap, Key> >();
Chris@16 260 function_requires< WritablePropertyMapConcept<PMap, Key> >();
Chris@16 261 function_requires< ConvertibleConcept<Category, ReadWriteTag> >();
Chris@16 262 }
Chris@16 263 };
Chris@16 264 template <typename KeyArchetype, typename ValueArchetype>
Chris@16 265 struct read_write_property_map_archetype
Chris@16 266 : public readable_property_map_archetype<KeyArchetype, ValueArchetype>,
Chris@16 267 public writable_property_map_archetype<KeyArchetype, ValueArchetype>
Chris@16 268 {
Chris@16 269 typedef KeyArchetype key_type;
Chris@16 270 typedef ValueArchetype value_type;
Chris@16 271 typedef convertible_to_archetype<ValueArchetype> reference;
Chris@16 272 typedef read_write_property_map_tag category;
Chris@16 273 };
Chris@16 274
Chris@16 275
Chris@16 276 template <class PMap, class Key>
Chris@16 277 struct LvaluePropertyMapConcept
Chris@16 278 {
Chris@16 279 typedef typename property_traits<PMap>::category Category;
Chris@16 280 typedef boost::lvalue_property_map_tag LvalueTag;
Chris@16 281 typedef typename property_traits<PMap>::reference reference;
Chris@16 282
Chris@16 283 void constraints() {
Chris@16 284 function_requires< ReadablePropertyMapConcept<PMap, Key> >();
Chris@16 285 function_requires< ConvertibleConcept<Category, LvalueTag> >();
Chris@16 286
Chris@16 287 typedef typename property_traits<PMap>::value_type value_type;
Chris@16 288 BOOST_MPL_ASSERT((boost::mpl::or_<
Chris@16 289 boost::is_same<const value_type&, reference>,
Chris@16 290 boost::is_same<value_type&, reference> >));
Chris@16 291
Chris@16 292 reference ref = pmap[k];
Chris@16 293 ignore_unused_variable_warning(ref);
Chris@16 294 }
Chris@16 295 PMap pmap;
Chris@16 296 Key k;
Chris@16 297 };
Chris@16 298 template <typename KeyArchetype, typename ValueArchetype>
Chris@16 299 struct lvalue_property_map_archetype
Chris@16 300 : public readable_property_map_archetype<KeyArchetype, ValueArchetype>
Chris@16 301 {
Chris@16 302 typedef KeyArchetype key_type;
Chris@16 303 typedef ValueArchetype value_type;
Chris@16 304 typedef const ValueArchetype& reference;
Chris@16 305 typedef lvalue_property_map_tag category;
Chris@16 306 const value_type& operator[](const key_type&) const {
Chris@16 307 return static_object<value_type>::get();
Chris@16 308 }
Chris@16 309 };
Chris@16 310
Chris@16 311 template <class PMap, class Key>
Chris@16 312 struct Mutable_LvaluePropertyMapConcept
Chris@16 313 {
Chris@16 314 typedef typename property_traits<PMap>::category Category;
Chris@16 315 typedef boost::lvalue_property_map_tag LvalueTag;
Chris@16 316 typedef typename property_traits<PMap>::reference reference;
Chris@16 317 void constraints() {
Chris@16 318 boost::function_requires< ReadWritePropertyMapConcept<PMap, Key> >();
Chris@16 319 boost::function_requires<ConvertibleConcept<Category, LvalueTag> >();
Chris@16 320
Chris@16 321 typedef typename property_traits<PMap>::value_type value_type;
Chris@16 322 BOOST_MPL_ASSERT((boost::is_same<value_type&, reference>));
Chris@16 323
Chris@16 324 reference ref = pmap[k];
Chris@16 325 ignore_unused_variable_warning(ref);
Chris@16 326 }
Chris@16 327 PMap pmap;
Chris@16 328 Key k;
Chris@16 329 };
Chris@16 330 template <typename KeyArchetype, typename ValueArchetype>
Chris@16 331 struct mutable_lvalue_property_map_archetype
Chris@16 332 : public readable_property_map_archetype<KeyArchetype, ValueArchetype>,
Chris@16 333 public writable_property_map_archetype<KeyArchetype, ValueArchetype>
Chris@16 334 {
Chris@16 335 typedef KeyArchetype key_type;
Chris@16 336 typedef ValueArchetype value_type;
Chris@16 337 typedef ValueArchetype& reference;
Chris@16 338 typedef lvalue_property_map_tag category;
Chris@16 339 value_type& operator[](const key_type&) const {
Chris@16 340 return static_object<value_type>::get();
Chris@16 341 }
Chris@16 342 };
Chris@16 343
Chris@16 344 template <typename T>
Chris@16 345 struct typed_identity_property_map;
Chris@16 346
Chris@16 347 // A helper class for constructing a property map
Chris@16 348 // from a class that implements operator[]
Chris@16 349
Chris@16 350 template <class Reference, class LvaluePropertyMap>
Chris@16 351 struct put_get_helper { };
Chris@16 352
Chris@16 353 template <class PropertyMap, class Reference, class K>
Chris@16 354 inline Reference
Chris@16 355 get(const put_get_helper<Reference, PropertyMap>& pa, const K& k)
Chris@16 356 {
Chris@16 357 Reference v = static_cast<const PropertyMap&>(pa)[k];
Chris@16 358 return v;
Chris@16 359 }
Chris@16 360 template <class PropertyMap, class Reference, class K, class V>
Chris@16 361 inline void
Chris@16 362 put(const put_get_helper<Reference, PropertyMap>& pa, K k, const V& v)
Chris@16 363 {
Chris@16 364 static_cast<const PropertyMap&>(pa)[k] = v;
Chris@16 365 }
Chris@16 366
Chris@16 367 //=========================================================================
Chris@16 368 // Adapter to turn a RandomAccessIterator into a property map
Chris@16 369
Chris@16 370 template <class RandomAccessIterator,
Chris@16 371 class IndexMap
Chris@16 372 #ifdef BOOST_NO_STD_ITERATOR_TRAITS
Chris@16 373 , class T, class R
Chris@16 374 #else
Chris@16 375 , class T = typename std::iterator_traits<RandomAccessIterator>::value_type
Chris@16 376 , class R = typename std::iterator_traits<RandomAccessIterator>::reference
Chris@16 377 #endif
Chris@16 378 >
Chris@16 379 class iterator_property_map
Chris@16 380 : public boost::put_get_helper< R,
Chris@16 381 iterator_property_map<RandomAccessIterator, IndexMap,
Chris@16 382 T, R> >
Chris@16 383 {
Chris@16 384 public:
Chris@16 385 typedef typename property_traits<IndexMap>::key_type key_type;
Chris@16 386 typedef T value_type;
Chris@16 387 typedef R reference;
Chris@16 388 typedef boost::lvalue_property_map_tag category;
Chris@16 389
Chris@16 390 inline iterator_property_map(
Chris@16 391 RandomAccessIterator cc = RandomAccessIterator(),
Chris@16 392 const IndexMap& _id = IndexMap() )
Chris@16 393 : iter(cc), index(_id) { }
Chris@16 394 inline R operator[](key_type v) const { return *(iter + get(index, v)) ; }
Chris@16 395 protected:
Chris@16 396 RandomAccessIterator iter;
Chris@16 397 IndexMap index;
Chris@16 398 };
Chris@16 399
Chris@16 400 #if !defined BOOST_NO_STD_ITERATOR_TRAITS
Chris@16 401 template <class RAIter, class ID>
Chris@16 402 inline iterator_property_map<
Chris@16 403 RAIter, ID,
Chris@16 404 typename std::iterator_traits<RAIter>::value_type,
Chris@16 405 typename std::iterator_traits<RAIter>::reference>
Chris@16 406 make_iterator_property_map(RAIter iter, ID id) {
Chris@16 407 function_requires< RandomAccessIteratorConcept<RAIter> >();
Chris@16 408 typedef iterator_property_map<
Chris@16 409 RAIter, ID,
Chris@16 410 typename std::iterator_traits<RAIter>::value_type,
Chris@16 411 typename std::iterator_traits<RAIter>::reference> PA;
Chris@16 412 return PA(iter, id);
Chris@16 413 }
Chris@16 414 #endif
Chris@16 415 template <class RAIter, class Value, class ID>
Chris@16 416 inline iterator_property_map<RAIter, ID, Value, Value&>
Chris@16 417 make_iterator_property_map(RAIter iter, ID id, Value) {
Chris@16 418 function_requires< RandomAccessIteratorConcept<RAIter> >();
Chris@16 419 typedef iterator_property_map<RAIter, ID, Value, Value&> PMap;
Chris@16 420 return PMap(iter, id);
Chris@16 421 }
Chris@16 422
Chris@16 423 template <class RandomAccessIterator,
Chris@16 424 class IndexMap
Chris@16 425 #ifdef BOOST_NO_STD_ITERATOR_TRAITS
Chris@16 426 , class T, class R
Chris@16 427 #else
Chris@16 428 , class T = typename std::iterator_traits<RandomAccessIterator>::value_type
Chris@16 429 , class R = typename std::iterator_traits<RandomAccessIterator>::reference
Chris@16 430 #endif
Chris@16 431 >
Chris@16 432 class safe_iterator_property_map
Chris@16 433 : public boost::put_get_helper< R,
Chris@16 434 safe_iterator_property_map<RandomAccessIterator, IndexMap,
Chris@16 435 T, R> >
Chris@16 436 {
Chris@16 437 public:
Chris@16 438 typedef typename property_traits<IndexMap>::key_type key_type;
Chris@16 439 typedef T value_type;
Chris@16 440 typedef R reference;
Chris@16 441 typedef boost::lvalue_property_map_tag category;
Chris@16 442
Chris@16 443 inline safe_iterator_property_map(
Chris@16 444 RandomAccessIterator first,
Chris@16 445 std::size_t n_ = 0,
Chris@16 446 const IndexMap& _id = IndexMap() )
Chris@16 447 : iter(first), n(n_), index(_id) { }
Chris@16 448 inline safe_iterator_property_map() { }
Chris@16 449 inline R operator[](key_type v) const {
Chris@16 450 BOOST_ASSERT(get(index, v) < n);
Chris@16 451 return *(iter + get(index, v)) ;
Chris@16 452 }
Chris@16 453 typename property_traits<IndexMap>::value_type size() const { return n; }
Chris@16 454 protected:
Chris@16 455 RandomAccessIterator iter;
Chris@16 456 typename property_traits<IndexMap>::value_type n;
Chris@16 457 IndexMap index;
Chris@16 458 };
Chris@16 459
Chris@16 460 #if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Chris@16 461 template <class RAIter, class ID>
Chris@16 462 inline safe_iterator_property_map<
Chris@16 463 RAIter, ID,
Chris@16 464 typename boost::detail::iterator_traits<RAIter>::value_type,
Chris@16 465 typename boost::detail::iterator_traits<RAIter>::reference>
Chris@16 466 make_safe_iterator_property_map(RAIter iter, std::size_t n, ID id) {
Chris@16 467 function_requires< RandomAccessIteratorConcept<RAIter> >();
Chris@16 468 typedef safe_iterator_property_map<
Chris@16 469 RAIter, ID,
Chris@16 470 typename boost::detail::iterator_traits<RAIter>::value_type,
Chris@16 471 typename boost::detail::iterator_traits<RAIter>::reference> PA;
Chris@16 472 return PA(iter, n, id);
Chris@16 473 }
Chris@16 474 #endif
Chris@16 475 template <class RAIter, class Value, class ID>
Chris@16 476 inline safe_iterator_property_map<RAIter, ID, Value, Value&>
Chris@16 477 make_safe_iterator_property_map(RAIter iter, std::size_t n, ID id, Value) {
Chris@16 478 function_requires< RandomAccessIteratorConcept<RAIter> >();
Chris@16 479 typedef safe_iterator_property_map<RAIter, ID, Value, Value&> PMap;
Chris@16 480 return PMap(iter, n, id);
Chris@16 481 }
Chris@16 482
Chris@16 483 //=========================================================================
Chris@16 484 // An adaptor to turn a Unique Pair Associative Container like std::map or
Chris@16 485 // std::hash_map into an Lvalue Property Map.
Chris@16 486
Chris@16 487 template <typename UniquePairAssociativeContainer>
Chris@16 488 class associative_property_map
Chris@16 489 : public boost::put_get_helper<
Chris@16 490 typename UniquePairAssociativeContainer::value_type::second_type&,
Chris@16 491 associative_property_map<UniquePairAssociativeContainer> >
Chris@16 492 {
Chris@16 493 typedef UniquePairAssociativeContainer C;
Chris@16 494 public:
Chris@16 495 typedef typename C::key_type key_type;
Chris@16 496 typedef typename C::value_type::second_type value_type;
Chris@16 497 typedef value_type& reference;
Chris@16 498 typedef lvalue_property_map_tag category;
Chris@16 499 associative_property_map() : m_c(0) { }
Chris@16 500 associative_property_map(C& c) : m_c(&c) { }
Chris@16 501 reference operator[](const key_type& k) const {
Chris@16 502 return (*m_c)[k];
Chris@16 503 }
Chris@16 504 private:
Chris@16 505 C* m_c;
Chris@16 506 };
Chris@16 507
Chris@16 508 template <class UniquePairAssociativeContainer>
Chris@16 509 associative_property_map<UniquePairAssociativeContainer>
Chris@16 510 make_assoc_property_map(UniquePairAssociativeContainer& c)
Chris@16 511 {
Chris@16 512 return associative_property_map<UniquePairAssociativeContainer>(c);
Chris@16 513 }
Chris@16 514
Chris@16 515 template <typename UniquePairAssociativeContainer>
Chris@16 516 class const_associative_property_map
Chris@16 517 : public boost::put_get_helper<
Chris@16 518 const typename UniquePairAssociativeContainer::value_type::second_type&,
Chris@16 519 const_associative_property_map<UniquePairAssociativeContainer> >
Chris@16 520 {
Chris@16 521 typedef UniquePairAssociativeContainer C;
Chris@16 522 public:
Chris@16 523 typedef typename C::key_type key_type;
Chris@16 524 typedef typename C::value_type::second_type value_type;
Chris@16 525 typedef const value_type& reference;
Chris@16 526 typedef lvalue_property_map_tag category;
Chris@16 527 const_associative_property_map() : m_c(0) { }
Chris@16 528 const_associative_property_map(const C& c) : m_c(&c) { }
Chris@16 529 reference operator[](const key_type& k) const {
Chris@16 530 return m_c->find(k)->second;
Chris@16 531 }
Chris@16 532 private:
Chris@16 533 C const* m_c;
Chris@16 534 };
Chris@16 535
Chris@16 536 template <class UniquePairAssociativeContainer>
Chris@16 537 const_associative_property_map<UniquePairAssociativeContainer>
Chris@16 538 make_assoc_property_map(const UniquePairAssociativeContainer& c)
Chris@16 539 {
Chris@16 540 return const_associative_property_map<UniquePairAssociativeContainer>(c);
Chris@16 541 }
Chris@16 542
Chris@16 543 //=========================================================================
Chris@16 544 // A property map that always returns the same object by value.
Chris@16 545 //
Chris@16 546 template <typename ValueType>
Chris@16 547 class static_property_map :
Chris@16 548 public
Chris@16 549 boost::put_get_helper<ValueType,static_property_map<ValueType> >
Chris@16 550 {
Chris@16 551 ValueType value;
Chris@16 552 public:
Chris@16 553 typedef void key_type;
Chris@16 554 typedef ValueType value_type;
Chris@16 555 typedef ValueType reference;
Chris@16 556 typedef readable_property_map_tag category;
Chris@16 557 static_property_map(ValueType v) : value(v) {}
Chris@16 558
Chris@16 559 template<typename T>
Chris@16 560 inline reference operator[](T) const { return value; }
Chris@16 561 };
Chris@16 562
Chris@16 563 //=========================================================================
Chris@16 564 // A property map that always returns a reference to the same object.
Chris@16 565 //
Chris@16 566 template <typename KeyType, typename ValueType>
Chris@16 567 class ref_property_map :
Chris@16 568 public
Chris@16 569 boost::put_get_helper<ValueType&,ref_property_map<KeyType,ValueType> >
Chris@16 570 {
Chris@16 571 ValueType* value;
Chris@16 572 public:
Chris@16 573 typedef KeyType key_type;
Chris@16 574 typedef ValueType value_type;
Chris@16 575 typedef ValueType& reference;
Chris@16 576 typedef lvalue_property_map_tag category;
Chris@16 577 ref_property_map(ValueType& v) : value(&v) {}
Chris@16 578 ValueType& operator[](key_type const&) const { return *value; }
Chris@16 579 };
Chris@16 580
Chris@16 581 //=========================================================================
Chris@16 582 // A generalized identity property map
Chris@16 583 template <typename T>
Chris@16 584 struct typed_identity_property_map
Chris@16 585 : public boost::put_get_helper<T, typed_identity_property_map<T> >
Chris@16 586 {
Chris@16 587 typedef T key_type;
Chris@16 588 typedef T value_type;
Chris@16 589 typedef T reference;
Chris@16 590 typedef boost::readable_property_map_tag category;
Chris@16 591
Chris@16 592 inline value_type operator[](const key_type& v) const { return v; }
Chris@16 593 };
Chris@16 594
Chris@16 595 //=========================================================================
Chris@16 596 // A property map that applies the identity function to integers
Chris@16 597 typedef typed_identity_property_map<std::size_t> identity_property_map;
Chris@16 598
Chris@16 599 //=========================================================================
Chris@16 600 // A property map that does not do anything, for
Chris@16 601 // when you have to supply a property map, but don't need it.
Chris@16 602 namespace detail {
Chris@16 603 struct dummy_pmap_reference {
Chris@16 604 template <class T>
Chris@16 605 dummy_pmap_reference& operator=(const T&) { return *this; }
Chris@16 606 operator int() { return 0; }
Chris@16 607 };
Chris@16 608 }
Chris@16 609 class dummy_property_map
Chris@16 610 : public boost::put_get_helper<detail::dummy_pmap_reference,
Chris@16 611 dummy_property_map >
Chris@16 612 {
Chris@16 613 public:
Chris@16 614 typedef void key_type;
Chris@16 615 typedef int value_type;
Chris@16 616 typedef detail::dummy_pmap_reference reference;
Chris@16 617 typedef boost::read_write_property_map_tag category;
Chris@16 618 inline dummy_property_map() : c(0) { }
Chris@16 619 inline dummy_property_map(value_type cc) : c(cc) { }
Chris@16 620 inline dummy_property_map(const dummy_property_map& x)
Chris@16 621 : c(x.c) { }
Chris@16 622 template <class Vertex>
Chris@16 623 inline reference operator[](Vertex) const { return reference(); }
Chris@16 624 protected:
Chris@16 625 value_type c;
Chris@16 626 };
Chris@16 627
Chris@16 628 // Convert a Readable property map into a function object
Chris@16 629 template <typename PropMap>
Chris@16 630 class property_map_function {
Chris@16 631 PropMap pm;
Chris@16 632 typedef typename property_traits<PropMap>::key_type param_type;
Chris@16 633 public:
Chris@16 634 explicit property_map_function(const PropMap& pm): pm(pm) {}
Chris@16 635 typedef typename property_traits<PropMap>::value_type result_type;
Chris@16 636 result_type operator()(const param_type& k) const {return get(pm, k);}
Chris@16 637 };
Chris@16 638
Chris@16 639 template <typename PropMap>
Chris@16 640 property_map_function<PropMap>
Chris@16 641 make_property_map_function(const PropMap& pm) {
Chris@16 642 return property_map_function<PropMap>(pm);
Chris@16 643 }
Chris@16 644
Chris@16 645 } // namespace boost
Chris@16 646
Chris@16 647 #ifdef BOOST_GRAPH_USE_MPI
Chris@16 648 #include <boost/property_map/parallel/distributed_property_map.hpp>
Chris@16 649 #include <boost/property_map/parallel/local_property_map.hpp>
Chris@16 650
Chris@16 651 namespace boost {
Chris@16 652 /** Distributed iterator property map.
Chris@16 653 *
Chris@16 654 * This specialization of @ref iterator_property_map builds a
Chris@16 655 * distributed iterator property map given the local index maps
Chris@16 656 * generated by distributed graph types that automatically have index
Chris@16 657 * properties.
Chris@16 658 *
Chris@16 659 * This specialization is useful when creating external distributed
Chris@16 660 * property maps via the same syntax used to create external
Chris@16 661 * sequential property maps.
Chris@16 662 */
Chris@16 663 template<typename RandomAccessIterator, typename ProcessGroup,
Chris@16 664 typename GlobalMap, typename StorageMap,
Chris@16 665 typename ValueType, typename Reference>
Chris@16 666 class iterator_property_map
Chris@16 667 <RandomAccessIterator,
Chris@16 668 local_property_map<ProcessGroup, GlobalMap, StorageMap>,
Chris@16 669 ValueType, Reference>
Chris@16 670 : public parallel::distributed_property_map
Chris@16 671 <ProcessGroup,
Chris@16 672 GlobalMap,
Chris@16 673 iterator_property_map<RandomAccessIterator, StorageMap,
Chris@16 674 ValueType, Reference> >
Chris@16 675 {
Chris@16 676 typedef iterator_property_map<RandomAccessIterator, StorageMap,
Chris@16 677 ValueType, Reference> local_iterator_map;
Chris@16 678
Chris@16 679 typedef parallel::distributed_property_map<ProcessGroup, GlobalMap,
Chris@16 680 local_iterator_map> inherited;
Chris@16 681
Chris@16 682 typedef local_property_map<ProcessGroup, GlobalMap, StorageMap>
Chris@16 683 index_map_type;
Chris@16 684 typedef iterator_property_map self_type;
Chris@16 685
Chris@16 686 public:
Chris@16 687 iterator_property_map() { }
Chris@16 688
Chris@16 689 iterator_property_map(RandomAccessIterator cc, const index_map_type& id)
Chris@16 690 : inherited(id.process_group(), id.global(),
Chris@16 691 local_iterator_map(cc, id.base())) { }
Chris@16 692 };
Chris@16 693
Chris@16 694 /** Distributed iterator property map.
Chris@16 695 *
Chris@16 696 * This specialization of @ref iterator_property_map builds a
Chris@16 697 * distributed iterator property map given a distributed index
Chris@16 698 * map. Only the local portion of the distributed index property map
Chris@16 699 * is utilized.
Chris@16 700 *
Chris@16 701 * This specialization is useful when creating external distributed
Chris@16 702 * property maps via the same syntax used to create external
Chris@16 703 * sequential property maps.
Chris@16 704 */
Chris@16 705 template<typename RandomAccessIterator, typename ProcessGroup,
Chris@16 706 typename GlobalMap, typename StorageMap,
Chris@16 707 typename ValueType, typename Reference>
Chris@16 708 class iterator_property_map<
Chris@16 709 RandomAccessIterator,
Chris@16 710 parallel::distributed_property_map<ProcessGroup,GlobalMap,StorageMap>,
Chris@16 711 ValueType, Reference
Chris@16 712 >
Chris@16 713 : public parallel::distributed_property_map
Chris@16 714 <ProcessGroup,
Chris@16 715 GlobalMap,
Chris@16 716 iterator_property_map<RandomAccessIterator, StorageMap,
Chris@16 717 ValueType, Reference> >
Chris@16 718 {
Chris@16 719 typedef iterator_property_map<RandomAccessIterator, StorageMap,
Chris@16 720 ValueType, Reference> local_iterator_map;
Chris@16 721
Chris@16 722 typedef parallel::distributed_property_map<ProcessGroup, GlobalMap,
Chris@16 723 local_iterator_map> inherited;
Chris@16 724
Chris@16 725 typedef parallel::distributed_property_map<ProcessGroup, GlobalMap,
Chris@16 726 StorageMap>
Chris@16 727 index_map_type;
Chris@16 728
Chris@16 729 public:
Chris@16 730 iterator_property_map() { }
Chris@16 731
Chris@16 732 iterator_property_map(RandomAccessIterator cc, const index_map_type& id)
Chris@16 733 : inherited(id.process_group(), id.global(),
Chris@16 734 local_iterator_map(cc, id.base())) { }
Chris@16 735 };
Chris@16 736
Chris@16 737 namespace parallel {
Chris@16 738 // Generate an iterator property map with a specific kind of ghost
Chris@16 739 // cells
Chris@16 740 template<typename RandomAccessIterator, typename ProcessGroup,
Chris@16 741 typename GlobalMap, typename StorageMap>
Chris@16 742 distributed_property_map<ProcessGroup,
Chris@16 743 GlobalMap,
Chris@16 744 iterator_property_map<RandomAccessIterator,
Chris@16 745 StorageMap> >
Chris@16 746 make_iterator_property_map(RandomAccessIterator cc,
Chris@16 747 local_property_map<ProcessGroup, GlobalMap,
Chris@16 748 StorageMap> index_map)
Chris@16 749 {
Chris@16 750 typedef distributed_property_map<
Chris@16 751 ProcessGroup, GlobalMap,
Chris@16 752 iterator_property_map<RandomAccessIterator, StorageMap> >
Chris@16 753 result_type;
Chris@16 754 return result_type(index_map.process_group(), index_map.global(),
Chris@16 755 make_iterator_property_map(cc, index_map.base()));
Chris@16 756 }
Chris@16 757
Chris@16 758 } // end namespace parallel
Chris@16 759
Chris@16 760 /** Distributed safe iterator property map.
Chris@16 761 *
Chris@16 762 * This specialization of @ref safe_iterator_property_map builds a
Chris@16 763 * distributed iterator property map given the local index maps
Chris@16 764 * generated by distributed graph types that automatically have index
Chris@16 765 * properties.
Chris@16 766 *
Chris@16 767 * This specialization is useful when creating external distributed
Chris@16 768 * property maps via the same syntax used to create external
Chris@16 769 * sequential property maps.
Chris@16 770 */
Chris@16 771 template<typename RandomAccessIterator, typename ProcessGroup,
Chris@16 772 typename GlobalMap, typename StorageMap, typename ValueType,
Chris@16 773 typename Reference>
Chris@16 774 class safe_iterator_property_map
Chris@16 775 <RandomAccessIterator,
Chris@16 776 local_property_map<ProcessGroup, GlobalMap, StorageMap>,
Chris@16 777 ValueType, Reference>
Chris@16 778 : public parallel::distributed_property_map
Chris@16 779 <ProcessGroup,
Chris@16 780 GlobalMap,
Chris@16 781 safe_iterator_property_map<RandomAccessIterator, StorageMap,
Chris@16 782 ValueType, Reference> >
Chris@16 783 {
Chris@16 784 typedef safe_iterator_property_map<RandomAccessIterator, StorageMap,
Chris@16 785 ValueType, Reference> local_iterator_map;
Chris@16 786
Chris@16 787 typedef parallel::distributed_property_map<ProcessGroup, GlobalMap,
Chris@16 788 local_iterator_map> inherited;
Chris@16 789
Chris@16 790 typedef local_property_map<ProcessGroup, GlobalMap, StorageMap> index_map_type;
Chris@16 791
Chris@16 792 public:
Chris@16 793 safe_iterator_property_map() { }
Chris@16 794
Chris@16 795 safe_iterator_property_map(RandomAccessIterator cc, std::size_t n,
Chris@16 796 const index_map_type& id)
Chris@16 797 : inherited(id.process_group(), id.global(),
Chris@16 798 local_iterator_map(cc, n, id.base())) { }
Chris@16 799 };
Chris@16 800
Chris@16 801 /** Distributed safe iterator property map.
Chris@16 802 *
Chris@16 803 * This specialization of @ref safe_iterator_property_map builds a
Chris@16 804 * distributed iterator property map given a distributed index
Chris@16 805 * map. Only the local portion of the distributed index property map
Chris@16 806 * is utilized.
Chris@16 807 *
Chris@16 808 * This specialization is useful when creating external distributed
Chris@16 809 * property maps via the same syntax used to create external
Chris@16 810 * sequential property maps.
Chris@16 811 */
Chris@16 812 template<typename RandomAccessIterator, typename ProcessGroup,
Chris@16 813 typename GlobalMap, typename StorageMap,
Chris@16 814 typename ValueType, typename Reference>
Chris@16 815 class safe_iterator_property_map<
Chris@16 816 RandomAccessIterator,
Chris@16 817 parallel::distributed_property_map<ProcessGroup,GlobalMap,StorageMap>,
Chris@16 818 ValueType, Reference>
Chris@16 819 : public parallel::distributed_property_map
Chris@16 820 <ProcessGroup,
Chris@16 821 GlobalMap,
Chris@16 822 safe_iterator_property_map<RandomAccessIterator, StorageMap,
Chris@16 823 ValueType, Reference> >
Chris@16 824 {
Chris@16 825 typedef safe_iterator_property_map<RandomAccessIterator, StorageMap,
Chris@16 826 ValueType, Reference> local_iterator_map;
Chris@16 827
Chris@16 828 typedef parallel::distributed_property_map<ProcessGroup, GlobalMap,
Chris@16 829 local_iterator_map> inherited;
Chris@16 830
Chris@16 831 typedef parallel::distributed_property_map<ProcessGroup, GlobalMap,
Chris@16 832 StorageMap>
Chris@16 833 index_map_type;
Chris@16 834
Chris@16 835 public:
Chris@16 836 safe_iterator_property_map() { }
Chris@16 837
Chris@16 838 safe_iterator_property_map(RandomAccessIterator cc, std::size_t n,
Chris@16 839 const index_map_type& id)
Chris@16 840 : inherited(id.process_group(), id.global(),
Chris@16 841 local_iterator_map(cc, n, id.base())) { }
Chris@16 842 };
Chris@16 843
Chris@16 844 }
Chris@16 845 #endif // BOOST_GRAPH_USE_MPI
Chris@16 846
Chris@16 847 #include <boost/property_map/vector_property_map.hpp>
Chris@16 848
Chris@16 849 #endif /* BOOST_PROPERTY_MAP_HPP */
Chris@16 850