[Lemon-commits] [lemon_svn] deba: r2998 - hugo/trunk/lemon
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 21:51:44 CET 2006
Author: deba
Date: Tue Oct 17 13:01:16 2006
New Revision: 2998
Modified:
hugo/trunk/lemon/maps.h
Log:
SimpleMap and SimpleWriteMap
- Trivial adaptors, but they are useful in some case
Some combined maps will be reference map if the first
template parameter map is reference map or not. If I want
to give a refernce map as first map but there is a non
reference map parameter then I should wrap my first map
to a regular read-write map.
Modified: hugo/trunk/lemon/maps.h
==============================================================================
--- hugo/trunk/lemon/maps.h (original)
+++ hugo/trunk/lemon/maps.h Tue Oct 17 13:01:16 2006
@@ -287,6 +287,47 @@
return ConvertMap<M, T>(m);
}
+ ///Simple wrapping of the map
+
+ ///This \ref concept::ReadMap "read only map" returns the simple
+ ///wrapping of the given map. Sometimes the reference maps cannot be
+ ///combined with simple read maps. This map adaptor wraps the given
+ ///map to simple read map.
+ template<typename M>
+ class SimpleMap : public MapBase<typename M::Key, typename M::Value> {
+ const M& m;
+
+ public:
+ typedef MapBase<typename M::Key, typename M::Value> Parent;
+ typedef typename Parent::Key Key;
+ typedef typename Parent::Value Value;
+
+ ///Constructor
+ SimpleMap(const M &_m) : m(_m) {};
+ Value operator[](Key k) const {return m[k];}
+ };
+
+ ///Simple writeable wrapping of the map
+
+ ///This \ref concept::ReadMap "read only map" returns the simple
+ ///wrapping of the given map. Sometimes the reference maps cannot be
+ ///combined with simple read-write maps. This map adaptor wraps the
+ ///given map to simple read-write map.
+ template<typename M>
+ class SimpleWriteMap : public MapBase<typename M::Key, typename M::Value> {
+ M& m;
+
+ public:
+ typedef MapBase<typename M::Key, typename M::Value> Parent;
+ typedef typename Parent::Key Key;
+ typedef typename Parent::Value Value;
+
+ ///Constructor
+ SimpleWriteMap(M &_m) : m(_m) {};
+ Value operator[](Key k) const {return m[k];}
+ void set(Key k, const Value& c) { m.set(k, c); }
+ };
+
///Sum of two maps
///This \ref concept::ReadMap "read only map" returns the sum of the two
More information about the Lemon-commits
mailing list