diff -r f2ea4aac9ada -r c94ef40a22ce src/lemon/default_map.h --- a/src/lemon/default_map.h Mon Oct 25 13:29:46 2004 +0000 +++ b/src/lemon/default_map.h Wed Oct 27 22:38:50 2004 +0000 @@ -23,7 +23,7 @@ ///\ingroup graphmaps ///\file -///\brief Graph maps that construates and destruates +///\brief Graph maps that construct and destruct ///their elements dynamically. namespace lemon { @@ -41,100 +41,185 @@ */ - /** Macro to implement the DefaultMap. - */ -#define DEFAULT_MAP_BODY(DynMap, Value) \ -{ \ -\ -public: \ -\ -typedef DynMap Parent; \ -\ -typedef typename MapRegistry::Graph Graph; \ -\ -DefaultMap(const Graph& g, MapRegistry& r) : Parent(g, r) {} \ -DefaultMap(const Graph& g, MapRegistry& r, const Value& v) \ - : Parent(g, r, v) {} \ -DefaultMap(const DefaultMap& copy) \ - : Parent(static_cast(copy)) {} \ -template \ -DefaultMap(const DefaultMap& copy) \ - : Parent(*copy.getGraph()) { \ - if (Parent::getGraph()) { \ - for (typename Parent::KeyIt it(*Parent::getGraph()); it!=INVALID; ++it) {\ - Parent::operator[](it) = copy[it]; \ - } \ - } \ -} \ -DefaultMap& operator=(const DefaultMap& copy) { \ - Parent::operator=(static_cast(copy)); \ - return *this; \ -} \ -template \ -DefaultMap& operator=(const DefaultMap& copy) { \ - if (Parent::getGraph() != copy.getGraph()) { \ - Parent::clear(); \ - Parent::MapBase::operator=(copy); \ - Parent::construct(); \ - } \ - if (Parent::getGraph()) { \ - for (typename Parent::KeyIt it(*Parent::getGraph()); it!=INVALID; ++it) {\ - Parent::operator[](it) = copy[it]; \ - } \ - } \ - return *this; \ -} \ -}; + template + struct DefaultMapSelector { + typedef ArrayMap<_Graph, _Item, _ItemIt, _IdMap, _Value> Map; + }; - template - class DefaultMap : public ArrayMap - DEFAULT_MAP_BODY(ArrayMap, Type); + // bool + template + struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, bool> { + typedef VectorMap<_Graph, _Item, _IdMap, bool> Map; + }; - template - class DefaultMap - : public VectorMap - DEFAULT_MAP_BODY(VectorMap, bool); + // char + template + struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, char> { + typedef VectorMap<_Graph, _Item, _IdMap, char> Map; + }; - template - class DefaultMap - : public VectorMap - DEFAULT_MAP_BODY(VectorMap, char); + template + struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, signed char> { + typedef VectorMap<_Graph, _Item, _IdMap, signed char> Map; + }; - template - class DefaultMap - : public VectorMap - DEFAULT_MAP_BODY(VectorMap, int); + template + struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, unsigned char> { + typedef VectorMap<_Graph, _Item, _IdMap, unsigned char> Map; + }; - template - class DefaultMap - : public VectorMap - DEFAULT_MAP_BODY(VectorMap, short); - template - class DefaultMap - : public VectorMap - DEFAULT_MAP_BODY(VectorMap, long); + // int + template + struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, signed int> { + typedef VectorMap<_Graph, _Item, _IdMap, signed int> Map; + }; - template - class DefaultMap - : public VectorMap - DEFAULT_MAP_BODY(VectorMap, float); + template + struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, unsigned int> { + typedef VectorMap<_Graph, _Item, _IdMap, unsigned int> Map; + }; - template - class DefaultMap - : public VectorMap - DEFAULT_MAP_BODY(VectorMap, double); - template - class DefaultMap - : public VectorMap - DEFAULT_MAP_BODY(VectorMap, long double); + // short + template + struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, signed short> { + typedef VectorMap<_Graph, _Item, _IdMap, signed short> Map; + }; - template - class DefaultMap - : public VectorMap - DEFAULT_MAP_BODY(VectorMap, Type*); + template + struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, unsigned short> { + typedef VectorMap<_Graph, _Item, _IdMap, unsigned short> Map; + }; + + + // long + template + struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, signed long> { + typedef VectorMap<_Graph, _Item, _IdMap, signed long> Map; + }; + + template + struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, unsigned long> { + typedef VectorMap<_Graph, _Item, _IdMap, unsigned long> Map; + }; + + // \todo handling long long type + + + // float + template + struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, float> { + typedef VectorMap<_Graph, _Item, _IdMap, float> Map; + }; + + + // double + template + struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, double> { + typedef VectorMap<_Graph, _Item, _IdMap, double> Map; + }; + + + // long double + template + struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, long double> { + typedef VectorMap<_Graph, _Item, _IdMap, long double> Map; + }; + + + // pointer + template + struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, _Ptr*> { + typedef VectorMap<_Graph, _Item, _IdMap, _Ptr*> Map; + }; + + + + template + class DefaultMap : public DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, _Value>::Map { + public: + typedef typename DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, _Value>::Map Parent; + typedef DefaultMap<_Graph, _Item, _ItemIt, _IdMap, bool> Map; + + typedef typename Parent::Graph Graph; + typedef typename Parent::Registry Registry; + typedef typename Parent::ValueType ValueType; + + DefaultMap(const Graph& _g, Registry& _r) : Parent(_g, _r) {} + DefaultMap(const Graph& _g, Registry& _r, const ValueType& _v) : Parent(_g, _r, _v) {} + }; + + + + template + class DefaultMappableGraphExtender : public _Base { + public: + + typedef DefaultMappableGraphExtender<_Base> Graph; + typedef _Base Parent; + + typedef typename Parent::Node Node; + typedef typename Parent::NodeIt NodeIt; + typedef typename Parent::NodeIdMap NodeIdMap; + typedef typename Parent::NodeObserverRegistry NodeObserverRegistry; + + typedef typename Parent::Edge Edge; + typedef typename Parent::EdgeIt EdgeIt; + typedef typename Parent::EdgeIdMap EdgeIdMap; + typedef typename Parent::EdgeObserverRegistry EdgeObserverRegistry; + + + + template + class NodeMap : public DefaultMap { + public: + typedef DefaultMappableGraphExtender<_Base> Graph; + + typedef typename Graph::Node Node; + typedef typename Graph::NodeIt NodeIt; + typedef typename Graph::NodeIdMap NodeIdMap; + + typedef DefaultMap Parent; + + typedef typename Parent::Graph Graph; + typedef typename Parent::ValueType ValueType; + + NodeMap(const Graph& g) + : Parent(g, g.getNodeObserverRegistry()) {} + NodeMap(const Graph& g, const ValueType& v) + : Parent(g, g.getNodeObserverRegistry(), v) {} + + }; + + template + class EdgeMap : public DefaultMap { + public: + typedef DefaultMappableGraphExtender<_Base> Graph; + + typedef typename Graph::Edge Edge; + typedef typename Graph::EdgeIt EdgeIt; + typedef typename Graph::EdgeIdMap EdgeIdMap; + + typedef DefaultMap Parent; + + typedef typename Parent::Graph Graph; + typedef typename Parent::ValueType ValueType; + + EdgeMap(const Graph& g) + : Parent(g, g.getEdgeObserverRegistry()) {} + EdgeMap(const Graph& g, const ValueType& v) + : Parent(g, g.getEdgeObserverRegistry(), v) {} + + }; + + }; + }