Fix compilation with Visual Studio 2005.
1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
3 * This file is a part of LEMON, a generic C++ optimization library.
5 * Copyright (C) 2003-2008
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
19 #ifndef LEMON_BITS_MAP_EXTENDER_H
20 #define LEMON_BITS_MAP_EXTENDER_H
24 #include <lemon/bits/traits.h>
26 #include <lemon/concept_check.h>
27 #include <lemon/concepts/maps.h>
30 ///\brief Extenders for iterable maps.
34 /// \ingroup graphbits
36 /// \brief Extender for maps
37 template <typename _Map>
38 class MapExtender : public _Map {
42 typedef MapExtender Map;
45 typedef typename Parent::Graph Graph;
46 typedef typename Parent::Key Item;
48 typedef typename Parent::Key Key;
49 typedef typename Parent::Value Value;
55 friend class ConstMapIt;
59 MapExtender(const Graph& graph)
62 MapExtender(const Graph& graph, const Value& value)
63 : Parent(graph, value) {}
66 MapExtender& operator=(const MapExtender& cmap) {
67 return operator=<MapExtender>(cmap);
70 template <typename CMap>
71 MapExtender& operator=(const CMap& cmap) {
72 Parent::operator=(cmap);
77 class MapIt : public Item {
81 typedef typename Map::Value Value;
85 MapIt(Invalid i) : Parent(i) { }
87 explicit MapIt(Map& _map) : map(_map) {
88 map.notifier()->first(*this);
91 MapIt(const Map& _map, const Item& item)
92 : Parent(item), map(_map) {}
95 map.notifier()->next(*this);
99 typename MapTraits<Map>::ConstReturnValue operator*() const {
103 typename MapTraits<Map>::ReturnValue operator*() {
107 void set(const Value& value) {
108 map.set(*this, value);
116 class ConstMapIt : public Item {
121 typedef typename Map::Value Value;
125 ConstMapIt(Invalid i) : Parent(i) { }
127 explicit ConstMapIt(Map& _map) : map(_map) {
128 map.notifier()->first(*this);
131 ConstMapIt(const Map& _map, const Item& item)
132 : Parent(item), map(_map) {}
134 ConstMapIt& operator++() {
135 map.notifier()->next(*this);
139 typename MapTraits<Map>::ConstReturnValue operator*() const {
147 class ItemIt : public Item {
154 ItemIt(Invalid i) : Parent(i) { }
156 explicit ItemIt(Map& _map) : map(_map) {
157 map.notifier()->first(*this);
160 ItemIt(const Map& _map, const Item& item)
161 : Parent(item), map(_map) {}
163 ItemIt& operator++() {
164 map.notifier()->next(*this);
174 /// \ingroup graphbits
176 /// \brief Extender for maps which use a subset of the items.
177 template <typename _Graph, typename _Map>
178 class SubMapExtender : public _Map {
182 typedef SubMapExtender Map;
184 typedef _Graph Graph;
186 typedef typename Parent::Key Item;
188 typedef typename Parent::Key Key;
189 typedef typename Parent::Value Value;
195 friend class ConstMapIt;
199 SubMapExtender(const Graph& _graph)
200 : Parent(_graph), graph(_graph) {}
202 SubMapExtender(const Graph& _graph, const Value& _value)
203 : Parent(_graph, _value), graph(_graph) {}
206 SubMapExtender& operator=(const SubMapExtender& cmap) {
207 return operator=<MapExtender>(cmap);
210 template <typename CMap>
211 SubMapExtender& operator=(const CMap& cmap) {
212 checkConcept<concepts::ReadMap<Key, Value>, CMap>();
214 for (graph.first(it); it != INVALID; graph.next(it)) {
215 Parent::set(it, cmap[it]);
221 class MapIt : public Item {
225 typedef typename Map::Value Value;
229 MapIt(Invalid i) : Parent(i) { }
231 explicit MapIt(Map& _map) : map(_map) {
232 map.graph.first(*this);
235 MapIt(const Map& _map, const Item& item)
236 : Parent(item), map(_map) {}
238 MapIt& operator++() {
239 map.graph.next(*this);
243 typename MapTraits<Map>::ConstReturnValue operator*() const {
247 typename MapTraits<Map>::ReturnValue operator*() {
251 void set(const Value& value) {
252 map.set(*this, value);
260 class ConstMapIt : public Item {
265 typedef typename Map::Value Value;
269 ConstMapIt(Invalid i) : Parent(i) { }
271 explicit ConstMapIt(Map& _map) : map(_map) {
272 map.graph.first(*this);
275 ConstMapIt(const Map& _map, const Item& item)
276 : Parent(item), map(_map) {}
278 ConstMapIt& operator++() {
279 map.graph.next(*this);
283 typename MapTraits<Map>::ConstReturnValue operator*() const {
291 class ItemIt : public Item {
298 ItemIt(Invalid i) : Parent(i) { }
300 explicit ItemIt(Map& _map) : map(_map) {
301 map.graph.first(*this);
304 ItemIt(const Map& _map, const Item& item)
305 : Parent(item), map(_map) {}
307 ItemIt& operator++() {
308 map.graph.next(*this);