deba@1810
|
1 |
/* -*- C++ -*-
|
deba@1810
|
2 |
*
|
alpar@1956
|
3 |
* This file is a part of LEMON, a generic C++ optimization library
|
alpar@1956
|
4 |
*
|
alpar@1956
|
5 |
* Copyright (C) 2003-2006
|
alpar@1956
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
alpar@1956
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
deba@1810
|
8 |
*
|
deba@1810
|
9 |
* Permission to use, modify and distribute this software is granted
|
deba@1810
|
10 |
* provided that this copyright notice appears in all copies. For
|
deba@1810
|
11 |
* precise terms see the accompanying LICENSE file.
|
deba@1810
|
12 |
*
|
deba@1810
|
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
deba@1810
|
14 |
* express or implied, and with no claim as to its suitability for any
|
deba@1810
|
15 |
* purpose.
|
deba@1810
|
16 |
*
|
deba@1810
|
17 |
*/
|
deba@1810
|
18 |
|
deba@1810
|
19 |
#ifndef LEMON_BITS_MAP_EXTENDER_H
|
deba@1810
|
20 |
#define LEMON_BITS_MAP_EXTENDER_H
|
deba@1810
|
21 |
|
deba@1810
|
22 |
#include <iterator>
|
deba@1810
|
23 |
|
deba@1993
|
24 |
#include <lemon/bits/traits.h>
|
deba@1810
|
25 |
|
deba@1810
|
26 |
///\file
|
deba@1810
|
27 |
///\brief Extenders for iterable maps.
|
deba@1810
|
28 |
|
deba@1810
|
29 |
namespace lemon {
|
deba@1810
|
30 |
|
deba@1996
|
31 |
/// \ingroup graphbits
|
deba@1999
|
32 |
///
|
deba@1999
|
33 |
/// \brief Extender for maps
|
deba@1810
|
34 |
template <typename _Map>
|
deba@1999
|
35 |
class MapExtender : public _Map {
|
deba@1810
|
36 |
public:
|
deba@1810
|
37 |
|
deba@1810
|
38 |
typedef _Map Parent;
|
deba@1999
|
39 |
typedef MapExtender Map;
|
deba@1810
|
40 |
|
deba@1810
|
41 |
|
alpar@1854
|
42 |
typedef typename Parent::Graph Graph;
|
alpar@1854
|
43 |
typedef typename Parent::Key Item;
|
deba@1810
|
44 |
|
alpar@1854
|
45 |
typedef typename Parent::Key Key;
|
alpar@1854
|
46 |
typedef typename Parent::Value Value;
|
deba@1810
|
47 |
|
deba@1810
|
48 |
class MapIt;
|
deba@1810
|
49 |
class ConstMapIt;
|
deba@1810
|
50 |
|
deba@1810
|
51 |
friend class MapIt;
|
deba@1810
|
52 |
friend class ConstMapIt;
|
deba@1810
|
53 |
|
deba@1810
|
54 |
public:
|
deba@1810
|
55 |
|
deba@1999
|
56 |
MapExtender(const Graph& graph)
|
deba@1999
|
57 |
: Parent(graph) {}
|
deba@1810
|
58 |
|
deba@1999
|
59 |
MapExtender(const Graph& graph, const Value& value)
|
deba@1810
|
60 |
: Parent(graph, value) {}
|
deba@1810
|
61 |
|
deba@1810
|
62 |
|
deba@1999
|
63 |
class MapIt : public Item {
|
deba@1810
|
64 |
public:
|
deba@1810
|
65 |
|
deba@1999
|
66 |
typedef Item Parent;
|
deba@1810
|
67 |
typedef typename Map::Value Value;
|
deba@1810
|
68 |
|
deba@1999
|
69 |
MapIt() {}
|
deba@1999
|
70 |
|
deba@1999
|
71 |
MapIt(Invalid i) : Parent(i) { }
|
deba@1999
|
72 |
|
deba@1999
|
73 |
explicit MapIt(Map& _map) : map(_map) {
|
deba@1999
|
74 |
map.getNotifier()->first(*this);
|
deba@1999
|
75 |
}
|
deba@1999
|
76 |
|
deba@1999
|
77 |
MapIt(const Map& _map, const Item& item)
|
deba@1999
|
78 |
: Parent(item), map(_map) {}
|
deba@1999
|
79 |
|
deba@1999
|
80 |
MapIt& operator++() {
|
deba@1999
|
81 |
map.getNotifier()->next(*this);
|
deba@1999
|
82 |
return *this;
|
deba@1999
|
83 |
}
|
deba@1810
|
84 |
|
deba@1810
|
85 |
typename MapTraits<Map>::ConstReturnValue operator*() const {
|
deba@1810
|
86 |
return map[*this];
|
deba@1810
|
87 |
}
|
deba@1810
|
88 |
|
deba@1810
|
89 |
typename MapTraits<Map>::ReturnValue operator*() {
|
deba@1810
|
90 |
return map[*this];
|
deba@1810
|
91 |
}
|
deba@1810
|
92 |
|
deba@1810
|
93 |
void set(const Value& value) {
|
deba@1810
|
94 |
map.set(*this, value);
|
deba@1810
|
95 |
}
|
deba@1810
|
96 |
|
deba@1810
|
97 |
protected:
|
deba@1810
|
98 |
Map& map;
|
deba@1810
|
99 |
|
deba@1810
|
100 |
};
|
deba@1810
|
101 |
|
deba@1999
|
102 |
class ConstMapIt : public Item {
|
deba@1810
|
103 |
public:
|
deba@1810
|
104 |
|
deba@1999
|
105 |
typedef Item Parent;
|
deba@1810
|
106 |
|
deba@1810
|
107 |
typedef typename Map::Value Value;
|
deba@1999
|
108 |
|
deba@1999
|
109 |
ConstMapIt() {}
|
deba@1810
|
110 |
|
deba@1999
|
111 |
ConstMapIt(Invalid i) : Parent(i) { }
|
deba@1999
|
112 |
|
deba@1999
|
113 |
explicit ConstMapIt(Map& _map) : map(_map) {
|
deba@1999
|
114 |
map.getNotifier()->first(*this);
|
deba@1999
|
115 |
}
|
deba@1999
|
116 |
|
deba@1999
|
117 |
ConstMapIt(const Map& _map, const Item& item)
|
deba@1999
|
118 |
: Parent(item), map(_map) {}
|
deba@1999
|
119 |
|
deba@1999
|
120 |
ConstMapIt& operator++() {
|
deba@1999
|
121 |
map.getNotifier()->next(*this);
|
deba@1999
|
122 |
return *this;
|
deba@1999
|
123 |
}
|
deba@1810
|
124 |
|
deba@1810
|
125 |
typename MapTraits<Map>::ConstReturnValue operator*() const {
|
deba@1810
|
126 |
return map[*this];
|
deba@1810
|
127 |
}
|
deba@1999
|
128 |
|
deba@1810
|
129 |
protected:
|
deba@1810
|
130 |
const Map& map;
|
deba@1810
|
131 |
};
|
deba@1810
|
132 |
|
deba@1999
|
133 |
class ItemIt : Item {
|
deba@1810
|
134 |
public:
|
deba@1810
|
135 |
|
deba@1999
|
136 |
typedef Item Parent;
|
deba@1999
|
137 |
|
deba@1999
|
138 |
ItemIt() {}
|
deba@1810
|
139 |
|
deba@1999
|
140 |
ItemIt(Invalid i) : Parent(i) { }
|
deba@1999
|
141 |
|
deba@1999
|
142 |
explicit ItemIt(Map& _map) : map(_map) {
|
deba@1999
|
143 |
map->getNotifier()->first(*this);
|
deba@1999
|
144 |
}
|
deba@1999
|
145 |
|
deba@1999
|
146 |
ItemIt(const Map& _map, const Item& item)
|
deba@1999
|
147 |
: Parent(item), map(_map) {}
|
deba@1999
|
148 |
|
deba@1999
|
149 |
ItemIt& operator++() {
|
deba@1999
|
150 |
map.getNotifier()->next(*this);
|
deba@1999
|
151 |
return *this;
|
deba@1999
|
152 |
}
|
deba@1999
|
153 |
|
deba@1999
|
154 |
protected:
|
deba@1999
|
155 |
const Map& map;
|
deba@1810
|
156 |
|
deba@1810
|
157 |
};
|
deba@1810
|
158 |
};
|
deba@1810
|
159 |
|
deba@1810
|
160 |
}
|
deba@1810
|
161 |
|
deba@1810
|
162 |
#endif
|