alpar@906: /* -*- C++ -*-
alpar@921:  * src/lemon/map_defines.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_MAP_DEFINES_H
alpar@921: #define LEMON_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<Graph, Edge, EdgeIt> 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<Graph, Node, NodeIt> 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) \
alpar@987: template <typename _Value> \
alpar@987: class NodeMap : public DynMap<NodeMapRegistry, _Value> { \
deba@782: public: \
alpar@987: typedef DynMap<NodeMapRegistry, _Value> Parent; \
deba@891: NodeMap(const typename Parent::Graph& g) \
deba@891:   : Parent(g, g.node_maps) {} \
alpar@987: 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<const Parent&>(copy)) {} \
deba@891: template <typename TT> \
deba@891: NodeMap(const NodeMap<TT>& copy) \
deba@891:   : Parent(static_cast<const typename NodeMap<TT>::Parent&>(copy)) {} \
deba@782: NodeMap& operator=(const NodeMap& copy) { \
deba@891:   Parent::operator=(static_cast<const Parent&>(copy));\
deba@782:   return *this; \
deba@782: } \
deba@891: template <typename TT> \
deba@891: NodeMap& operator=(const NodeMap<TT>& copy) { \
deba@891:   Parent::operator=(static_cast<const typename NodeMap<TT>::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) \
alpar@987: template <typename _Value> \
alpar@987: class EdgeMap : public DynMap<EdgeMapRegistry, _Value> { \
deba@782: public: \
alpar@987: typedef DynMap<EdgeMapRegistry, _Value> Parent; \
deba@891: \
deba@891: EdgeMap(const typename Parent::Graph& g) \
deba@891:   : Parent(g, g.edge_maps) {} \
alpar@987: 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<const Parent&>(copy)) {} \
deba@891: template <typename TT> \
deba@891: EdgeMap(const EdgeMap<TT>& copy) \
deba@891:   : Parent(static_cast<const typename EdgeMap<TT>::Parent&>(copy)) {} \
deba@782: EdgeMap& operator=(const EdgeMap& copy) { \
deba@891:   Parent::operator=(static_cast<const Parent&>(copy));\
deba@782:   return *this; \
deba@782: } \
deba@891: template <typename TT> \
deba@891: EdgeMap& operator=(const EdgeMap<TT>& copy) { \
deba@891:   Parent::operator=(static_cast<const typename EdgeMap<TT>::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@937: typedef MapRegistry<Graph, SymEdge, SymEdgeIt> 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) \
alpar@987: template <typename _Value> \
alpar@987: class SymEdgeMap : public DynMap<SymEdgeMapRegistry, _Value> { \
deba@891: public: \
alpar@987: typedef DynMap<SymEdgeMapRegistry, _Value> Parent; \
deba@822: \
deba@891: SymEdgeMap(const typename Parent::Graph& g) \
deba@891:   : Parent(g, g.sym_edge_maps) {} \
alpar@987: 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<const Parent&>(copy)) {} \
deba@891: template <typename TT> \
deba@891: SymEdgeMap(const NodeMap<TT>& copy) \
deba@891:   : Parent(static_cast<const typename SymEdgeMap<TT>::Parent&>(copy)) {} \
deba@891: SymEdgeMap& operator=(const SymEdgeMap& copy) { \
deba@891:   Parent::operator=(static_cast<const Parent&>(copy));\
deba@891:   return *this; \
deba@891: } \
deba@891: template <typename TT> \
deba@891: SymEdgeMap& operator=(const SymEdgeMap<TT>& copy) { \
deba@891:   Parent::operator=(static_cast<const typename SymEdgeMap<TT>::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) \
alpar@987: template <typename _Value> \
alpar@987: class NodeMap : public From::template NodeMap<_Value> { \
deba@782: \
deba@891: public: \
alpar@987: typedef typename From::template NodeMap<_Value> Parent; \
deba@782: \
deba@891: NodeMap(const To& to) \
deba@891:   : Parent(static_cast<const From&>(from)) { } \
alpar@987: NodeMap(const To& to, const _Value& value) \
deba@891:   : Parent(static_cast<const From&>(from), value) { } \
deba@891: NodeMap(const NodeMap& copy) \
deba@891:   : Parent(static_cast<const Parent&>(copy)) {} \
deba@891: template <typename TT> \
deba@891: NodeMap(const NodeMap<TT>& copy) \
deba@891:   : Parent(static_cast<const typename NodeMap<TT>::Parent&>(copy)) {} \
deba@891: NodeMap& operator=(const NodeMap& copy) { \
deba@891:   Parent::operator=(static_cast<const Parent&>(copy)); \
deba@891:   return *this; \
deba@891: } \
deba@891: template <typename TT> \
deba@891: NodeMap& operator=(const NodeMap<TT>& copy) { \
deba@891:   Parent::operator=(static_cast<const typename NodeMap<TT>::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) \
alpar@987: template <typename _Value> \
alpar@987: class EdgeMap : public From::template EdgeMap<_Value> { \
deba@782: \
deba@891: public: \
alpar@987: typedef typename From::template EdgeMap<_Value> Parent; \
deba@782: \
deba@891: EdgeMap(const To& to) \
deba@891:   : Parent(static_cast<const From&>(from)) { } \
alpar@987: EdgeMap(const To& to, const _Value& value) \
deba@891:   : Parent(static_cast<const From&>(from), value) { } \
deba@891: EdgeMap(const EdgeMap& copy) \
deba@891:   : Parent(static_cast<const Parent&>(copy)) {} \
deba@891: template <typename TT> \
deba@891: EdgeMap(const EdgeMap<TT>& copy) \
deba@891:   : Parent(static_cast<const typename EdgeMap<TT>::Parent&>(copy)) {} \
deba@891: EdgeMap& operator=(const EdgeMap& copy) { \
deba@891:   Parent::operator=(static_cast<const Parent&>(copy)); \
deba@891:   return *this; \
deba@891: } \
deba@891: template <typename TT> \
deba@891: EdgeMap& operator=(const EdgeMap<TT>& copy) { \
deba@891:   Parent::operator=(static_cast<const typename EdgeMap<TT>::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