/* -*- C++ -*- * src/hugo/map_defines.h - Part of HUGOlib, 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 HUGO_MAP_DEFINES_H #define HUGO_MAP_DEFINES_H ///\ingroup graphmaps ///\file ///\brief Defines to help creating graph maps. /// \addtogroup graphmapfactory /// @{ /** Creates the EdgeMapRegistry type an declare a mutable instance * named edge_maps. */ #define CREATE_EDGE_MAP_REGISTRY \ typedef MapRegistry EdgeMapRegistry; \ mutable EdgeMapRegistry edge_maps; /** Creates the NodeMapRegistry type an declare a mutable instance * named node_maps. */ #define CREATE_NODE_MAP_REGISTRY \ typedef MapRegistry NodeMapRegistry; \ mutable NodeMapRegistry node_maps; /** Creates both map registries. */ #define CREATE_MAP_REGISTRIES \ CREATE_NODE_MAP_REGISTRY \ CREATE_EDGE_MAP_REGISTRY /** Creates a map from a template map. The import method is * an overloading of the map type. * The reason to use these macro is that the c++ does not support * the template typedefs. If a future release of the c++ * supports this feature it should be fixed. */ #define CREATE_NODE_MAP(DynMap) \ template \ class NodeMap : public DynMap { \ public: \ typedef DynMap Parent; \ NodeMap(const typename Parent::Graph& g) \ : Parent(g, g.node_maps) {} \ NodeMap(const typename Parent::Graph& g, const Value& v) \ : Parent(g, g.node_maps, v) {} \ NodeMap(const NodeMap& copy) : Parent(static_cast(copy)) {} \ template \ NodeMap(const NodeMap& copy) \ : Parent(static_cast::Parent&>(copy)) {} \ NodeMap& operator=(const NodeMap& copy) { \ Parent::operator=(static_cast(copy));\ return *this; \ } \ template \ NodeMap& operator=(const NodeMap& copy) { \ Parent::operator=(static_cast::Parent&>(copy));\ return *this; \ } \ }; /** Creates a map from a template map. The import method is * an overloading of the map type. * The reason to use these macro is that the c++ does not support * the template typedefs. If a future release of the c++ * supports this feature it should be fixed. */ #define CREATE_EDGE_MAP(DynMap) \ template \ class EdgeMap : public DynMap { \ public: \ typedef DynMap Parent; \ \ EdgeMap(const typename Parent::Graph& g) \ : Parent(g, g.edge_maps) {} \ EdgeMap(const typename Parent::Graph& g, const Value& v) \ : Parent(g, g.edge_maps, v) {} \ EdgeMap(const EdgeMap& copy) : Parent(static_cast(copy)) {} \ template \ EdgeMap(const EdgeMap& copy) \ : Parent(static_cast::Parent&>(copy)) {} \ EdgeMap& operator=(const EdgeMap& copy) { \ Parent::operator=(static_cast(copy));\ return *this; \ } \ template \ EdgeMap& operator=(const EdgeMap& copy) { \ Parent::operator=(static_cast::Parent&>(copy));\ return *this; \ } \ }; /** This macro creates both maps. */ #define CREATE_MAPS(DynMap) \ CREATE_NODE_MAP(DynMap) \ CREATE_EDGE_MAP(DynMap) /** This macro creates MapRegistry for Symmetric Edge Maps. */ #define CREATE_SYM_EDGE_MAP_REGISTRY \ typedef SymEdgeIt SymEdgeIt; \ typedef MapRegistry SymEdgeMapRegistry; \ mutable SymEdgeMapRegistry sym_edge_maps; /** Creates a map from a template map. The import method is * an overloading of the map type. * The reason to use these macro is that the c++ does not support * the template typedefs. If a future release of the c++ * supports this feature it should be fixed. */ #define CREATE_SYM_EDGE_MAP(DynMap) \ template \ class SymEdgeMap : public SymMap { \ public: \ typedef SymMap Parent; \ \ SymEdgeMap(const typename Parent::Graph& g) \ : Parent(g, g.sym_edge_maps) {} \ SymEdgeMap(const typename Parent::Graph& g, const Value& v) \ : Parent(g, g.sym_edge_maps, v) {} \ SymEdgeMap(const SymEdgeMap& copy) \ : Parent(static_cast(copy)) {} \ template \ SymEdgeMap(const NodeMap& copy) \ : Parent(static_cast::Parent&>(copy)) {} \ SymEdgeMap& operator=(const SymEdgeMap& copy) { \ Parent::operator=(static_cast(copy));\ return *this; \ } \ template \ SymEdgeMap& operator=(const SymEdgeMap& copy) { \ Parent::operator=(static_cast::Parent&>(copy));\ return *this; \ } \ }; /** This is a macro to import an node map into a graph class. */ #define IMPORT_NODE_MAP(From, from, To, to) \ template \ class NodeMap : public From::template NodeMap { \ \ public: \ typedef typename From::template NodeMap Parent; \ \ NodeMap(const To& to) \ : Parent(static_cast(from)) { } \ NodeMap(const To& to, const Value& value) \ : Parent(static_cast(from), value) { } \ NodeMap(const NodeMap& copy) \ : Parent(static_cast(copy)) {} \ template \ NodeMap(const NodeMap& copy) \ : Parent(static_cast::Parent&>(copy)) {} \ NodeMap& operator=(const NodeMap& copy) { \ Parent::operator=(static_cast(copy)); \ return *this; \ } \ template \ NodeMap& operator=(const NodeMap& copy) { \ Parent::operator=(static_cast::Parent&>(copy));\ return *this; \ } \ }; /** This is a macro to import an edge map into a graph class. */ #define IMPORT_EDGE_MAP(From, from, To, to) \ template \ class EdgeMap : public From::template EdgeMap { \ \ public: \ typedef typename From::template EdgeMap Parent; \ \ EdgeMap(const To& to) \ : Parent(static_cast(from)) { } \ EdgeMap(const To& to, const Value& value) \ : Parent(static_cast(from), value) { } \ EdgeMap(const EdgeMap& copy) \ : Parent(static_cast(copy)) {} \ template \ EdgeMap(const EdgeMap& copy) \ : Parent(static_cast::Parent&>(copy)) {} \ EdgeMap& operator=(const EdgeMap& copy) { \ Parent::operator=(static_cast(copy)); \ return *this; \ } \ template \ EdgeMap& operator=(const EdgeMap& copy) { \ Parent::operator=(static_cast::Parent&>(copy));\ return *this; \ } \ }; #define KEEP_EDGE_MAP(From, To) \ IMPORT_EDGE_MAP(From, graph, To, graph) #define KEEP_NODE_MAP(From, To) \ IMPORT_NODE_MAP(From, graph, To, graph) /** This is a macro to keep the node and edge maps for a graph class. */ #define KEEP_MAPS(From, To) \ KEEP_EDGE_MAP(From, To) \ KEEP_NODE_MAP(From, To) /// @} #endif