Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
1 // (C) Copyright Jeremy Siek 1999-2001.
2 // Distributed under the Boost Software License, Version 1.0. (See
3 // accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
6 // See http://www.boost.org/libs/property_map for documentation.
8 #ifndef BOOST_PROPERTY_MAP_HPP
9 #define BOOST_PROPERTY_MAP_HPP
12 #include <boost/config.hpp>
13 #include <boost/pending/cstddef.hpp>
14 #include <boost/detail/iterator.hpp>
15 #include <boost/concept_check.hpp>
16 #include <boost/concept_archetype.hpp>
20 //=========================================================================
21 // property_traits class
23 template <typename PA>
24 struct property_traits {
25 typedef typename PA::key_type key_type;
26 typedef typename PA::value_type value_type;
27 typedef typename PA::reference reference;
28 typedef typename PA::category category;
31 //=========================================================================
32 // property_traits category tags
35 enum ePropertyMapID { READABLE_PA, WRITABLE_PA,
36 READ_WRITE_PA, LVALUE_PA, OP_BRACKET_PA,
37 RAND_ACCESS_ITER_PA, LAST_PA };
39 struct readable_property_map_tag { enum { id = detail::READABLE_PA }; };
40 struct writable_property_map_tag { enum { id = detail::WRITABLE_PA }; };
41 struct read_write_property_map_tag :
42 public readable_property_map_tag,
43 public writable_property_map_tag
44 { enum { id = detail::READ_WRITE_PA }; };
46 struct lvalue_property_map_tag : public read_write_property_map_tag
47 { enum { id = detail::LVALUE_PA }; };
49 //=========================================================================
50 // property_traits specialization for pointers
52 #ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
53 // The user will just have to create their own specializations for
54 // other pointers types if the compiler does not have partial
55 // specializations. Sorry!
56 #define BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(TYPE) \
58 struct property_traits<TYPE*> { \
59 typedef TYPE value_type; \
60 typedef value_type& reference; \
61 typedef std::ptrdiff_t key_type; \
62 typedef lvalue_property_map_tag category; \
65 struct property_traits<const TYPE*> { \
66 typedef TYPE value_type; \
67 typedef const value_type& reference; \
68 typedef std::ptrdiff_t key_type; \
69 typedef lvalue_property_map_tag category; \
72 BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(long);
73 BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(unsigned long);
74 BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(int);
75 BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(unsigned int);
76 BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(short);
77 BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(unsigned short);
78 BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(char);
79 BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(unsigned char);
80 BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(signed char);
81 BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(bool);
82 BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(float);
83 BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(double);
84 BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(long double);
86 // This may need to be turned off for some older compilers that don't have
87 // wchar_t intrinsically.
88 # ifndef BOOST_NO_INTRINSIC_WCHAR_T
90 struct property_traits<wchar_t*> {
91 typedef wchar_t value_type;
92 typedef value_type& reference;
93 typedef std::ptrdiff_t key_type;
94 typedef lvalue_property_map_tag category;
97 struct property_traits<const wchar_t*> {
98 typedef wchar_t value_type;
99 typedef const value_type& reference;
100 typedef std::ptrdiff_t key_type;
101 typedef lvalue_property_map_tag category;
107 struct property_traits<T*> {
108 typedef T value_type;
109 typedef value_type& reference;
110 typedef std::ptrdiff_t key_type;
111 typedef lvalue_property_map_tag category;
114 struct property_traits<const T*> {
115 typedef T value_type;
116 typedef const value_type& reference;
117 typedef std::ptrdiff_t key_type;
118 typedef lvalue_property_map_tag category;
122 #if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
123 // MSVC doesn't have Koenig lookup, so the user has to
124 // do boost::get() anyways, and the using clause
125 // doesn't really work for MSVC.
129 // These need to go in global namespace because Koenig
130 // lookup does not apply to T*.
132 // V must be convertible to T
133 template <class T, class V>
134 inline void put(T* pa, std::ptrdiff_t k, const V& val) { pa[k] = val; }
137 inline const T& get(const T* pa, std::ptrdiff_t k) { return pa[k]; }
139 #if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
145 //=========================================================================
146 // concept checks for property maps
148 template <class PMap, class Key>
149 struct ReadablePropertyMapConcept
151 typedef typename property_traits<PMap>::key_type key_type;
152 typedef typename property_traits<PMap>::reference reference;
153 typedef typename property_traits<PMap>::category Category;
154 typedef boost::readable_property_map_tag ReadableTag;
156 function_requires< ConvertibleConcept<Category, ReadableTag> >();
162 typename property_traits<PMap>::value_type val;
164 template <typename KeyArchetype, typename ValueArchetype>
165 struct readable_property_map_archetype {
166 typedef KeyArchetype key_type;
167 typedef ValueArchetype value_type;
168 typedef convertible_to_archetype<ValueArchetype> reference;
169 typedef readable_property_map_tag category;
171 template <typename K, typename V>
172 const typename readable_property_map_archetype<K,V>::reference&
173 get(const readable_property_map_archetype<K,V>&,
174 const typename readable_property_map_archetype<K,V>::key_type&)
176 typedef typename readable_property_map_archetype<K,V>::reference R;
177 return static_object<R>::get();
181 template <class PMap, class Key>
182 struct WritablePropertyMapConcept
184 typedef typename property_traits<PMap>::key_type key_type;
185 typedef typename property_traits<PMap>::category Category;
186 typedef boost::writable_property_map_tag WritableTag;
188 function_requires< ConvertibleConcept<Category, WritableTag> >();
193 typename property_traits<PMap>::value_type val;
195 template <typename KeyArchetype, typename ValueArchetype>
196 struct writable_property_map_archetype {
197 typedef KeyArchetype key_type;
198 typedef ValueArchetype value_type;
199 typedef void reference;
200 typedef writable_property_map_tag category;
202 template <typename K, typename V>
203 void put(const writable_property_map_archetype<K,V>&,
204 const typename writable_property_map_archetype<K,V>::key_type&,
205 const typename writable_property_map_archetype<K,V>::value_type&) { }
208 template <class PMap, class Key>
209 struct ReadWritePropertyMapConcept
211 typedef typename property_traits<PMap>::category Category;
212 typedef boost::read_write_property_map_tag ReadWriteTag;
214 function_requires< ReadablePropertyMapConcept<PMap, Key> >();
215 function_requires< WritablePropertyMapConcept<PMap, Key> >();
216 function_requires< ConvertibleConcept<Category, ReadWriteTag> >();
219 template <typename KeyArchetype, typename ValueArchetype>
220 struct read_write_property_map_archetype
221 : public readable_property_map_archetype<KeyArchetype, ValueArchetype>,
222 public writable_property_map_archetype<KeyArchetype, ValueArchetype>
224 typedef KeyArchetype key_type;
225 typedef ValueArchetype value_type;
226 typedef convertible_to_archetype<ValueArchetype> reference;
227 typedef read_write_property_map_tag category;
231 template <class PMap, class Key>
232 struct LvaluePropertyMapConcept
234 typedef typename property_traits<PMap>::category Category;
235 typedef boost::lvalue_property_map_tag LvalueTag;
236 typedef typename property_traits<PMap>::reference reference;
239 function_requires< ReadablePropertyMapConcept<PMap, Key> >();
240 function_requires< ConvertibleConcept<Category, LvalueTag> >();
242 typedef typename property_traits<PMap>::value_type value_type;
243 typedef typename require_same<
244 const value_type&, reference>::type req;
246 reference ref = pmap[k];
247 ignore_unused_variable_warning(ref);
252 template <typename KeyArchetype, typename ValueArchetype>
253 struct lvalue_property_map_archetype
254 : public readable_property_map_archetype<KeyArchetype, ValueArchetype>
256 typedef KeyArchetype key_type;
257 typedef ValueArchetype value_type;
258 typedef const ValueArchetype& reference;
259 typedef lvalue_property_map_tag category;
260 const value_type& operator[](const key_type&) const {
261 return static_object<value_type>::get();
265 template <class PMap, class Key>
266 struct Mutable_LvaluePropertyMapConcept
268 typedef typename property_traits<PMap>::category Category;
269 typedef boost::lvalue_property_map_tag LvalueTag;
270 typedef typename property_traits<PMap>::reference reference;
272 boost::function_requires< ReadWritePropertyMapConcept<PMap, Key> >();
273 boost::function_requires<ConvertibleConcept<Category, LvalueTag> >();
275 typedef typename property_traits<PMap>::value_type value_type;
276 typedef typename require_same<
278 reference>::type req;
280 reference ref = pmap[k];
281 ignore_unused_variable_warning(ref);
286 template <typename KeyArchetype, typename ValueArchetype>
287 struct mutable_lvalue_property_map_archetype
288 : public readable_property_map_archetype<KeyArchetype, ValueArchetype>,
289 public writable_property_map_archetype<KeyArchetype, ValueArchetype>
291 typedef KeyArchetype key_type;
292 typedef ValueArchetype value_type;
293 typedef ValueArchetype& reference;
294 typedef lvalue_property_map_tag category;
295 value_type& operator[](const key_type&) const {
296 return static_object<value_type>::get();
300 struct identity_property_map;
302 // A helper class for constructing a property map
303 // from a class that implements operator[]
305 template <class Reference, class LvaluePropertyMap>
306 struct put_get_helper { };
308 template <class PropertyMap, class Reference, class K>
310 get(const put_get_helper<Reference, PropertyMap>& pa, const K& k)
312 Reference v = static_cast<const PropertyMap&>(pa)[k];
315 template <class PropertyMap, class Reference, class K, class V>
317 put(const put_get_helper<Reference, PropertyMap>& pa, K k, const V& v)
319 static_cast<const PropertyMap&>(pa)[k] = v;
322 //=========================================================================
323 // Adapter to turn a RandomAccessIterator into a property map
325 template <class RandomAccessIterator,
327 #ifdef BOOST_NO_STD_ITERATOR_TRAITS
330 , class T = typename std::iterator_traits<RandomAccessIterator>::value_type
331 , class R = typename std::iterator_traits<RandomAccessIterator>::reference
334 class iterator_property_map
335 : public boost::put_get_helper< R,
336 iterator_property_map<RandomAccessIterator, IndexMap,
340 typedef typename property_traits<IndexMap>::key_type key_type;
341 typedef T value_type;
343 typedef boost::lvalue_property_map_tag category;
345 inline iterator_property_map(
346 RandomAccessIterator cc = RandomAccessIterator(),
347 const IndexMap& _id = IndexMap() )
348 : iter(cc), index(_id) { }
349 inline R operator[](key_type v) const { return *(iter + get(index, v)) ; }
351 RandomAccessIterator iter;
355 #if !defined BOOST_NO_STD_ITERATOR_TRAITS
356 template <class RAIter, class ID>
357 inline iterator_property_map<
359 typename std::iterator_traits<RAIter>::value_type,
360 typename std::iterator_traits<RAIter>::reference>
361 make_iterator_property_map(RAIter iter, ID id) {
362 function_requires< RandomAccessIteratorConcept<RAIter> >();
363 typedef iterator_property_map<
365 typename std::iterator_traits<RAIter>::value_type,
366 typename std::iterator_traits<RAIter>::reference> PA;
370 template <class RAIter, class Value, class ID>
371 inline iterator_property_map<RAIter, ID, Value, Value&>
372 make_iterator_property_map(RAIter iter, ID id, Value) {
373 function_requires< RandomAccessIteratorConcept<RAIter> >();
374 typedef iterator_property_map<RAIter, ID, Value, Value&> PMap;
375 return PMap(iter, id);
378 template <class RandomAccessIterator,
380 #ifdef BOOST_NO_STD_ITERATOR_TRAITS
383 , class T = typename std::iterator_traits<RandomAccessIterator>::value_type
384 , class R = typename std::iterator_traits<RandomAccessIterator>::reference
387 class safe_iterator_property_map
388 : public boost::put_get_helper< R,
389 safe_iterator_property_map<RandomAccessIterator, IndexMap,
393 typedef typename property_traits<IndexMap>::key_type key_type;
394 typedef T value_type;
396 typedef boost::lvalue_property_map_tag category;
398 inline safe_iterator_property_map(
399 RandomAccessIterator first,
401 const IndexMap& _id = IndexMap() )
402 : iter(first), n(n_), index(_id) { }
403 inline safe_iterator_property_map() { }
404 inline R operator[](key_type v) const {
405 assert(get(index, v) < n);
406 return *(iter + get(index, v)) ;
408 typename property_traits<IndexMap>::value_type size() const { return n; }
410 RandomAccessIterator iter;
411 typename property_traits<IndexMap>::value_type n;
415 #if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
416 template <class RAIter, class ID>
417 inline safe_iterator_property_map<
419 typename boost::detail::iterator_traits<RAIter>::value_type,
420 typename boost::detail::iterator_traits<RAIter>::reference>
421 make_safe_iterator_property_map(RAIter iter, std::size_t n, ID id) {
422 function_requires< RandomAccessIteratorConcept<RAIter> >();
423 typedef safe_iterator_property_map<
425 typename boost::detail::iterator_traits<RAIter>::value_type,
426 typename boost::detail::iterator_traits<RAIter>::reference> PA;
427 return PA(iter, n, id);
430 template <class RAIter, class Value, class ID>
431 inline safe_iterator_property_map<RAIter, ID, Value, Value&>
432 make_safe_iterator_property_map(RAIter iter, std::size_t n, ID id, Value) {
433 function_requires< RandomAccessIteratorConcept<RAIter> >();
434 typedef safe_iterator_property_map<RAIter, ID, Value, Value&> PMap;
435 return PMap(iter, n, id);
438 //=========================================================================
439 // An adaptor to turn a Unique Pair Associative Container like std::map or
440 // std::hash_map into an Lvalue Property Map.
442 template <typename UniquePairAssociativeContainer>
443 class associative_property_map
444 : public boost::put_get_helper<
445 typename UniquePairAssociativeContainer::value_type::second_type&,
446 associative_property_map<UniquePairAssociativeContainer> >
448 typedef UniquePairAssociativeContainer C;
450 typedef typename C::key_type key_type;
451 typedef typename C::value_type::second_type value_type;
452 typedef value_type& reference;
453 typedef lvalue_property_map_tag category;
454 associative_property_map() : m_c(0) { }
455 associative_property_map(C& c) : m_c(&c) { }
456 reference operator[](const key_type& k) const {
463 template <class UniquePairAssociativeContainer>
464 associative_property_map<UniquePairAssociativeContainer>
465 make_assoc_property_map(UniquePairAssociativeContainer& c)
467 return associative_property_map<UniquePairAssociativeContainer>(c);
470 template <typename UniquePairAssociativeContainer>
471 class const_associative_property_map
472 : public boost::put_get_helper<
473 const typename UniquePairAssociativeContainer::value_type::second_type&,
474 const_associative_property_map<UniquePairAssociativeContainer> >
476 typedef UniquePairAssociativeContainer C;
478 typedef typename C::key_type key_type;
479 typedef typename C::value_type::second_type value_type;
480 typedef const value_type& reference;
481 typedef lvalue_property_map_tag category;
482 const_associative_property_map() : m_c(0) { }
483 const_associative_property_map(const C& c) : m_c(&c) { }
484 reference operator[](const key_type& k) const {
485 return m_c->find(k)->second;
491 template <class UniquePairAssociativeContainer>
492 const_associative_property_map<UniquePairAssociativeContainer>
493 make_assoc_property_map(const UniquePairAssociativeContainer& c)
495 return const_associative_property_map<UniquePairAssociativeContainer>(c);
498 //=========================================================================
499 // A property map that applies the identity function to integers
500 struct identity_property_map
501 : public boost::put_get_helper<std::size_t,
502 identity_property_map>
504 typedef std::size_t key_type;
505 typedef std::size_t value_type;
506 typedef std::size_t reference;
507 typedef boost::readable_property_map_tag category;
509 inline value_type operator[](const key_type& v) const { return v; }
512 //=========================================================================
513 // A property map that does not do anything, for
514 // when you have to supply a property map, but don't need it.
516 struct dummy_pmap_reference {
518 dummy_pmap_reference& operator=(const T&) { return *this; }
519 operator int() { return 0; }
522 class dummy_property_map
523 : public boost::put_get_helper<detail::dummy_pmap_reference,
527 typedef void key_type;
528 typedef int value_type;
529 typedef detail::dummy_pmap_reference reference;
530 typedef boost::read_write_property_map_tag category;
531 inline dummy_property_map() : c(0) { }
532 inline dummy_property_map(value_type cc) : c(cc) { }
533 inline dummy_property_map(const dummy_property_map& x)
535 template <class Vertex>
536 inline reference operator[](Vertex) const { return reference(); }
545 #endif /* BOOST_PROPERTY_MAP_HPP */