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 construct and destruct
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.
45 template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap, typename _Value>
46 struct DefaultMapSelector {
47 typedef ArrayMap<_Graph, _Item, _ItemIt, _IdMap, _Value> Map;
51 template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
52 struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, bool> {
53 typedef VectorMap<_Graph, _Item, _IdMap, bool> Map;
57 template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
58 struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, char> {
59 typedef VectorMap<_Graph, _Item, _IdMap, char> Map;
62 template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
63 struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, signed char> {
64 typedef VectorMap<_Graph, _Item, _IdMap, signed char> Map;
67 template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
68 struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, unsigned char> {
69 typedef VectorMap<_Graph, _Item, _IdMap, unsigned char> Map;
74 template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
75 struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, signed int> {
76 typedef VectorMap<_Graph, _Item, _IdMap, signed int> Map;
79 template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
80 struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, unsigned int> {
81 typedef VectorMap<_Graph, _Item, _IdMap, unsigned int> Map;
86 template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
87 struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, signed short> {
88 typedef VectorMap<_Graph, _Item, _IdMap, signed short> Map;
91 template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
92 struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, unsigned short> {
93 typedef VectorMap<_Graph, _Item, _IdMap, unsigned short> Map;
98 template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
99 struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, signed long> {
100 typedef VectorMap<_Graph, _Item, _IdMap, signed long> Map;
103 template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
104 struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, unsigned long> {
105 typedef VectorMap<_Graph, _Item, _IdMap, unsigned long> Map;
108 // \todo handling long long type
112 template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
113 struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, float> {
114 typedef VectorMap<_Graph, _Item, _IdMap, float> Map;
119 template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
120 struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, double> {
121 typedef VectorMap<_Graph, _Item, _IdMap, double> Map;
126 template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
127 struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, long double> {
128 typedef VectorMap<_Graph, _Item, _IdMap, long double> Map;
133 template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap, typename _Ptr>
134 struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, _Ptr*> {
135 typedef VectorMap<_Graph, _Item, _IdMap, _Ptr*> Map;
140 template <typename _Graph,
145 class DefaultMap : public DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, _Value>::Map {
147 typedef typename DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, _Value>::Map Parent;
148 typedef DefaultMap<_Graph, _Item, _ItemIt, _IdMap, bool> Map;
150 typedef typename Parent::Graph Graph;
151 typedef typename Parent::Registry Registry;
152 typedef typename Parent::ValueType ValueType;
154 DefaultMap(const Graph& _g, Registry& _r) : Parent(_g, _r) {}
155 DefaultMap(const Graph& _g, Registry& _r, const ValueType& _v) : Parent(_g, _r, _v) {}
160 template <typename _Base>
161 class DefaultMappableGraphExtender : public _Base {
164 typedef DefaultMappableGraphExtender<_Base> Graph;
165 typedef _Base Parent;
167 typedef typename Parent::Node Node;
168 typedef typename Parent::NodeIt NodeIt;
169 typedef typename Parent::NodeIdMap NodeIdMap;
170 typedef typename Parent::NodeObserverRegistry NodeObserverRegistry;
172 typedef typename Parent::Edge Edge;
173 typedef typename Parent::EdgeIt EdgeIt;
174 typedef typename Parent::EdgeIdMap EdgeIdMap;
175 typedef typename Parent::EdgeObserverRegistry EdgeObserverRegistry;
179 template <typename _Value>
180 class NodeMap : public DefaultMap<Graph, Node, NodeIt, NodeIdMap, _Value> {
182 typedef DefaultMappableGraphExtender<_Base> Graph;
184 typedef typename Graph::Node Node;
185 typedef typename Graph::NodeIt NodeIt;
186 typedef typename Graph::NodeIdMap NodeIdMap;
188 typedef DefaultMap<Graph, Node, NodeIt, NodeIdMap, _Value> Parent;
190 typedef typename Parent::Graph Graph;
191 typedef typename Parent::ValueType ValueType;
193 NodeMap(const Graph& g)
194 : Parent(g, g.getNodeObserverRegistry()) {}
195 NodeMap(const Graph& g, const ValueType& v)
196 : Parent(g, g.getNodeObserverRegistry(), v) {}
200 template <typename _Value>
201 class EdgeMap : public DefaultMap<Graph, Edge, EdgeIt, EdgeIdMap, _Value> {
203 typedef DefaultMappableGraphExtender<_Base> Graph;
205 typedef typename Graph::Edge Edge;
206 typedef typename Graph::EdgeIt EdgeIt;
207 typedef typename Graph::EdgeIdMap EdgeIdMap;
209 typedef DefaultMap<Graph, Edge, EdgeIt, EdgeIdMap, _Value> Parent;
211 typedef typename Parent::Graph Graph;
212 typedef typename Parent::ValueType ValueType;
214 EdgeMap(const Graph& g)
215 : Parent(g, g.getEdgeObserverRegistry()) {}
216 EdgeMap(const Graph& g, const ValueType& v)
217 : Parent(g, g.getEdgeObserverRegistry(), v) {}