COIN-OR::LEMON - Graph Library

source: lemon-0.x/lemon/bits/map_extender.h @ 2006:00d59f733817

Last change on this file since 2006:00d59f733817 was 1999:2ff283124dfc, checked in by Balazs Dezso, 18 years ago

Clarifing alteration observing system
It is directly connected now to a container

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