1.1 --- a/lemon/maps.h Tue Oct 09 09:36:54 2007 +0000
1.2 +++ b/lemon/maps.h Tue Oct 09 15:46:12 2007 +0000
1.3 @@ -29,9 +29,6 @@
1.4 ///\ingroup maps
1.5 ///\brief Miscellaneous property maps
1.6 ///
1.7 -///\todo This file has the same name as the concept file in concepts/,
1.8 -/// and this is not easily detectable in docs...
1.9 -
1.10 #include <map>
1.11
1.12 namespace lemon {
1.13 @@ -79,8 +76,7 @@
1.14 /// Constant map.
1.15
1.16 /// This is a readable map which assigns a specified value to each key.
1.17 - /// In other aspects it is equivalent to the \ref NullMap.
1.18 - /// \todo set could be used to set the value.
1.19 + /// In other aspects it is equivalent to the \c NullMap.
1.20 template<typename K, typename T>
1.21 class ConstMap : public MapBase<K, T> {
1.22 private:
1.23 @@ -101,9 +97,14 @@
1.24 /// \param _v The initial value of the map.
1.25 ///
1.26 ConstMap(const T &_v) : v(_v) {}
1.27 +
1.28 + ///\e
1.29 + T operator[](const K&) const { return v; }
1.30
1.31 - T operator[](const K&) const { return v; }
1.32 - void set(const K&, const T&) {}
1.33 + ///\e
1.34 + void setAll(const T &t) {
1.35 + v = t;
1.36 + }
1.37
1.38 template<typename T1>
1.39 struct rebind {
1.40 @@ -114,9 +115,9 @@
1.41 ConstMap(const ConstMap<K, T1> &, const T &_v) : v(_v) {}
1.42 };
1.43
1.44 - ///Returns a \ref ConstMap class
1.45 + ///Returns a \c ConstMap class
1.46
1.47 - ///This function just returns a \ref ConstMap class.
1.48 + ///This function just returns a \c ConstMap class.
1.49 ///\relates ConstMap
1.50 template<typename K, typename V>
1.51 inline ConstMap<K, V> constMap(const V &v) {
1.52 @@ -124,11 +125,13 @@
1.53 }
1.54
1.55
1.56 - //\todo to document later
1.57 template<typename T, T v>
1.58 struct Const { };
1.59
1.60 - //\todo to document later
1.61 + /// Constant map with inlined constant value.
1.62 +
1.63 + /// This is a readable map which assigns a specified value to each key.
1.64 + /// In other aspects it is equivalent to the \c NullMap.
1.65 template<typename K, typename V, V v>
1.66 class ConstMap<K, Const<V, v> > : public MapBase<K, V> {
1.67 public:
1.68 @@ -137,32 +140,32 @@
1.69 typedef typename Parent::Value Value;
1.70
1.71 ConstMap() { }
1.72 + ///\e
1.73 V operator[](const K&) const { return v; }
1.74 + ///\e
1.75 void set(const K&, const V&) { }
1.76 };
1.77
1.78 - ///Returns a \ref ConstMap class
1.79 + ///Returns a \c ConstMap class
1.80
1.81 - ///This function just returns a \ref ConstMap class.
1.82 + ///This function just returns a \c ConstMap class with inlined value.
1.83 ///\relates ConstMap
1.84 template<typename K, typename V, V v>
1.85 inline ConstMap<K, Const<V, v> > constMap() {
1.86 return ConstMap<K, Const<V, v> >();
1.87 }
1.88
1.89 - /// \c std::map wrapper
1.90 + ///Map based on std::map
1.91
1.92 - /// This is essentially a wrapper for \c std::map. With addition that
1.93 - /// you can specify a default value different from \c Value() .
1.94 - ///
1.95 - /// \todo Provide allocator parameter...
1.96 + ///This is essentially a wrapper for \c std::map. With addition that
1.97 + ///you can specify a default value different from \c Value() .
1.98 template <typename K, typename T, typename Compare = std::less<K> >
1.99 - class StdMap : public std::map<K, T, Compare> {
1.100 - typedef std::map<K, T, Compare> parent;
1.101 - T v;
1.102 - typedef typename parent::value_type PairType;
1.103 + class StdMap {
1.104 + template <typename K1, typename T1, typename C1>
1.105 + friend class StdMap;
1.106 + public:
1.107
1.108 - public:
1.109 + typedef True ReferenceMapTag;
1.110 ///\e
1.111 typedef K Key;
1.112 ///\e
1.113 @@ -172,50 +175,69 @@
1.114 ///\e
1.115 typedef const T& ConstReference;
1.116
1.117 + private:
1.118 +
1.119 + typedef std::map<K, T, Compare> Map;
1.120 + Value _value;
1.121 + Map _map;
1.122
1.123 - StdMap() : v() {}
1.124 + public:
1.125 +
1.126 /// Constructor with specified default value
1.127 - StdMap(const T& _v) : v(_v) {}
1.128 -
1.129 - /// \brief Constructs the map from an appropriate std::map.
1.130 - ///
1.131 - /// \warning Inefficient: copies the content of \c m !
1.132 - StdMap(const parent &m) : parent(m) {}
1.133 + StdMap(const T& value = T()) : _value(value) {}
1.134 /// \brief Constructs the map from an appropriate std::map, and explicitly
1.135 /// specifies a default value.
1.136 - ///
1.137 - /// \warning Inefficient: copies the content of \c m !
1.138 - StdMap(const parent &m, const T& _v) : parent(m), v(_v) {}
1.139 + template <typename T1, typename Comp1>
1.140 + StdMap(const std::map<Key, T1, Comp1> &map, const T& value = T())
1.141 + : _map(map.begin(), map.end()), _value(value) {}
1.142
1.143 + /// \brief Constructs a map from an other StdMap.
1.144 template<typename T1, typename Comp1>
1.145 - StdMap(const StdMap<Key, T1,Comp1> &m, const T &_v) {
1.146 - //FIXME;
1.147 + StdMap(const StdMap<Key, T1, Comp1> &c)
1.148 + : _map(c._map.begin(), c._map.end()), _value(c._value) {}
1.149 +
1.150 + private:
1.151 +
1.152 + StdMap& operator=(const StdMap&);
1.153 +
1.154 + public:
1.155 +
1.156 + ///\e
1.157 + Reference operator[](const Key &k) {
1.158 + typename Map::iterator it = _map.lower_bound(k);
1.159 + if (it != _map.end() && !_map.key_comp()(k, it->first))
1.160 + return it->second;
1.161 + else
1.162 + return _map.insert(it, std::make_pair(k, _value))->second;
1.163 }
1.164
1.165 - Reference operator[](const Key &k) {
1.166 - return insert(PairType(k,v)).first -> second;
1.167 + /// \e
1.168 + ConstReference operator[](const Key &k) const {
1.169 + typename Map::const_iterator it = _map.find(k);
1.170 + if (it != _map.end())
1.171 + return it->second;
1.172 + else
1.173 + return _value;
1.174 }
1.175
1.176 - ConstReference operator[](const Key &k) const {
1.177 - typename parent::iterator i = lower_bound(k);
1.178 - if (i == parent::end() || parent::key_comp()(k, (*i).first))
1.179 - return v;
1.180 - return (*i).second;
1.181 - }
1.182 + /// \e
1.183 void set(const Key &k, const T &t) {
1.184 - parent::operator[](k) = t;
1.185 + typename Map::iterator it = _map.lower_bound(k);
1.186 + if (it != _map.end() && !_map.key_comp()(k, it->first))
1.187 + it->second = t;
1.188 + else
1.189 + _map.insert(it, std::make_pair(k, t));
1.190 }
1.191
1.192 - /// Changes the default value of the map.
1.193 - /// \return Returns the previous default value.
1.194 - ///
1.195 - /// \warning The value of some keys (which has already been queried, but
1.196 - /// the value has been unchanged from the default) may change!
1.197 - T setDefault(const T &_v) { T old=v; v=_v; return old; }
1.198 + /// \e
1.199 + void setAll(const T &t) {
1.200 + _value = t;
1.201 + _map.clear();
1.202 + }
1.203
1.204 - template<typename T1>
1.205 + template <typename T1, typename C1 = std::less<T1> >
1.206 struct rebind {
1.207 - typedef StdMap<Key, T1,Compare> other;
1.208 + typedef StdMap<Key, T1, C1> other;
1.209 };
1.210 };
1.211
1.212 @@ -235,14 +257,15 @@
1.213 typedef typename Parent::Key Key;
1.214 typedef typename Parent::Value Value;
1.215
1.216 + /// \e
1.217 const T& operator[](const T& t) const {
1.218 return t;
1.219 }
1.220 };
1.221
1.222 - ///Returns an \ref IdentityMap class
1.223 + ///Returns an \c IdentityMap class
1.224
1.225 - ///This function just returns an \ref IdentityMap class.
1.226 + ///This function just returns an \c IdentityMap class.
1.227 ///\relates IdentityMap
1.228 template<typename T>
1.229 inline IdentityMap<T> identityMap() {
1.230 @@ -252,7 +275,7 @@
1.231
1.232 ///Convert the \c Value of a map to another type.
1.233
1.234 - ///This \ref concepts::ReadMap "read only map"
1.235 + ///This \c concepts::ReadMap "read only map"
1.236 ///converts the \c Value of a maps to type \c T.
1.237 ///Its \c Key is inherited from \c M.
1.238 template <typename M, typename T>
1.239 @@ -277,11 +300,10 @@
1.240 Value operator[](const Key& k) const {return m[k];}
1.241 };
1.242
1.243 - ///Returns an \ref ConvertMap class
1.244 + ///Returns an \c ConvertMap class
1.245
1.246 - ///This function just returns an \ref ConvertMap class.
1.247 + ///This function just returns an \c ConvertMap class.
1.248 ///\relates ConvertMap
1.249 - ///\todo The order of the template parameters are changed.
1.250 template<typename T, typename M>
1.251 inline ConvertMap<M, T> convertMap(const M &m) {
1.252 return ConvertMap<M, T>(m);
1.253 @@ -289,7 +311,7 @@
1.254
1.255 ///Simple wrapping of the map
1.256
1.257 - ///This \ref concepts::ReadMap "read only map" returns the simple
1.258 + ///This \c concepts::ReadMap "read only map" returns the simple
1.259 ///wrapping of the given map. Sometimes the reference maps cannot be
1.260 ///combined with simple read maps. This map adaptor wraps the given
1.261 ///map to simple read map.
1.262 @@ -304,12 +326,13 @@
1.263
1.264 ///Constructor
1.265 SimpleMap(const M &_m) : m(_m) {};
1.266 + ///\e
1.267 Value operator[](Key k) const {return m[k];}
1.268 };
1.269
1.270 ///Simple writeable wrapping of the map
1.271
1.272 - ///This \ref concepts::ReadMap "read only map" returns the simple
1.273 + ///This \c concepts::ReadMap "read only map" returns the simple
1.274 ///wrapping of the given map. Sometimes the reference maps cannot be
1.275 ///combined with simple read-write maps. This map adaptor wraps the
1.276 ///given map to simple read-write map.
1.277 @@ -324,13 +347,15 @@
1.278
1.279 ///Constructor
1.280 SimpleWriteMap(M &_m) : m(_m) {};
1.281 + ///\e
1.282 Value operator[](Key k) const {return m[k];}
1.283 + ///\e
1.284 void set(Key k, const Value& c) { m.set(k, c); }
1.285 };
1.286
1.287 ///Sum of two maps
1.288
1.289 - ///This \ref concepts::ReadMap "read only map" returns the sum of the two
1.290 + ///This \c concepts::ReadMap "read only map" returns the sum of the two
1.291 ///given maps. Its \c Key and \c Value will be inherited from \c M1.
1.292 ///The \c Key and \c Value of M2 must be convertible to those of \c M1.
1.293
1.294 @@ -346,16 +371,16 @@
1.295
1.296 ///Constructor
1.297 AddMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
1.298 + ///\e
1.299 Value operator[](Key k) const {return m1[k]+m2[k];}
1.300 };
1.301
1.302 - ///Returns an \ref AddMap class
1.303 + ///Returns an \c AddMap class
1.304
1.305 - ///This function just returns an \ref AddMap class.
1.306 + ///This function just returns an \c AddMap class.
1.307 ///\todo How to call these type of functions?
1.308 ///
1.309 ///\relates AddMap
1.310 - ///\todo Wrong scope in Doxygen when \c \\relates is used
1.311 template<typename M1, typename M2>
1.312 inline AddMap<M1, M2> addMap(const M1 &m1,const M2 &m2) {
1.313 return AddMap<M1, M2>(m1,m2);
1.314 @@ -363,7 +388,7 @@
1.315
1.316 ///Shift a map with a constant.
1.317
1.318 - ///This \ref concepts::ReadMap "read only map" returns the sum of the
1.319 + ///This \c concepts::ReadMap "read only map" returns the sum of the
1.320 ///given map and a constant value.
1.321 ///Its \c Key and \c Value is inherited from \c M.
1.322 ///
1.323 @@ -391,12 +416,13 @@
1.324 ///\param _m is the undelying map
1.325 ///\param _v is the shift value
1.326 ShiftMap(const M &_m, const C &_v ) : m(_m), v(_v) {};
1.327 + ///\e
1.328 Value operator[](Key k) const {return m[k] + v;}
1.329 };
1.330
1.331 ///Shift a map with a constant.
1.332
1.333 - ///This \ref concepts::ReadWriteMap "read-write map" returns the sum of the
1.334 + ///This \c concepts::ReadWriteMap "read-write map" returns the sum of the
1.335 ///given map and a constant value. It makes also possible to write the map.
1.336 ///Its \c Key and \c Value is inherited from \c M.
1.337 ///
1.338 @@ -424,15 +450,16 @@
1.339 ///\param _m is the undelying map
1.340 ///\param _v is the shift value
1.341 ShiftWriteMap(M &_m, const C &_v ) : m(_m), v(_v) {};
1.342 + /// \e
1.343 Value operator[](Key k) const {return m[k] + v;}
1.344 + /// \e
1.345 void set(Key k, const Value& c) { m.set(k, c - v); }
1.346 };
1.347
1.348 - ///Returns an \ref ShiftMap class
1.349 + ///Returns an \c ShiftMap class
1.350
1.351 - ///This function just returns an \ref ShiftMap class.
1.352 + ///This function just returns an \c ShiftMap class.
1.353 ///\relates ShiftMap
1.354 - ///\todo A better name is required.
1.355 template<typename M, typename C>
1.356 inline ShiftMap<M, C> shiftMap(const M &m,const C &v) {
1.357 return ShiftMap<M, C>(m,v);
1.358 @@ -445,7 +472,7 @@
1.359
1.360 ///Difference of two maps
1.361
1.362 - ///This \ref concepts::ReadMap "read only map" returns the difference
1.363 + ///This \c concepts::ReadMap "read only map" returns the difference
1.364 ///of the values of the two
1.365 ///given maps. Its \c Key and \c Value will be inherited from \c M1.
1.366 ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
1.367 @@ -461,12 +488,13 @@
1.368
1.369 ///Constructor
1.370 SubMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
1.371 + /// \e
1.372 Value operator[](Key k) const {return m1[k]-m2[k];}
1.373 };
1.374
1.375 - ///Returns a \ref SubMap class
1.376 + ///Returns a \c SubMap class
1.377
1.378 - ///This function just returns a \ref SubMap class.
1.379 + ///This function just returns a \c SubMap class.
1.380 ///
1.381 ///\relates SubMap
1.382 template<typename M1, typename M2>
1.383 @@ -476,7 +504,7 @@
1.384
1.385 ///Product of two maps
1.386
1.387 - ///This \ref concepts::ReadMap "read only map" returns the product of the
1.388 + ///This \c concepts::ReadMap "read only map" returns the product of the
1.389 ///values of the two
1.390 ///given
1.391 ///maps. Its \c Key and \c Value will be inherited from \c M1.
1.392 @@ -493,12 +521,13 @@
1.393
1.394 ///Constructor
1.395 MulMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
1.396 + /// \e
1.397 Value operator[](Key k) const {return m1[k]*m2[k];}
1.398 };
1.399
1.400 - ///Returns a \ref MulMap class
1.401 + ///Returns a \c MulMap class
1.402
1.403 - ///This function just returns a \ref MulMap class.
1.404 + ///This function just returns a \c MulMap class.
1.405 ///\relates MulMap
1.406 template<typename M1, typename M2>
1.407 inline MulMap<M1, M2> mulMap(const M1 &m1,const M2 &m2) {
1.408 @@ -507,7 +536,7 @@
1.409
1.410 ///Scales a maps with a constant.
1.411
1.412 - ///This \ref concepts::ReadMap "read only map" returns the value of the
1.413 + ///This \c concepts::ReadMap "read only map" returns the value of the
1.414 ///given map multiplied from the left side with a constant value.
1.415 ///Its \c Key and \c Value is inherited from \c M.
1.416 ///
1.417 @@ -535,12 +564,13 @@
1.418 ///\param _m is the undelying map
1.419 ///\param _v is the scaling value
1.420 ScaleMap(const M &_m, const C &_v ) : m(_m), v(_v) {};
1.421 + /// \e
1.422 Value operator[](Key k) const {return v * m[k];}
1.423 };
1.424
1.425 ///Scales a maps with a constant.
1.426
1.427 - ///This \ref concepts::ReadWriteMap "read-write map" returns the value of the
1.428 + ///This \c concepts::ReadWriteMap "read-write map" returns the value of the
1.429 ///given map multiplied from the left side with a constant value. It can
1.430 ///be used as write map also if the given multiplier is not zero.
1.431 ///Its \c Key and \c Value is inherited from \c M.
1.432 @@ -559,15 +589,16 @@
1.433 ///\param _m is the undelying map
1.434 ///\param _v is the scaling value
1.435 ScaleWriteMap(M &_m, const C &_v ) : m(_m), v(_v) {};
1.436 + /// \e
1.437 Value operator[](Key k) const {return v * m[k];}
1.438 + /// \e
1.439 void set(Key k, const Value& c) { m.set(k, c / v);}
1.440 };
1.441
1.442 - ///Returns an \ref ScaleMap class
1.443 + ///Returns an \c ScaleMap class
1.444
1.445 - ///This function just returns an \ref ScaleMap class.
1.446 + ///This function just returns an \c ScaleMap class.
1.447 ///\relates ScaleMap
1.448 - ///\todo A better name is required.
1.449 template<typename M, typename C>
1.450 inline ScaleMap<M, C> scaleMap(const M &m,const C &v) {
1.451 return ScaleMap<M, C>(m,v);
1.452 @@ -580,7 +611,7 @@
1.453
1.454 ///Quotient of two maps
1.455
1.456 - ///This \ref concepts::ReadMap "read only map" returns the quotient of the
1.457 + ///This \c concepts::ReadMap "read only map" returns the quotient of the
1.458 ///values of the two
1.459 ///given maps. Its \c Key and \c Value will be inherited from \c M1.
1.460 ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
1.461 @@ -596,12 +627,13 @@
1.462
1.463 ///Constructor
1.464 DivMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
1.465 + /// \e
1.466 Value operator[](Key k) const {return m1[k]/m2[k];}
1.467 };
1.468
1.469 - ///Returns a \ref DivMap class
1.470 + ///Returns a \c DivMap class
1.471
1.472 - ///This function just returns a \ref DivMap class.
1.473 + ///This function just returns a \c DivMap class.
1.474 ///\relates DivMap
1.475 template<typename M1, typename M2>
1.476 inline DivMap<M1, M2> divMap(const M1 &m1,const M2 &m2) {
1.477 @@ -610,7 +642,7 @@
1.478
1.479 ///Composition of two maps
1.480
1.481 - ///This \ref concepts::ReadMap "read only map" returns the composition of
1.482 + ///This \c concepts::ReadMap "read only map" returns the composition of
1.483 ///two
1.484 ///given maps. That is to say, if \c m1 is of type \c M1 and \c m2 is
1.485 ///of \c M2,
1.486 @@ -624,7 +656,6 @@
1.487 ///\c M1.
1.488 ///The \c M2::Value must be convertible to \c M1::Key.
1.489 ///\todo Check the requirements.
1.490 -
1.491 template <typename M1, typename M2>
1.492 class ComposeMap : public MapBase<typename M2::Key, typename M1::Value> {
1.493 const M1& m1;
1.494 @@ -638,11 +669,12 @@
1.495 ComposeMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
1.496
1.497 typename MapTraits<M1>::ConstReturnValue
1.498 + /// \e
1.499 operator[](Key k) const {return m1[m2[k]];}
1.500 };
1.501 - ///Returns a \ref ComposeMap class
1.502 + ///Returns a \c ComposeMap class
1.503
1.504 - ///This function just returns a \ref ComposeMap class.
1.505 + ///This function just returns a \c ComposeMap class.
1.506 ///
1.507 ///\relates ComposeMap
1.508 template <typename M1, typename M2>
1.509 @@ -655,7 +687,7 @@
1.510 ///Combines of two maps using an STL (binary) functor.
1.511 ///
1.512 ///
1.513 - ///This \ref concepts::ReadMap "read only map" takes two maps and a
1.514 + ///This \c concepts::ReadMap "read only map" takes two maps and a
1.515 ///binary functor and returns the composition of
1.516 ///the two
1.517 ///given maps unsing the functor.
1.518 @@ -672,10 +704,8 @@
1.519 ///input parameter of \c F and the return type of \c F must be convertible
1.520 ///to \c V.
1.521 ///\todo Check the requirements.
1.522 -
1.523 template<typename M1, typename M2, typename F,
1.524 - typename V = typename F::result_type,
1.525 - typename NC = False>
1.526 + typename V = typename F::result_type>
1.527 class CombineMap : public MapBase<typename M1::Key, V> {
1.528 const M1& m1;
1.529 const M2& m2;
1.530 @@ -686,26 +716,28 @@
1.531 typedef typename Parent::Value Value;
1.532
1.533 ///Constructor
1.534 - CombineMap(const M1 &_m1,const M2 &_m2,const F &_f)
1.535 + CombineMap(const M1 &_m1,const M2 &_m2,const F &_f = F())
1.536 : m1(_m1), m2(_m2), f(_f) {};
1.537 + /// \e
1.538 Value operator[](Key k) const {return f(m1[k],m2[k]);}
1.539 };
1.540
1.541 - ///Returns a \ref CombineMap class
1.542 + ///Returns a \c CombineMap class
1.543
1.544 - ///This function just returns a \ref CombineMap class.
1.545 - ///
1.546 - ///Only the first template parameter (the value type) must be given.
1.547 + ///This function just returns a \c CombineMap class.
1.548 ///
1.549 ///For example if \c m1 and \c m2 are both \c double valued maps, then
1.550 ///\code
1.551 - ///combineMap<double>(m1,m2,std::plus<double>)
1.552 + ///combineMap<double>(m1,m2,std::plus<double>())
1.553 ///\endcode
1.554 ///is equivalent with
1.555 ///\code
1.556 ///addMap(m1,m2)
1.557 ///\endcode
1.558 ///
1.559 + ///This function is specialized for adaptable binary function
1.560 + ///classes and c++ functions.
1.561 + ///
1.562 ///\relates CombineMap
1.563 template<typename M1, typename M2, typename F, typename V>
1.564 inline CombineMap<M1, M2, F, V>
1.565 @@ -727,7 +759,7 @@
1.566
1.567 ///Negative value of a map
1.568
1.569 - ///This \ref concepts::ReadMap "read only map" returns the negative
1.570 + ///This \c concepts::ReadMap "read only map" returns the negative
1.571 ///value of the
1.572 ///value returned by the
1.573 ///given map. Its \c Key and \c Value will be inherited from \c M.
1.574 @@ -743,12 +775,13 @@
1.575
1.576 ///Constructor
1.577 NegMap(const M &_m) : m(_m) {};
1.578 + /// \e
1.579 Value operator[](Key k) const {return -m[k];}
1.580 };
1.581
1.582 ///Negative value of a map
1.583
1.584 - ///This \ref concepts::ReadWriteMap "read-write map" returns the negative
1.585 + ///This \c concepts::ReadWriteMap "read-write map" returns the negative
1.586 ///value of the value returned by the
1.587 ///given map. Its \c Key and \c Value will be inherited from \c M.
1.588 ///The unary \c - operator must be defined for \c Value, of course.
1.589 @@ -763,13 +796,15 @@
1.590
1.591 ///Constructor
1.592 NegWriteMap(M &_m) : m(_m) {};
1.593 + /// \e
1.594 Value operator[](Key k) const {return -m[k];}
1.595 + /// \e
1.596 void set(Key k, const Value& v) { m.set(k, -v); }
1.597 };
1.598
1.599 - ///Returns a \ref NegMap class
1.600 + ///Returns a \c NegMap class
1.601
1.602 - ///This function just returns a \ref NegMap class.
1.603 + ///This function just returns a \c NegMap class.
1.604 ///\relates NegMap
1.605 template <typename M>
1.606 inline NegMap<M> negMap(const M &m) {
1.607 @@ -783,7 +818,7 @@
1.608
1.609 ///Absolute value of a map
1.610
1.611 - ///This \ref concepts::ReadMap "read only map" returns the absolute value
1.612 + ///This \c concepts::ReadMap "read only map" returns the absolute value
1.613 ///of the
1.614 ///value returned by the
1.615 ///given map. Its \c Key and \c Value will be inherited
1.616 @@ -814,6 +849,7 @@
1.617
1.618 ///Constructor
1.619 AbsMap(const M &_m) : m(_m) {};
1.620 + /// \e
1.621 Value operator[](Key k) const {
1.622 Value tmp = m[k];
1.623 return tmp >= 0 ? tmp : -tmp;
1.624 @@ -821,9 +857,9 @@
1.625
1.626 };
1.627
1.628 - ///Returns a \ref AbsMap class
1.629 + ///Returns a \c AbsMap class
1.630
1.631 - ///This function just returns a \ref AbsMap class.
1.632 + ///This function just returns a \c AbsMap class.
1.633 ///\relates AbsMap
1.634 template<typename M>
1.635 inline AbsMap<M> absMap(const M &m) {
1.636 @@ -832,7 +868,7 @@
1.637
1.638 ///Converts an STL style functor to a map
1.639
1.640 - ///This \ref concepts::ReadMap "read only map" returns the value
1.641 + ///This \c concepts::ReadMap "read only map" returns the value
1.642 ///of a
1.643 ///given map.
1.644 ///
1.645 @@ -841,12 +877,9 @@
1.646 ///because a functor does not provide such typedefs.
1.647 ///
1.648 ///Parameter \c F is the type of the used functor.
1.649 -
1.650 -
1.651 template<typename F,
1.652 typename K = typename F::argument_type,
1.653 - typename V = typename F::result_type,
1.654 - typename NC = False>
1.655 + typename V = typename F::result_type>
1.656 class FunctorMap : public MapBase<K, V> {
1.657 F f;
1.658 public:
1.659 @@ -855,16 +888,17 @@
1.660 typedef typename Parent::Value Value;
1.661
1.662 ///Constructor
1.663 - FunctorMap(const F &_f) : f(_f) {}
1.664 -
1.665 + FunctorMap(const F &_f = F()) : f(_f) {}
1.666 + /// \e
1.667 Value operator[](Key k) const { return f(k);}
1.668 };
1.669
1.670 - ///Returns a \ref FunctorMap class
1.671 + ///Returns a \c FunctorMap class
1.672
1.673 - ///This function just returns a \ref FunctorMap class.
1.674 + ///This function just returns a \c FunctorMap class.
1.675 ///
1.676 - ///The third template parameter isn't necessary to be given.
1.677 + ///It is specialized for adaptable function classes and
1.678 + ///c++ functions.
1.679 ///\relates FunctorMap
1.680 template<typename K, typename V, typename F> inline
1.681 FunctorMap<F, K, V> functorMap(const F &f) {
1.682 @@ -890,9 +924,8 @@
1.683 ///that is it provides an <tt>operator()</tt> to read its values.
1.684 ///
1.685 ///For the sake of convenience it also works as
1.686 - ///a ususal \ref concepts::ReadMap "readable map",
1.687 + ///a ususal \c concepts::ReadMap "readable map",
1.688 ///i.e. <tt>operator[]</tt> and the \c Key and \c Value typedefs also exist.
1.689 -
1.690 template <typename M>
1.691 class MapFunctor : public MapBase<typename M::Key, typename M::Value> {
1.692 const M& m;
1.693 @@ -901,22 +934,20 @@
1.694 typedef typename Parent::Key Key;
1.695 typedef typename Parent::Value Value;
1.696
1.697 - ///\e
1.698 typedef typename M::Key argument_type;
1.699 - ///\e
1.700 typedef typename M::Value result_type;
1.701
1.702 ///Constructor
1.703 MapFunctor(const M &_m) : m(_m) {};
1.704 - ///Returns a value of the map
1.705 + ///\e
1.706 Value operator()(Key k) const {return m[k];}
1.707 ///\e
1.708 Value operator[](Key k) const {return m[k];}
1.709 };
1.710
1.711 - ///Returns a \ref MapFunctor class
1.712 + ///Returns a \c MapFunctor class
1.713
1.714 - ///This function just returns a \ref MapFunctor class.
1.715 + ///This function just returns a \c MapFunctor class.
1.716 ///\relates MapFunctor
1.717 template<typename M>
1.718 inline MapFunctor<M> mapFunctor(const M &m) {
1.719 @@ -925,13 +956,12 @@
1.720
1.721 ///Applies all map setting operations to two maps
1.722
1.723 - ///This map has two \ref concepts::ReadMap "readable map"
1.724 + ///This map has two \c concepts::ReadMap "readable map"
1.725 ///parameters and each read request will be passed just to the
1.726 ///first map. This class is the just readable map type of the ForkWriteMap.
1.727 ///
1.728 ///The \c Key and \c Value will be inherited from \c M1.
1.729 ///The \c Key and \c Value of M2 must be convertible from those of \c M1.
1.730 -
1.731 template<typename M1, typename M2>
1.732 class ForkMap : public MapBase<typename M1::Key, typename M1::Value> {
1.733 const M1& m1;
1.734 @@ -943,21 +973,21 @@
1.735
1.736 ///Constructor
1.737 ForkMap(const M1 &_m1, const M2 &_m2) : m1(_m1), m2(_m2) {};
1.738 + /// \e
1.739 Value operator[](Key k) const {return m1[k];}
1.740 };
1.741
1.742
1.743 ///Applies all map setting operations to two maps
1.744
1.745 - ///This map has two \ref concepts::WriteMap "writable map"
1.746 + ///This map has two \c concepts::WriteMap "writable map"
1.747 ///parameters and each write request will be passed to both of them.
1.748 - ///If \c M1 is also \ref concepts::ReadMap "readable",
1.749 + ///If \c M1 is also \c concepts::ReadMap "readable",
1.750 ///then the read operations will return the
1.751 ///corresponding values of \c M1.
1.752 ///
1.753 ///The \c Key and \c Value will be inherited from \c M1.
1.754 ///The \c Key and \c Value of M2 must be convertible from those of \c M1.
1.755 -
1.756 template<typename M1, typename M2>
1.757 class ForkWriteMap : public MapBase<typename M1::Key, typename M1::Value> {
1.758 M1& m1;
1.759 @@ -969,17 +999,17 @@
1.760
1.761 ///Constructor
1.762 ForkWriteMap(M1 &_m1, M2 &_m2) : m1(_m1), m2(_m2) {};
1.763 + ///\e
1.764 Value operator[](Key k) const {return m1[k];}
1.765 + ///\e
1.766 void set(Key k, const Value &v) {m1.set(k,v); m2.set(k,v);}
1.767 };
1.768
1.769 - ///Returns an \ref ForkMap class
1.770 + ///Returns an \c ForkMap class
1.771
1.772 - ///This function just returns an \ref ForkMap class.
1.773 - ///\todo How to call these type of functions?
1.774 + ///This function just returns an \c ForkMap class.
1.775 ///
1.776 ///\relates ForkMap
1.777 - ///\todo Wrong scope in Doxygen when \c \\relates is used
1.778 template <typename M1, typename M2>
1.779 inline ForkMap<M1, M2> forkMap(const M1 &m1, const M2 &m2) {
1.780 return ForkMap<M1, M2>(m1,m2);
1.781 @@ -996,12 +1026,11 @@
1.782
1.783 ///Logical 'not' of a map
1.784
1.785 - ///This bool \ref concepts::ReadMap "read only map" returns the
1.786 + ///This bool \c concepts::ReadMap "read only map" returns the
1.787 ///logical negation of
1.788 ///value returned by the
1.789 ///given map. Its \c Key and will be inherited from \c M,
1.790 ///its Value is <tt>bool</tt>.
1.791 -
1.792 template <typename M>
1.793 class NotMap : public MapBase<typename M::Key, bool> {
1.794 const M& m;
1.795 @@ -1012,12 +1041,13 @@
1.796
1.797 /// Constructor
1.798 NotMap(const M &_m) : m(_m) {};
1.799 + ///\e
1.800 Value operator[](Key k) const {return !m[k];}
1.801 };
1.802
1.803 ///Logical 'not' of a map with writing possibility
1.804
1.805 - ///This bool \ref concepts::ReadWriteMap "read-write map" returns the
1.806 + ///This bool \c concepts::ReadWriteMap "read-write map" returns the
1.807 ///logical negation of value returned by the given map. When it is set,
1.808 ///the opposite value is set to the original map.
1.809 ///Its \c Key and will be inherited from \c M,
1.810 @@ -1032,13 +1062,15 @@
1.811
1.812 /// Constructor
1.813 NotWriteMap(M &_m) : m(_m) {};
1.814 + ///\e
1.815 Value operator[](Key k) const {return !m[k];}
1.816 + ///\e
1.817 void set(Key k, bool v) { m.set(k, !v); }
1.818 };
1.819
1.820 - ///Returns a \ref NotMap class
1.821 + ///Returns a \c NotMap class
1.822
1.823 - ///This function just returns a \ref NotMap class.
1.824 + ///This function just returns a \c NotMap class.
1.825 ///\relates NotMap
1.826 template <typename M>
1.827 inline NotMap<M> notMap(const M &m) {
1.828 @@ -1277,7 +1309,6 @@
1.829 /// }
1.830 /// }
1.831 ///\endcode
1.832 -
1.833 template <typename Map>
1.834 class FillBoolMap {
1.835 public:
1.836 @@ -1325,7 +1356,7 @@
1.837 ///
1.838 /// Writable bool map which stores for each true assigned elements
1.839 /// the setting order number. It make easy to calculate the leaving
1.840 - /// order of the nodes in the \ref dfs "Dfs" algorithm.
1.841 + /// order of the nodes in the \c Dfs algorithm.
1.842 ///
1.843 ///\code
1.844 /// typedef Graph::NodeMap<int> OrderMap;