lemon/maps.h
changeset 2510 bb523a4758f7
parent 2423 02fedd6652c6
child 2511 a99186a9b6b0
equal deleted inserted replaced
29:e304063824dc 30:370a65be8358
    27 
    27 
    28 ///\file
    28 ///\file
    29 ///\ingroup maps
    29 ///\ingroup maps
    30 ///\brief Miscellaneous property maps
    30 ///\brief Miscellaneous property maps
    31 ///
    31 ///
    32 ///\todo This file has the same name as the concept file in concepts/,
       
    33 /// and this is not easily detectable in docs...
       
    34 
       
    35 #include <map>
    32 #include <map>
    36 
    33 
    37 namespace lemon {
    34 namespace lemon {
    38 
    35 
    39   /// \addtogroup maps
    36   /// \addtogroup maps
    77 
    74 
    78 
    75 
    79   /// Constant map.
    76   /// Constant map.
    80 
    77 
    81   /// This is a readable map which assigns a specified value to each key.
    78   /// This is a readable map which assigns a specified value to each key.
    82   /// In other aspects it is equivalent to the \ref NullMap.
    79   /// In other aspects it is equivalent to the \c NullMap.
    83   /// \todo set could be used to set the value.
       
    84   template<typename K, typename T>
    80   template<typename K, typename T>
    85   class ConstMap : public MapBase<K, T> {
    81   class ConstMap : public MapBase<K, T> {
    86   private:
    82   private:
    87     T v;
    83     T v;
    88   public:
    84   public:
    99     ///\e
    95     ///\e
   100 
    96 
   101     /// \param _v The initial value of the map.
    97     /// \param _v The initial value of the map.
   102     ///
    98     ///
   103     ConstMap(const T &_v) : v(_v) {}
    99     ConstMap(const T &_v) : v(_v) {}
   104 
   100     
       
   101     ///\e
   105     T operator[](const K&) const { return v; }
   102     T operator[](const K&) const { return v; }
   106     void set(const K&, const T&) {}
   103 
       
   104     ///\e
       
   105     void setAll(const T &t) {
       
   106       v = t;
       
   107     }    
   107 
   108 
   108     template<typename T1>
   109     template<typename T1>
   109     struct rebind {
   110     struct rebind {
   110       typedef ConstMap<K, T1> other;
   111       typedef ConstMap<K, T1> other;
   111     };
   112     };
   112 
   113 
   113     template<typename T1>
   114     template<typename T1>
   114     ConstMap(const ConstMap<K, T1> &, const T &_v) : v(_v) {}
   115     ConstMap(const ConstMap<K, T1> &, const T &_v) : v(_v) {}
   115   };
   116   };
   116 
   117 
   117   ///Returns a \ref ConstMap class
   118   ///Returns a \c ConstMap class
   118 
   119 
   119   ///This function just returns a \ref ConstMap class.
   120   ///This function just returns a \c ConstMap class.
   120   ///\relates ConstMap
   121   ///\relates ConstMap
   121   template<typename K, typename V> 
   122   template<typename K, typename V> 
   122   inline ConstMap<K, V> constMap(const V &v) {
   123   inline ConstMap<K, V> constMap(const V &v) {
   123     return ConstMap<K, V>(v);
   124     return ConstMap<K, V>(v);
   124   }
   125   }
   125 
   126 
   126 
   127 
   127   //\todo to document later
       
   128   template<typename T, T v>
   128   template<typename T, T v>
   129   struct Const { };
   129   struct Const { };
   130 
   130 
   131   //\todo to document later
   131   /// Constant map with inlined constant value.
       
   132 
       
   133   /// This is a readable map which assigns a specified value to each key.
       
   134   /// In other aspects it is equivalent to the \c NullMap.
   132   template<typename K, typename V, V v>
   135   template<typename K, typename V, V v>
   133   class ConstMap<K, Const<V, v> > : public MapBase<K, V> {
   136   class ConstMap<K, Const<V, v> > : public MapBase<K, V> {
   134   public:
   137   public:
   135     typedef MapBase<K, V> Parent;
   138     typedef MapBase<K, V> Parent;
   136     typedef typename Parent::Key Key;
   139     typedef typename Parent::Key Key;
   137     typedef typename Parent::Value Value;
   140     typedef typename Parent::Value Value;
   138 
   141 
   139     ConstMap() { }
   142     ConstMap() { }
       
   143     ///\e
   140     V operator[](const K&) const { return v; }
   144     V operator[](const K&) const { return v; }
       
   145     ///\e
   141     void set(const K&, const V&) { }
   146     void set(const K&, const V&) { }
   142   };
   147   };
   143 
   148 
   144   ///Returns a \ref ConstMap class
   149   ///Returns a \c ConstMap class
   145 
   150 
   146   ///This function just returns a \ref ConstMap class.
   151   ///This function just returns a \c ConstMap class with inlined value.
   147   ///\relates ConstMap
   152   ///\relates ConstMap
   148   template<typename K, typename V, V v> 
   153   template<typename K, typename V, V v> 
   149   inline ConstMap<K, Const<V, v> > constMap() {
   154   inline ConstMap<K, Const<V, v> > constMap() {
   150     return ConstMap<K, Const<V, v> >();
   155     return ConstMap<K, Const<V, v> >();
   151   }
   156   }
   152 
   157 
   153   /// \c std::map wrapper
   158   ///Map based on std::map
   154 
   159 
   155   /// This is essentially a wrapper for \c std::map. With addition that
   160   ///This is essentially a wrapper for \c std::map. With addition that
   156   /// you can specify a default value different from \c Value() .
   161   ///you can specify a default value different from \c Value() .
   157   ///
       
   158   /// \todo Provide allocator parameter...
       
   159   template <typename K, typename T, typename Compare = std::less<K> >
   162   template <typename K, typename T, typename Compare = std::less<K> >
   160   class StdMap : public std::map<K, T, Compare> {
   163   class StdMap {
   161     typedef std::map<K, T, Compare> parent;
   164     template <typename K1, typename T1, typename C1>
   162     T v;
   165     friend class StdMap;
   163     typedef typename parent::value_type PairType;
   166   public:
   164 
   167 
   165   public:
   168     typedef True ReferenceMapTag;
   166     ///\e
   169     ///\e
   167     typedef K Key;
   170     typedef K Key;
   168     ///\e
   171     ///\e
   169     typedef T Value;
   172     typedef T Value;
   170     ///\e
   173     ///\e
   171     typedef T& Reference;
   174     typedef T& Reference;
   172     ///\e
   175     ///\e
   173     typedef const T& ConstReference;
   176     typedef const T& ConstReference;
   174 
   177 
   175 
   178   private:
   176     StdMap() : v() {}
   179     
       
   180     typedef std::map<K, T, Compare> Map;
       
   181     Value _value;
       
   182     Map _map;
       
   183 
       
   184   public:
       
   185 
   177     /// Constructor with specified default value
   186     /// Constructor with specified default value
   178     StdMap(const T& _v) : v(_v) {}
   187     StdMap(const T& value = T()) : _value(value) {}
   179 
       
   180     /// \brief Constructs the map from an appropriate std::map.
       
   181     ///
       
   182     /// \warning Inefficient: copies the content of \c m !
       
   183     StdMap(const parent &m) : parent(m) {}
       
   184     /// \brief Constructs the map from an appropriate std::map, and explicitly
   188     /// \brief Constructs the map from an appropriate std::map, and explicitly
   185     /// specifies a default value.
   189     /// specifies a default value.
   186     ///
   190     template <typename T1, typename Comp1>
   187     /// \warning Inefficient: copies the content of \c m !
   191     StdMap(const std::map<Key, T1, Comp1> &map, const T& value = T()) 
   188     StdMap(const parent &m, const T& _v) : parent(m), v(_v) {}
   192       : _map(map.begin(), map.end()), _value(value) {}
   189     
   193     
       
   194     /// \brief Constructs a map from an other StdMap.
   190     template<typename T1, typename Comp1>
   195     template<typename T1, typename Comp1>
   191     StdMap(const StdMap<Key, T1,Comp1> &m, const T &_v) { 
   196     StdMap(const StdMap<Key, T1, Comp1> &c) 
   192       //FIXME; 
   197       : _map(c._map.begin(), c._map.end()), _value(c._value) {}
       
   198 
       
   199   private:
       
   200 
       
   201     StdMap& operator=(const StdMap&);
       
   202 
       
   203   public:
       
   204 
       
   205     ///\e
       
   206     Reference operator[](const Key &k) {
       
   207       typename Map::iterator it = _map.lower_bound(k);
       
   208       if (it != _map.end() && !_map.key_comp()(k, it->first))
       
   209 	return it->second;
       
   210       else
       
   211 	return _map.insert(it, std::make_pair(k, _value))->second;
   193     }
   212     }
   194 
   213 
   195     Reference operator[](const Key &k) {
   214     /// \e 
   196       return insert(PairType(k,v)).first -> second;
   215     ConstReference operator[](const Key &k) const {
       
   216       typename Map::const_iterator it = _map.find(k);
       
   217       if (it != _map.end())
       
   218 	return it->second;
       
   219       else
       
   220 	return _value;
   197     }
   221     }
   198 
   222 
   199     ConstReference operator[](const Key &k) const {
   223     /// \e 
   200       typename parent::iterator i = lower_bound(k);
   224     void set(const Key &k, const T &t) {
   201       if (i == parent::end() || parent::key_comp()(k, (*i).first))
   225       typename Map::iterator it = _map.lower_bound(k);
   202 	return v;
   226       if (it != _map.end() && !_map.key_comp()(k, it->first))
   203       return (*i).second;
   227 	it->second = t;
       
   228       else
       
   229 	_map.insert(it, std::make_pair(k, t));
   204     }
   230     }
   205     void set(const Key &k, const T &t) {
   231 
   206       parent::operator[](k) = t;
   232     /// \e
   207     }
   233     void setAll(const T &t) {
   208 
   234       _value = t;
   209     /// Changes the default value of the map.
   235       _map.clear();
   210     /// \return Returns the previous default value.
   236     }    
   211     ///
   237 
   212     /// \warning The value of some keys (which has already been queried, but
   238     template <typename T1, typename C1 = std::less<T1> >
   213     /// the value has been unchanged from the default) may change!
       
   214     T setDefault(const T &_v) { T old=v; v=_v; return old; }
       
   215 
       
   216     template<typename T1>
       
   217     struct rebind {
   239     struct rebind {
   218       typedef StdMap<Key, T1,Compare> other;
   240       typedef StdMap<Key, T1, C1> other;
   219     };
   241     };
   220   };
   242   };
   221 
   243 
   222   /// @}
   244   /// @}
   223 
   245 
   233   public:
   255   public:
   234     typedef MapBase<T, T> Parent;
   256     typedef MapBase<T, T> Parent;
   235     typedef typename Parent::Key Key;
   257     typedef typename Parent::Key Key;
   236     typedef typename Parent::Value Value;
   258     typedef typename Parent::Value Value;
   237 
   259 
       
   260     /// \e
   238     const T& operator[](const T& t) const {
   261     const T& operator[](const T& t) const {
   239       return t;
   262       return t;
   240     }
   263     }
   241   };
   264   };
   242 
   265 
   243   ///Returns an \ref IdentityMap class
   266   ///Returns an \c IdentityMap class
   244 
   267 
   245   ///This function just returns an \ref IdentityMap class.
   268   ///This function just returns an \c IdentityMap class.
   246   ///\relates IdentityMap
   269   ///\relates IdentityMap
   247   template<typename T>
   270   template<typename T>
   248   inline IdentityMap<T> identityMap() {
   271   inline IdentityMap<T> identityMap() {
   249     return IdentityMap<T>();
   272     return IdentityMap<T>();
   250   }
   273   }
   251   
   274   
   252 
   275 
   253   ///Convert the \c Value of a map to another type.
   276   ///Convert the \c Value of a map to another type.
   254 
   277 
   255   ///This \ref concepts::ReadMap "read only map"
   278   ///This \c concepts::ReadMap "read only map"
   256   ///converts the \c Value of a maps to type \c T.
   279   ///converts the \c Value of a maps to type \c T.
   257   ///Its \c Key is inherited from \c M.
   280   ///Its \c Key is inherited from \c M.
   258   template <typename M, typename T> 
   281   template <typename M, typename T> 
   259   class ConvertMap : public MapBase<typename M::Key, T> {
   282   class ConvertMap : public MapBase<typename M::Key, T> {
   260     const M& m;
   283     const M& m;
   275     /// \param k The key
   298     /// \param k The key
   276     /// \return The target of the edge 
   299     /// \return The target of the edge 
   277     Value operator[](const Key& k) const {return m[k];}
   300     Value operator[](const Key& k) const {return m[k];}
   278   };
   301   };
   279   
   302   
   280   ///Returns an \ref ConvertMap class
   303   ///Returns an \c ConvertMap class
   281 
   304 
   282   ///This function just returns an \ref ConvertMap class.
   305   ///This function just returns an \c ConvertMap class.
   283   ///\relates ConvertMap
   306   ///\relates ConvertMap
   284   ///\todo The order of the template parameters are changed.
       
   285   template<typename T, typename M>
   307   template<typename T, typename M>
   286   inline ConvertMap<M, T> convertMap(const M &m) {
   308   inline ConvertMap<M, T> convertMap(const M &m) {
   287     return ConvertMap<M, T>(m);
   309     return ConvertMap<M, T>(m);
   288   }
   310   }
   289 
   311 
   290   ///Simple wrapping of the map
   312   ///Simple wrapping of the map
   291 
   313 
   292   ///This \ref concepts::ReadMap "read only map" returns the simple
   314   ///This \c concepts::ReadMap "read only map" returns the simple
   293   ///wrapping of the given map. Sometimes the reference maps cannot be
   315   ///wrapping of the given map. Sometimes the reference maps cannot be
   294   ///combined with simple read maps. This map adaptor wraps the given
   316   ///combined with simple read maps. This map adaptor wraps the given
   295   ///map to simple read map.
   317   ///map to simple read map.
   296   template<typename M> 
   318   template<typename M> 
   297   class SimpleMap : public MapBase<typename M::Key, typename M::Value> {
   319   class SimpleMap : public MapBase<typename M::Key, typename M::Value> {
   302     typedef typename Parent::Key Key;
   324     typedef typename Parent::Key Key;
   303     typedef typename Parent::Value Value;
   325     typedef typename Parent::Value Value;
   304 
   326 
   305     ///Constructor
   327     ///Constructor
   306     SimpleMap(const M &_m) : m(_m) {};
   328     SimpleMap(const M &_m) : m(_m) {};
       
   329     ///\e
   307     Value operator[](Key k) const {return m[k];}
   330     Value operator[](Key k) const {return m[k];}
   308   };
   331   };
   309 
   332 
   310   ///Simple writeable wrapping of the map
   333   ///Simple writeable wrapping of the map
   311 
   334 
   312   ///This \ref concepts::ReadMap "read only map" returns the simple
   335   ///This \c concepts::ReadMap "read only map" returns the simple
   313   ///wrapping of the given map. Sometimes the reference maps cannot be
   336   ///wrapping of the given map. Sometimes the reference maps cannot be
   314   ///combined with simple read-write maps. This map adaptor wraps the
   337   ///combined with simple read-write maps. This map adaptor wraps the
   315   ///given map to simple read-write map.
   338   ///given map to simple read-write map.
   316   template<typename M> 
   339   template<typename M> 
   317   class SimpleWriteMap : public MapBase<typename M::Key, typename M::Value> {
   340   class SimpleWriteMap : public MapBase<typename M::Key, typename M::Value> {
   322     typedef typename Parent::Key Key;
   345     typedef typename Parent::Key Key;
   323     typedef typename Parent::Value Value;
   346     typedef typename Parent::Value Value;
   324 
   347 
   325     ///Constructor
   348     ///Constructor
   326     SimpleWriteMap(M &_m) : m(_m) {};
   349     SimpleWriteMap(M &_m) : m(_m) {};
       
   350     ///\e
   327     Value operator[](Key k) const {return m[k];}
   351     Value operator[](Key k) const {return m[k];}
       
   352     ///\e
   328     void set(Key k, const Value& c) { m.set(k, c); }
   353     void set(Key k, const Value& c) { m.set(k, c); }
   329   };
   354   };
   330 
   355 
   331   ///Sum of two maps
   356   ///Sum of two maps
   332 
   357 
   333   ///This \ref concepts::ReadMap "read only map" returns the sum of the two
   358   ///This \c concepts::ReadMap "read only map" returns the sum of the two
   334   ///given maps. Its \c Key and \c Value will be inherited from \c M1.
   359   ///given maps. Its \c Key and \c Value will be inherited from \c M1.
   335   ///The \c Key and \c Value of M2 must be convertible to those of \c M1.
   360   ///The \c Key and \c Value of M2 must be convertible to those of \c M1.
   336 
   361 
   337   template<typename M1, typename M2> 
   362   template<typename M1, typename M2> 
   338   class AddMap : public MapBase<typename M1::Key, typename M1::Value> {
   363   class AddMap : public MapBase<typename M1::Key, typename M1::Value> {
   344     typedef typename Parent::Key Key;
   369     typedef typename Parent::Key Key;
   345     typedef typename Parent::Value Value;
   370     typedef typename Parent::Value Value;
   346 
   371 
   347     ///Constructor
   372     ///Constructor
   348     AddMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
   373     AddMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
       
   374     ///\e
   349     Value operator[](Key k) const {return m1[k]+m2[k];}
   375     Value operator[](Key k) const {return m1[k]+m2[k];}
   350   };
   376   };
   351   
   377   
   352   ///Returns an \ref AddMap class
   378   ///Returns an \c AddMap class
   353 
   379 
   354   ///This function just returns an \ref AddMap class.
   380   ///This function just returns an \c AddMap class.
   355   ///\todo How to call these type of functions?
   381   ///\todo How to call these type of functions?
   356   ///
   382   ///
   357   ///\relates AddMap
   383   ///\relates AddMap
   358   ///\todo Wrong scope in Doxygen when \c \\relates is used
       
   359   template<typename M1, typename M2> 
   384   template<typename M1, typename M2> 
   360   inline AddMap<M1, M2> addMap(const M1 &m1,const M2 &m2) {
   385   inline AddMap<M1, M2> addMap(const M1 &m1,const M2 &m2) {
   361     return AddMap<M1, M2>(m1,m2);
   386     return AddMap<M1, M2>(m1,m2);
   362   }
   387   }
   363 
   388 
   364   ///Shift a map with a constant.
   389   ///Shift a map with a constant.
   365 
   390 
   366   ///This \ref concepts::ReadMap "read only map" returns the sum of the
   391   ///This \c concepts::ReadMap "read only map" returns the sum of the
   367   ///given map and a constant value.
   392   ///given map and a constant value.
   368   ///Its \c Key and \c Value is inherited from \c M.
   393   ///Its \c Key and \c Value is inherited from \c M.
   369   ///
   394   ///
   370   ///Actually,
   395   ///Actually,
   371   ///\code
   396   ///\code
   389 
   414 
   390     ///Constructor
   415     ///Constructor
   391     ///\param _m is the undelying map
   416     ///\param _m is the undelying map
   392     ///\param _v is the shift value
   417     ///\param _v is the shift value
   393     ShiftMap(const M &_m, const C &_v ) : m(_m), v(_v) {};
   418     ShiftMap(const M &_m, const C &_v ) : m(_m), v(_v) {};
       
   419     ///\e
   394     Value operator[](Key k) const {return m[k] + v;}
   420     Value operator[](Key k) const {return m[k] + v;}
   395   };
   421   };
   396 
   422 
   397   ///Shift a map with a constant.
   423   ///Shift a map with a constant.
   398 
   424 
   399   ///This \ref concepts::ReadWriteMap "read-write map" returns the sum of the
   425   ///This \c concepts::ReadWriteMap "read-write map" returns the sum of the
   400   ///given map and a constant value. It makes also possible to write the map.
   426   ///given map and a constant value. It makes also possible to write the map.
   401   ///Its \c Key and \c Value is inherited from \c M.
   427   ///Its \c Key and \c Value is inherited from \c M.
   402   ///
   428   ///
   403   ///Actually,
   429   ///Actually,
   404   ///\code
   430   ///\code
   422 
   448 
   423     ///Constructor
   449     ///Constructor
   424     ///\param _m is the undelying map
   450     ///\param _m is the undelying map
   425     ///\param _v is the shift value
   451     ///\param _v is the shift value
   426     ShiftWriteMap(M &_m, const C &_v ) : m(_m), v(_v) {};
   452     ShiftWriteMap(M &_m, const C &_v ) : m(_m), v(_v) {};
       
   453     /// \e
   427     Value operator[](Key k) const {return m[k] + v;}
   454     Value operator[](Key k) const {return m[k] + v;}
       
   455     /// \e
   428     void set(Key k, const Value& c) { m.set(k, c - v); }
   456     void set(Key k, const Value& c) { m.set(k, c - v); }
   429   };
   457   };
   430   
   458   
   431   ///Returns an \ref ShiftMap class
   459   ///Returns an \c ShiftMap class
   432 
   460 
   433   ///This function just returns an \ref ShiftMap class.
   461   ///This function just returns an \c ShiftMap class.
   434   ///\relates ShiftMap
   462   ///\relates ShiftMap
   435   ///\todo A better name is required.
       
   436   template<typename M, typename C> 
   463   template<typename M, typename C> 
   437   inline ShiftMap<M, C> shiftMap(const M &m,const C &v) {
   464   inline ShiftMap<M, C> shiftMap(const M &m,const C &v) {
   438     return ShiftMap<M, C>(m,v);
   465     return ShiftMap<M, C>(m,v);
   439   }
   466   }
   440 
   467 
   443     return ShiftWriteMap<M, C>(m,v);
   470     return ShiftWriteMap<M, C>(m,v);
   444   }
   471   }
   445 
   472 
   446   ///Difference of two maps
   473   ///Difference of two maps
   447 
   474 
   448   ///This \ref concepts::ReadMap "read only map" returns the difference
   475   ///This \c concepts::ReadMap "read only map" returns the difference
   449   ///of the values of the two
   476   ///of the values of the two
   450   ///given maps. Its \c Key and \c Value will be inherited from \c M1.
   477   ///given maps. Its \c Key and \c Value will be inherited from \c M1.
   451   ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
   478   ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
   452 
   479 
   453   template<typename M1, typename M2> 
   480   template<typename M1, typename M2> 
   459     typedef typename Parent::Key Key;
   486     typedef typename Parent::Key Key;
   460     typedef typename Parent::Value Value;
   487     typedef typename Parent::Value Value;
   461 
   488 
   462     ///Constructor
   489     ///Constructor
   463     SubMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
   490     SubMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
       
   491     /// \e
   464     Value operator[](Key k) const {return m1[k]-m2[k];}
   492     Value operator[](Key k) const {return m1[k]-m2[k];}
   465   };
   493   };
   466   
   494   
   467   ///Returns a \ref SubMap class
   495   ///Returns a \c SubMap class
   468 
   496 
   469   ///This function just returns a \ref SubMap class.
   497   ///This function just returns a \c SubMap class.
   470   ///
   498   ///
   471   ///\relates SubMap
   499   ///\relates SubMap
   472   template<typename M1, typename M2> 
   500   template<typename M1, typename M2> 
   473   inline SubMap<M1, M2> subMap(const M1 &m1, const M2 &m2) {
   501   inline SubMap<M1, M2> subMap(const M1 &m1, const M2 &m2) {
   474     return SubMap<M1, M2>(m1, m2);
   502     return SubMap<M1, M2>(m1, m2);
   475   }
   503   }
   476 
   504 
   477   ///Product of two maps
   505   ///Product of two maps
   478 
   506 
   479   ///This \ref concepts::ReadMap "read only map" returns the product of the
   507   ///This \c concepts::ReadMap "read only map" returns the product of the
   480   ///values of the two
   508   ///values of the two
   481   ///given
   509   ///given
   482   ///maps. Its \c Key and \c Value will be inherited from \c M1.
   510   ///maps. Its \c Key and \c Value will be inherited from \c M1.
   483   ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
   511   ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
   484 
   512 
   491     typedef typename Parent::Key Key;
   519     typedef typename Parent::Key Key;
   492     typedef typename Parent::Value Value;
   520     typedef typename Parent::Value Value;
   493 
   521 
   494     ///Constructor
   522     ///Constructor
   495     MulMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
   523     MulMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
       
   524     /// \e
   496     Value operator[](Key k) const {return m1[k]*m2[k];}
   525     Value operator[](Key k) const {return m1[k]*m2[k];}
   497   };
   526   };
   498   
   527   
   499   ///Returns a \ref MulMap class
   528   ///Returns a \c MulMap class
   500 
   529 
   501   ///This function just returns a \ref MulMap class.
   530   ///This function just returns a \c MulMap class.
   502   ///\relates MulMap
   531   ///\relates MulMap
   503   template<typename M1, typename M2> 
   532   template<typename M1, typename M2> 
   504   inline MulMap<M1, M2> mulMap(const M1 &m1,const M2 &m2) {
   533   inline MulMap<M1, M2> mulMap(const M1 &m1,const M2 &m2) {
   505     return MulMap<M1, M2>(m1,m2);
   534     return MulMap<M1, M2>(m1,m2);
   506   }
   535   }
   507  
   536  
   508   ///Scales a maps with a constant.
   537   ///Scales a maps with a constant.
   509 
   538 
   510   ///This \ref concepts::ReadMap "read only map" returns the value of the
   539   ///This \c concepts::ReadMap "read only map" returns the value of the
   511   ///given map multiplied from the left side with a constant value.
   540   ///given map multiplied from the left side with a constant value.
   512   ///Its \c Key and \c Value is inherited from \c M.
   541   ///Its \c Key and \c Value is inherited from \c M.
   513   ///
   542   ///
   514   ///Actually,
   543   ///Actually,
   515   ///\code
   544   ///\code
   533 
   562 
   534     ///Constructor
   563     ///Constructor
   535     ///\param _m is the undelying map
   564     ///\param _m is the undelying map
   536     ///\param _v is the scaling value
   565     ///\param _v is the scaling value
   537     ScaleMap(const M &_m, const C &_v ) : m(_m), v(_v) {};
   566     ScaleMap(const M &_m, const C &_v ) : m(_m), v(_v) {};
       
   567     /// \e
   538     Value operator[](Key k) const {return v * m[k];}
   568     Value operator[](Key k) const {return v * m[k];}
   539   };
   569   };
   540 
   570 
   541   ///Scales a maps with a constant.
   571   ///Scales a maps with a constant.
   542 
   572 
   543   ///This \ref concepts::ReadWriteMap "read-write map" returns the value of the
   573   ///This \c concepts::ReadWriteMap "read-write map" returns the value of the
   544   ///given map multiplied from the left side with a constant value. It can
   574   ///given map multiplied from the left side with a constant value. It can
   545   ///be used as write map also if the given multiplier is not zero.
   575   ///be used as write map also if the given multiplier is not zero.
   546   ///Its \c Key and \c Value is inherited from \c M.
   576   ///Its \c Key and \c Value is inherited from \c M.
   547   template<typename M, typename C = typename M::Value> 
   577   template<typename M, typename C = typename M::Value> 
   548   class ScaleWriteMap : public MapBase<typename M::Key, typename M::Value> {
   578   class ScaleWriteMap : public MapBase<typename M::Key, typename M::Value> {
   557 
   587 
   558     ///Constructor
   588     ///Constructor
   559     ///\param _m is the undelying map
   589     ///\param _m is the undelying map
   560     ///\param _v is the scaling value
   590     ///\param _v is the scaling value
   561     ScaleWriteMap(M &_m, const C &_v ) : m(_m), v(_v) {};
   591     ScaleWriteMap(M &_m, const C &_v ) : m(_m), v(_v) {};
       
   592     /// \e
   562     Value operator[](Key k) const {return v * m[k];}
   593     Value operator[](Key k) const {return v * m[k];}
       
   594     /// \e
   563     void set(Key k, const Value& c) { m.set(k, c / v);}
   595     void set(Key k, const Value& c) { m.set(k, c / v);}
   564   };
   596   };
   565   
   597   
   566   ///Returns an \ref ScaleMap class
   598   ///Returns an \c ScaleMap class
   567 
   599 
   568   ///This function just returns an \ref ScaleMap class.
   600   ///This function just returns an \c ScaleMap class.
   569   ///\relates ScaleMap
   601   ///\relates ScaleMap
   570   ///\todo A better name is required.
       
   571   template<typename M, typename C> 
   602   template<typename M, typename C> 
   572   inline ScaleMap<M, C> scaleMap(const M &m,const C &v) {
   603   inline ScaleMap<M, C> scaleMap(const M &m,const C &v) {
   573     return ScaleMap<M, C>(m,v);
   604     return ScaleMap<M, C>(m,v);
   574   }
   605   }
   575 
   606 
   578     return ScaleWriteMap<M, C>(m,v);
   609     return ScaleWriteMap<M, C>(m,v);
   579   }
   610   }
   580 
   611 
   581   ///Quotient of two maps
   612   ///Quotient of two maps
   582 
   613 
   583   ///This \ref concepts::ReadMap "read only map" returns the quotient of the
   614   ///This \c concepts::ReadMap "read only map" returns the quotient of the
   584   ///values of the two
   615   ///values of the two
   585   ///given maps. Its \c Key and \c Value will be inherited from \c M1.
   616   ///given maps. Its \c Key and \c Value will be inherited from \c M1.
   586   ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
   617   ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
   587 
   618 
   588   template<typename M1, typename M2> 
   619   template<typename M1, typename M2> 
   594     typedef typename Parent::Key Key;
   625     typedef typename Parent::Key Key;
   595     typedef typename Parent::Value Value;
   626     typedef typename Parent::Value Value;
   596 
   627 
   597     ///Constructor
   628     ///Constructor
   598     DivMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
   629     DivMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
       
   630     /// \e
   599     Value operator[](Key k) const {return m1[k]/m2[k];}
   631     Value operator[](Key k) const {return m1[k]/m2[k];}
   600   };
   632   };
   601   
   633   
   602   ///Returns a \ref DivMap class
   634   ///Returns a \c DivMap class
   603 
   635 
   604   ///This function just returns a \ref DivMap class.
   636   ///This function just returns a \c DivMap class.
   605   ///\relates DivMap
   637   ///\relates DivMap
   606   template<typename M1, typename M2> 
   638   template<typename M1, typename M2> 
   607   inline DivMap<M1, M2> divMap(const M1 &m1,const M2 &m2) {
   639   inline DivMap<M1, M2> divMap(const M1 &m1,const M2 &m2) {
   608     return DivMap<M1, M2>(m1,m2);
   640     return DivMap<M1, M2>(m1,m2);
   609   }
   641   }
   610   
   642   
   611   ///Composition of two maps
   643   ///Composition of two maps
   612 
   644 
   613   ///This \ref concepts::ReadMap "read only map" returns the composition of
   645   ///This \c concepts::ReadMap "read only map" returns the composition of
   614   ///two
   646   ///two
   615   ///given maps. That is to say, if \c m1 is of type \c M1 and \c m2 is
   647   ///given maps. That is to say, if \c m1 is of type \c M1 and \c m2 is
   616   ///of \c M2,
   648   ///of \c M2,
   617   ///then for
   649   ///then for
   618   ///\code
   650   ///\code
   622   ///
   654   ///
   623   ///Its \c Key is inherited from \c M2 and its \c Value is from
   655   ///Its \c Key is inherited from \c M2 and its \c Value is from
   624   ///\c M1.
   656   ///\c M1.
   625   ///The \c M2::Value must be convertible to \c M1::Key.
   657   ///The \c M2::Value must be convertible to \c M1::Key.
   626   ///\todo Check the requirements.
   658   ///\todo Check the requirements.
   627 
       
   628   template <typename M1, typename M2> 
   659   template <typename M1, typename M2> 
   629   class ComposeMap : public MapBase<typename M2::Key, typename M1::Value> {
   660   class ComposeMap : public MapBase<typename M2::Key, typename M1::Value> {
   630     const M1& m1;
   661     const M1& m1;
   631     const M2& m2;
   662     const M2& m2;
   632   public:
   663   public:
   636 
   667 
   637     ///Constructor
   668     ///Constructor
   638     ComposeMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
   669     ComposeMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
   639     
   670     
   640     typename MapTraits<M1>::ConstReturnValue
   671     typename MapTraits<M1>::ConstReturnValue
       
   672     /// \e
   641     operator[](Key k) const {return m1[m2[k]];}
   673     operator[](Key k) const {return m1[m2[k]];}
   642   };
   674   };
   643   ///Returns a \ref ComposeMap class
   675   ///Returns a \c ComposeMap class
   644 
   676 
   645   ///This function just returns a \ref ComposeMap class.
   677   ///This function just returns a \c ComposeMap class.
   646   ///
   678   ///
   647   ///\relates ComposeMap
   679   ///\relates ComposeMap
   648   template <typename M1, typename M2> 
   680   template <typename M1, typename M2> 
   649   inline ComposeMap<M1, M2> composeMap(const M1 &m1,const M2 &m2) {
   681   inline ComposeMap<M1, M2> composeMap(const M1 &m1,const M2 &m2) {
   650     return ComposeMap<M1, M2>(m1,m2);
   682     return ComposeMap<M1, M2>(m1,m2);
   653   ///Combines of two maps using an STL (binary) functor.
   685   ///Combines of two maps using an STL (binary) functor.
   654 
   686 
   655   ///Combines of two maps using an STL (binary) functor.
   687   ///Combines of two maps using an STL (binary) functor.
   656   ///
   688   ///
   657   ///
   689   ///
   658   ///This \ref concepts::ReadMap "read only map" takes two maps and a
   690   ///This \c concepts::ReadMap "read only map" takes two maps and a
   659   ///binary functor and returns the composition of
   691   ///binary functor and returns the composition of
   660   ///the two
   692   ///the two
   661   ///given maps unsing the functor. 
   693   ///given maps unsing the functor. 
   662   ///That is to say, if \c m1 and \c m2 is of type \c M1 and \c M2
   694   ///That is to say, if \c m1 and \c m2 is of type \c M1 and \c M2
   663   ///and \c f is of \c F,
   695   ///and \c f is of \c F,
   670   ///Its \c Key is inherited from \c M1 and its \c Value is \c V.
   702   ///Its \c Key is inherited from \c M1 and its \c Value is \c V.
   671   ///The \c M2::Value and \c M1::Value must be convertible to the corresponding
   703   ///The \c M2::Value and \c M1::Value must be convertible to the corresponding
   672   ///input parameter of \c F and the return type of \c F must be convertible
   704   ///input parameter of \c F and the return type of \c F must be convertible
   673   ///to \c V.
   705   ///to \c V.
   674   ///\todo Check the requirements.
   706   ///\todo Check the requirements.
   675 
       
   676   template<typename M1, typename M2, typename F,
   707   template<typename M1, typename M2, typename F,
   677 	   typename V = typename F::result_type,
   708 	   typename V = typename F::result_type> 
   678 	   typename NC = False> 
       
   679   class CombineMap : public MapBase<typename M1::Key, V> {
   709   class CombineMap : public MapBase<typename M1::Key, V> {
   680     const M1& m1;
   710     const M1& m1;
   681     const M2& m2;
   711     const M2& m2;
   682     F f;
   712     F f;
   683   public:
   713   public:
   684     typedef MapBase<typename M1::Key, V> Parent;
   714     typedef MapBase<typename M1::Key, V> Parent;
   685     typedef typename Parent::Key Key;
   715     typedef typename Parent::Key Key;
   686     typedef typename Parent::Value Value;
   716     typedef typename Parent::Value Value;
   687 
   717 
   688     ///Constructor
   718     ///Constructor
   689     CombineMap(const M1 &_m1,const M2 &_m2,const F &_f)
   719     CombineMap(const M1 &_m1,const M2 &_m2,const F &_f = F())
   690       : m1(_m1), m2(_m2), f(_f) {};
   720       : m1(_m1), m2(_m2), f(_f) {};
       
   721     /// \e
   691     Value operator[](Key k) const {return f(m1[k],m2[k]);}
   722     Value operator[](Key k) const {return f(m1[k],m2[k]);}
   692   };
   723   };
   693   
   724   
   694   ///Returns a \ref CombineMap class
   725   ///Returns a \c CombineMap class
   695 
   726 
   696   ///This function just returns a \ref CombineMap class.
   727   ///This function just returns a \c CombineMap class.
   697   ///
       
   698   ///Only the first template parameter (the value type) must be given.
       
   699   ///
   728   ///
   700   ///For example if \c m1 and \c m2 are both \c double valued maps, then 
   729   ///For example if \c m1 and \c m2 are both \c double valued maps, then 
   701   ///\code
   730   ///\code
   702   ///combineMap<double>(m1,m2,std::plus<double>)
   731   ///combineMap<double>(m1,m2,std::plus<double>())
   703   ///\endcode
   732   ///\endcode
   704   ///is equivalent with
   733   ///is equivalent with
   705   ///\code
   734   ///\code
   706   ///addMap(m1,m2)
   735   ///addMap(m1,m2)
   707   ///\endcode
   736   ///\endcode
       
   737   ///
       
   738   ///This function is specialized for adaptable binary function
       
   739   ///classes and c++ functions.
   708   ///
   740   ///
   709   ///\relates CombineMap
   741   ///\relates CombineMap
   710   template<typename M1, typename M2, typename F, typename V> 
   742   template<typename M1, typename M2, typename F, typename V> 
   711   inline CombineMap<M1, M2, F, V> 
   743   inline CombineMap<M1, M2, F, V> 
   712   combineMap(const M1& m1,const M2& m2, const F& f) {
   744   combineMap(const M1& m1,const M2& m2, const F& f) {
   725     return combineMap<M1, M2, V (*)(K1, K2), V>(m1,m2,f);
   757     return combineMap<M1, M2, V (*)(K1, K2), V>(m1,m2,f);
   726   }
   758   }
   727 
   759 
   728   ///Negative value of a map
   760   ///Negative value of a map
   729 
   761 
   730   ///This \ref concepts::ReadMap "read only map" returns the negative
   762   ///This \c concepts::ReadMap "read only map" returns the negative
   731   ///value of the
   763   ///value of the
   732   ///value returned by the
   764   ///value returned by the
   733   ///given map. Its \c Key and \c Value will be inherited from \c M.
   765   ///given map. Its \c Key and \c Value will be inherited from \c M.
   734   ///The unary \c - operator must be defined for \c Value, of course.
   766   ///The unary \c - operator must be defined for \c Value, of course.
   735 
   767 
   741     typedef typename Parent::Key Key;
   773     typedef typename Parent::Key Key;
   742     typedef typename Parent::Value Value;
   774     typedef typename Parent::Value Value;
   743 
   775 
   744     ///Constructor
   776     ///Constructor
   745     NegMap(const M &_m) : m(_m) {};
   777     NegMap(const M &_m) : m(_m) {};
       
   778     /// \e
   746     Value operator[](Key k) const {return -m[k];}
   779     Value operator[](Key k) const {return -m[k];}
   747   };
   780   };
   748   
   781   
   749   ///Negative value of a map
   782   ///Negative value of a map
   750 
   783 
   751   ///This \ref concepts::ReadWriteMap "read-write map" returns the negative
   784   ///This \c concepts::ReadWriteMap "read-write map" returns the negative
   752   ///value of the value returned by the
   785   ///value of the value returned by the
   753   ///given map. Its \c Key and \c Value will be inherited from \c M.
   786   ///given map. Its \c Key and \c Value will be inherited from \c M.
   754   ///The unary \c - operator must be defined for \c Value, of course.
   787   ///The unary \c - operator must be defined for \c Value, of course.
   755 
   788 
   756   template<typename M> 
   789   template<typename M> 
   761     typedef typename Parent::Key Key;
   794     typedef typename Parent::Key Key;
   762     typedef typename Parent::Value Value;
   795     typedef typename Parent::Value Value;
   763 
   796 
   764     ///Constructor
   797     ///Constructor
   765     NegWriteMap(M &_m) : m(_m) {};
   798     NegWriteMap(M &_m) : m(_m) {};
       
   799     /// \e
   766     Value operator[](Key k) const {return -m[k];}
   800     Value operator[](Key k) const {return -m[k];}
       
   801     /// \e
   767     void set(Key k, const Value& v) { m.set(k, -v); }
   802     void set(Key k, const Value& v) { m.set(k, -v); }
   768   };
   803   };
   769 
   804 
   770   ///Returns a \ref NegMap class
   805   ///Returns a \c NegMap class
   771 
   806 
   772   ///This function just returns a \ref NegMap class.
   807   ///This function just returns a \c NegMap class.
   773   ///\relates NegMap
   808   ///\relates NegMap
   774   template <typename M> 
   809   template <typename M> 
   775   inline NegMap<M> negMap(const M &m) {
   810   inline NegMap<M> negMap(const M &m) {
   776     return NegMap<M>(m);
   811     return NegMap<M>(m);
   777   }
   812   }
   781     return NegWriteMap<M>(m);
   816     return NegWriteMap<M>(m);
   782   }
   817   }
   783 
   818 
   784   ///Absolute value of a map
   819   ///Absolute value of a map
   785 
   820 
   786   ///This \ref concepts::ReadMap "read only map" returns the absolute value
   821   ///This \c concepts::ReadMap "read only map" returns the absolute value
   787   ///of the
   822   ///of the
   788   ///value returned by the
   823   ///value returned by the
   789   ///given map. Its \c Key and \c Value will be inherited
   824   ///given map. Its \c Key and \c Value will be inherited
   790   ///from <tt>M</tt>. <tt>Value</tt>
   825   ///from <tt>M</tt>. <tt>Value</tt>
   791   ///must be comparable to <tt>0</tt> and the unary <tt>-</tt>
   826   ///must be comparable to <tt>0</tt> and the unary <tt>-</tt>
   812     typedef typename Parent::Key Key;
   847     typedef typename Parent::Key Key;
   813     typedef typename Parent::Value Value;
   848     typedef typename Parent::Value Value;
   814 
   849 
   815     ///Constructor
   850     ///Constructor
   816     AbsMap(const M &_m) : m(_m) {};
   851     AbsMap(const M &_m) : m(_m) {};
       
   852     /// \e
   817     Value operator[](Key k) const {
   853     Value operator[](Key k) const {
   818       Value tmp = m[k]; 
   854       Value tmp = m[k]; 
   819       return tmp >= 0 ? tmp : -tmp;
   855       return tmp >= 0 ? tmp : -tmp;
   820     }
   856     }
   821 
   857 
   822   };
   858   };
   823   
   859   
   824   ///Returns a \ref AbsMap class
   860   ///Returns a \c AbsMap class
   825 
   861 
   826   ///This function just returns a \ref AbsMap class.
   862   ///This function just returns a \c AbsMap class.
   827   ///\relates AbsMap
   863   ///\relates AbsMap
   828   template<typename M> 
   864   template<typename M> 
   829   inline AbsMap<M> absMap(const M &m) {
   865   inline AbsMap<M> absMap(const M &m) {
   830     return AbsMap<M>(m);
   866     return AbsMap<M>(m);
   831   }
   867   }
   832 
   868 
   833   ///Converts an STL style functor to a map
   869   ///Converts an STL style functor to a map
   834 
   870 
   835   ///This \ref concepts::ReadMap "read only map" returns the value
   871   ///This \c concepts::ReadMap "read only map" returns the value
   836   ///of a
   872   ///of a
   837   ///given map.
   873   ///given map.
   838   ///
   874   ///
   839   ///Template parameters \c K and \c V will become its
   875   ///Template parameters \c K and \c V will become its
   840   ///\c Key and \c Value. They must be given explicitely
   876   ///\c Key and \c Value. They must be given explicitely
   841   ///because a functor does not provide such typedefs.
   877   ///because a functor does not provide such typedefs.
   842   ///
   878   ///
   843   ///Parameter \c F is the type of the used functor.
   879   ///Parameter \c F is the type of the used functor.
   844   
       
   845 
       
   846   template<typename F, 
   880   template<typename F, 
   847 	   typename K = typename F::argument_type, 
   881 	   typename K = typename F::argument_type, 
   848 	   typename V = typename F::result_type,
   882 	   typename V = typename F::result_type> 
   849 	   typename NC = False> 
       
   850   class FunctorMap : public MapBase<K, V> {
   883   class FunctorMap : public MapBase<K, V> {
   851     F f;
   884     F f;
   852   public:
   885   public:
   853     typedef MapBase<K, V> Parent;
   886     typedef MapBase<K, V> Parent;
   854     typedef typename Parent::Key Key;
   887     typedef typename Parent::Key Key;
   855     typedef typename Parent::Value Value;
   888     typedef typename Parent::Value Value;
   856 
   889 
   857     ///Constructor
   890     ///Constructor
   858     FunctorMap(const F &_f) : f(_f) {}
   891     FunctorMap(const F &_f = F()) : f(_f) {}
   859 
   892     /// \e
   860     Value operator[](Key k) const { return f(k);}
   893     Value operator[](Key k) const { return f(k);}
   861   };
   894   };
   862   
   895   
   863   ///Returns a \ref FunctorMap class
   896   ///Returns a \c FunctorMap class
   864 
   897 
   865   ///This function just returns a \ref FunctorMap class.
   898   ///This function just returns a \c FunctorMap class.
   866   ///
   899   ///
   867   ///The third template parameter isn't necessary to be given.
   900   ///It is specialized for adaptable function classes and
       
   901   ///c++ functions.
   868   ///\relates FunctorMap
   902   ///\relates FunctorMap
   869   template<typename K, typename V, typename F> inline 
   903   template<typename K, typename V, typename F> inline 
   870   FunctorMap<F, K, V> functorMap(const F &f) {
   904   FunctorMap<F, K, V> functorMap(const F &f) {
   871     return FunctorMap<F, K, V>(f);
   905     return FunctorMap<F, K, V>(f);
   872   }
   906   }
   888 
   922 
   889   ///This class Converts a map to an STL style (unary) functor.
   923   ///This class Converts a map to an STL style (unary) functor.
   890   ///that is it provides an <tt>operator()</tt> to read its values.
   924   ///that is it provides an <tt>operator()</tt> to read its values.
   891   ///
   925   ///
   892   ///For the sake of convenience it also works as
   926   ///For the sake of convenience it also works as
   893   ///a ususal \ref concepts::ReadMap "readable map",
   927   ///a ususal \c concepts::ReadMap "readable map",
   894   ///i.e. <tt>operator[]</tt> and the \c Key and \c Value typedefs also exist.
   928   ///i.e. <tt>operator[]</tt> and the \c Key and \c Value typedefs also exist.
   895 
       
   896   template <typename M> 
   929   template <typename M> 
   897   class MapFunctor : public MapBase<typename M::Key, typename M::Value> {
   930   class MapFunctor : public MapBase<typename M::Key, typename M::Value> {
   898     const M& m;
   931     const M& m;
   899   public:
   932   public:
   900     typedef MapBase<typename M::Key, typename M::Value> Parent;
   933     typedef MapBase<typename M::Key, typename M::Value> Parent;
   901     typedef typename Parent::Key Key;
   934     typedef typename Parent::Key Key;
   902     typedef typename Parent::Value Value;
   935     typedef typename Parent::Value Value;
   903 
   936 
   904     ///\e
       
   905     typedef typename M::Key argument_type;
   937     typedef typename M::Key argument_type;
   906     ///\e
       
   907     typedef typename M::Value result_type;
   938     typedef typename M::Value result_type;
   908 
   939 
   909     ///Constructor
   940     ///Constructor
   910     MapFunctor(const M &_m) : m(_m) {};
   941     MapFunctor(const M &_m) : m(_m) {};
   911     ///Returns a value of the map
   942     ///\e
   912     Value operator()(Key k) const {return m[k];}
   943     Value operator()(Key k) const {return m[k];}
   913     ///\e
   944     ///\e
   914     Value operator[](Key k) const {return m[k];}
   945     Value operator[](Key k) const {return m[k];}
   915   };
   946   };
   916   
   947   
   917   ///Returns a \ref MapFunctor class
   948   ///Returns a \c MapFunctor class
   918 
   949 
   919   ///This function just returns a \ref MapFunctor class.
   950   ///This function just returns a \c MapFunctor class.
   920   ///\relates MapFunctor
   951   ///\relates MapFunctor
   921   template<typename M> 
   952   template<typename M> 
   922   inline MapFunctor<M> mapFunctor(const M &m) {
   953   inline MapFunctor<M> mapFunctor(const M &m) {
   923     return MapFunctor<M>(m);
   954     return MapFunctor<M>(m);
   924   }
   955   }
   925 
   956 
   926   ///Applies all map setting operations to two maps
   957   ///Applies all map setting operations to two maps
   927 
   958 
   928   ///This map has two \ref concepts::ReadMap "readable map"
   959   ///This map has two \c concepts::ReadMap "readable map"
   929   ///parameters and each read request will be passed just to the
   960   ///parameters and each read request will be passed just to the
   930   ///first map. This class is the just readable map type of the ForkWriteMap.
   961   ///first map. This class is the just readable map type of the ForkWriteMap.
   931   ///
   962   ///
   932   ///The \c Key and \c Value will be inherited from \c M1.
   963   ///The \c Key and \c Value will be inherited from \c M1.
   933   ///The \c Key and \c Value of M2 must be convertible from those of \c M1.
   964   ///The \c Key and \c Value of M2 must be convertible from those of \c M1.
   934 
       
   935   template<typename  M1, typename M2> 
   965   template<typename  M1, typename M2> 
   936   class ForkMap : public MapBase<typename M1::Key, typename M1::Value> {
   966   class ForkMap : public MapBase<typename M1::Key, typename M1::Value> {
   937     const M1& m1;
   967     const M1& m1;
   938     const M2& m2;
   968     const M2& m2;
   939   public:
   969   public:
   941     typedef typename Parent::Key Key;
   971     typedef typename Parent::Key Key;
   942     typedef typename Parent::Value Value;
   972     typedef typename Parent::Value Value;
   943 
   973 
   944     ///Constructor
   974     ///Constructor
   945     ForkMap(const M1 &_m1, const M2 &_m2) : m1(_m1), m2(_m2) {};
   975     ForkMap(const M1 &_m1, const M2 &_m2) : m1(_m1), m2(_m2) {};
       
   976     /// \e
   946     Value operator[](Key k) const {return m1[k];}
   977     Value operator[](Key k) const {return m1[k];}
   947   };
   978   };
   948 
   979 
   949 
   980 
   950   ///Applies all map setting operations to two maps
   981   ///Applies all map setting operations to two maps
   951 
   982 
   952   ///This map has two \ref concepts::WriteMap "writable map"
   983   ///This map has two \c concepts::WriteMap "writable map"
   953   ///parameters and each write request will be passed to both of them.
   984   ///parameters and each write request will be passed to both of them.
   954   ///If \c M1 is also \ref concepts::ReadMap "readable",
   985   ///If \c M1 is also \c concepts::ReadMap "readable",
   955   ///then the read operations will return the
   986   ///then the read operations will return the
   956   ///corresponding values of \c M1.
   987   ///corresponding values of \c M1.
   957   ///
   988   ///
   958   ///The \c Key and \c Value will be inherited from \c M1.
   989   ///The \c Key and \c Value will be inherited from \c M1.
   959   ///The \c Key and \c Value of M2 must be convertible from those of \c M1.
   990   ///The \c Key and \c Value of M2 must be convertible from those of \c M1.
   960 
       
   961   template<typename  M1, typename M2> 
   991   template<typename  M1, typename M2> 
   962   class ForkWriteMap : public MapBase<typename M1::Key, typename M1::Value> {
   992   class ForkWriteMap : public MapBase<typename M1::Key, typename M1::Value> {
   963     M1& m1;
   993     M1& m1;
   964     M2& m2;
   994     M2& m2;
   965   public:
   995   public:
   967     typedef typename Parent::Key Key;
   997     typedef typename Parent::Key Key;
   968     typedef typename Parent::Value Value;
   998     typedef typename Parent::Value Value;
   969 
   999 
   970     ///Constructor
  1000     ///Constructor
   971     ForkWriteMap(M1 &_m1, M2 &_m2) : m1(_m1), m2(_m2) {};
  1001     ForkWriteMap(M1 &_m1, M2 &_m2) : m1(_m1), m2(_m2) {};
       
  1002     ///\e
   972     Value operator[](Key k) const {return m1[k];}
  1003     Value operator[](Key k) const {return m1[k];}
       
  1004     ///\e
   973     void set(Key k, const Value &v) {m1.set(k,v); m2.set(k,v);}
  1005     void set(Key k, const Value &v) {m1.set(k,v); m2.set(k,v);}
   974   };
  1006   };
   975   
  1007   
   976   ///Returns an \ref ForkMap class
  1008   ///Returns an \c ForkMap class
   977 
  1009 
   978   ///This function just returns an \ref ForkMap class.
  1010   ///This function just returns an \c ForkMap class.
   979   ///\todo How to call these type of functions?
       
   980   ///
  1011   ///
   981   ///\relates ForkMap
  1012   ///\relates ForkMap
   982   ///\todo Wrong scope in Doxygen when \c \\relates is used
       
   983   template <typename M1, typename M2> 
  1013   template <typename M1, typename M2> 
   984   inline ForkMap<M1, M2> forkMap(const M1 &m1, const M2 &m2) {
  1014   inline ForkMap<M1, M2> forkMap(const M1 &m1, const M2 &m2) {
   985     return ForkMap<M1, M2>(m1,m2);
  1015     return ForkMap<M1, M2>(m1,m2);
   986   }
  1016   }
   987 
  1017 
   994   
  1024   
   995   /* ************* BOOL MAPS ******************* */
  1025   /* ************* BOOL MAPS ******************* */
   996   
  1026   
   997   ///Logical 'not' of a map
  1027   ///Logical 'not' of a map
   998   
  1028   
   999   ///This bool \ref concepts::ReadMap "read only map" returns the 
  1029   ///This bool \c concepts::ReadMap "read only map" returns the 
  1000   ///logical negation of
  1030   ///logical negation of
  1001   ///value returned by the
  1031   ///value returned by the
  1002   ///given map. Its \c Key and will be inherited from \c M,
  1032   ///given map. Its \c Key and will be inherited from \c M,
  1003   ///its Value is <tt>bool</tt>.
  1033   ///its Value is <tt>bool</tt>.
  1004 
       
  1005   template <typename M> 
  1034   template <typename M> 
  1006   class NotMap : public MapBase<typename M::Key, bool> {
  1035   class NotMap : public MapBase<typename M::Key, bool> {
  1007     const M& m;
  1036     const M& m;
  1008   public:
  1037   public:
  1009     typedef MapBase<typename M::Key, bool> Parent;
  1038     typedef MapBase<typename M::Key, bool> Parent;
  1010     typedef typename Parent::Key Key;
  1039     typedef typename Parent::Key Key;
  1011     typedef typename Parent::Value Value;
  1040     typedef typename Parent::Value Value;
  1012 
  1041 
  1013     /// Constructor
  1042     /// Constructor
  1014     NotMap(const M &_m) : m(_m) {};
  1043     NotMap(const M &_m) : m(_m) {};
       
  1044     ///\e
  1015     Value operator[](Key k) const {return !m[k];}
  1045     Value operator[](Key k) const {return !m[k];}
  1016   };
  1046   };
  1017 
  1047 
  1018   ///Logical 'not' of a map with writing possibility
  1048   ///Logical 'not' of a map with writing possibility
  1019   
  1049   
  1020   ///This bool \ref concepts::ReadWriteMap "read-write map" returns the 
  1050   ///This bool \c concepts::ReadWriteMap "read-write map" returns the 
  1021   ///logical negation of value returned by the given map. When it is set,
  1051   ///logical negation of value returned by the given map. When it is set,
  1022   ///the opposite value is set to the original map.
  1052   ///the opposite value is set to the original map.
  1023   ///Its \c Key and will be inherited from \c M,
  1053   ///Its \c Key and will be inherited from \c M,
  1024   ///its Value is <tt>bool</tt>.
  1054   ///its Value is <tt>bool</tt>.
  1025   template <typename M> 
  1055   template <typename M> 
  1030     typedef typename Parent::Key Key;
  1060     typedef typename Parent::Key Key;
  1031     typedef typename Parent::Value Value;
  1061     typedef typename Parent::Value Value;
  1032 
  1062 
  1033     /// Constructor
  1063     /// Constructor
  1034     NotWriteMap(M &_m) : m(_m) {};
  1064     NotWriteMap(M &_m) : m(_m) {};
       
  1065     ///\e
  1035     Value operator[](Key k) const {return !m[k];}
  1066     Value operator[](Key k) const {return !m[k];}
       
  1067     ///\e
  1036     void set(Key k, bool v) { m.set(k, !v); }
  1068     void set(Key k, bool v) { m.set(k, !v); }
  1037   };
  1069   };
  1038   
  1070   
  1039   ///Returns a \ref NotMap class
  1071   ///Returns a \c NotMap class
  1040   
  1072   
  1041   ///This function just returns a \ref NotMap class.
  1073   ///This function just returns a \c NotMap class.
  1042   ///\relates NotMap
  1074   ///\relates NotMap
  1043   template <typename M> 
  1075   template <typename M> 
  1044   inline NotMap<M> notMap(const M &m) {
  1076   inline NotMap<M> notMap(const M &m) {
  1045     return NotMap<M>(m);
  1077     return NotMap<M>(m);
  1046   }
  1078   }
  1275   ///     dfs.start();
  1307   ///     dfs.start();
  1276   ///     ++filler.fillValue();
  1308   ///     ++filler.fillValue();
  1277   ///   }
  1309   ///   }
  1278   /// }
  1310   /// }
  1279   ///\endcode
  1311   ///\endcode
  1280 
       
  1281   template <typename Map>
  1312   template <typename Map>
  1282   class FillBoolMap {
  1313   class FillBoolMap {
  1283   public:
  1314   public:
  1284     typedef typename Map::Key Key;
  1315     typedef typename Map::Key Key;
  1285     typedef bool Value;
  1316     typedef bool Value;
  1323   /// \brief Writable bool map which stores for each true assigned elements  
  1354   /// \brief Writable bool map which stores for each true assigned elements  
  1324   /// the setting order number.
  1355   /// the setting order number.
  1325   ///
  1356   ///
  1326   /// Writable bool map which stores for each true assigned elements  
  1357   /// Writable bool map which stores for each true assigned elements  
  1327   /// the setting order number. It make easy to calculate the leaving
  1358   /// the setting order number. It make easy to calculate the leaving
  1328   /// order of the nodes in the \ref dfs "Dfs" algorithm.
  1359   /// order of the nodes in the \c Dfs algorithm.
  1329   ///
  1360   ///
  1330   ///\code
  1361   ///\code
  1331   /// typedef Graph::NodeMap<int> OrderMap;
  1362   /// typedef Graph::NodeMap<int> OrderMap;
  1332   /// OrderMap order(graph);
  1363   /// OrderMap order(graph);
  1333   /// typedef SettingOrderBoolMap<OrderMap> OrderSetterMap;
  1364   /// typedef SettingOrderBoolMap<OrderMap> OrderSetterMap;