src/lemon/map_defines.h
author marci
Wed, 26 Jan 2005 15:54:06 +0000
changeset 1097 c91e765266d7
parent 937 d4e911acef3d
permissions -rw-r--r--
A proposal or test implementation for linear expression`
     1 /* -*- C++ -*-
     2  * src/lemon/map_defines.h - Part of LEMON, a generic C++ optimization library
     3  *
     4  * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     5  * (Egervary Combinatorial Optimization Research Group, EGRES).
     6  *
     7  * Permission to use, modify and distribute this software is granted
     8  * provided that this copyright notice appears in all copies. For
     9  * precise terms see the accompanying LICENSE file.
    10  *
    11  * This software is provided "AS IS" with no warranty of any kind,
    12  * express or implied, and with no claim as to its suitability for any
    13  * purpose.
    14  *
    15  */
    16 
    17 #ifndef LEMON_MAP_DEFINES_H
    18 #define LEMON_MAP_DEFINES_H
    19 
    20 ///\ingroup graphmaps
    21 ///\file
    22 ///\brief Defines to help creating graph maps.
    23 
    24 /// \addtogroup graphmapfactory
    25 /// @{
    26 
    27 /** Creates the EdgeMapRegistry type an declare a mutable instance 
    28  *  named edge_maps.
    29  */
    30 #define CREATE_EDGE_MAP_REGISTRY \
    31 typedef MapRegistry<Graph, Edge, EdgeIt> EdgeMapRegistry; \
    32 mutable EdgeMapRegistry edge_maps;
    33 
    34 /** Creates the NodeMapRegistry type an declare a mutable instance 
    35  *  named node_maps.
    36  */
    37 #define CREATE_NODE_MAP_REGISTRY \
    38 typedef MapRegistry<Graph, Node, NodeIt> NodeMapRegistry; \
    39 mutable NodeMapRegistry node_maps;
    40 
    41 /** Creates both map registries.
    42  */
    43 #define CREATE_MAP_REGISTRIES \
    44 CREATE_NODE_MAP_REGISTRY \
    45 CREATE_EDGE_MAP_REGISTRY
    46 
    47 /** Creates a map from a template map. The import method is
    48  *  an overloading of the map type.
    49  *  The reason to use these macro is that the c++ does not support
    50  *  the template typedefs. If a future release of the c++ 
    51  *  supports this feature it should be fixed.
    52  */
    53 #define CREATE_NODE_MAP(DynMap) \
    54 template <typename _Value> \
    55 class NodeMap : public DynMap<NodeMapRegistry, _Value> { \
    56 public: \
    57 typedef DynMap<NodeMapRegistry, _Value> Parent; \
    58 NodeMap(const typename Parent::Graph& g) \
    59   : Parent(g, g.node_maps) {} \
    60 NodeMap(const typename Parent::Graph& g, const _Value& v) \
    61   : Parent(g, g.node_maps, v) {} \
    62 NodeMap(const NodeMap& copy) : Parent(static_cast<const Parent&>(copy)) {} \
    63 template <typename TT> \
    64 NodeMap(const NodeMap<TT>& copy) \
    65   : Parent(static_cast<const typename NodeMap<TT>::Parent&>(copy)) {} \
    66 NodeMap& operator=(const NodeMap& copy) { \
    67   Parent::operator=(static_cast<const Parent&>(copy));\
    68   return *this; \
    69 } \
    70 template <typename TT> \
    71 NodeMap& operator=(const NodeMap<TT>& copy) { \
    72   Parent::operator=(static_cast<const typename NodeMap<TT>::Parent&>(copy));\
    73   return *this; \
    74 } \
    75 };
    76 
    77 /** Creates a map from a template map. The import method is
    78  *  an overloading of the map type.
    79  *  The reason to use these macro is that the c++ does not support
    80  *  the template typedefs. If a future release of the c++ 
    81  *  supports this feature it should be fixed.
    82  */
    83 #define CREATE_EDGE_MAP(DynMap) \
    84 template <typename _Value> \
    85 class EdgeMap : public DynMap<EdgeMapRegistry, _Value> { \
    86 public: \
    87 typedef DynMap<EdgeMapRegistry, _Value> Parent; \
    88 \
    89 EdgeMap(const typename Parent::Graph& g) \
    90   : Parent(g, g.edge_maps) {} \
    91 EdgeMap(const typename Parent::Graph& g, const _Value& v) \
    92   : Parent(g, g.edge_maps, v) {} \
    93 EdgeMap(const EdgeMap& copy) : Parent(static_cast<const Parent&>(copy)) {} \
    94 template <typename TT> \
    95 EdgeMap(const EdgeMap<TT>& copy) \
    96   : Parent(static_cast<const typename EdgeMap<TT>::Parent&>(copy)) {} \
    97 EdgeMap& operator=(const EdgeMap& copy) { \
    98   Parent::operator=(static_cast<const Parent&>(copy));\
    99   return *this; \
   100 } \
   101 template <typename TT> \
   102 EdgeMap& operator=(const EdgeMap<TT>& copy) { \
   103   Parent::operator=(static_cast<const typename EdgeMap<TT>::Parent&>(copy));\
   104   return *this; \
   105 } \
   106 };
   107 
   108 /** This macro creates both maps.
   109  */
   110 #define CREATE_MAPS(DynMap) \
   111 CREATE_NODE_MAP(DynMap) \
   112 CREATE_EDGE_MAP(DynMap)
   113 
   114 /** This macro creates MapRegistry for Symmetric Edge Maps.
   115  */
   116 #define CREATE_SYM_EDGE_MAP_REGISTRY \
   117 typedef MapRegistry<Graph, SymEdge, SymEdgeIt> SymEdgeMapRegistry; \
   118 mutable SymEdgeMapRegistry sym_edge_maps;
   119 
   120 
   121 /** Creates a map from a template map. The import method is
   122  *  an overloading of the map type.
   123  *  The reason to use these macro is that the c++ does not support
   124  *  the template typedefs. If a future release of the c++ 
   125  *  supports this feature it should be fixed.
   126  */
   127 #define CREATE_SYM_EDGE_MAP(DynMap) \
   128 template <typename _Value> \
   129 class SymEdgeMap : public DynMap<SymEdgeMapRegistry, _Value> { \
   130 public: \
   131 typedef DynMap<SymEdgeMapRegistry, _Value> Parent; \
   132 \
   133 SymEdgeMap(const typename Parent::Graph& g) \
   134   : Parent(g, g.sym_edge_maps) {} \
   135 SymEdgeMap(const typename Parent::Graph& g, const _Value& v) \
   136   : Parent(g, g.sym_edge_maps, v) {} \
   137 SymEdgeMap(const SymEdgeMap& copy) \
   138   : Parent(static_cast<const Parent&>(copy)) {} \
   139 template <typename TT> \
   140 SymEdgeMap(const NodeMap<TT>& copy) \
   141   : Parent(static_cast<const typename SymEdgeMap<TT>::Parent&>(copy)) {} \
   142 SymEdgeMap& operator=(const SymEdgeMap& copy) { \
   143   Parent::operator=(static_cast<const Parent&>(copy));\
   144   return *this; \
   145 } \
   146 template <typename TT> \
   147 SymEdgeMap& operator=(const SymEdgeMap<TT>& copy) { \
   148   Parent::operator=(static_cast<const typename SymEdgeMap<TT>::Parent&>(copy));\
   149   return *this; \
   150 } \
   151 };
   152 
   153 /** This is a macro to import an node map into a graph class.
   154  */
   155 #define IMPORT_NODE_MAP(From, from, To, to) \
   156 template <typename _Value> \
   157 class NodeMap : public From::template NodeMap<_Value> { \
   158 \
   159 public: \
   160 typedef typename From::template NodeMap<_Value> Parent; \
   161 \
   162 NodeMap(const To& to) \
   163   : Parent(static_cast<const From&>(from)) { } \
   164 NodeMap(const To& to, const _Value& value) \
   165   : Parent(static_cast<const From&>(from), value) { } \
   166 NodeMap(const NodeMap& copy) \
   167   : Parent(static_cast<const Parent&>(copy)) {} \
   168 template <typename TT> \
   169 NodeMap(const NodeMap<TT>& copy) \
   170   : Parent(static_cast<const typename NodeMap<TT>::Parent&>(copy)) {} \
   171 NodeMap& operator=(const NodeMap& copy) { \
   172   Parent::operator=(static_cast<const Parent&>(copy)); \
   173   return *this; \
   174 } \
   175 template <typename TT> \
   176 NodeMap& operator=(const NodeMap<TT>& copy) { \
   177   Parent::operator=(static_cast<const typename NodeMap<TT>::Parent&>(copy));\
   178   return *this; \
   179 } \
   180 };
   181 
   182 /** This is a macro to import an edge map into a graph class.
   183  */
   184 #define IMPORT_EDGE_MAP(From, from, To, to) \
   185 template <typename _Value> \
   186 class EdgeMap : public From::template EdgeMap<_Value> { \
   187 \
   188 public: \
   189 typedef typename From::template EdgeMap<_Value> Parent; \
   190 \
   191 EdgeMap(const To& to) \
   192   : Parent(static_cast<const From&>(from)) { } \
   193 EdgeMap(const To& to, const _Value& value) \
   194   : Parent(static_cast<const From&>(from), value) { } \
   195 EdgeMap(const EdgeMap& copy) \
   196   : Parent(static_cast<const Parent&>(copy)) {} \
   197 template <typename TT> \
   198 EdgeMap(const EdgeMap<TT>& copy) \
   199   : Parent(static_cast<const typename EdgeMap<TT>::Parent&>(copy)) {} \
   200 EdgeMap& operator=(const EdgeMap& copy) { \
   201   Parent::operator=(static_cast<const Parent&>(copy)); \
   202   return *this; \
   203 } \
   204 template <typename TT> \
   205 EdgeMap& operator=(const EdgeMap<TT>& copy) { \
   206   Parent::operator=(static_cast<const typename EdgeMap<TT>::Parent&>(copy));\
   207   return *this; \
   208 } \
   209 };
   210 
   211 #define KEEP_EDGE_MAP(From, To) \
   212 IMPORT_EDGE_MAP(From, graph, To, graph)
   213 
   214 
   215 #define KEEP_NODE_MAP(From, To) \
   216 IMPORT_NODE_MAP(From, graph, To, graph)
   217 
   218 /** This is a macro to keep the node and edge maps for a graph class.
   219  */
   220 #define KEEP_MAPS(From, To) \
   221 KEEP_EDGE_MAP(From, To) \
   222 KEEP_NODE_MAP(From, To)
   223 
   224   
   225 /// @}
   226   
   227 #endif