| ... |
... |
@@ -95,75 +95,80 @@
|
| 95 |
95 |
///
|
| 96 |
96 |
/// The simplest way of using this map is through the constMap()
|
| 97 |
97 |
/// function.
|
| 98 |
98 |
///
|
| 99 |
99 |
/// \sa NullMap
|
| 100 |
100 |
/// \sa IdentityMap
|
| 101 |
101 |
template<typename K, typename V>
|
| 102 |
102 |
class ConstMap : public MapBase<K, V> {
|
| 103 |
103 |
private:
|
| 104 |
104 |
V _value;
|
| 105 |
105 |
public:
|
| 106 |
106 |
typedef MapBase<K, V> Parent;
|
| 107 |
107 |
typedef typename Parent::Key Key;
|
| 108 |
108 |
typedef typename Parent::Value Value;
|
| 109 |
109 |
|
| 110 |
110 |
/// Default constructor
|
| 111 |
111 |
|
| 112 |
112 |
/// Default constructor.
|
| 113 |
113 |
/// The value of the map will be default constructed.
|
| 114 |
114 |
ConstMap() {}
|
| 115 |
115 |
|
| 116 |
116 |
/// Constructor with specified initial value
|
| 117 |
117 |
|
| 118 |
118 |
/// Constructor with specified initial value.
|
| 119 |
|
/// \param v is the initial value of the map.
|
|
119 |
/// \param v The initial value of the map.
|
| 120 |
120 |
ConstMap(const Value &v) : _value(v) {}
|
| 121 |
121 |
|
| 122 |
122 |
/// Gives back the specified value.
|
| 123 |
123 |
Value operator[](const Key&) const { return _value; }
|
| 124 |
124 |
|
| 125 |
125 |
/// Absorbs the value.
|
| 126 |
126 |
void set(const Key&, const Value&) {}
|
| 127 |
127 |
|
| 128 |
128 |
/// Sets the value that is assigned to each key.
|
| 129 |
129 |
void setAll(const Value &v) {
|
| 130 |
130 |
_value = v;
|
| 131 |
131 |
}
|
| 132 |
132 |
|
| 133 |
133 |
template<typename V1>
|
| 134 |
134 |
ConstMap(const ConstMap<K, V1> &, const Value &v) : _value(v) {}
|
| 135 |
135 |
};
|
| 136 |
136 |
|
| 137 |
137 |
/// Returns a \ref ConstMap class
|
| 138 |
138 |
|
| 139 |
139 |
/// This function just returns a \ref ConstMap class.
|
| 140 |
140 |
/// \relates ConstMap
|
| 141 |
141 |
template<typename K, typename V>
|
| 142 |
142 |
inline ConstMap<K, V> constMap(const V &v) {
|
| 143 |
143 |
return ConstMap<K, V>(v);
|
| 144 |
144 |
}
|
| 145 |
145 |
|
|
146 |
template<typename K, typename V>
|
|
147 |
inline ConstMap<K, V> constMap() {
|
|
148 |
return ConstMap<K, V>();
|
|
149 |
}
|
|
150 |
|
| 146 |
151 |
|
| 147 |
152 |
template<typename T, T v>
|
| 148 |
153 |
struct Const {};
|
| 149 |
154 |
|
| 150 |
155 |
/// Constant map with inlined constant value.
|
| 151 |
156 |
|
| 152 |
157 |
/// This \ref concepts::ReadMap "readable map" assigns a specified
|
| 153 |
158 |
/// value to each key.
|
| 154 |
159 |
///
|
| 155 |
160 |
/// In other aspects it is equivalent to \ref NullMap.
|
| 156 |
161 |
/// So it conforms the \ref concepts::ReadWriteMap "ReadWriteMap"
|
| 157 |
162 |
/// concept, but it absorbs the data written to it.
|
| 158 |
163 |
///
|
| 159 |
164 |
/// The simplest way of using this map is through the constMap()
|
| 160 |
165 |
/// function.
|
| 161 |
166 |
///
|
| 162 |
167 |
/// \sa NullMap
|
| 163 |
168 |
/// \sa IdentityMap
|
| 164 |
169 |
template<typename K, typename V, V v>
|
| 165 |
170 |
class ConstMap<K, Const<V, v> > : public MapBase<K, V> {
|
| 166 |
171 |
public:
|
| 167 |
172 |
typedef MapBase<K, V> Parent;
|
| 168 |
173 |
typedef typename Parent::Key Key;
|
| 169 |
174 |
typedef typename Parent::Value Value;
|
| ... |
... |
@@ -592,49 +597,49 @@
|
| 592 |
597 |
return combineMap<M1, M2, V (*)(K1, K2), V>(m1,m2,f);
|
| 593 |
598 |
}
|
| 594 |
599 |
|
| 595 |
600 |
|
| 596 |
601 |
/// Converts an STL style (unary) functor to a map
|
| 597 |
602 |
|
| 598 |
603 |
/// This \ref concepts::ReadMap "read-only map" returns the value
|
| 599 |
604 |
/// of a given functor. Actually, it just wraps the functor and
|
| 600 |
605 |
/// provides the \c Key and \c Value typedefs.
|
| 601 |
606 |
///
|
| 602 |
607 |
/// Template parameters \c K and \c V will become its \c Key and
|
| 603 |
608 |
/// \c Value. In most cases they have to be given explicitly because
|
| 604 |
609 |
/// a functor typically does not provide \c argument_type and
|
| 605 |
610 |
/// \c result_type typedefs.
|
| 606 |
611 |
/// Parameter \c F is the type of the used functor.
|
| 607 |
612 |
///
|
| 608 |
613 |
/// The simplest way of using this map is through the functorToMap()
|
| 609 |
614 |
/// function.
|
| 610 |
615 |
///
|
| 611 |
616 |
/// \sa MapToFunctor
|
| 612 |
617 |
template<typename F,
|
| 613 |
618 |
typename K = typename F::argument_type,
|
| 614 |
619 |
typename V = typename F::result_type>
|
| 615 |
620 |
class FunctorToMap : public MapBase<K, V> {
|
| 616 |
|
const F &_f;
|
|
621 |
F _f;
|
| 617 |
622 |
public:
|
| 618 |
623 |
typedef MapBase<K, V> Parent;
|
| 619 |
624 |
typedef typename Parent::Key Key;
|
| 620 |
625 |
typedef typename Parent::Value Value;
|
| 621 |
626 |
|
| 622 |
627 |
/// Constructor
|
| 623 |
628 |
FunctorToMap(const F &f = F()) : _f(f) {}
|
| 624 |
629 |
/// \e
|
| 625 |
630 |
Value operator[](const Key &k) const { return _f(k); }
|
| 626 |
631 |
};
|
| 627 |
632 |
|
| 628 |
633 |
/// Returns a \ref FunctorToMap class
|
| 629 |
634 |
|
| 630 |
635 |
/// This function just returns a \ref FunctorToMap class.
|
| 631 |
636 |
///
|
| 632 |
637 |
/// This function is specialized for adaptable binary function
|
| 633 |
638 |
/// classes and C++ functions.
|
| 634 |
639 |
///
|
| 635 |
640 |
/// \relates FunctorToMap
|
| 636 |
641 |
template<typename K, typename V, typename F>
|
| 637 |
642 |
inline FunctorToMap<F, K, V> functorToMap(const F &f) {
|
| 638 |
643 |
return FunctorToMap<F, K, V>(f);
|
| 639 |
644 |
}
|
| 640 |
645 |
|