# HG changeset patch # User deba # Date 1116092253 0 # Node ID e37cca875667554735925312ab1f6b5c83324362 # Parent c3244a26adb19de518cf801f0ee64c86e20aadd5 Smart reference handling in map adaptors diff -r c3244a26adb1 -r e37cca875667 src/lemon/maps.h --- a/src/lemon/maps.h Sat May 14 17:34:31 2005 +0000 +++ b/src/lemon/maps.h Sat May 14 17:37:33 2005 +0000 @@ -17,6 +17,9 @@ #ifndef LEMON_MAPS_H #define LEMON_MAPS_H +#include +#include + ///\file ///\ingroup maps @@ -55,6 +58,8 @@ class NullMap : public MapBase { public: + + typedef True NeedCopy; /// Gives back a default constructed element. T operator[](const K&) const { return T(); } @@ -62,6 +67,11 @@ void set(const K&, const T&) {} }; + template + NullMap nullMap() { + return NullMap(); + } + /// Constant map. @@ -74,6 +84,8 @@ T v; public: + typedef True NeedCopy; + /// Default constructor /// The value of the map will be uninitialized. @@ -208,10 +220,12 @@ ///\endcode ///\bug wrong documentation template - class ConvertMap - { - const M &m; + class ConvertMap { + typename SmartConstReference::Type m; public: + + typedef True NeedCopy; + typedef typename M::Key Key; typedef T Value; @@ -250,9 +264,13 @@ template class AddMap { - const M1 &m1; - const M2 &m2; + typename SmartConstReference::Type m1; + typename SmartConstReference::Type m2; + public: + + typedef True NeedCopy; + typedef typename M1::Key Key; typedef typename M1::Value Value; @@ -295,9 +313,11 @@ template class ShiftMap { - const M &m; + typename SmartConstReference::Type m; typename M::Value v; public: + + typedef True NeedCopy; typedef typename M::Key Key; typedef typename M::Value Value; @@ -331,9 +351,11 @@ template class SubMap { - const M1 &m1; - const M2 &m2; + typename SmartConstReference::Type m1; + typename SmartConstReference::Type m2; public: + + typedef True NeedCopy; typedef typename M1::Key Key; typedef typename M1::Value Value; @@ -367,9 +389,11 @@ template class MulMap { - const M1 &m1; - const M2 &m2; + typename SmartConstReference::Type m1; + typename SmartConstReference::Type m2; public: + + typedef True NeedCopy; typedef typename M1::Key Key; typedef typename M1::Value Value; @@ -409,9 +433,11 @@ template class ScaleMap { - const M &m; + typename SmartConstReference::Type m; typename M::Value v; public: + + typedef True NeedCopy; typedef typename M::Key Key; typedef typename M::Value Value; @@ -445,9 +471,11 @@ template class DivMap { - const M1 &m1; - const M2 &m2; + typename SmartConstReference::Type m1; + typename SmartConstReference::Type m2; public: + + typedef True NeedCopy; typedef typename M1::Key Key; typedef typename M1::Value Value; @@ -489,12 +517,16 @@ template class ComposeMap { - const M1 &m1; - const M2 &m2; + typename SmartConstReference::Type m1; + typename SmartConstReference::Type m2; public: + + typedef True NeedCopy; typedef typename M2::Key Key; typedef typename M1::Value Value; + typedef True NeedCopy; + ///Constructor ///\e @@ -536,13 +568,15 @@ ///to \c V. ///\todo Check the requirements. - template + template class CombineMap { - const M1 &m1; - const M2 &m2; - const F &f; + typename SmartConstReference::Type m1; + typename SmartConstReference::Type m2; + F f; public: + + typedef True NeedCopy; typedef typename M1::Key Key; typedef V Value; @@ -571,10 +605,10 @@ ///\endcode /// ///\relates CombineMap - template - inline CombineMap combineMap(const M1 &m1,const M2 &m2,const F &f) + template + inline CombineMap combineMap(const M1 &m1,const M2 &m2,const F &f) { - return CombineMap(m1,m2,f); + return CombineMap(m1,m2,f); } ///Negative value of a map @@ -588,8 +622,10 @@ template class NegMap { - const M &m; + typename SmartConstReference::Type m; public: + + typedef True NeedCopy; typedef typename M::Key Key; typedef typename M::Value Value; @@ -638,8 +674,10 @@ template class AbsMap { - const M &m; + typename SmartConstReference::Type m; public: + + typedef True NeedCopy; typedef typename M::Key Key; typedef typename M::Value Value; @@ -679,6 +717,8 @@ { const F &f; public: + + typedef True NeedCopy; typedef K Key; typedef V Value; @@ -714,8 +754,10 @@ template class MapFunctor { - const M &m; + typename SmartConstReference::Type m; public: + + typedef True NeedCopy; typedef typename M::Key argument_type; typedef typename M::Value result_type; typedef typename M::Key Key; @@ -761,9 +803,11 @@ template class ForkMap { - const M1 &m1; - const M2 &m2; + typename SmartConstReference::Type m1; + typename SmartConstReference::Type m2; public: + + typedef True NeedCopy; typedef typename M1::Key Key; typedef typename M1::Value Value; diff -r c3244a26adb1 -r e37cca875667 src/lemon/xy.h --- a/src/lemon/xy.h Sat May 14 17:34:31 2005 +0000 +++ b/src/lemon/xy.h Sat May 14 17:37:33 2005 +0000 @@ -18,6 +18,7 @@ #define LEMON_XY_H #include +#include ///\ingroup misc ///\file @@ -350,12 +351,14 @@ template class XMap { - M &_map; + typename SmartReference::Type _map; public: + typedef True NeedCopy; + typedef typename M::Value::Value Value; typedef typename M::Key Key; ///\e - XMap(M &map) : _map(map) {} + XMap(typename SmartParameter::Type map) : _map(map) {} Value operator[](Key k) const {return _map[k].x;} void set(Key k,Value v) {_map.set(k,typename M::Value(v,_map[k].y));} }; @@ -372,6 +375,12 @@ return XMap(m); } + template + inline XMap xMap(const M &m) + { + return XMap(m); + } + ///Constant (read only) version of \ref XMap ///\ingroup maps @@ -379,8 +388,10 @@ template class ConstXMap { - const M &_map; + typename SmartConstReference::Type _map; public: + typedef True NeedCopy; + typedef typename M::Value::Value Value; typedef typename M::Key Key; ///\e @@ -407,12 +418,14 @@ template class YMap { - M &_map; + typename SmartReference::Type _map; public: + typedef True NeedCopy; + typedef typename M::Value::Value Value; typedef typename M::Key Key; ///\e - YMap(M &map) : _map(map) {} + YMap(typename SmartParameter::Type map) : _map(map) {} Value operator[](Key k) const {return _map[k].y;} void set(Key k,Value v) {_map.set(k,typename M::Value(_map[k].x,v));} }; @@ -429,6 +442,12 @@ return YMap(m); } + template + inline YMap yMap(const M &m) + { + return YMap(m); + } + ///Constant (read only) version of \ref YMap ///\ingroup maps @@ -436,8 +455,10 @@ template class ConstYMap { - const M &_map; + typename SmartConstReference::Type _map; public: + typedef True NeedCopy; + typedef typename M::Value::Value Value; typedef typename M::Key Key; ///\e @@ -466,8 +487,10 @@ template class NormSquareMap { - const M &_map; + typename SmartConstReference::Type _map; public: + typedef True NeedCopy; + typedef typename M::Value::Value Value; typedef typename M::Key Key; ///\e