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