diff -r 789bad021e2d -r 67a115cdade4 src/lemon/maps.h --- a/src/lemon/maps.h Tue Jan 11 17:16:29 2005 +0000 +++ b/src/lemon/maps.h Wed Jan 12 12:51:30 2005 +0000 @@ -98,6 +98,17 @@ ConstMap(const ConstMap &, const T &_v) : v(_v) {} }; + ///Returns a \ref ConstMap class + + ///This function just returns a \ref ConstMap class. + ///\relates ConstMap + template + inline ConstMap constMap(const K &k) + { + return ConstMap(k); + } + + //to document later template struct Const { }; @@ -532,6 +543,89 @@ return AbsMap(m); } + ///Converts an STL style functor to a a map + + ///This \ref concept::ReadMap "read only map" returns the value + ///of a + ///given map. + /// + ///Template parameters \c K and \c V will become its + ///\c Key and \c Value. They must be given explicitely + ///because a functor does not provide such typedefs. + /// + ///Parameter \c F is the type of the used functor. + + + template + class FunctorMap + { + const F &f; + public: + typedef K Key; + typedef V Value; + + ///Constructor + + ///\e + /// + FunctorMap(const F &_f) : f(_f) {}; + Value operator[](Key k) const {return f(k);} + }; + + ///Returns a \ref FunctorMap class + + ///This function just returns a \ref FunctorMap class. + /// + ///The third template parameter isn't necessary to be given. + ///\relates FunctorMap + template + inline FunctorMap functorMap(const F &f) + { + return FunctorMap(f); + } + + ///Converts a map to an STL style functor + + ///This class Converts a map to an STL style 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 + ///operator[] and the \c Key and \c Valu typedefs also exist. + + template + class MapFunctor + { + const M &m; + public: + typedef typename M::Key Key; + typedef typename M::Value Value; + + ///Constructor + + ///\e + /// + MapFunctor(const M &_m) : m(_m) {}; + ///Returns a value of the map + + ///\e + /// + Value operator()(Key k) const {return m[k];} + ///\e + /// + Value operator[](Key k) const {return m[k];} + }; + + ///Returns a \ref MapFunctor class + + ///This function just returns a \ref MapFunctor class. + ///\relates MapFunctor + template + inline MapFunctor mapFunctor(const M &m) + { + return MapFunctor(m); + } + + /// @} }