| 1 | // -*- c++ -*- |
|---|
| 2 | #ifndef MAP_DEFINES_H |
|---|
| 3 | #define MAP_DEFINES_H |
|---|
| 4 | |
|---|
| 5 | ///\ingroup graphmaps |
|---|
| 6 | ///\file |
|---|
| 7 | ///\brief Defines to help creating graph maps. |
|---|
| 8 | |
|---|
| 9 | /// \addtogroup graphmapfactory |
|---|
| 10 | /// @{ |
|---|
| 11 | |
|---|
| 12 | /** Creates the EdgeMapRegistry type an declare a mutable instance |
|---|
| 13 | * named edge_maps. |
|---|
| 14 | */ |
|---|
| 15 | #define CREATE_EDGE_MAP_REGISTRY \ |
|---|
| 16 | typedef MapRegistry<Graph, Edge, EdgeIt> EdgeMapRegistry; \ |
|---|
| 17 | mutable EdgeMapRegistry edge_maps; |
|---|
| 18 | |
|---|
| 19 | /** Creates the NodeMapRegistry type an declare a mutable instance |
|---|
| 20 | * named node_maps. |
|---|
| 21 | */ |
|---|
| 22 | #define CREATE_NODE_MAP_REGISTRY \ |
|---|
| 23 | typedef MapRegistry<Graph, Node, NodeIt> NodeMapRegistry; \ |
|---|
| 24 | mutable NodeMapRegistry node_maps; |
|---|
| 25 | |
|---|
| 26 | /** Creates both map registries. |
|---|
| 27 | */ |
|---|
| 28 | #define CREATE_MAP_REGISTRIES \ |
|---|
| 29 | CREATE_NODE_MAP_REGISTRY \ |
|---|
| 30 | CREATE_EDGE_MAP_REGISTRY |
|---|
| 31 | |
|---|
| 32 | /** Creates a map from a template map. The import method is |
|---|
| 33 | * an overloading of the map type. |
|---|
| 34 | * The reason to use these macro is that the c++ does not support |
|---|
| 35 | * the template typedefs. If a future release of the c++ |
|---|
| 36 | * supports this feature it should be fixed. |
|---|
| 37 | */ |
|---|
| 38 | #define CREATE_NODE_MAP(DynMap) \ |
|---|
| 39 | template <typename Value> \ |
|---|
| 40 | class NodeMap : public DynMap<NodeMapRegistry, Value> { \ |
|---|
| 41 | public: \ |
|---|
| 42 | typedef DynMap<NodeMapRegistry, Value> Parent; \ |
|---|
| 43 | NodeMap() {} \ |
|---|
| 44 | NodeMap(const typename Parent::Graph& g) \ |
|---|
| 45 | : Parent(g, g.node_maps) {} \ |
|---|
| 46 | NodeMap(const typename Parent::Graph& g, const Value& v) \ |
|---|
| 47 | : Parent(g, g.node_maps, v) {} \ |
|---|
| 48 | NodeMap(const NodeMap& copy) : Parent(static_cast<const Parent&>(copy)) {} \ |
|---|
| 49 | template <typename TT> \ |
|---|
| 50 | NodeMap(const NodeMap<TT>& copy) \ |
|---|
| 51 | : Parent(static_cast<const typename NodeMap<TT>::Parent&>(copy)) {} \ |
|---|
| 52 | NodeMap& operator=(const NodeMap& copy) { \ |
|---|
| 53 | Parent::operator=(static_cast<const Parent&>(copy));\ |
|---|
| 54 | return *this; \ |
|---|
| 55 | } \ |
|---|
| 56 | template <typename TT> \ |
|---|
| 57 | NodeMap& operator=(const NodeMap<TT>& copy) { \ |
|---|
| 58 | Parent::operator=(static_cast<const typename NodeMap<TT>::Parent&>(copy));\ |
|---|
| 59 | return *this; \ |
|---|
| 60 | } \ |
|---|
| 61 | }; |
|---|
| 62 | |
|---|
| 63 | /** Creates a map from a template map. The import method is |
|---|
| 64 | * an overloading of the map type. |
|---|
| 65 | * The reason to use these macro is that the c++ does not support |
|---|
| 66 | * the template typedefs. If a future release of the c++ |
|---|
| 67 | * supports this feature it should be fixed. |
|---|
| 68 | */ |
|---|
| 69 | #define CREATE_EDGE_MAP(DynMap) \ |
|---|
| 70 | template <typename Value> \ |
|---|
| 71 | class EdgeMap : public DynMap<EdgeMapRegistry, Value> { \ |
|---|
| 72 | public: \ |
|---|
| 73 | typedef DynMap<EdgeMapRegistry, Value> Parent; \ |
|---|
| 74 | \ |
|---|
| 75 | EdgeMap() {} \ |
|---|
| 76 | EdgeMap(const typename Parent::Graph& g) \ |
|---|
| 77 | : Parent(g, g.edge_maps) {} \ |
|---|
| 78 | EdgeMap(const typename Parent::Graph& g, const Value& v) \ |
|---|
| 79 | : Parent(g, g.edge_maps, v) {} \ |
|---|
| 80 | EdgeMap(const EdgeMap& copy) : Parent(static_cast<const Parent&>(copy)) {} \ |
|---|
| 81 | template <typename TT> \ |
|---|
| 82 | EdgeMap(const EdgeMap<TT>& copy) \ |
|---|
| 83 | : Parent(static_cast<const typename EdgeMap<TT>::Parent&>(copy)) {} \ |
|---|
| 84 | EdgeMap& operator=(const EdgeMap& copy) { \ |
|---|
| 85 | Parent::operator=(static_cast<const Parent&>(copy));\ |
|---|
| 86 | return *this; \ |
|---|
| 87 | } \ |
|---|
| 88 | template <typename TT> \ |
|---|
| 89 | EdgeMap& operator=(const EdgeMap<TT>& copy) { \ |
|---|
| 90 | Parent::operator=(static_cast<const typename EdgeMap<TT>::Parent&>(copy));\ |
|---|
| 91 | return *this; \ |
|---|
| 92 | } \ |
|---|
| 93 | }; |
|---|
| 94 | |
|---|
| 95 | /** This macro creates both maps. |
|---|
| 96 | */ |
|---|
| 97 | #define CREATE_MAPS(DynMap) \ |
|---|
| 98 | CREATE_NODE_MAP(DynMap) \ |
|---|
| 99 | CREATE_EDGE_MAP(DynMap) |
|---|
| 100 | |
|---|
| 101 | /** This macro creates MapRegistry for Symmetric Edge Maps. |
|---|
| 102 | */ |
|---|
| 103 | #define CREATE_SYM_EDGE_MAP_REGISTRY \ |
|---|
| 104 | typedef SymEdgeIt<Graph, Edge, EdgeIt> SymEdgeIt; \ |
|---|
| 105 | typedef MapRegistry<Graph, Edge, SymEdgeIt> SymEdgeMapRegistry; \ |
|---|
| 106 | mutable SymEdgeMapRegistry sym_edge_maps; |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | /** Creates a map from a template map. The import method is |
|---|
| 110 | * an overloading of the map type. |
|---|
| 111 | * The reason to use these macro is that the c++ does not support |
|---|
| 112 | * the template typedefs. If a future release of the c++ |
|---|
| 113 | * supports this feature it should be fixed. |
|---|
| 114 | */ |
|---|
| 115 | #define CREATE_SYM_EDGE_MAP(DynMap) \ |
|---|
| 116 | template <typename Value> \ |
|---|
| 117 | class SymEdgeMap : public SymMap<DynMap, SymEdgeMapRegistry, Value> { \ |
|---|
| 118 | public: \ |
|---|
| 119 | typedef SymMap<DynMap, SymEdgeMapRegistry, Value> Parent; \ |
|---|
| 120 | \ |
|---|
| 121 | SymEdgeMap() {} \ |
|---|
| 122 | SymEdgeMap(const typename Parent::Graph& g) \ |
|---|
| 123 | : Parent(g, g.sym_edge_maps) {} \ |
|---|
| 124 | SymEdgeMap(const typename Parent::Graph& g, const Value& v) \ |
|---|
| 125 | : Parent(g, g.sym_edge_maps, v) {} \ |
|---|
| 126 | SymEdgeMap(const SymEdgeMap& copy) \ |
|---|
| 127 | : Parent(static_cast<const Parent&>(copy)) {} \ |
|---|
| 128 | template <typename TT> \ |
|---|
| 129 | SymEdgeMap(const NodeMap<TT>& copy) \ |
|---|
| 130 | : Parent(static_cast<const typename SymEdgeMap<TT>::Parent&>(copy)) {} \ |
|---|
| 131 | SymEdgeMap& operator=(const SymEdgeMap& copy) { \ |
|---|
| 132 | Parent::operator=(static_cast<const Parent&>(copy));\ |
|---|
| 133 | return *this; \ |
|---|
| 134 | } \ |
|---|
| 135 | template <typename TT> \ |
|---|
| 136 | SymEdgeMap& operator=(const SymEdgeMap<TT>& copy) { \ |
|---|
| 137 | Parent::operator=(static_cast<const typename SymEdgeMap<TT>::Parent&>(copy));\ |
|---|
| 138 | return *this; \ |
|---|
| 139 | } \ |
|---|
| 140 | }; |
|---|
| 141 | |
|---|
| 142 | /** This is a macro to import an node map into a graph class. |
|---|
| 143 | */ |
|---|
| 144 | #define IMPORT_NODE_MAP(From, from, To, to) \ |
|---|
| 145 | template <typename Value> \ |
|---|
| 146 | class NodeMap : public From::template NodeMap<Value> { \ |
|---|
| 147 | \ |
|---|
| 148 | public: \ |
|---|
| 149 | typedef typename From::template NodeMap<Value> Parent; \ |
|---|
| 150 | \ |
|---|
| 151 | NodeMap() : Parent() {} \ |
|---|
| 152 | NodeMap(const To& to) \ |
|---|
| 153 | : Parent(static_cast<const From&>(from)) { } \ |
|---|
| 154 | NodeMap(const To& to, const Value& value) \ |
|---|
| 155 | : Parent(static_cast<const From&>(from), value) { } \ |
|---|
| 156 | NodeMap(const NodeMap& copy) \ |
|---|
| 157 | : Parent(static_cast<const Parent&>(copy)) {} \ |
|---|
| 158 | template <typename TT> \ |
|---|
| 159 | NodeMap(const NodeMap<TT>& copy) \ |
|---|
| 160 | : Parent(static_cast<const typename NodeMap<TT>::Parent&>(copy)) {} \ |
|---|
| 161 | NodeMap& operator=(const NodeMap& copy) { \ |
|---|
| 162 | Parent::operator=(static_cast<const Parent&>(copy)); \ |
|---|
| 163 | return *this; \ |
|---|
| 164 | } \ |
|---|
| 165 | template <typename TT> \ |
|---|
| 166 | NodeMap& operator=(const NodeMap<TT>& copy) { \ |
|---|
| 167 | Parent::operator=(static_cast<const typename NodeMap<TT>::Parent&>(copy));\ |
|---|
| 168 | return *this; \ |
|---|
| 169 | } \ |
|---|
| 170 | }; |
|---|
| 171 | |
|---|
| 172 | /** This is a macro to import an edge map into a graph class. |
|---|
| 173 | */ |
|---|
| 174 | #define IMPORT_EDGE_MAP(From, from, To, to) \ |
|---|
| 175 | template <typename Value> \ |
|---|
| 176 | class EdgeMap : public From::template EdgeMap<Value> { \ |
|---|
| 177 | \ |
|---|
| 178 | public: \ |
|---|
| 179 | typedef typename From::template EdgeMap<Value> Parent; \ |
|---|
| 180 | \ |
|---|
| 181 | EdgeMap() : Parent() {} \ |
|---|
| 182 | EdgeMap(const To& to) \ |
|---|
| 183 | : Parent(static_cast<const From&>(from)) { } \ |
|---|
| 184 | EdgeMap(const To& to, const Value& value) \ |
|---|
| 185 | : Parent(static_cast<const From&>(from), value) { } \ |
|---|
| 186 | EdgeMap(const EdgeMap& copy) \ |
|---|
| 187 | : Parent(static_cast<const Parent&>(copy)) {} \ |
|---|
| 188 | template <typename TT> \ |
|---|
| 189 | EdgeMap(const EdgeMap<TT>& copy) \ |
|---|
| 190 | : Parent(static_cast<const typename EdgeMap<TT>::Parent&>(copy)) {} \ |
|---|
| 191 | EdgeMap& operator=(const EdgeMap& copy) { \ |
|---|
| 192 | Parent::operator=(static_cast<const Parent&>(copy)); \ |
|---|
| 193 | return *this; \ |
|---|
| 194 | } \ |
|---|
| 195 | template <typename TT> \ |
|---|
| 196 | EdgeMap& operator=(const EdgeMap<TT>& copy) { \ |
|---|
| 197 | Parent::operator=(static_cast<const typename EdgeMap<TT>::Parent&>(copy));\ |
|---|
| 198 | return *this; \ |
|---|
| 199 | } \ |
|---|
| 200 | }; |
|---|
| 201 | |
|---|
| 202 | #define KEEP_EDGE_MAP(From, To) \ |
|---|
| 203 | IMPORT_EDGE_MAP(From, graph, To, graph) |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | #define KEEP_NODE_MAP(From, To) \ |
|---|
| 207 | IMPORT_NODE_MAP(From, graph, To, graph) |
|---|
| 208 | |
|---|
| 209 | /** This is a macro to keep the node and edge maps for a graph class. |
|---|
| 210 | */ |
|---|
| 211 | #define KEEP_MAPS(From, To) \ |
|---|
| 212 | KEEP_EDGE_MAP(From, To) \ |
|---|
| 213 | KEEP_NODE_MAP(From, To) |
|---|
| 214 | |
|---|
| 215 | |
|---|
| 216 | /// @} |
|---|
| 217 | |
|---|
| 218 | #endif |
|---|