annotate DEPENDENCIES/generic/include/boost/property_map/property_map.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
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@101 17 #include <cstddef>
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 template <class T>
Chris@16 96 struct property_traits<T*> {
Chris@16 97 // BOOST_STATIC_ASSERT(boost::is_same<T, T*>::value && !"Using pointers as property maps is deprecated");
Chris@16 98 typedef T value_type;
Chris@16 99 typedef value_type& reference;
Chris@16 100 typedef std::ptrdiff_t key_type;
Chris@16 101 typedef lvalue_property_map_tag category;
Chris@16 102 };
Chris@16 103 template <class T>
Chris@16 104 struct property_traits<const T*> {
Chris@16 105 // BOOST_STATIC_ASSERT(boost::is_same<T, T*>::value && !"Using pointers as property maps is deprecated");
Chris@16 106 typedef T value_type;
Chris@16 107 typedef const value_type& reference;
Chris@16 108 typedef std::ptrdiff_t key_type;
Chris@16 109 typedef lvalue_property_map_tag category;
Chris@16 110 };
Chris@16 111
Chris@16 112 #if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
Chris@16 113 // MSVC doesn't have Koenig lookup, so the user has to
Chris@16 114 // do boost::get() anyways, and the using clause
Chris@16 115 // doesn't really work for MSVC.
Chris@16 116 } // namespace boost
Chris@16 117 #endif
Chris@16 118
Chris@16 119 // These need to go in global namespace because Koenig
Chris@16 120 // lookup does not apply to T*.
Chris@16 121
Chris@16 122 // V must be convertible to T
Chris@16 123 template <class T, class V>
Chris@16 124 inline void put(T* pa, std::ptrdiff_t k, const V& val) { pa[k] = val; }
Chris@16 125
Chris@16 126 template <class T>
Chris@16 127 inline const T& get(const T* pa, std::ptrdiff_t k) { return pa[k]; }
Chris@16 128
Chris@16 129 #if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
Chris@16 130 namespace boost {
Chris@16 131 using ::put;
Chris@16 132 using ::get;
Chris@16 133 #endif
Chris@16 134
Chris@16 135 //=========================================================================
Chris@16 136 // concept checks for property maps
Chris@16 137
Chris@16 138 template <class PMap, class Key>
Chris@16 139 struct ReadablePropertyMapConcept
Chris@16 140 {
Chris@16 141 typedef typename property_traits<PMap>::key_type key_type;
Chris@16 142 typedef typename property_traits<PMap>::reference reference;
Chris@16 143 typedef typename property_traits<PMap>::category Category;
Chris@16 144 typedef boost::readable_property_map_tag ReadableTag;
Chris@16 145 void constraints() {
Chris@16 146 function_requires< ConvertibleConcept<Category, ReadableTag> >();
Chris@16 147
Chris@16 148 val = get(pmap, k);
Chris@16 149 }
Chris@16 150 PMap pmap;
Chris@16 151 Key k;
Chris@16 152 typename property_traits<PMap>::value_type val;
Chris@16 153 };
Chris@16 154 template <typename KeyArchetype, typename ValueArchetype>
Chris@16 155 struct readable_property_map_archetype {
Chris@16 156 typedef KeyArchetype key_type;
Chris@16 157 typedef ValueArchetype value_type;
Chris@16 158 typedef convertible_to_archetype<ValueArchetype> reference;
Chris@16 159 typedef readable_property_map_tag category;
Chris@16 160 };
Chris@16 161 template <typename K, typename V>
Chris@16 162 const typename readable_property_map_archetype<K,V>::reference&
Chris@16 163 get(const readable_property_map_archetype<K,V>&,
Chris@16 164 const typename readable_property_map_archetype<K,V>::key_type&)
Chris@16 165 {
Chris@16 166 typedef typename readable_property_map_archetype<K,V>::reference R;
Chris@16 167 return static_object<R>::get();
Chris@16 168 }
Chris@16 169
Chris@16 170
Chris@16 171 template <class PMap, class Key>
Chris@16 172 struct WritablePropertyMapConcept
Chris@16 173 {
Chris@16 174 typedef typename property_traits<PMap>::key_type key_type;
Chris@16 175 typedef typename property_traits<PMap>::category Category;
Chris@16 176 typedef boost::writable_property_map_tag WritableTag;
Chris@16 177 void constraints() {
Chris@16 178 function_requires< ConvertibleConcept<Category, WritableTag> >();
Chris@16 179 put(pmap, k, val);
Chris@16 180 }
Chris@16 181 PMap pmap;
Chris@16 182 Key k;
Chris@16 183 typename property_traits<PMap>::value_type val;
Chris@16 184 };
Chris@16 185 template <typename KeyArchetype, typename ValueArchetype>
Chris@16 186 struct writable_property_map_archetype {
Chris@16 187 typedef KeyArchetype key_type;
Chris@16 188 typedef ValueArchetype value_type;
Chris@16 189 typedef void reference;
Chris@16 190 typedef writable_property_map_tag category;
Chris@16 191 };
Chris@16 192 template <typename K, typename V>
Chris@16 193 void put(const writable_property_map_archetype<K,V>&,
Chris@16 194 const typename writable_property_map_archetype<K,V>::key_type&,
Chris@16 195 const typename writable_property_map_archetype<K,V>::value_type&) { }
Chris@16 196
Chris@16 197
Chris@16 198 template <class PMap, class Key>
Chris@16 199 struct ReadWritePropertyMapConcept
Chris@16 200 {
Chris@16 201 typedef typename property_traits<PMap>::category Category;
Chris@16 202 typedef boost::read_write_property_map_tag ReadWriteTag;
Chris@16 203 void constraints() {
Chris@16 204 function_requires< ReadablePropertyMapConcept<PMap, Key> >();
Chris@16 205 function_requires< WritablePropertyMapConcept<PMap, Key> >();
Chris@16 206 function_requires< ConvertibleConcept<Category, ReadWriteTag> >();
Chris@16 207 }
Chris@16 208 };
Chris@16 209 template <typename KeyArchetype, typename ValueArchetype>
Chris@16 210 struct read_write_property_map_archetype
Chris@16 211 : public readable_property_map_archetype<KeyArchetype, ValueArchetype>,
Chris@16 212 public writable_property_map_archetype<KeyArchetype, ValueArchetype>
Chris@16 213 {
Chris@16 214 typedef KeyArchetype key_type;
Chris@16 215 typedef ValueArchetype value_type;
Chris@16 216 typedef convertible_to_archetype<ValueArchetype> reference;
Chris@16 217 typedef read_write_property_map_tag category;
Chris@16 218 };
Chris@16 219
Chris@16 220
Chris@16 221 template <class PMap, class Key>
Chris@16 222 struct LvaluePropertyMapConcept
Chris@16 223 {
Chris@16 224 typedef typename property_traits<PMap>::category Category;
Chris@16 225 typedef boost::lvalue_property_map_tag LvalueTag;
Chris@16 226 typedef typename property_traits<PMap>::reference reference;
Chris@16 227
Chris@16 228 void constraints() {
Chris@16 229 function_requires< ReadablePropertyMapConcept<PMap, Key> >();
Chris@16 230 function_requires< ConvertibleConcept<Category, LvalueTag> >();
Chris@16 231
Chris@16 232 typedef typename property_traits<PMap>::value_type value_type;
Chris@16 233 BOOST_MPL_ASSERT((boost::mpl::or_<
Chris@16 234 boost::is_same<const value_type&, reference>,
Chris@16 235 boost::is_same<value_type&, reference> >));
Chris@16 236
Chris@16 237 reference ref = pmap[k];
Chris@16 238 ignore_unused_variable_warning(ref);
Chris@16 239 }
Chris@16 240 PMap pmap;
Chris@16 241 Key k;
Chris@16 242 };
Chris@16 243 template <typename KeyArchetype, typename ValueArchetype>
Chris@16 244 struct lvalue_property_map_archetype
Chris@16 245 : public readable_property_map_archetype<KeyArchetype, ValueArchetype>
Chris@16 246 {
Chris@16 247 typedef KeyArchetype key_type;
Chris@16 248 typedef ValueArchetype value_type;
Chris@16 249 typedef const ValueArchetype& reference;
Chris@16 250 typedef lvalue_property_map_tag category;
Chris@16 251 const value_type& operator[](const key_type&) const {
Chris@16 252 return static_object<value_type>::get();
Chris@16 253 }
Chris@16 254 };
Chris@16 255
Chris@16 256 template <class PMap, class Key>
Chris@16 257 struct Mutable_LvaluePropertyMapConcept
Chris@16 258 {
Chris@16 259 typedef typename property_traits<PMap>::category Category;
Chris@16 260 typedef boost::lvalue_property_map_tag LvalueTag;
Chris@16 261 typedef typename property_traits<PMap>::reference reference;
Chris@16 262 void constraints() {
Chris@16 263 boost::function_requires< ReadWritePropertyMapConcept<PMap, Key> >();
Chris@16 264 boost::function_requires<ConvertibleConcept<Category, LvalueTag> >();
Chris@16 265
Chris@16 266 typedef typename property_traits<PMap>::value_type value_type;
Chris@16 267 BOOST_MPL_ASSERT((boost::is_same<value_type&, reference>));
Chris@16 268
Chris@16 269 reference ref = pmap[k];
Chris@16 270 ignore_unused_variable_warning(ref);
Chris@16 271 }
Chris@16 272 PMap pmap;
Chris@16 273 Key k;
Chris@16 274 };
Chris@16 275 template <typename KeyArchetype, typename ValueArchetype>
Chris@16 276 struct mutable_lvalue_property_map_archetype
Chris@16 277 : public readable_property_map_archetype<KeyArchetype, ValueArchetype>,
Chris@16 278 public writable_property_map_archetype<KeyArchetype, ValueArchetype>
Chris@16 279 {
Chris@16 280 typedef KeyArchetype key_type;
Chris@16 281 typedef ValueArchetype value_type;
Chris@16 282 typedef ValueArchetype& reference;
Chris@16 283 typedef lvalue_property_map_tag category;
Chris@16 284 value_type& operator[](const key_type&) const {
Chris@16 285 return static_object<value_type>::get();
Chris@16 286 }
Chris@16 287 };
Chris@16 288
Chris@16 289 template <typename T>
Chris@16 290 struct typed_identity_property_map;
Chris@16 291
Chris@16 292 // A helper class for constructing a property map
Chris@16 293 // from a class that implements operator[]
Chris@16 294
Chris@16 295 template <class Reference, class LvaluePropertyMap>
Chris@16 296 struct put_get_helper { };
Chris@16 297
Chris@16 298 template <class PropertyMap, class Reference, class K>
Chris@16 299 inline Reference
Chris@16 300 get(const put_get_helper<Reference, PropertyMap>& pa, const K& k)
Chris@16 301 {
Chris@16 302 Reference v = static_cast<const PropertyMap&>(pa)[k];
Chris@16 303 return v;
Chris@16 304 }
Chris@16 305 template <class PropertyMap, class Reference, class K, class V>
Chris@16 306 inline void
Chris@16 307 put(const put_get_helper<Reference, PropertyMap>& pa, K k, const V& v)
Chris@16 308 {
Chris@16 309 static_cast<const PropertyMap&>(pa)[k] = v;
Chris@16 310 }
Chris@16 311
Chris@16 312 //=========================================================================
Chris@16 313 // Adapter to turn a RandomAccessIterator into a property map
Chris@16 314
Chris@16 315 template <class RandomAccessIterator,
Chris@16 316 class IndexMap
Chris@16 317 #ifdef BOOST_NO_STD_ITERATOR_TRAITS
Chris@16 318 , class T, class R
Chris@16 319 #else
Chris@16 320 , class T = typename std::iterator_traits<RandomAccessIterator>::value_type
Chris@16 321 , class R = typename std::iterator_traits<RandomAccessIterator>::reference
Chris@16 322 #endif
Chris@16 323 >
Chris@16 324 class iterator_property_map
Chris@16 325 : public boost::put_get_helper< R,
Chris@16 326 iterator_property_map<RandomAccessIterator, IndexMap,
Chris@16 327 T, R> >
Chris@16 328 {
Chris@16 329 public:
Chris@16 330 typedef typename property_traits<IndexMap>::key_type key_type;
Chris@16 331 typedef T value_type;
Chris@16 332 typedef R reference;
Chris@16 333 typedef boost::lvalue_property_map_tag category;
Chris@16 334
Chris@16 335 inline iterator_property_map(
Chris@16 336 RandomAccessIterator cc = RandomAccessIterator(),
Chris@16 337 const IndexMap& _id = IndexMap() )
Chris@16 338 : iter(cc), index(_id) { }
Chris@16 339 inline R operator[](key_type v) const { return *(iter + get(index, v)) ; }
Chris@16 340 protected:
Chris@16 341 RandomAccessIterator iter;
Chris@16 342 IndexMap index;
Chris@16 343 };
Chris@16 344
Chris@16 345 #if !defined BOOST_NO_STD_ITERATOR_TRAITS
Chris@16 346 template <class RAIter, class ID>
Chris@16 347 inline iterator_property_map<
Chris@16 348 RAIter, ID,
Chris@16 349 typename std::iterator_traits<RAIter>::value_type,
Chris@16 350 typename std::iterator_traits<RAIter>::reference>
Chris@16 351 make_iterator_property_map(RAIter iter, ID id) {
Chris@16 352 function_requires< RandomAccessIteratorConcept<RAIter> >();
Chris@16 353 typedef iterator_property_map<
Chris@16 354 RAIter, ID,
Chris@16 355 typename std::iterator_traits<RAIter>::value_type,
Chris@16 356 typename std::iterator_traits<RAIter>::reference> PA;
Chris@16 357 return PA(iter, id);
Chris@16 358 }
Chris@16 359 #endif
Chris@16 360 template <class RAIter, class Value, class ID>
Chris@16 361 inline iterator_property_map<RAIter, ID, Value, Value&>
Chris@16 362 make_iterator_property_map(RAIter iter, ID id, Value) {
Chris@16 363 function_requires< RandomAccessIteratorConcept<RAIter> >();
Chris@16 364 typedef iterator_property_map<RAIter, ID, Value, Value&> PMap;
Chris@16 365 return PMap(iter, id);
Chris@16 366 }
Chris@16 367
Chris@16 368 template <class RandomAccessIterator,
Chris@16 369 class IndexMap
Chris@16 370 #ifdef BOOST_NO_STD_ITERATOR_TRAITS
Chris@16 371 , class T, class R
Chris@16 372 #else
Chris@16 373 , class T = typename std::iterator_traits<RandomAccessIterator>::value_type
Chris@16 374 , class R = typename std::iterator_traits<RandomAccessIterator>::reference
Chris@16 375 #endif
Chris@16 376 >
Chris@16 377 class safe_iterator_property_map
Chris@16 378 : public boost::put_get_helper< R,
Chris@16 379 safe_iterator_property_map<RandomAccessIterator, IndexMap,
Chris@16 380 T, R> >
Chris@16 381 {
Chris@16 382 public:
Chris@16 383 typedef typename property_traits<IndexMap>::key_type key_type;
Chris@16 384 typedef T value_type;
Chris@16 385 typedef R reference;
Chris@16 386 typedef boost::lvalue_property_map_tag category;
Chris@16 387
Chris@16 388 inline safe_iterator_property_map(
Chris@16 389 RandomAccessIterator first,
Chris@16 390 std::size_t n_ = 0,
Chris@16 391 const IndexMap& _id = IndexMap() )
Chris@16 392 : iter(first), n(n_), index(_id) { }
Chris@16 393 inline safe_iterator_property_map() { }
Chris@16 394 inline R operator[](key_type v) const {
Chris@16 395 BOOST_ASSERT(get(index, v) < n);
Chris@16 396 return *(iter + get(index, v)) ;
Chris@16 397 }
Chris@16 398 typename property_traits<IndexMap>::value_type size() const { return n; }
Chris@16 399 protected:
Chris@16 400 RandomAccessIterator iter;
Chris@16 401 typename property_traits<IndexMap>::value_type n;
Chris@16 402 IndexMap index;
Chris@16 403 };
Chris@16 404
Chris@16 405 template <class RAIter, class ID>
Chris@16 406 inline safe_iterator_property_map<
Chris@16 407 RAIter, ID,
Chris@16 408 typename boost::detail::iterator_traits<RAIter>::value_type,
Chris@16 409 typename boost::detail::iterator_traits<RAIter>::reference>
Chris@16 410 make_safe_iterator_property_map(RAIter iter, std::size_t n, ID id) {
Chris@16 411 function_requires< RandomAccessIteratorConcept<RAIter> >();
Chris@16 412 typedef safe_iterator_property_map<
Chris@16 413 RAIter, ID,
Chris@16 414 typename boost::detail::iterator_traits<RAIter>::value_type,
Chris@16 415 typename boost::detail::iterator_traits<RAIter>::reference> PA;
Chris@16 416 return PA(iter, n, id);
Chris@16 417 }
Chris@16 418 template <class RAIter, class Value, class ID>
Chris@16 419 inline safe_iterator_property_map<RAIter, ID, Value, Value&>
Chris@16 420 make_safe_iterator_property_map(RAIter iter, std::size_t n, ID id, Value) {
Chris@16 421 function_requires< RandomAccessIteratorConcept<RAIter> >();
Chris@16 422 typedef safe_iterator_property_map<RAIter, ID, Value, Value&> PMap;
Chris@16 423 return PMap(iter, n, id);
Chris@16 424 }
Chris@16 425
Chris@16 426 //=========================================================================
Chris@16 427 // An adaptor to turn a Unique Pair Associative Container like std::map or
Chris@16 428 // std::hash_map into an Lvalue Property Map.
Chris@16 429
Chris@16 430 template <typename UniquePairAssociativeContainer>
Chris@16 431 class associative_property_map
Chris@16 432 : public boost::put_get_helper<
Chris@16 433 typename UniquePairAssociativeContainer::value_type::second_type&,
Chris@16 434 associative_property_map<UniquePairAssociativeContainer> >
Chris@16 435 {
Chris@16 436 typedef UniquePairAssociativeContainer C;
Chris@16 437 public:
Chris@16 438 typedef typename C::key_type key_type;
Chris@16 439 typedef typename C::value_type::second_type value_type;
Chris@16 440 typedef value_type& reference;
Chris@16 441 typedef lvalue_property_map_tag category;
Chris@16 442 associative_property_map() : m_c(0) { }
Chris@16 443 associative_property_map(C& c) : m_c(&c) { }
Chris@16 444 reference operator[](const key_type& k) const {
Chris@16 445 return (*m_c)[k];
Chris@16 446 }
Chris@16 447 private:
Chris@16 448 C* m_c;
Chris@16 449 };
Chris@16 450
Chris@16 451 template <class UniquePairAssociativeContainer>
Chris@16 452 associative_property_map<UniquePairAssociativeContainer>
Chris@16 453 make_assoc_property_map(UniquePairAssociativeContainer& c)
Chris@16 454 {
Chris@16 455 return associative_property_map<UniquePairAssociativeContainer>(c);
Chris@16 456 }
Chris@16 457
Chris@16 458 template <typename UniquePairAssociativeContainer>
Chris@16 459 class const_associative_property_map
Chris@16 460 : public boost::put_get_helper<
Chris@16 461 const typename UniquePairAssociativeContainer::value_type::second_type&,
Chris@16 462 const_associative_property_map<UniquePairAssociativeContainer> >
Chris@16 463 {
Chris@16 464 typedef UniquePairAssociativeContainer C;
Chris@16 465 public:
Chris@16 466 typedef typename C::key_type key_type;
Chris@16 467 typedef typename C::value_type::second_type value_type;
Chris@16 468 typedef const value_type& reference;
Chris@16 469 typedef lvalue_property_map_tag category;
Chris@16 470 const_associative_property_map() : m_c(0) { }
Chris@16 471 const_associative_property_map(const C& c) : m_c(&c) { }
Chris@16 472 reference operator[](const key_type& k) const {
Chris@16 473 return m_c->find(k)->second;
Chris@16 474 }
Chris@16 475 private:
Chris@16 476 C const* m_c;
Chris@16 477 };
Chris@16 478
Chris@16 479 template <class UniquePairAssociativeContainer>
Chris@16 480 const_associative_property_map<UniquePairAssociativeContainer>
Chris@16 481 make_assoc_property_map(const UniquePairAssociativeContainer& c)
Chris@16 482 {
Chris@16 483 return const_associative_property_map<UniquePairAssociativeContainer>(c);
Chris@16 484 }
Chris@16 485
Chris@16 486 //=========================================================================
Chris@16 487 // A property map that always returns the same object by value.
Chris@16 488 //
Chris@101 489 template <typename ValueType, typename KeyType = void>
Chris@16 490 class static_property_map :
Chris@16 491 public
Chris@16 492 boost::put_get_helper<ValueType,static_property_map<ValueType> >
Chris@16 493 {
Chris@16 494 ValueType value;
Chris@16 495 public:
Chris@101 496 typedef KeyType key_type;
Chris@16 497 typedef ValueType value_type;
Chris@16 498 typedef ValueType reference;
Chris@16 499 typedef readable_property_map_tag category;
Chris@16 500 static_property_map(ValueType v) : value(v) {}
Chris@16 501
Chris@16 502 template<typename T>
Chris@16 503 inline reference operator[](T) const { return value; }
Chris@16 504 };
Chris@16 505
Chris@101 506 template <typename KeyType, typename ValueType>
Chris@101 507 static_property_map<ValueType, KeyType>
Chris@101 508 make_static_property_map(const ValueType& v) {
Chris@101 509 return static_property_map<ValueType, KeyType>(v);
Chris@101 510 }
Chris@101 511
Chris@16 512 //=========================================================================
Chris@16 513 // A property map that always returns a reference to the same object.
Chris@16 514 //
Chris@16 515 template <typename KeyType, typename ValueType>
Chris@16 516 class ref_property_map :
Chris@16 517 public
Chris@16 518 boost::put_get_helper<ValueType&,ref_property_map<KeyType,ValueType> >
Chris@16 519 {
Chris@16 520 ValueType* value;
Chris@16 521 public:
Chris@16 522 typedef KeyType key_type;
Chris@16 523 typedef ValueType value_type;
Chris@16 524 typedef ValueType& reference;
Chris@16 525 typedef lvalue_property_map_tag category;
Chris@16 526 ref_property_map(ValueType& v) : value(&v) {}
Chris@16 527 ValueType& operator[](key_type const&) const { return *value; }
Chris@16 528 };
Chris@16 529
Chris@16 530 //=========================================================================
Chris@16 531 // A generalized identity property map
Chris@16 532 template <typename T>
Chris@16 533 struct typed_identity_property_map
Chris@16 534 : public boost::put_get_helper<T, typed_identity_property_map<T> >
Chris@16 535 {
Chris@16 536 typedef T key_type;
Chris@16 537 typedef T value_type;
Chris@16 538 typedef T reference;
Chris@16 539 typedef boost::readable_property_map_tag category;
Chris@16 540
Chris@16 541 inline value_type operator[](const key_type& v) const { return v; }
Chris@16 542 };
Chris@16 543
Chris@16 544 //=========================================================================
Chris@16 545 // A property map that applies the identity function to integers
Chris@16 546 typedef typed_identity_property_map<std::size_t> identity_property_map;
Chris@16 547
Chris@16 548 //=========================================================================
Chris@16 549 // A property map that does not do anything, for
Chris@16 550 // when you have to supply a property map, but don't need it.
Chris@16 551 namespace detail {
Chris@16 552 struct dummy_pmap_reference {
Chris@16 553 template <class T>
Chris@16 554 dummy_pmap_reference& operator=(const T&) { return *this; }
Chris@16 555 operator int() { return 0; }
Chris@16 556 };
Chris@16 557 }
Chris@16 558 class dummy_property_map
Chris@16 559 : public boost::put_get_helper<detail::dummy_pmap_reference,
Chris@16 560 dummy_property_map >
Chris@16 561 {
Chris@16 562 public:
Chris@16 563 typedef void key_type;
Chris@16 564 typedef int value_type;
Chris@16 565 typedef detail::dummy_pmap_reference reference;
Chris@16 566 typedef boost::read_write_property_map_tag category;
Chris@16 567 inline dummy_property_map() : c(0) { }
Chris@16 568 inline dummy_property_map(value_type cc) : c(cc) { }
Chris@16 569 inline dummy_property_map(const dummy_property_map& x)
Chris@16 570 : c(x.c) { }
Chris@16 571 template <class Vertex>
Chris@16 572 inline reference operator[](Vertex) const { return reference(); }
Chris@16 573 protected:
Chris@16 574 value_type c;
Chris@16 575 };
Chris@16 576
Chris@16 577 // Convert a Readable property map into a function object
Chris@16 578 template <typename PropMap>
Chris@16 579 class property_map_function {
Chris@16 580 PropMap pm;
Chris@16 581 typedef typename property_traits<PropMap>::key_type param_type;
Chris@16 582 public:
Chris@16 583 explicit property_map_function(const PropMap& pm): pm(pm) {}
Chris@16 584 typedef typename property_traits<PropMap>::value_type result_type;
Chris@16 585 result_type operator()(const param_type& k) const {return get(pm, k);}
Chris@16 586 };
Chris@16 587
Chris@16 588 template <typename PropMap>
Chris@16 589 property_map_function<PropMap>
Chris@16 590 make_property_map_function(const PropMap& pm) {
Chris@16 591 return property_map_function<PropMap>(pm);
Chris@16 592 }
Chris@16 593
Chris@16 594 } // namespace boost
Chris@16 595
Chris@16 596 #ifdef BOOST_GRAPH_USE_MPI
Chris@101 597 #include <boost/property_map/parallel/parallel_property_maps.hpp>
Chris@101 598 #endif
Chris@16 599
Chris@16 600 #include <boost/property_map/vector_property_map.hpp>
Chris@16 601
Chris@16 602 #endif /* BOOST_PROPERTY_MAP_HPP */
Chris@16 603