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