EXAMPLE_PATH is set to the demo dir.
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 /// Base class of maps.
18 /// It provides the necessary <tt>typedef</tt>s required by the map concept.
19 template<typename K, typename T>
29 /// Null map. (a.k.a. DoNothingMap)
31 /// If you have to provide a map only for its type definitions,
32 /// or if you have to provide a writable map, but
33 /// data written to it will sent to <tt>/dev/null</tt>...
34 template<typename K, typename T>
35 class NullMap : public MapBase<K,T>
39 /// Gives back a default constructed element.
40 T operator[](const K&) const { return T(); }
41 /// Absorbs the value.
42 void set(const K&, const T&) {}
48 /// This is a readable map which assigns a specified value to each key.
49 /// In other aspects it is equivalent to the \ref NullMap.
50 /// \todo set could be used to set the value.
51 template<typename K, typename T>
52 class ConstMap : public MapBase<K,T>
57 /// Default constructor
59 /// The value of the map will be uninitialized.
60 /// (More exactly it will be default constructed.)
64 /// \param _v The initial value of the map.
65 ConstMap(const T &_v) : v(_v) {}
67 T operator[](const K&) const { return v; }
68 void set(const K&, const T&) {}
72 typedef ConstMap<K,T1> other;
76 ConstMap(const ConstMap<K,T1> &, const T &_v) : v(_v) {}
81 /// \c std::map wrapper
83 /// This is essentially a wrapper for \c std::map. With addition that
84 /// you can specify a default value different from \c ValueType() .
86 /// \todo Provide allocator parameter...
87 template <typename Key, typename T, typename Compare = std::less<Key> >
88 class StdMap : public std::map<Key,T,Compare> {
89 typedef std::map<Key,T,Compare> parent;
91 typedef typename parent::value_type PairType;
96 typedef T& ReferenceType;
97 typedef const T& ConstReferenceType;
101 /// Constructor with specified default value
102 StdMap(const T& _v) : v(_v) {}
104 /// \brief Constructs the map from an appropriate std::map.
106 /// \warning Inefficient: copies the content of \c m !
107 StdMap(const parent &m) : parent(m) {}
108 /// \brief Constructs the map from an appropriate std::map, and explicitly
109 /// specifies a default value.
111 /// \warning Inefficient: copies the content of \c m !
112 StdMap(const parent &m, const T& _v) : parent(m), v(_v) {}
114 template<typename T1, typename Comp1>
115 StdMap(const StdMap<Key,T1,Comp1> &m, const T &_v) {
119 ReferenceType operator[](const Key &k) {
120 return insert(PairType(k,v)).first -> second;
122 ConstReferenceType operator[](const Key &k) const {
123 typename parent::iterator i = lower_bound(k);
124 if (i == parent::end() || parent::key_comp()(k, (*i).first))
128 void set(const Key &k, const T &t) {
129 parent::operator[](k) = t;
132 /// Changes the default value of the map.
133 /// \return Returns the previous default value.
135 /// \warning The value of some keys (which has already been queried, but
136 /// the value has been unchanged from the default) may change!
137 T setDefault(const T &_v) { T old=v; v=_v; return old; }
139 template<typename T1>
141 typedef StdMap<Key,T1,Compare> other;
146 #endif // HUGO_MAPS_H