alpar@906: /* -*- C++ -*- alpar@921: * src/lemon/default_map.h - Part of LEMON, a generic C++ optimization library alpar@906: * alpar@906: * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport alpar@906: * (Egervary Combinatorial Optimization Research Group, EGRES). alpar@906: * alpar@906: * Permission to use, modify and distribute this software is granted alpar@906: * provided that this copyright notice appears in all copies. For alpar@906: * precise terms see the accompanying LICENSE file. alpar@906: * alpar@906: * This software is provided "AS IS" with no warranty of any kind, alpar@906: * express or implied, and with no claim as to its suitability for any alpar@906: * purpose. alpar@906: * alpar@906: */ alpar@906: alpar@921: #ifndef LEMON_DEFAULT_MAP_H alpar@921: #define LEMON_DEFAULT_MAP_H deba@822: deba@822: alpar@921: #include alpar@921: #include deba@822: deba@822: ///\ingroup graphmaps deba@822: ///\file klao@946: ///\brief Graph maps that construct and destruct deba@822: ///their elements dynamically. deba@822: alpar@921: namespace lemon { deba@822: deba@822: /// \addtogroup graphmaps deba@822: /// @{ deba@822: deba@822: /** The ArrayMap template class is graph map structure what deba@822: * automatically updates the map when a key is added to or erased from deba@822: * the map. This map uses the VectorMap if the ValueType is a primitive deba@822: * type and the ArrayMap for the other cases. deba@822: * deba@822: * The template parameter is the MapRegistry that the maps deba@822: * will belong to and the ValueType. deba@822: */ deba@822: deba@822: deba@822: klao@946: template klao@946: struct DefaultMapSelector { klao@946: typedef ArrayMap<_Graph, _Item, _ItemIt, _IdMap, _Value> Map; klao@946: }; deba@822: klao@946: // bool klao@946: template klao@946: struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, bool> { klao@946: typedef VectorMap<_Graph, _Item, _IdMap, bool> Map; klao@946: }; deba@822: klao@946: // char klao@946: template klao@946: struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, char> { klao@946: typedef VectorMap<_Graph, _Item, _IdMap, char> Map; klao@946: }; deba@822: klao@946: template klao@946: struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, signed char> { klao@946: typedef VectorMap<_Graph, _Item, _IdMap, signed char> Map; klao@946: }; deba@822: klao@946: template klao@946: struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, unsigned char> { klao@946: typedef VectorMap<_Graph, _Item, _IdMap, unsigned char> Map; klao@946: }; deba@822: deba@822: klao@946: // int klao@946: template klao@946: struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, signed int> { klao@946: typedef VectorMap<_Graph, _Item, _IdMap, signed int> Map; klao@946: }; deba@822: klao@946: template klao@946: struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, unsigned int> { klao@946: typedef VectorMap<_Graph, _Item, _IdMap, unsigned int> Map; klao@946: }; deba@822: deba@822: klao@946: // short klao@946: template klao@946: struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, signed short> { klao@946: typedef VectorMap<_Graph, _Item, _IdMap, signed short> Map; klao@946: }; deba@822: klao@946: template klao@946: struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, unsigned short> { klao@946: typedef VectorMap<_Graph, _Item, _IdMap, unsigned short> Map; klao@946: }; klao@946: klao@946: klao@946: // long klao@946: template klao@946: struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, signed long> { klao@946: typedef VectorMap<_Graph, _Item, _IdMap, signed long> Map; klao@946: }; klao@946: klao@946: template klao@946: struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, unsigned long> { klao@946: typedef VectorMap<_Graph, _Item, _IdMap, unsigned long> Map; klao@946: }; klao@946: klao@946: // \todo handling long long type klao@946: klao@946: klao@946: // float klao@946: template klao@946: struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, float> { klao@946: typedef VectorMap<_Graph, _Item, _IdMap, float> Map; klao@946: }; klao@946: klao@946: klao@946: // double klao@946: template klao@946: struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, double> { klao@946: typedef VectorMap<_Graph, _Item, _IdMap, double> Map; klao@946: }; klao@946: klao@946: klao@946: // long double klao@946: template klao@946: struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, long double> { klao@946: typedef VectorMap<_Graph, _Item, _IdMap, long double> Map; klao@946: }; klao@946: klao@946: klao@946: // pointer klao@946: template klao@946: struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, _Ptr*> { klao@946: typedef VectorMap<_Graph, _Item, _IdMap, _Ptr*> Map; klao@946: }; klao@946: klao@946: klao@946: klao@946: template klao@946: class DefaultMap : public DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, _Value>::Map { klao@946: public: klao@946: typedef typename DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, _Value>::Map Parent; klao@946: typedef DefaultMap<_Graph, _Item, _ItemIt, _IdMap, bool> Map; klao@946: klao@946: typedef typename Parent::Graph Graph; klao@946: typedef typename Parent::Registry Registry; klao@946: typedef typename Parent::ValueType ValueType; klao@946: klao@946: DefaultMap(const Graph& _g, Registry& _r) : Parent(_g, _r) {} klao@946: DefaultMap(const Graph& _g, Registry& _r, const ValueType& _v) : Parent(_g, _r, _v) {} klao@946: }; klao@946: klao@946: klao@946: klao@946: template klao@946: class DefaultMappableGraphExtender : public _Base { klao@946: public: klao@946: klao@946: typedef DefaultMappableGraphExtender<_Base> Graph; klao@946: typedef _Base Parent; klao@946: klao@946: typedef typename Parent::Node Node; klao@946: typedef typename Parent::NodeIt NodeIt; klao@946: typedef typename Parent::NodeIdMap NodeIdMap; klao@946: typedef typename Parent::NodeObserverRegistry NodeObserverRegistry; klao@946: klao@946: typedef typename Parent::Edge Edge; klao@946: typedef typename Parent::EdgeIt EdgeIt; klao@946: typedef typename Parent::EdgeIdMap EdgeIdMap; klao@946: typedef typename Parent::EdgeObserverRegistry EdgeObserverRegistry; klao@946: klao@946: klao@946: klao@946: template klao@946: class NodeMap : public DefaultMap { klao@946: public: klao@946: typedef DefaultMappableGraphExtender<_Base> Graph; klao@946: klao@946: typedef typename Graph::Node Node; klao@946: typedef typename Graph::NodeIt NodeIt; klao@946: typedef typename Graph::NodeIdMap NodeIdMap; klao@946: klao@946: typedef DefaultMap Parent; klao@946: klao@946: typedef typename Parent::Graph Graph; klao@946: typedef typename Parent::ValueType ValueType; klao@946: klao@946: NodeMap(const Graph& g) klao@946: : Parent(g, g.getNodeObserverRegistry()) {} klao@946: NodeMap(const Graph& g, const ValueType& v) klao@946: : Parent(g, g.getNodeObserverRegistry(), v) {} klao@946: klao@946: }; klao@946: klao@946: template klao@946: class EdgeMap : public DefaultMap { klao@946: public: klao@946: typedef DefaultMappableGraphExtender<_Base> Graph; klao@946: klao@946: typedef typename Graph::Edge Edge; klao@946: typedef typename Graph::EdgeIt EdgeIt; klao@946: typedef typename Graph::EdgeIdMap EdgeIdMap; klao@946: klao@946: typedef DefaultMap Parent; klao@946: klao@946: typedef typename Parent::Graph Graph; klao@946: typedef typename Parent::ValueType ValueType; klao@946: klao@946: EdgeMap(const Graph& g) klao@946: : Parent(g, g.getEdgeObserverRegistry()) {} klao@946: EdgeMap(const Graph& g, const ValueType& v) klao@946: : Parent(g, g.getEdgeObserverRegistry(), v) {} klao@946: klao@946: }; klao@946: klao@946: }; klao@946: deba@822: deba@822: } deba@822: deba@822: #endif