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 deba@822: ///\brief Graph maps that construates and destruates 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: /** Macro to implement the DefaultMap. deba@822: */ deba@822: #define DEFAULT_MAP_BODY(DynMap, Value) \ deba@891: { \ deba@891: \ deba@891: public: \ deba@891: \ deba@891: typedef DynMap Parent; \ deba@891: \ deba@891: typedef typename MapRegistry::Graph Graph; \ deba@891: \ deba@891: DefaultMap(const Graph& g, MapRegistry& r) : Parent(g, r) {} \ deba@891: DefaultMap(const Graph& g, MapRegistry& r, const Value& v) \ deba@891: : Parent(g, r, v) {} \ deba@891: DefaultMap(const DefaultMap& copy) \ deba@891: : Parent(static_cast(copy)) {} \ deba@891: template \ deba@897: DefaultMap(const DefaultMap& copy) \ deba@937: : Parent(*copy.getGraph()) { \ deba@891: if (Parent::getGraph()) { \ deba@891: for (typename Parent::KeyIt it(*Parent::getGraph()); it!=INVALID; ++it) {\ deba@891: Parent::operator[](it) = copy[it]; \ deba@822: } \ deba@891: } \ deba@891: } \ deba@891: DefaultMap& operator=(const DefaultMap& copy) { \ deba@891: Parent::operator=(static_cast(copy)); \ deba@891: return *this; \ deba@891: } \ deba@891: template \ deba@891: DefaultMap& operator=(const DefaultMap& copy) { \ deba@897: if (Parent::getGraph() != copy.getGraph()) { \ deba@897: Parent::clear(); \ deba@897: Parent::MapBase::operator=(copy); \ deba@897: Parent::construct(); \ deba@897: } \ deba@891: if (Parent::getGraph()) { \ deba@891: for (typename Parent::KeyIt it(*Parent::getGraph()); it!=INVALID; ++it) {\ deba@891: Parent::operator[](it) = copy[it]; \ deba@822: } \ deba@891: } \ deba@891: return *this; \ deba@891: } \ deba@891: }; deba@822: deba@822: deba@822: template deba@822: class DefaultMap : public ArrayMap deba@822: DEFAULT_MAP_BODY(ArrayMap, Type); deba@822: deba@822: template deba@822: class DefaultMap deba@822: : public VectorMap deba@822: DEFAULT_MAP_BODY(VectorMap, bool); deba@822: deba@822: template deba@822: class DefaultMap deba@822: : public VectorMap deba@822: DEFAULT_MAP_BODY(VectorMap, char); deba@822: deba@822: template deba@822: class DefaultMap deba@822: : public VectorMap deba@822: DEFAULT_MAP_BODY(VectorMap, int); deba@822: deba@822: template deba@822: class DefaultMap deba@822: : public VectorMap deba@822: DEFAULT_MAP_BODY(VectorMap, short); deba@822: deba@822: template deba@822: class DefaultMap deba@822: : public VectorMap deba@822: DEFAULT_MAP_BODY(VectorMap, long); deba@822: deba@822: template deba@822: class DefaultMap deba@822: : public VectorMap deba@822: DEFAULT_MAP_BODY(VectorMap, float); deba@822: deba@822: template deba@822: class DefaultMap deba@822: : public VectorMap deba@822: DEFAULT_MAP_BODY(VectorMap, double); deba@822: deba@822: template deba@822: class DefaultMap deba@822: : public VectorMap deba@822: DEFAULT_MAP_BODY(VectorMap, long double); deba@822: deba@822: template deba@822: class DefaultMap deba@822: : public VectorMap deba@822: DEFAULT_MAP_BODY(VectorMap, Type*); deba@822: deba@822: } deba@822: deba@822: #endif