diff -r 5331168bbb18 -r ce885274b754 src/lemon/maps.h --- a/src/lemon/maps.h Wed Mar 16 07:56:25 2005 +0000 +++ b/src/lemon/maps.h Wed Mar 16 13:25:19 2005 +0000 @@ -491,16 +491,80 @@ ComposeMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {}; Value operator[](Key k) const {return m1[m2[k]];} }; - ///Returns a \ref ComposeMap class ///This function just returns a \ref ComposeMap class. + /// ///\relates ComposeMap template inline ComposeMap composeMap(const M1 &m1,const M2 &m2) { return ComposeMap(m1,m2); } + + ///Combine of two maps using an STL (binary) functor. + + ///Combine of two maps using an STL (binary) functor. + /// + /// + ///This \ref concept::ReadMap "read only map" takes to maps and a + ///binary functor and returns the composition of + ///two + ///given maps unsing the functor. + ///That is to say, if \c m1 and \c m2 is of type \c M1 and \c M2 + ///and \c f is of \c F, + ///then for + ///\code + /// CombineMap cm(m1,m2,f); + ///\endcode + /// cm[x] will be equal to f(m1[x],m2[x]) + /// + ///Its \c Key is inherited from \c M1 and its \c Value is \c V. + ///The \c M2::Value and \c M1::Value must be convertible to the corresponding + ///input parameter of \c F and the return type of \c F must be convertible + ///to \c V. + ///\todo Check the requirements. + + template + class CombineMap + { + const M1 &m1; + const M2 &m2; + const F &f; + public: + typedef typename M1::Key Key; + typedef V Value; + + ///Constructor + + ///\e + /// + CombineMap(const M1 &_m1,const M2 &_m2,const F &_f) + : m1(_m1), m2(_m2), f(_f) {}; + Value operator[](Key k) const {return f(m1[k],m2[k]);} + }; + + ///Returns a \ref CombineMap class + + ///This function just returns a \ref CombineMap class. + /// + ///Only the first template parameter (the value type) must be given. + /// + ///For example if \c m1 and \c m2 are both \c double valued maps, then + ///\code + ///combineMap(m1,m2,std::plus) + ///\endcode + ///is equivalent with + ///\code + ///addMap(m1,m2) + ///\endcode + /// + ///\relates CombineMap + template + inline CombineMap combineMap(const M1 &m1,const M2 &m2,const F &f) + { + return CombineMap(m1,m2,f); + } ///Negative value of a map @@ -627,9 +691,9 @@ return FunctorMap(f); } - ///Converts a map to an STL style functor + ///Converts a map to an STL style (unary) functor - ///This class Converts a map to an STL style functor. + ///This class Converts a map to an STL style (unary) functor. ///that is it provides an operator() to read its values. /// ///For the sake of convenience it also works as a ususal map, i.e @@ -669,6 +733,48 @@ } + ///Apply all map setting operations to two maps + + ///This map has two \ref concept::WriteMap "writable map" + ///parameters and each write request will be passed to both of them. + ///If \c M1 is also \ref concept::ReadMap "readable", + ///then the read operations will return the + ///corresponding values \c M1. + /// + ///The \c Key and \c Value will be inherited from \c M1. + ///The \c Key and \c Value of M2 must be convertible from those of \c M1. + + template + class ForkMap + { + const M1 &m1; + const M2 &m2; + public: + typedef typename M1::Key Key; + typedef typename M1::Value Value; + + ///Constructor + + ///\e + /// + ForkMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {}; + Value operator[](Key k) const {return m1[k];} + void set(Key k,const Value &v) {m1.set(k,v); m2.set(k,v);} + }; + + ///Returns an \ref ForkMap class + + ///This function just returns an \ref ForkMap class. + ///\todo How to call these type of functions? + /// + ///\relates ForkMap + ///\todo Wrong scope in Doxygen when \c \\relates is used + template + inline ForkMap forkMap(const M1 &m1,const M2 &m2) + { + return ForkMap(m1,m2); + } + /// @} }