epoc32/include/stdapis/boost/property_map.hpp
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
williamr@2
     1
//  (C) Copyright Jeremy Siek 1999-2001.
williamr@2
     2
// Distributed under the Boost Software License, Version 1.0. (See
williamr@2
     3
// accompanying file LICENSE_1_0.txt or copy at
williamr@2
     4
// http://www.boost.org/LICENSE_1_0.txt)
williamr@2
     5
williamr@2
     6
//  See http://www.boost.org/libs/property_map for documentation.
williamr@2
     7
williamr@2
     8
#ifndef BOOST_PROPERTY_MAP_HPP
williamr@2
     9
#define BOOST_PROPERTY_MAP_HPP
williamr@2
    10
williamr@2
    11
#include <cassert>
williamr@2
    12
#include <boost/config.hpp>
williamr@2
    13
#include <boost/pending/cstddef.hpp>
williamr@2
    14
#include <boost/detail/iterator.hpp>
williamr@2
    15
#include <boost/concept_check.hpp>
williamr@2
    16
#include <boost/concept_archetype.hpp>
williamr@2
    17
williamr@2
    18
namespace boost {
williamr@2
    19
williamr@2
    20
  //=========================================================================
williamr@2
    21
  // property_traits class
williamr@2
    22
williamr@2
    23
  template <typename PA>
williamr@2
    24
  struct property_traits {
williamr@2
    25
    typedef typename PA::key_type key_type;
williamr@2
    26
    typedef typename PA::value_type value_type; 
williamr@2
    27
    typedef typename PA::reference reference;
williamr@2
    28
    typedef typename PA::category   category;
williamr@2
    29
  };
williamr@2
    30
williamr@2
    31
  //=========================================================================
williamr@2
    32
  // property_traits category tags
williamr@2
    33
williamr@2
    34
  namespace detail {
williamr@2
    35
    enum ePropertyMapID { READABLE_PA, WRITABLE_PA, 
williamr@2
    36
                          READ_WRITE_PA, LVALUE_PA, OP_BRACKET_PA, 
williamr@2
    37
                          RAND_ACCESS_ITER_PA, LAST_PA };
williamr@2
    38
  }
williamr@2
    39
  struct readable_property_map_tag { enum { id = detail::READABLE_PA }; };
williamr@2
    40
  struct writable_property_map_tag { enum { id = detail::WRITABLE_PA }; };
williamr@2
    41
  struct read_write_property_map_tag :
williamr@2
    42
    public readable_property_map_tag,
williamr@2
    43
    public writable_property_map_tag
williamr@2
    44
  { enum { id = detail::READ_WRITE_PA }; };
williamr@2
    45
williamr@2
    46
  struct lvalue_property_map_tag : public read_write_property_map_tag
williamr@2
    47
  { enum { id = detail::LVALUE_PA }; };
williamr@2
    48
williamr@2
    49
  //=========================================================================
williamr@2
    50
  // property_traits specialization for pointers
williamr@2
    51
williamr@2
    52
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
williamr@2
    53
  // The user will just have to create their own specializations for
williamr@2
    54
  // other pointers types if the compiler does not have partial
williamr@2
    55
  // specializations. Sorry!
williamr@2
    56
#define BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(TYPE) \
williamr@2
    57
  template <> \
williamr@2
    58
  struct property_traits<TYPE*> { \
williamr@2
    59
    typedef TYPE value_type; \
williamr@2
    60
    typedef value_type& reference; \
williamr@2
    61
    typedef std::ptrdiff_t key_type; \
williamr@2
    62
    typedef lvalue_property_map_tag   category; \
williamr@2
    63
  }; \
williamr@2
    64
  template <> \
williamr@2
    65
  struct property_traits<const TYPE*> { \
williamr@2
    66
    typedef TYPE value_type; \
williamr@2
    67
    typedef const value_type& reference; \
williamr@2
    68
    typedef std::ptrdiff_t key_type; \
williamr@2
    69
    typedef lvalue_property_map_tag   category; \
williamr@2
    70
  }
williamr@2
    71
williamr@2
    72
  BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(long);
williamr@2
    73
  BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(unsigned long);
williamr@2
    74
  BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(int);
williamr@2
    75
  BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(unsigned int);
williamr@2
    76
  BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(short);
williamr@2
    77
  BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(unsigned short);
williamr@2
    78
  BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(char);
williamr@2
    79
  BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(unsigned char);
williamr@2
    80
  BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(signed char);
williamr@2
    81
  BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(bool);
williamr@2
    82
  BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(float);
williamr@2
    83
  BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(double);
williamr@2
    84
  BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(long double);
williamr@2
    85
williamr@2
    86
  // This may need to be turned off for some older compilers that don't have
williamr@2
    87
  // wchar_t intrinsically.
williamr@2
    88
# ifndef BOOST_NO_INTRINSIC_WCHAR_T
williamr@2
    89
  template <>
williamr@2
    90
  struct property_traits<wchar_t*> {
williamr@2
    91
    typedef wchar_t value_type;
williamr@2
    92
    typedef value_type& reference;
williamr@2
    93
    typedef std::ptrdiff_t key_type;
williamr@2
    94
    typedef lvalue_property_map_tag   category;
williamr@2
    95
  };
williamr@2
    96
  template <>
williamr@2
    97
  struct property_traits<const wchar_t*> {
williamr@2
    98
    typedef wchar_t value_type;
williamr@2
    99
    typedef const value_type& reference;
williamr@2
   100
    typedef std::ptrdiff_t key_type;
williamr@2
   101
    typedef lvalue_property_map_tag   category;
williamr@2
   102
  };
williamr@2
   103
# endif
williamr@2
   104
williamr@2
   105
#else
williamr@2
   106
  template <class T>
williamr@2
   107
  struct property_traits<T*> {
williamr@2
   108
    typedef T value_type;
williamr@2
   109
    typedef value_type& reference;
williamr@2
   110
    typedef std::ptrdiff_t key_type;
williamr@2
   111
    typedef lvalue_property_map_tag category;
williamr@2
   112
  };
williamr@2
   113
  template <class T>
williamr@2
   114
  struct property_traits<const T*> {
williamr@2
   115
    typedef T value_type;
williamr@2
   116
    typedef const value_type& reference;
williamr@2
   117
    typedef std::ptrdiff_t key_type;
williamr@2
   118
    typedef lvalue_property_map_tag category;
williamr@2
   119
  };
williamr@2
   120
#endif
williamr@2
   121
williamr@2
   122
#if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
williamr@2
   123
  // MSVC doesn't have Koenig lookup, so the user has to
williamr@2
   124
  // do boost::get() anyways, and the using clause
williamr@2
   125
  // doesn't really work for MSVC.
williamr@2
   126
} // namespace boost
williamr@2
   127
