Naming and coding style fixes and various other changes.
2 * src/lemon/default_map.h - Part of LEMON, a generic C++ optimization library
4 * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
5 * (Egervary Combinatorial Optimization Research Group, EGRES).
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.
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
17 #ifndef LEMON_DEFAULT_MAP_H
18 #define LEMON_DEFAULT_MAP_H
21 #include <lemon/array_map.h>
22 #include <lemon/vector_map.h>
26 ///\brief Graph maps that construates and destruates
27 ///their elements dynamically.
31 /// \addtogroup graphmaps
34 /** The ArrayMap template class is graph map structure what
35 * automatically updates the map when a key is added to or erased from
36 * the map. This map uses the VectorMap if the ValueType is a primitive
37 * type and the ArrayMap for the other cases.
39 * The template parameter is the MapRegistry that the maps
40 * will belong to and the ValueType.
44 /** Macro to implement the DefaultMap.
46 #define DEFAULT_MAP_BODY(DynMap, Value) \
51 typedef DynMap<MapRegistry, Value> Parent; \
53 typedef typename MapRegistry::Graph Graph; \
55 DefaultMap(const Graph& g, MapRegistry& r) : Parent(g, r) {} \
56 DefaultMap(const Graph& g, MapRegistry& r, const Value& v) \
57 : Parent(g, r, v) {} \
58 DefaultMap(const DefaultMap& copy) \
59 : Parent(static_cast<const Parent&>(copy)) {} \
60 template <typename TT> \
61 DefaultMap(const DefaultMap<MapRegistry, TT>& copy) \
62 : Parent(*copy.getGraph()) { \
63 if (Parent::getGraph()) { \
64 for (typename Parent::KeyIt it(*Parent::getGraph()); it!=INVALID; ++it) {\
65 Parent::operator[](it) = copy[it]; \
69 DefaultMap& operator=(const DefaultMap& copy) { \
70 Parent::operator=(static_cast<const Parent&>(copy)); \
73 template <typename TT> \
74 DefaultMap& operator=(const DefaultMap<MapRegistry, TT>& copy) { \
75 if (Parent::getGraph() != copy.getGraph()) { \
77 Parent::MapBase::operator=(copy); \
78 Parent::construct(); \
80 if (Parent::getGraph()) { \
81 for (typename Parent::KeyIt it(*Parent::getGraph()); it!=INVALID; ++it) {\
82 Parent::operator[](it) = copy[it]; \
90 template <typename MapRegistry, typename Type>
91 class DefaultMap : public ArrayMap<MapRegistry, Type>
92 DEFAULT_MAP_BODY(ArrayMap, Type);
94 template <typename MapRegistry>
95 class DefaultMap<MapRegistry, bool>
96 : public VectorMap<MapRegistry, bool>
97 DEFAULT_MAP_BODY(VectorMap, bool);
99 template <typename MapRegistry>
100 class DefaultMap<MapRegistry, char>
101 : public VectorMap<MapRegistry, char>
102 DEFAULT_MAP_BODY(VectorMap, char);
104 template <typename MapRegistry>
105 class DefaultMap<MapRegistry, int>
106 : public VectorMap<MapRegistry, int>
107 DEFAULT_MAP_BODY(VectorMap, int);
109 template <typename MapRegistry>
110 class DefaultMap<MapRegistry, short>
111 : public VectorMap<MapRegistry, short>
112 DEFAULT_MAP_BODY(VectorMap, short);
114 template <typename MapRegistry>
115 class DefaultMap<MapRegistry, long>
116 : public VectorMap<MapRegistry, long>
117 DEFAULT_MAP_BODY(VectorMap, long);
119 template <typename MapRegistry>
120 class DefaultMap<MapRegistry, float>
121 : public VectorMap<MapRegistry, float>
122 DEFAULT_MAP_BODY(VectorMap, float);
124 template <typename MapRegistry>
125 class DefaultMap<MapRegistry, double>
126 : public VectorMap<MapRegistry, double>
127 DEFAULT_MAP_BODY(VectorMap, double);
129 template <typename MapRegistry>
130 class DefaultMap<MapRegistry, long double>
131 : public VectorMap<MapRegistry, long double>
132 DEFAULT_MAP_BODY(VectorMap, long double);
134 template <typename MapRegistry, typename Type>
135 class DefaultMap<MapRegistry, Type*>
136 : public VectorMap<MapRegistry, Type*>
137 DEFAULT_MAP_BODY(VectorMap, Type*);