/* -*- 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 construates and destruates ///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. */ /** 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::MapBase::operator= \ (static_cast(copy)); \ if (Parent::getGraph()) { \ for (typename Parent::KeyIt it(*Parent::getGraph()); it!=INVALID; ++it) {\ Parent::add(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 class DefaultMap : public ArrayMap DEFAULT_MAP_BODY(ArrayMap, Type); template class DefaultMap : public VectorMap DEFAULT_MAP_BODY(VectorMap, bool); template class DefaultMap : public VectorMap DEFAULT_MAP_BODY(VectorMap, char); template class DefaultMap : public VectorMap DEFAULT_MAP_BODY(VectorMap, int); template class DefaultMap : public VectorMap DEFAULT_MAP_BODY(VectorMap, short); template class DefaultMap : public VectorMap DEFAULT_MAP_BODY(VectorMap, long); template class DefaultMap : public VectorMap DEFAULT_MAP_BODY(VectorMap, float); template class DefaultMap : public VectorMap DEFAULT_MAP_BODY(VectorMap, double); template class DefaultMap : public VectorMap DEFAULT_MAP_BODY(VectorMap, long double); template class DefaultMap : public VectorMap DEFAULT_MAP_BODY(VectorMap, Type*); } #endif