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