1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/stdapis/boost/property_map.hpp Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -0,0 +1,546 @@
1.4 +// (C) Copyright Jeremy Siek 1999-2001.
1.5 +// Distributed under the Boost Software License, Version 1.0. (See
1.6 +// accompanying file LICENSE_1_0.txt or copy at
1.7 +// http://www.boost.org/LICENSE_1_0.txt)
1.8 +
1.9 +// See http://www.boost.org/libs/property_map for documentation.
1.10 +
1.11 +#ifndef BOOST_PROPERTY_MAP_HPP
1.12 +#define BOOST_PROPERTY_MAP_HPP
1.13 +
1.14 +#include <cassert>
1.15 +#include <boost/config.hpp>
1.16 +#include <boost/pending/cstddef.hpp>
1.17 +#include <boost/detail/iterator.hpp>
1.18 +#include <boost/concept_check.hpp>
1.19 +#include <boost/concept_archetype.hpp>
1.20 +
1.21 +namespace boost {
1.22 +
1.23 + //=========================================================================
1.24 + // property_traits class
1.25 +
1.26 + template <typename PA>
1.27 + struct property_traits {
1.28 + typedef typename PA::key_type key_type;
1.29 + typedef typename PA::value_type value_type;
1.30 + typedef typename PA::reference reference;
1.31 + typedef typename PA::category category;
1.32 + };
1.33 +
1.34 + //=========================================================================
1.35 + // property_traits category tags
1.36 +
1.37 + namespace detail {
1.38 + enum ePropertyMapID { READABLE_PA, WRITABLE_PA,
1.39 + READ_WRITE_PA, LVALUE_PA, OP_BRACKET_PA,
1.40 + RAND_ACCESS_ITER_PA, LAST_PA };
1.41 + }
1.42 + struct readable_property_map_tag { enum { id = detail::READABLE_PA }; };
1.43 + struct writable_property_map_tag { enum { id = detail::WRITABLE_PA }; };
1.44 + struct read_write_property_map_tag :
1.45 + public readable_property_map_tag,
1.46 + public writable_property_map_tag
1.47 + { enum { id = detail::READ_WRITE_PA }; };
1.48 +
1.49 + struct lvalue_property_map_tag : public read_write_property_map_tag
1.50 + { enum { id = detail::LVALUE_PA }; };
1.51 +
1.52 + //=========================================================================
1.53 + // property_traits specialization for pointers
1.54 +
1.55 +#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
1.56 + // The user will just have to create their own specializations for
1.57 + // other pointers types if the compiler does not have partial
1.58 + // specializations. Sorry!
1.59 +#define BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(TYPE) \
1.60 + template <> \
1.61 + struct property_traits<TYPE*> { \
1.62 + typedef TYPE value_type; \
1.63 + typedef value_type& reference; \
1.64 + typedef std::ptrdiff_t key_type; \
1.65 + typedef lvalue_property_map_tag category; \
1.66 + }; \
1.67 + template <> \
1.68 + struct property_traits<const TYPE*> { \
1.69 + typedef TYPE value_type; \
1.70 + typedef const value_type& reference; \
1.71 + typedef std::ptrdiff_t key_type; \
1.72 + typedef lvalue_property_map_tag category; \
1.73 + }
1.74 +
1.75 + BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(long);
1.76 + BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(unsigned long);
1.77 + BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(int);
1.78 + BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(unsigned int);
1.79 + BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(short);
1.80 + BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(unsigned short);
1.81 + BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(char);
1.82 + BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(unsigned char);
1.83 + BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(signed char);
1.84 + BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(bool);
1.85 + BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(float);
1.86 + BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(double);
1.87 + BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(long double);
1.88 +
1.89 + // This may need to be turned off for some older compilers that don't have
1.90 + // wchar_t intrinsically.
1.91 +# ifndef BOOST_NO_INTRINSIC_WCHAR_T
1.92 + template <>
1.93 + struct property_traits<wchar_t*> {
1.94 + typedef wchar_t value_type;
1.95 + typedef value_type& reference;
1.96 + typedef std::ptrdiff_t key_type;
1.97 + typedef lvalue_property_map_tag category;
1.98 + };
1.99 + template <>
1.100 + struct property_traits<const wchar_t*> {
1.101 + typedef wchar_t value_type;
1.102 + typedef const value_type& reference;
1.103 + typedef std::ptrdiff_t key_type;
1.104 + typedef lvalue_property_map_tag category;
1.105 + };
1.106 +# endif
1.107 +
1.108 +#else
1.109 + template <class T>
1.110 + struct property_traits<T*> {
1.111 + typedef T value_type;
1.112 + typedef value_type& reference;
1.113 + typedef std::ptrdiff_t key_type;
1.114 + typedef lvalue_property_map_tag category;
1.115 + };
1.116 + template <class T>
1.117 + struct property_traits<const T*> {
1.118 + typedef T value_type;
1.119 + typedef const value_type& reference;
1.120 + typedef std::ptrdiff_t key_type;
1.121 + typedef lvalue_property_map_tag category;
1.122 + };
1.123 +#endif
1.124 +
1.125 +#if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
1.126 + // MSVC doesn't have Koenig lookup, so the user has to
1.127 + // do boost::get() anyways, and the using clause
1.128 + // doesn't really work for MSVC.
1.129 +} // namespace boost
1.130 +#endif
1.131 +
1.132 + // These need to go in global namespace because Koenig
1.133 + // lookup does not apply to T*.
1.134 +
1.135 + // V must be convertible to T
1.136 + template <class T, class V>
1.137 + inline void put(T* pa, std::ptrdiff_t k, const V& val) { pa[k] = val; }
1.138 +
1.139 + template <class T>
1.140 + inline const T& get(const T* pa, std::ptrdiff_t k) { return pa[k]; }
1.141 +
1.142 +#if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
1.143 +namespace boost {
1.144 + using ::put;
1.145 + using ::get;
1.146 +#endif
1.147 +
1.148 + //=========================================================================
1.149 + // concept checks for property maps
1.150 +
1.151 + template <class PMap, class Key>
1.152 + struct ReadablePropertyMapConcept
1.153 + {
1.154 + typedef typename property_traits<PMap>::key_type key_type;
1.155 + typedef typename property_traits<PMap>::reference reference;
1.156 + typedef typename property_traits<PMap>::category Category;
1.157 + typedef boost::readable_property_map_tag ReadableTag;
1.158 + void constraints() {
1.159 + function_requires< ConvertibleConcept<Category, ReadableTag> >();
1.160 +
1.161 + val = get(pmap, k);
1.162 + }
1.163 + PMap pmap;
1.164 + Key k;
1.165 + typename property_traits<PMap>::value_type val;
1.166 + };
1.167 + template <typename KeyArchetype, typename ValueArchetype>
1.168 + struct readable_property_map_archetype {
1.169 + typedef KeyArchetype key_type;
1.170 + typedef ValueArchetype value_type;
1.171 + typedef convertible_to_archetype<ValueArchetype> reference;
1.172 + typedef readable_property_map_tag category;
1.173 + };
1.174 + template <typename K, typename V>
1.175 + const typename readable_property_map_archetype<K,V>::reference&
1.176 + get(const readable_property_map_archetype<K,V>&,
1.177 + const typename readable_property_map_archetype<K,V>::key_type&)
1.178 + {
1.179 + typedef typename readable_property_map_archetype<K,V>::reference R;
1.180 + return static_object<R>::get();
1.181 + }
1.182 +
1.183 +
1.184 + template <class PMap, class Key>
1.185 + struct WritablePropertyMapConcept
1.186 + {
1.187 + typedef typename property_traits<PMap>::key_type key_type;
1.188 + typedef typename property_traits<PMap>::category Category;
1.189 + typedef boost::writable_property_map_tag WritableTag;
1.190 + void constraints() {
1.191 + function_requires< ConvertibleConcept<Category, WritableTag> >();
1.192 + put(pmap, k, val);
1.193 + }
1.194 + PMap pmap;
1.195 + Key k;
1.196 + typename property_traits<PMap>::value_type val;
1.197 + };
1.198 + template <typename KeyArchetype, typename ValueArchetype>
1.199 + struct writable_property_map_archetype {
1.200 + typedef KeyArchetype key_type;
1.201 + typedef ValueArchetype value_type;
1.202 + typedef void reference;
1.203 + typedef writable_property_map_tag category;
1.204 + };
1.205 + template <typename K, typename V>
1.206 + void put(const writable_property_map_archetype<K,V>&,
1.207 + const typename writable_property_map_archetype<K,V>::key_type&,
1.208 + const typename writable_property_map_archetype<K,V>::value_type&) { }
1.209 +
1.210 +
1.211 + template <class PMap, class Key>
1.212 + struct ReadWritePropertyMapConcept
1.213 + {
1.214 + typedef typename property_traits<PMap>::category Category;
1.215 + typedef boost::read_write_property_map_tag ReadWriteTag;
1.216 + void constraints() {
1.217 + function_requires< ReadablePropertyMapConcept<PMap, Key> >();
1.218 + function_requires< WritablePropertyMapConcept<PMap, Key> >();
1.219 + function_requires< ConvertibleConcept<Category, ReadWriteTag> >();
1.220 + }
1.221 + };
1.222 + template <typename KeyArchetype, typename ValueArchetype>
1.223 + struct read_write_property_map_archetype
1.224 + : public readable_property_map_archetype<KeyArchetype, ValueArchetype>,
1.225 + public writable_property_map_archetype<KeyArchetype, ValueArchetype>
1.226 + {
1.227 + typedef KeyArchetype key_type;
1.228 + typedef ValueArchetype value_type;
1.229 + typedef convertible_to_archetype<ValueArchetype> reference;
1.230 + typedef read_write_property_map_tag category;
1.231 + };
1.232 +
1.233 +
1.234 + template <class PMap, class Key>
1.235 + struct LvaluePropertyMapConcept
1.236 + {
1.237 + typedef typename property_traits<PMap>::category Category;
1.238 + typedef boost::lvalue_property_map_tag LvalueTag;
1.239 + typedef typename property_traits<PMap>::reference reference;
1.240 +
1.241 + void constraints() {
1.242 + function_requires< ReadablePropertyMapConcept<PMap, Key> >();
1.243 + function_requires< ConvertibleConcept<Category, LvalueTag> >();
1.244 +
1.245 + typedef typename property_traits<PMap>::value_type value_type;
1.246 + typedef typename require_same<
1.247 + const value_type&, reference>::type req;
1.248 +
1.249 + reference ref = pmap[k];
1.250 + ignore_unused_variable_warning(ref);
1.251 + }
1.252 + PMap pmap;
1.253 + Key k;
1.254 + };
1.255 + template <typename KeyArchetype, typename ValueArchetype>
1.256 + struct lvalue_property_map_archetype
1.257 + : public readable_property_map_archetype<KeyArchetype, ValueArchetype>
1.258 + {
1.259 + typedef KeyArchetype key_type;
1.260 + typedef ValueArchetype value_type;
1.261 + typedef const ValueArchetype& reference;
1.262 + typedef lvalue_property_map_tag category;
1.263 + const value_type& operator[](const key_type&) const {
1.264 + return static_object<value_type>::get();
1.265 + }
1.266 + };
1.267 +
1.268 + template <class PMap, class Key>
1.269 + struct Mutable_LvaluePropertyMapConcept
1.270 + {
1.271 + typedef typename property_traits<PMap>::category Category;
1.272 + typedef boost::lvalue_property_map_tag LvalueTag;
1.273 + typedef typename property_traits<PMap>::reference reference;
1.274 + void constraints() {
1.275 + boost::function_requires< ReadWritePropertyMapConcept<PMap, Key> >();
1.276 + boost::function_requires<ConvertibleConcept<Category, LvalueTag> >();
1.277 +
1.278 + typedef typename property_traits<PMap>::value_type value_type;
1.279 + typedef typename require_same<
1.280 + value_type&,
1.281 + reference>::type req;
1.282 +
1.283 + reference ref = pmap[k];
1.284 + ignore_unused_variable_warning(ref);
1.285 + }
1.286 + PMap pmap;
1.287 + Key k;
1.288 + };
1.289 + template <typename KeyArchetype, typename ValueArchetype>
1.290 + struct mutable_lvalue_property_map_archetype
1.291 + : public readable_property_map_archetype<KeyArchetype, ValueArchetype>,
1.292 + public writable_property_map_archetype<KeyArchetype, ValueArchetype>
1.293 + {
1.294 + typedef KeyArchetype key_type;
1.295 + typedef ValueArchetype value_type;
1.296 + typedef ValueArchetype& reference;
1.297 + typedef lvalue_property_map_tag category;
1.298 + value_type& operator[](const key_type&) const {
1.299 + return static_object<value_type>::get();
1.300 + }
1.301 + };
1.302 +
1.303 + struct identity_property_map;
1.304 +
1.305 + // A helper class for constructing a property map
1.306 + // from a class that implements operator[]
1.307 +
1.308 + template <class Reference, class LvaluePropertyMap>
1.309 + struct put_get_helper { };
1.310 +
1.311 + template <class PropertyMap, class Reference, class K>
1.312 + inline Reference
1.313 + get(const put_get_helper<Reference, PropertyMap>& pa, const K& k)
1.314 + {
1.315 + Reference v = static_cast<const PropertyMap&>(pa)[k];
1.316 + return v;
1.317 + }
1.318 + template <class PropertyMap, class Reference, class K, class V>
1.319 + inline void
1.320 + put(const put_get_helper<Reference, PropertyMap>& pa, K k, const V& v)
1.321 + {
1.322 + static_cast<const PropertyMap&>(pa)[k] = v;
1.323 + }
1.324 +
1.325 + //=========================================================================
1.326 + // Adapter to turn a RandomAccessIterator into a property map
1.327 +
1.328 + template <class RandomAccessIterator,
1.329 + class IndexMap
1.330 +#ifdef BOOST_NO_STD_ITERATOR_TRAITS
1.331 + , class T, class R
1.332 +#else
1.333 + , class T = typename std::iterator_traits<RandomAccessIterator>::value_type
1.334 + , class R = typename std::iterator_traits<RandomAccessIterator>::reference
1.335 +#endif
1.336 + >
1.337 + class iterator_property_map
1.338 + : public boost::put_get_helper< R,
1.339 + iterator_property_map<RandomAccessIterator, IndexMap,
1.340 + T, R> >
1.341 + {
1.342 + public:
1.343 + typedef typename property_traits<IndexMap>::key_type key_type;
1.344 + typedef T value_type;
1.345 + typedef R reference;
1.346 + typedef boost::lvalue_property_map_tag category;
1.347 +
1.348 + inline iterator_property_map(
1.349 + RandomAccessIterator cc = RandomAccessIterator(),
1.350 + const IndexMap& _id = IndexMap() )
1.351 + : iter(cc), index(_id) { }
1.352 + inline R operator[](key_type v) const { return *(iter + get(index, v)) ; }
1.353 + protected:
1.354 + RandomAccessIterator iter;
1.355 + IndexMap index;
1.356 + };
1.357 +
1.358 +#if !defined BOOST_NO_STD_ITERATOR_TRAITS
1.359 + template <class RAIter, class ID>
1.360 + inline iterator_property_map<
1.361 + RAIter, ID,
1.362 + typename std::iterator_traits<RAIter>::value_type,
1.363 + typename std::iterator_traits<RAIter>::reference>
1.364 + make_iterator_property_map(RAIter iter, ID id) {
1.365 + function_requires< RandomAccessIteratorConcept<RAIter> >();
1.366 + typedef iterator_property_map<
1.367 + RAIter, ID,
1.368 + typename std::iterator_traits<RAIter>::value_type,
1.369 + typename std::iterator_traits<RAIter>::reference> PA;
1.370 + return PA(iter, id);
1.371 + }
1.372 +#endif
1.373 + template <class RAIter, class Value, class ID>
1.374 + inline iterator_property_map<RAIter, ID, Value, Value&>
1.375 + make_iterator_property_map(RAIter iter, ID id, Value) {
1.376 + function_requires< RandomAccessIteratorConcept<RAIter> >();
1.377 + typedef iterator_property_map<RAIter, ID, Value, Value&> PMap;
1.378 + return PMap(iter, id);
1.379 + }
1.380 +
1.381 + template <class RandomAccessIterator,
1.382 + class IndexMap
1.383 +#ifdef BOOST_NO_STD_ITERATOR_TRAITS
1.384 + , class T, class R
1.385 +#else
1.386 + , class T = typename std::iterator_traits<RandomAccessIterator>::value_type
1.387 + , class R = typename std::iterator_traits<RandomAccessIterator>::reference
1.388 +#endif
1.389 + >
1.390 + class safe_iterator_property_map
1.391 + : public boost::put_get_helper< R,
1.392 + safe_iterator_property_map<RandomAccessIterator, IndexMap,
1.393 + T, R> >
1.394 + {
1.395 + public:
1.396 + typedef typename property_traits<IndexMap>::key_type key_type;
1.397 + typedef T value_type;
1.398 + typedef R reference;
1.399 + typedef boost::lvalue_property_map_tag category;
1.400 +
1.401 + inline safe_iterator_property_map(
1.402 + RandomAccessIterator first,
1.403 + std::size_t n_ = 0,
1.404 + const IndexMap& _id = IndexMap() )
1.405 + : iter(first), n(n_), index(_id) { }
1.406 + inline safe_iterator_property_map() { }
1.407 + inline R operator[](key_type v) const {
1.408 + assert(get(index, v) < n);
1.409 + return *(iter + get(index, v)) ;
1.410 + }
1.411 + typename property_traits<IndexMap>::value_type size() const { return n; }
1.412 + protected:
1.413 + RandomAccessIterator iter;
1.414 + typename property_traits<IndexMap>::value_type n;
1.415 + IndexMap index;
1.416 + };
1.417 +
1.418 +#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
1.419 + template <class RAIter, class ID>
1.420 + inline safe_iterator_property_map<
1.421 + RAIter, ID,
1.422 + typename boost::detail::iterator_traits<RAIter>::value_type,
1.423 + typename boost::detail::iterator_traits<RAIter>::reference>
1.424 + make_safe_iterator_property_map(RAIter iter, std::size_t n, ID id) {
1.425 + function_requires< RandomAccessIteratorConcept<RAIter> >();
1.426 + typedef safe_iterator_property_map<
1.427 + RAIter, ID,
1.428 + typename boost::detail::iterator_traits<RAIter>::value_type,
1.429 + typename boost::detail::iterator_traits<RAIter>::reference> PA;
1.430 + return PA(iter, n, id);
1.431 + }
1.432 +#endif
1.433 + template <class RAIter, class Value, class ID>
1.434 + inline safe_iterator_property_map<RAIter, ID, Value, Value&>
1.435 + make_safe_iterator_property_map(RAIter iter, std::size_t n, ID id, Value) {
1.436 + function_requires< RandomAccessIteratorConcept<RAIter> >();
1.437 + typedef safe_iterator_property_map<RAIter, ID, Value, Value&> PMap;
1.438 + return PMap(iter, n, id);
1.439 + }
1.440 +
1.441 + //=========================================================================
1.442 + // An adaptor to turn a Unique Pair Associative Container like std::map or
1.443 + // std::hash_map into an Lvalue Property Map.
1.444 +
1.445 + template <typename UniquePairAssociativeContainer>
1.446 + class associative_property_map
1.447 + : public boost::put_get_helper<
1.448 + typename UniquePairAssociativeContainer::value_type::second_type&,
1.449 + associative_property_map<UniquePairAssociativeContainer> >
1.450 + {
1.451 + typedef UniquePairAssociativeContainer C;
1.452 + public:
1.453 + typedef typename C::key_type key_type;
1.454 + typedef typename C::value_type::second_type value_type;
1.455 + typedef value_type& reference;
1.456 + typedef lvalue_property_map_tag category;
1.457 + associative_property_map() : m_c(0) { }
1.458 + associative_property_map(C& c) : m_c(&c) { }
1.459 + reference operator[](const key_type& k) const {
1.460 + return (*m_c)[k];
1.461 + }
1.462 + private:
1.463 + C* m_c;
1.464 + };
1.465 +
1.466 + template <class UniquePairAssociativeContainer>
1.467 + associative_property_map<UniquePairAssociativeContainer>
1.468 + make_assoc_property_map(UniquePairAssociativeContainer& c)
1.469 + {
1.470 + return associative_property_map<UniquePairAssociativeContainer>(c);
1.471 + }
1.472 +
1.473 + template <typename UniquePairAssociativeContainer>
1.474 + class const_associative_property_map
1.475 + : public boost::put_get_helper<
1.476 + const typename UniquePairAssociativeContainer::value_type::second_type&,
1.477 + const_associative_property_map<UniquePairAssociativeContainer> >
1.478 + {
1.479 + typedef UniquePairAssociativeContainer C;
1.480 + public:
1.481 + typedef typename C::key_type key_type;
1.482 + typedef typename C::value_type::second_type value_type;
1.483 + typedef const value_type& reference;
1.484 + typedef lvalue_property_map_tag category;
1.485 + const_associative_property_map() : m_c(0) { }
1.486 + const_associative_property_map(const C& c) : m_c(&c) { }
1.487 + reference operator[](const key_type& k) const {
1.488 + return m_c->find(k)->second;
1.489 + }
1.490 + private:
1.491 + C const* m_c;
1.492 + };
1.493 +
1.494 + template <class UniquePairAssociativeContainer>
1.495 + const_associative_property_map<UniquePairAssociativeContainer>
1.496 + make_assoc_property_map(const UniquePairAssociativeContainer& c)
1.497 + {
1.498 + return const_associative_property_map<UniquePairAssociativeContainer>(c);
1.499 + }
1.500 +
1.501 + //=========================================================================
1.502 + // A property map that applies the identity function to integers
1.503 + struct identity_property_map
1.504 + : public boost::put_get_helper<std::size_t,
1.505 + identity_property_map>
1.506 + {
1.507 + typedef std::size_t key_type;
1.508 + typedef std::size_t value_type;
1.509 + typedef std::size_t reference;
1.510 + typedef boost::readable_property_map_tag category;
1.511 +
1.512 + inline value_type operator[](const key_type& v) const { return v; }
1.513 + };
1.514 +
1.515 + //=========================================================================
1.516 + // A property map that does not do anything, for
1.517 + // when you have to supply a property map, but don't need it.
1.518 + namespace detail {
1.519 + struct dummy_pmap_reference {
1.520 + template <class T>
1.521 + dummy_pmap_reference& operator=(const T&) { return *this; }
1.522 + operator int() { return 0; }
1.523 + };
1.524 + }
1.525 + class dummy_property_map
1.526 + : public boost::put_get_helper<detail::dummy_pmap_reference,
1.527 + dummy_property_map >
1.528 + {
1.529 + public:
1.530 + typedef void key_type;
1.531 + typedef int value_type;
1.532 + typedef detail::dummy_pmap_reference reference;
1.533 + typedef boost::read_write_property_map_tag category;
1.534 + inline dummy_property_map() : c(0) { }
1.535 + inline dummy_property_map(value_type cc) : c(cc) { }
1.536 + inline dummy_property_map(const dummy_property_map& x)
1.537 + : c(x.c) { }
1.538 + template <class Vertex>
1.539 + inline reference operator[](Vertex) const { return reference(); }
1.540 + protected:
1.541 + value_type c;
1.542 + };
1.543 +
1.544 +
1.545 +} // namespace boost
1.546 +
1.547 +
1.548 +#endif /* BOOST_PROPERTY_MAP_HPP */
1.549 +