[Lemon-commits] [lemon_svn] alpar: r1639 - hugo/trunk/src/lemon
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:46:44 CET 2006
Author: alpar
Date: Wed Mar 16 14:25:19 2005
New Revision: 1639
Modified:
hugo/trunk/src/lemon/maps.h
Log:
ForkMap and CombineMap added.
Modified: hugo/trunk/src/lemon/maps.h
==============================================================================
--- hugo/trunk/src/lemon/maps.h (original)
+++ hugo/trunk/src/lemon/maps.h Wed Mar 16 14:25:19 2005
@@ -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<class M1,class M2>
inline ComposeMap<M1,M2> composeMap(const M1 &m1,const M2 &m2)
{
return ComposeMap<M1,M2>(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<M1,M2,F,V> cm(m1,m2,f);
+ ///\endcode
+ /// <tt>cm[x]</tt> will be equal to <tt>f(m1[x],m2[x])</tt>
+ ///
+ ///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 M1,class M2,class F,class V>
+ 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<double>(m1,m2,std::plus<double>)
+ ///\endcode
+ ///is equivalent with
+ ///\code
+ ///addMap(m1,m2)
+ ///\endcode
+ ///
+ ///\relates CombineMap
+ template<class V,class M1,class M2,class F>
+ inline CombineMap<M1,M2,F,V> combineMap(const M1 &m1,const M2 &m2,const F &f)
+ {
+ return CombineMap<M1,M2,F,V>(m1,m2,f);
+ }
///Negative value of a map
@@ -627,9 +691,9 @@
return FunctorMap<K,V,F>(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 <tt>operator()</tt> 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 M1,class M2>
+ 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<class M1,class M2>
+ inline ForkMap<M1,M2> forkMap(const M1 &m1,const M2 &m2)
+ {
+ return ForkMap<M1,M2>(m1,m2);
+ }
+
/// @}
}
More information about the Lemon-commits
mailing list