ForkMap and CombineMap added.
1.1 --- a/src/lemon/maps.h Wed Mar 16 07:56:25 2005 +0000
1.2 +++ b/src/lemon/maps.h Wed Mar 16 13:25:19 2005 +0000
1.3 @@ -491,16 +491,80 @@
1.4 ComposeMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
1.5 Value operator[](Key k) const {return m1[m2[k]];}
1.6 };
1.7 -
1.8 ///Returns a \ref ComposeMap class
1.9
1.10 ///This function just returns a \ref ComposeMap class.
1.11 + ///
1.12 ///\relates ComposeMap
1.13 template<class M1,class M2>
1.14 inline ComposeMap<M1,M2> composeMap(const M1 &m1,const M2 &m2)
1.15 {
1.16 return ComposeMap<M1,M2>(m1,m2);
1.17 }
1.18 +
1.19 + ///Combine of two maps using an STL (binary) functor.
1.20 +
1.21 + ///Combine of two maps using an STL (binary) functor.
1.22 + ///
1.23 + ///
1.24 + ///This \ref concept::ReadMap "read only map" takes to maps and a
1.25 + ///binary functor and returns the composition of
1.26 + ///two
1.27 + ///given maps unsing the functor.
1.28 + ///That is to say, if \c m1 and \c m2 is of type \c M1 and \c M2
1.29 + ///and \c f is of \c F,
1.30 + ///then for
1.31 + ///\code
1.32 + /// CombineMap<M1,M2,F,V> cm(m1,m2,f);
1.33 + ///\endcode
1.34 + /// <tt>cm[x]</tt> will be equal to <tt>f(m1[x],m2[x])</tt>
1.35 + ///
1.36 + ///Its \c Key is inherited from \c M1 and its \c Value is \c V.
1.37 + ///The \c M2::Value and \c M1::Value must be convertible to the corresponding
1.38 + ///input parameter of \c F and the return type of \c F must be convertible
1.39 + ///to \c V.
1.40 + ///\todo Check the requirements.
1.41 +
1.42 + template<class M1,class M2,class F,class V>
1.43 + class CombineMap
1.44 + {
1.45 + const M1 &m1;
1.46 + const M2 &m2;
1.47 + const F &f;
1.48 + public:
1.49 + typedef typename M1::Key Key;
1.50 + typedef V Value;
1.51 +
1.52 + ///Constructor
1.53 +
1.54 + ///\e
1.55 + ///
1.56 + CombineMap(const M1 &_m1,const M2 &_m2,const F &_f)
1.57 + : m1(_m1), m2(_m2), f(_f) {};
1.58 + Value operator[](Key k) const {return f(m1[k],m2[k]);}
1.59 + };
1.60 +
1.61 + ///Returns a \ref CombineMap class
1.62 +
1.63 + ///This function just returns a \ref CombineMap class.
1.64 + ///
1.65 + ///Only the first template parameter (the value type) must be given.
1.66 + ///
1.67 + ///For example if \c m1 and \c m2 are both \c double valued maps, then
1.68 + ///\code
1.69 + ///combineMap<double>(m1,m2,std::plus<double>)
1.70 + ///\endcode
1.71 + ///is equivalent with
1.72 + ///\code
1.73 + ///addMap(m1,m2)
1.74 + ///\endcode
1.75 + ///
1.76 + ///\relates CombineMap
1.77 + template<class V,class M1,class M2,class F>
1.78 + inline CombineMap<M1,M2,F,V> combineMap(const M1 &m1,const M2 &m2,const F &f)
1.79 + {
1.80 + return CombineMap<M1,M2,F,V>(m1,m2,f);
1.81 + }
1.82
1.83 ///Negative value of a map
1.84
1.85 @@ -627,9 +691,9 @@
1.86 return FunctorMap<K,V,F>(f);
1.87 }
1.88
1.89 - ///Converts a map to an STL style functor
1.90 + ///Converts a map to an STL style (unary) functor
1.91
1.92 - ///This class Converts a map to an STL style functor.
1.93 + ///This class Converts a map to an STL style (unary) functor.
1.94 ///that is it provides an <tt>operator()</tt> to read its values.
1.95 ///
1.96 ///For the sake of convenience it also works as a ususal map, i.e
1.97 @@ -669,6 +733,48 @@
1.98 }
1.99
1.100
1.101 + ///Apply all map setting operations to two maps
1.102 +
1.103 + ///This map has two \ref concept::WriteMap "writable map"
1.104 + ///parameters and each write request will be passed to both of them.
1.105 + ///If \c M1 is also \ref concept::ReadMap "readable",
1.106 + ///then the read operations will return the
1.107 + ///corresponding values \c M1.
1.108 + ///
1.109 + ///The \c Key and \c Value will be inherited from \c M1.
1.110 + ///The \c Key and \c Value of M2 must be convertible from those of \c M1.
1.111 +
1.112 + template<class M1,class M2>
1.113 + class ForkMap
1.114 + {
1.115 + const M1 &m1;
1.116 + const M2 &m2;
1.117 + public:
1.118 + typedef typename M1::Key Key;
1.119 + typedef typename M1::Value Value;
1.120 +
1.121 + ///Constructor
1.122 +
1.123 + ///\e
1.124 + ///
1.125 + ForkMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
1.126 + Value operator[](Key k) const {return m1[k];}
1.127 + void set(Key k,const Value &v) {m1.set(k,v); m2.set(k,v);}
1.128 + };
1.129 +
1.130 + ///Returns an \ref ForkMap class
1.131 +
1.132 + ///This function just returns an \ref ForkMap class.
1.133 + ///\todo How to call these type of functions?
1.134 + ///
1.135 + ///\relates ForkMap
1.136 + ///\todo Wrong scope in Doxygen when \c \\relates is used
1.137 + template<class M1,class M2>
1.138 + inline ForkMap<M1,M2> forkMap(const M1 &m1,const M2 &m2)
1.139 + {
1.140 + return ForkMap<M1,M2>(m1,m2);
1.141 + }
1.142 +
1.143 /// @}
1.144
1.145 }