/* -*- C++ -*- * src/lemon/default_map.h - Part of LEMON, a generic C++ optimization library * * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport * (Egervary Combinatorial Optimization Research Group, EGRES). * * Permission to use, modify and distribute this software is granted * provided that this copyright notice appears in all copies. For * precise terms see the accompanying LICENSE file. * * This software is provided "AS IS" with no warranty of any kind, * express or implied, and with no claim as to its suitability for any * purpose. * */ #ifndef LEMON_DEFAULT_MAP_H #define LEMON_DEFAULT_MAP_H #include #include ///\ingroup graphmaps ///\file ///\brief Graph maps that construct and destruct ///their elements dynamically. namespace lemon { /// \addtogroup graphmaps /// @{ /** The ArrayMap template class is graph map structure what * automatically updates the map when a key is added to or erased from * the map. This map uses the VectorMap if the ValueType is a primitive * type and the ArrayMap for the other cases. * * The template parameter is the MapRegistry that the maps * will belong to and the ValueType. */ template struct DefaultMapSelector { typedef ArrayMap<_Graph, _Item, _ItemIt, _IdMap, _Value> Map; }; // bool template struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, bool> { typedef VectorMap<_Graph, _Item, _IdMap, bool> Map; }; // char template struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, char> { typedef VectorMap<_Graph, _Item, _IdMap, char> Map; }; template struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, signed char> { typedef VectorMap<_Graph, _Item, _IdMap, signed char> Map; }; template struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, unsigned char> { typedef VectorMap<_Graph, _Item, _IdMap, unsigned char> Map; }; // int template struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, signed int> { typedef VectorMap<_Graph, _Item, _IdMap, signed int> Map; }; template struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, unsigned int> { typedef VectorMap<_Graph, _Item, _IdMap, unsigned int> Map; }; // short template struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, signed short> { typedef VectorMap<_Graph, _Item, _IdMap, signed short> Map; }; 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) {} }; }; } #endif