A remark added.
6 ///\brief Miscellaneous property maps
8 ///\todo This file has the same name as the concept file in skeletons,
9 /// and this is not easily detectable in docs...
15 /// Base class of maps.
17 template<typename K, typename T>
27 /// Null map. (aka DoNothingMap)
29 /// If you have to provide a map only for its type definitions,
30 /// or if you have to provide a writable map, but will not use the
31 /// data written to it...
32 template<typename K, typename T>
33 class NullMap : public MapBase<K,T>
37 T operator[](const K&) const { return T(); }
38 void set(const K&, const T&) {}
39 ///\bug when update is removed from map concepts by being dynamic
40 ///stuffs, this line have to be removed.
47 /// This is a readable map which assignes a specified value to each key.
48 /// In other aspects it is equivalent to the \ref NullMap
49 template<typename K, typename T>
50 class ConstMap : public MapBase<K,T>
56 ConstMap(const T &_v) : v(_v) {}
58 T operator[](const K&) const { return v; }
59 void set(const K&, const T&) {}
63 typedef ConstMap<K,T1> other;
67 ConstMap(const ConstMap<K,T1> &, const T &_v) : v(_v) {}
72 /// \c std::map wrapper
74 /// This is essentially a wrapper for \c std::map. With addition that
75 /// you can specify a default value different from \c ValueType() .
77 /// \todo Provide allocator parameter...
78 template <typename Key, typename T, typename Compare = std::less<Key> >
79 class StdMap : public std::map<Key,T,Compare> {
80 typedef std::map<Key,T,Compare> parent;
82 typedef typename parent::value_type PairType;
87 typedef T& ReferenceType;
88 typedef const T& ConstReferenceType;
92 /// Constructor with specified default value
93 StdMap(const T& _v) : v(_v) {}
95 /// \brief Constructs the map from an appropriate std::map.
97 /// \warning Inefficient: copies the content of \c m !
98 StdMap(const parent &m) : parent(m) {}
99 /// \brief Constructs the map from an appropriate std::map, and explicitly
100 /// specifies a default value.
102 /// \warning Inefficient: copies the content of \c m !
103 StdMap(const parent &m, const T& _v) : parent(m), v(_v) {}
105 template<typename T1, typename Comp1>
106 StdMap(const StdMap<Key,T1,Comp1> &m, const T &_v) {
110 ReferenceType operator[](const Key &k) {
111 return insert(PairType(k,v)).first -> second;
113 ConstReferenceType operator[](const Key &k) const {
114 typename parent::iterator i = lower_bound(k);
115 if (i == parent::end() || parent::key_comp()(k, (*i).first))
119 void set(const Key &k, const T &t) {
120 parent::operator[](k) = t;
123 /// Changes the default value of the map.
124 /// \return Returns the previous default value.
126 /// \warning The value of some keys (which has alredy been queried, but
127 /// the value has been unchanged from the default) may change!
128 T setDefault(const T &_v) { T old=v; v=_v; return old; }
130 template<typename T1>
132 typedef StdMap<Key,T1,Compare> other;
137 #endif // HUGO_MAPS_H