#endif
williamr@2
   128
williamr@2
   129
  // These need to go in global namespace because Koenig
williamr@2
   130
  // lookup does not apply to T*.
williamr@2
   131
williamr@2
   132
  // V must be convertible to T
williamr@2
   133
  template <class T, class V>
williamr@2
   134
  inline void put(T* pa, std::ptrdiff_t k, const V& val) { pa[k] = val;  }
williamr@2
   135
williamr@2
   136
  template <class T>
williamr@2
   137
  inline const T& get(const T* pa, std::ptrdiff_t k) { return pa[k]; }
williamr@2
   138
williamr@2
   139
#if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
williamr@2
   140
namespace boost {
williamr@2
   141
  using ::put;
williamr@2
   142
  using ::get;
williamr@2
   143
#endif
williamr@2
   144
williamr@2
   145
  //=========================================================================
williamr@2
   146
  // concept checks for property maps
williamr@2
   147
williamr@2
   148
  template <class PMap, class Key>
williamr@2
   149
  struct ReadablePropertyMapConcept
williamr@2
   150
  {
williamr@2
   151
    typedef typename property_traits<PMap>::key_type key_type;
williamr@2
   152
    typedef typename property_traits<PMap>::reference reference;
williamr@2
   153
    typedef typename property_traits<PMap>::category Category;
williamr@2
   154
    typedef boost::readable_property_map_tag ReadableTag;
williamr@2
   155
    void constraints() {
williamr@2
   156
      function_requires< ConvertibleConcept<Category, ReadableTag> >();
williamr@2
   157
williamr@2
   158
      val = get(pmap, k);
williamr@2
   159
    }
williamr@2
   160
    PMap pmap;
williamr@2
   161
    Key k;
williamr@2
   162
    typename property_traits<PMap>::value_type val;
williamr@2
   163
  };
williamr@2
   164
  template <typename KeyArchetype, typename ValueArchetype>
williamr@2
   165
  struct readable_property_map_archetype {
williamr@2
   166
    typedef KeyArchetype key_type;
williamr@2
   167
    typedef ValueArchetype value_type;
williamr@2
   168
    typedef convertible_to_archetype<ValueArchetype> reference;
williamr@2
   169
    typedef readable_property_map_tag category;
williamr@2
   170
  };
williamr@2
   171
  template <typename K, typename V>
williamr@2
   172
  const typename readable_property_map_archetype<K,V>::reference&
williamr@2
   173
  get(const readable_property_map_archetype<K,V>&, 
williamr@2
   174
      const typename readable_property_map_archetype<K,V>::key_type&)
williamr@2
   175
  {
williamr@2
   176
    typedef typename readable_property_map_archetype<K,V>::reference R;
williamr@2
   177
    return static_object<R>::get();
williamr@2
   178
  }
williamr@2
   179
williamr@2
   180
williamr@2
   181
  template <class PMap, class Key>
williamr@2
   182
  struct WritablePropertyMapConcept
williamr@2
   183
  {
williamr@2
   184
    typedef typename property_traits<PMap>::key_type key_type;
williamr@2
   185
    typedef typename property_traits<PMap>::category Category;
williamr@2
   186
    typedef boost::writable_property_map_tag WritableTag;
williamr@2
   187
    void constraints() {
williamr@2
   188
      function_requires< ConvertibleConcept<Category, WritableTag> >();
williamr@2
   189
      put(pmap, k, val);
williamr@2
   190
    }
williamr@2
   191
    PMap pmap;
williamr@2
   192
    Key k;
williamr@2
   193
    typename property_traits<PMap>::value_type val;
williamr@2
   194
  };
williamr@2
   195
  template <typename KeyArchetype, typename ValueArchetype>
williamr@2
   196
  struct writable_property_map_archetype {
williamr@2
   197
    typedef KeyArchetype key_type;
williamr@2
   198
    typedef ValueArchetype value_type;
williamr@2
   199
    typedef void reference;
williamr@2
   200
    typedef writable_property_map_tag category;
williamr@2
   201
  };
williamr@2
   202
  template <typename K, typename V>
williamr@2
   203
  void put(const writable_property_map_archetype<K,V>&, 
williamr@2
   204
           const typename writable_property_map_archetype<K,V>::key_type&, 
williamr@2
   205
           const typename writable_property_map_archetype<K,V>::value_type&) { }
williamr@2
   206
williamr@2
   207
williamr@2
   208
  template <class PMap, class Key>
williamr@2
   209
  struct ReadWritePropertyMapConcept
williamr@2
   210
  {
williamr@2
   211
    typedef typename property_traits<PMap>::category Category;
williamr@2
   212
    typedef boost::read_write_property_map_tag ReadWriteTag;
williamr@2
   213
    void constraints() {
williamr@2
   214
      function_requires< ReadablePropertyMapConcept<PMap, Key> >();
williamr@2
   215
      function_requires< WritablePropertyMapConcept<PMap, Key> >();
williamr@2
   216
      function_requires< ConvertibleConcept<Category, ReadWriteTag> >();
williamr@2
   217
    }
williamr@2
   218
  };
williamr@2
   219
  template <typename KeyArchetype, typename ValueArchetype>
williamr@2
   220
  struct read_write_property_map_archetype
williamr@2
   221
    : public readable_property_map_archetype<KeyArchetype, ValueArchetype>,
williamr@2
   222
      public writable_property_map_archetype<KeyArchetype, ValueArchetype>
williamr@2
   223
  {
williamr@2
   224
    typedef KeyArchetype key_type;
williamr@2
   225
    typedef ValueArchetype value_type;
williamr@2
   226
    typedef convertible_to_archetype<ValueArchetype> reference;
williamr@2
   227
    typedef read_write_property_map_tag category;
williamr@2
   228
  };
williamr@2
   229
williamr@2
   230
williamr@2
   231
  template <class PMap, class Key>
williamr@2
   232
  struct LvaluePropertyMapConcept
williamr@2
   233
  {
williamr@2
   234
    typedef typename property_traits<PMap>::category Category;
williamr@2
   235
    typedef boost::lvalue_property_map_tag LvalueTag;
williamr@2
   236
    typedef typename property_traits<PMap>::reference reference;
williamr@2
   237
williamr@2
   238
    void constraints() {
williamr@2
   239
      function_requires< ReadablePropertyMapConcept<PMap, Key> >();
williamr@2
   240
      function_requires< ConvertibleConcept<Category, LvalueTag> >();
williamr@2
   241
williamr@2
   242
      typedef typename property_traits<PMap>::value_type value_type;
williamr@2
   243
      typedef typename require_same<
williamr@2
   244
        const value_type&, reference>::type req;
williamr@2
   245
williamr@2
   246
      reference ref = pmap[k];
williamr@2
   247
      ignore_unused_variable_warning(ref);
williamr@2
   248
    }
williamr@2
   249
    PMap pmap;
williamr@2
   250
    Key k;
williamr@2
   251
  };
williamr@2
   252
  template <typename KeyArchetype, typename ValueArchetype>
williamr@2
   253
  struct lvalue_property_map_archetype
williamr@2
   254
    : public readable_property_map_archetype<KeyArchetype, ValueArchetype>
williamr@2
   255
  {
williamr@2
   256
    typedef KeyArchetype key_type;
williamr@2
   257
    typedef ValueArchetype value_type;
williamr@2
   258
    typedef const ValueArchetype& reference;
williamr@2
   259
    typedef lvalue_property_map_tag category;
williamr@2
   260
    const value_type& operator[](const key_type&) const {
williamr@2
   261
      return static_object<value_type>::get();
williamr@2
   262
    }
williamr@2
   263
  };
williamr@2
   264
williamr@2
   265
  template <class PMap, class Key>
williamr@2
   266
  struct Mutable_LvaluePropertyMapConcept
williamr@2
   267
  {
williamr@2
   268
    typedef typename property_traits<PMap>::category Category;
williamr@2
   269
    typedef boost::lvalue_property_map_tag LvalueTag;
williamr@2
   270
    typedef typename property_traits<PMap>::reference reference;
williamr@2
   271
    void constraints() { 
williamr@2
   272
      boost::function_requires< ReadWritePropertyMapConcept<PMap, Key> >();
williamr@2
   273
      boost::function_requires<ConvertibleConcept<Category, LvalueTag> >();
williamr@2
   274
      
williamr@2
   275
      typedef typename property_traits<PMap>::value_type value_type;
williamr@2
   276
      typedef typename require_same<
williamr@2
   277
        value_type&,
williamr@2
   278
        reference>::type req;
williamr@2
   279
williamr@2
   280
      reference ref = pmap[k];
williamr@2
   281
      ignore_unused_variable_warning(ref);
williamr@2
   282
    }
williamr@2
   283
    PMap pmap;
williamr@2
   284
    Key k;
williamr@2
   285
  };
williamr@2
   286
  template <typename KeyArchetype, typename ValueArchetype>
williamr@2
   287
  struct mutable_lvalue_property_map_archetype
williamr@2
   288
    : public readable_property_map_archetype<KeyArchetype, ValueArchetype>,
williamr@2
   289
      public writable_property_map_archetype<KeyArchetype, ValueArchetype>
williamr@2
   290
  {
williamr@2
   291
    typedef KeyArchetype key_type;
williamr@2
   292
    typedef ValueArchetype value_type;
williamr@2
   293
    typedef ValueArchetype& reference;
williamr@2
   294
    typedef lvalue_property_map_tag category;
williamr@2
   295
    value_type& operator[](const key_type&) const { 
williamr@2
   296
      return static_object<value_type>::get();
williamr@2
   297
    }
williamr@2
   298
  };
williamr@2
   299
williamr@2
   300
  struct identity_property_map;
williamr@2
   301
williamr@2
   302
  // A helper class for constructing a property map
williamr@2
   303
  // from a class that implements operator[]
williamr@2
   304
williamr@2
   305
  template <class Reference, class LvaluePropertyMap>
williamr@2
   306
  struct put_get_helper { };
williamr@2
   307
williamr@2
   308
  template <class PropertyMap, class Reference, class K>
williamr@2
   309
  inline Reference
williamr@2
   310
  get(const put_get_helper<Reference, PropertyMap>& pa, const K& k)
williamr@2
   311
  {
williamr@2
   312
    Reference v = static_cast<const PropertyMap&>(pa)[k];
williamr@2
   313
    return v;
williamr@2
   314
  }
williamr@2
   315
  template <class PropertyMap, class Reference, class K, class V>
williamr@2
   316
  inline void
williamr@2
   317
  put(const put_get_helper<Reference, PropertyMap>& pa, K k, const V& v)
williamr@2
   318
  {
williamr@2
   319
    static_cast<const PropertyMap&>(pa)[k] = v;
williamr@2
   320
  }
williamr@2
   321
williamr@2
   322
  //=========================================================================
williamr@2
   323
  // Adapter to turn a RandomAccessIterator into a property map
williamr@2
   324
williamr@2
   325
  template <class RandomAccessIterator, 
williamr@2
   326
    class IndexMap
williamr@2
   327
#ifdef BOOST_NO_STD_ITERATOR_TRAITS
williamr@2
   328
    , class T, class R
williamr@2
   329
#else
williamr@2
   330
    , class T = typename std::iterator_traits<RandomAccessIterator>::value_type
williamr@2
   331
    , class R = typename std::iterator_traits<RandomAccessIterator>::reference
williamr@2
   332
#endif
williamr@2
   333
     >
williamr@2
   334
  class iterator_property_map
williamr@2
   335
    : public boost::put_get_helper< R, 
williamr@2
   336
        iterator_property_map<RandomAccessIterator, IndexMap,
williamr@2
   337
        T, R> >
williamr@2
   338
  {
williamr@2
   339
  public:
williamr@2
   340
    typedef typename property_traits<IndexMap>::key_type key_type;
williamr@2
   341
    typedef T value_type;
williamr@2
   342
    typedef R reference;
williamr@2
   343
    typedef boost::lvalue_property_map_tag category;
williamr@2
   344
williamr@2
   345
    inline iterator_property_map(
williamr@2
   346
      RandomAccessIterator cc = RandomAccessIterator(), 
williamr@2
   347
      const IndexMap& _id = IndexMap() ) 
williamr@2
   348
      : iter(cc), index(_id) { }
williamr@2
   349
    inline R operator[](key_type v) const { return *(iter + get(index, v)) ; }
williamr@2
   350
  protected:
williamr@2
   351
    RandomAccessIterator iter;
williamr@2
   352
    IndexMap index;
williamr@2
   353
  };
williamr@2
   354
williamr@2
   355
#if !defined BOOST_NO_STD_ITERATOR_TRAITS
williamr@2
   356
  template <class RAIter, class ID>
williamr@2
   357
  inline iterator_property_map<
williamr@2
   358
    RAIter, ID,
williamr@2
   359
    typename std::iterator_traits<RAIter>::value_type,
williamr@2
   360
    typename std::iterator_traits<RAIter>::reference>
williamr@2
   361
  make_iterator_property_map(RAIter iter, ID id) {
williamr@2
   362
    function_requires< RandomAccessIteratorConcept<RAIter> >();
williamr@2
   363
    typedef iterator_property_map<
williamr@2
   364
      RAIter, ID,
williamr@2
   365
      typename std::iterator_traits<RAIter>::value_type,
williamr@2
   366
      typename std::iterator_traits<RAIter>::reference> PA;
williamr@2
   367
    return PA(iter, id);
williamr@2
   368
  }
williamr@2
   369
#endif
williamr@2
   370
  template <class RAIter, class Value, class ID>
williamr@2
   371
  inline iterator_property_map<RAIter, ID, Value, Value&>
williamr@2
   372
  make_iterator_property_map(RAIter iter, ID id, Value) {
williamr@2
   373
    function_requires< RandomAccessIteratorConcept<RAIter> >();
williamr@2
   374
    typedef iterator_property_map<RAIter, ID, Value, Value&> PMap;
williamr@2
   375
    return PMap(iter, id);
williamr@2
   376
  }
williamr@2
   377
williamr@2
   378
  template <class RandomAccessIterator, 
williamr@2
   379
    class IndexMap
williamr@2
   380
#ifdef BOOST_NO_STD_ITERATOR_TRAITS
williamr@2
   381
    , class T, class R
williamr@2
   382
#else
williamr@2
   383
    , class T = typename std::iterator_traits<RandomAccessIterator>::value_type
williamr@2
   384
    , class R = typename std::iterator_traits<RandomAccessIterator>::reference
williamr@2
   385
#endif
williamr@2
   386
     >
williamr@2
   387
  class safe_iterator_property_map
williamr@2
   388
    : public boost::put_get_helper< R, 
williamr@2
   389
        safe_iterator_property_map<RandomAccessIterator, IndexMap,
williamr@2
   390
        T, R> >
williamr@2
   391
  {
williamr@2
   392
  public:
williamr@2
   393
    typedef typename property_traits<IndexMap>::key_type key_type; 
williamr@2
   394
    typedef T value_type;
williamr@2
   395
    typedef R reference;
williamr@2
   396
    typedef boost::lvalue_property_map_tag category;
williamr@2
   397
williamr@2
   398
    inline safe_iterator_property_map(
williamr@2
   399
      RandomAccessIterator first, 
williamr@2
   400
      std::size_t n_ = 0, 
williamr@2
   401
      const IndexMap& _id = IndexMap() ) 
williamr@2
   402
      : iter(first), n(n_), index(_id) { }
williamr@2
   403
    inline safe_iterator_property_map() { }
williamr@2
   404
    inline R operator[](key_type v) const {
williamr@2
   405
      assert(get(index, v) < n);
williamr@2
   406
      return *(iter + get(index, v)) ;
williamr@2
   407
    }
williamr@2
   408
    typename property_traits<IndexMap>::value_type size() const { return n; }
williamr@2
   409
  protected:
williamr@2
   410
    RandomAccessIterator iter;
williamr@2
   411
    typename property_traits<IndexMap>::value_type n;
williamr@2
   412
    IndexMap index;
williamr@2
   413
  };
williamr@2
   414
williamr@2
   415
#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
williamr@2
   416
  template <class RAIter, class ID>
williamr@2
   417
  inline safe_iterator_property_map<
williamr@2
   418
    RAIter, ID,
williamr@2
   419
    typename boost::detail::iterator_traits<RAIter>::value_type,
williamr@2
   420
    typename boost::detail::iterator_traits<RAIter>::reference>
williamr@2
   421
  make_safe_iterator_property_map(RAIter iter, std::size_t n, ID id) {
williamr@2
   422
    function_requires< RandomAccessIteratorConcept<RAIter> >();
williamr@2
   423
    typedef safe_iterator_property_map<
williamr@2
   424
      RAIter, ID,
williamr@2
   425
      typename boost::detail::iterator_traits<RAIter>::value_type,
williamr@2
   426
      typename boost::detail::iterator_traits<RAIter>::reference> PA;
williamr@2
   427
    return PA(iter, n, id);
williamr@2
   428
  }
williamr@2
   429
#endif
williamr@2
   430
  template <class RAIter, class Value, class ID>
williamr@2
   431
  inline safe_iterator_property_map<RAIter, ID, Value, Value&>
williamr@2
   432
  make_safe_iterator_property_map(RAIter iter, std::size_t n, ID id, Value) {
williamr@2
   433
    function_requires< RandomAccessIteratorConcept<RAIter> >();
williamr@2
   434
    typedef safe_iterator_property_map<RAIter, ID, Value, Value&> PMap;
williamr@2
   435
    return PMap(iter, n, id);
williamr@2
   436
  }
williamr@2
   437
williamr@2
   438
  //=========================================================================
williamr@2
   439
  // An adaptor to turn a Unique Pair Associative Container like std::map or
williamr@2
   440
  // std::hash_map into an Lvalue Property Map.
williamr@2
   441
williamr@2
   442
  template <typename UniquePairAssociativeContainer>
williamr@2
   443
  class associative_property_map
williamr@2
   444
    : public boost::put_get_helper<
williamr@2
   445
       typename UniquePairAssociativeContainer::value_type::second_type&,
williamr@2
   446
       associative_property_map<UniquePairAssociativeContainer> >
williamr@2
   447
  {
williamr@2
   448
    typedef UniquePairAssociativeContainer C;
williamr@2
   449
  public:
williamr@2
   450
    typedef typename C::key_type key_type;
williamr@2
   451
    typedef typename C::value_type::second_type value_type;
williamr@2
   452
    typedef value_type& reference;
williamr@2
   453
    typedef lvalue_property_map_tag category;
williamr@2
   454
    associative_property_map() : m_c(0) { }
williamr@2
   455
    associative_property_map(C& c) : m_c(&c) { }
williamr@2
   456
    reference operator[](const key_type& k) const {
williamr@2
   457
      return (*m_c)[k];
williamr@2
   458
    }
williamr@2
   459
  private:
williamr@2
   460
    C* m_c;
williamr@2
   461
  };
williamr@2
   462
williamr@2
   463
  template <class UniquePairAssociativeContainer>
williamr@2
   464
  associative_property_map<UniquePairAssociativeContainer>
williamr@2
   465
  make_assoc_property_map(UniquePairAssociativeContainer& c)
williamr@2
   466
  {
williamr@2
   467
    return associative_property_map<UniquePairAssociativeContainer>(c);
williamr@2
   468
  }
williamr@2
   469
williamr@2
   470
  template <typename UniquePairAssociativeContainer>
williamr@2
   471
  class const_associative_property_map
williamr@2
   472
    : public boost::put_get_helper<
williamr@2
   473
       const typename UniquePairAssociativeContainer::value_type::second_type&,
williamr@2
   474
       const_associative_property_map<UniquePairAssociativeContainer> >
williamr@2
   475
  {
williamr@2
   476
    typedef UniquePairAssociativeContainer C;
williamr@2
   477
  public:
williamr@2
   478
    typedef typename C::key_type key_type;
williamr@2
   479
    typedef typename C::value_type::second_type value_type;
williamr@2
   480
    typedef const value_type& reference;
williamr@2
   481
    typedef lvalue_property_map_tag category;
williamr@2
   482
    const_associative_property_map() : m_c(0) { }
williamr@2
   483
    const_associative_property_map(const C& c) : m_c(&c) { }
williamr@2
   484
    reference operator[](const key_type& k) const {
williamr@2
   485
      return m_c->find(k)->second;
williamr@2
   486
    }
williamr@2
   487
  private:
williamr@2
   488
    C const* m_c;
williamr@2
   489
  };
williamr@2
   490
  
williamr@2
   491
  template <class UniquePairAssociativeContainer>
williamr@2
   492
  const_associative_property_map<UniquePairAssociativeContainer>
williamr@2
   493
  make_assoc_property_map(const UniquePairAssociativeContainer& c)
williamr@2
   494
  {
williamr@2
   495
    return const_associative_property_map<UniquePairAssociativeContainer>(c);
williamr@2
   496
  }
williamr@2
   497
williamr@2
   498
  //=========================================================================
williamr@2
   499
  // A property map that applies the identity function to integers
williamr@2
   500
  struct identity_property_map
williamr@2
   501
    : public boost::put_get_helper<std::size_t, 
williamr@2
   502
        identity_property_map>
williamr@2
   503
  {
williamr@2
   504
    typedef std::size_t key_type;
williamr@2
   505
    typedef std::size_t value_type;
williamr@2
   506
    typedef std::size_t reference;
williamr@2
   507
    typedef boost::readable_property_map_tag category;
williamr@2
   508
williamr@2
   509
    inline value_type operator[](const key_type& v) const { return v; }
williamr@2
   510
  };
williamr@2
   511
williamr@2
   512
  //=========================================================================
williamr@2
   513
  // A property map that does not do anything, for
williamr@2
   514
  // when you have to supply a property map, but don't need it.
williamr@2
   515
  namespace detail {
williamr@2
   516
    struct dummy_pmap_reference {
williamr@2
   517
      template <class T>
williamr@2
   518
      dummy_pmap_reference& operator=(const T&) { return *this; }
williamr@2
   519
      operator int() { return 0; }
williamr@2
   520
    };
williamr@2
   521
  }
williamr@2
   522
  class dummy_property_map 
williamr@2
   523
    : public boost::put_get_helper<detail::dummy_pmap_reference,
williamr@2
   524
        dummy_property_map  > 
williamr@2
   525
  {
williamr@2
   526
  public:
williamr@2
   527
    typedef void key_type; 
williamr@2
   528
    typedef int value_type;
williamr@2
   529
    typedef detail::dummy_pmap_reference reference;
williamr@2
   530
    typedef boost::read_write_property_map_tag category;
williamr@2
   531
    inline dummy_property_map() : c(0) { }
williamr@2
   532
    inline dummy_property_map(value_type cc) : c(cc) { }
williamr@2
   533
    inline dummy_property_map(const dummy_property_map& x)
williamr@2
   534
      : c(x.c) { }
williamr@2
   535
    template <class Vertex>
williamr@2
   536
    inline reference operator[](Vertex) const { return reference(); }
williamr@2
   537
   protected:
williamr@2
   538
    value_type c;
williamr@2
   539
  };
williamr@2
   540
williamr@2
   541
williamr@2
   542
} // namespace boost
williamr@2
   543
williamr@2
   544
williamr@2
   545
#endif /* BOOST_PROPERTY_MAP_HPP */
williamr@2
   546