[906] | 1 | /* -*- C++ -*- |
---|
| 2 | * src/hugo/map_defines.h - Part of HUGOlib, 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 | |
---|
[901] | 17 | #ifndef HUGO_MAP_DEFINES_H |
---|
| 18 | #define HUGO_MAP_DEFINES_H |
---|
[782] | 19 | |
---|
[822] | 20 | ///\ingroup graphmaps |
---|
[785] | 21 | ///\file |
---|
| 22 | ///\brief Defines to help creating graph maps. |
---|
| 23 | |
---|
| 24 | /// \addtogroup graphmapfactory |
---|
| 25 | /// @{ |
---|
| 26 | |
---|
[782] | 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 | |
---|
[822] | 47 | /** Creates a map from a template map. The import method is |
---|
[782] | 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 | */ |
---|
[822] | 53 | #define CREATE_NODE_MAP(DynMap) \ |
---|
| 54 | template <typename Value> \ |
---|
| 55 | class NodeMap : public DynMap<NodeMapRegistry, Value> { \ |
---|
[782] | 56 | public: \ |
---|
[891] | 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)) {} \ |
---|
[782] | 66 | NodeMap& operator=(const NodeMap& copy) { \ |
---|
[891] | 67 | Parent::operator=(static_cast<const Parent&>(copy));\ |
---|
[782] | 68 | return *this; \ |
---|
| 69 | } \ |
---|
[891] | 70 | template <typename TT> \ |
---|
| 71 | NodeMap& operator=(const NodeMap<TT>& copy) { \ |
---|
| 72 | Parent::operator=(static_cast<const typename NodeMap<TT>::Parent&>(copy));\ |
---|
[782] | 73 | return *this; \ |
---|
| 74 | } \ |
---|
| 75 | }; |
---|
| 76 | |
---|
[822] | 77 | /** Creates a map from a template map. The import method is |
---|
[782] | 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 | */ |
---|
[822] | 83 | #define CREATE_EDGE_MAP(DynMap) \ |
---|
| 84 | template <typename Value> \ |
---|
| 85 | class EdgeMap : public DynMap<EdgeMapRegistry, Value> { \ |
---|
[782] | 86 | public: \ |
---|
[891] | 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)) {} \ |
---|
[782] | 97 | EdgeMap& operator=(const EdgeMap& copy) { \ |
---|
[891] | 98 | Parent::operator=(static_cast<const Parent&>(copy));\ |
---|
[782] | 99 | return *this; \ |
---|
| 100 | } \ |
---|
[891] | 101 | template <typename TT> \ |
---|
| 102 | EdgeMap& operator=(const EdgeMap<TT>& copy) { \ |
---|
| 103 | Parent::operator=(static_cast<const typename EdgeMap<TT>::Parent&>(copy));\ |
---|
[782] | 104 | return *this; \ |
---|
| 105 | } \ |
---|
| 106 | }; |
---|
| 107 | |
---|
[822] | 108 | /** This macro creates both maps. |
---|
[782] | 109 | */ |
---|
[822] | 110 | #define CREATE_MAPS(DynMap) \ |
---|
| 111 | CREATE_NODE_MAP(DynMap) \ |
---|
| 112 | CREATE_EDGE_MAP(DynMap) |
---|
[782] | 113 | |
---|
| 114 | /** This macro creates MapRegistry for Symmetric Edge Maps. |
---|
| 115 | */ |
---|
| 116 | #define CREATE_SYM_EDGE_MAP_REGISTRY \ |
---|
[909] | 117 | typedef MapRegistry<Graph, SymEdge, SymEdgeIt> SymEdgeMapRegistry; \ |
---|
[844] | 118 | mutable SymEdgeMapRegistry sym_edge_maps; |
---|
[782] | 119 | |
---|
| 120 | |
---|
[822] | 121 | /** Creates a map from a template map. The import method is |
---|
[782] | 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 | */ |
---|
[822] | 127 | #define CREATE_SYM_EDGE_MAP(DynMap) \ |
---|
| 128 | template <typename Value> \ |
---|
[909] | 129 | class SymEdgeMap : public DynMap<SymEdgeMapRegistry, Value> { \ |
---|
[891] | 130 | public: \ |
---|
[909] | 131 | typedef DynMap<SymEdgeMapRegistry, Value> Parent; \ |
---|
[822] | 132 | \ |
---|
[891] | 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 | } \ |
---|
[782] | 151 | }; |
---|
| 152 | |
---|
[822] | 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> \ |
---|
[891] | 157 | class NodeMap : public From::template NodeMap<Value> { \ |
---|
[782] | 158 | \ |
---|
[891] | 159 | public: \ |
---|
| 160 | typedef typename From::template NodeMap<Value> Parent; \ |
---|
[782] | 161 | \ |
---|
[891] | 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 | } \ |
---|
[822] | 180 | }; |
---|
[782] | 181 | |
---|
[822] | 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> \ |
---|
[891] | 186 | class EdgeMap : public From::template EdgeMap<Value> { \ |
---|
[782] | 187 | \ |
---|
[891] | 188 | public: \ |
---|
| 189 | typedef typename From::template EdgeMap<Value> Parent; \ |
---|
[782] | 190 | \ |
---|
[891] | 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 | } \ |
---|
[822] | 209 | }; |
---|
[782] | 210 | |
---|
[877] | 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) |
---|
[822] | 217 | |
---|
| 218 | /** This is a macro to keep the node and edge maps for a graph class. |
---|
| 219 | */ |
---|
| 220 | #define KEEP_MAPS(From, To) \ |
---|
[877] | 221 | KEEP_EDGE_MAP(From, To) \ |
---|
| 222 | KEEP_NODE_MAP(From, To) |
---|
| 223 | |
---|
[785] | 224 | |
---|
| 225 | /// @} |
---|
| 226 | |
---|
[782] | 227 | #endif |
---|