COIN-OR::LEMON - Graph Library

source: lemon-0.x/lemon/bits/map_extender.h @ 1993:2115143eceea

Last change on this file since 1993:2115143eceea was 1993:2115143eceea, checked in by Balazs Dezso, 14 years ago

utility, invalid and traits moved to bits

File size: 2.6 KB
Line 
1/* -*- C++ -*-
2 *
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).
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
24#include <lemon/bits/traits.h>
25
26///\file
27///\brief Extenders for iterable maps.
28
29namespace lemon {
30
31  template <typename _Map>
32  class IterableMapExtender : public _Map {
33  public:
34
35    typedef _Map Parent;
36    typedef IterableMapExtender Map;
37
38
39    typedef typename Parent::Graph Graph;
40    typedef typename Parent::Key Item;
41
42    typedef typename Parent::Key Key;
43    typedef typename Parent::Value Value;
44
45    class MapIt;
46    class ConstMapIt;
47
48    friend class MapIt;
49    friend class ConstMapIt;
50
51  protected:
52
53    using Parent::getGraph;
54
55  public:
56
57    IterableMapExtender(const Graph& graph) : Parent(graph) {}
58
59    IterableMapExtender(const Graph& graph, const Value& value)
60      : Parent(graph, value) {}
61
62
63    class MapIt : public ItemSetTraits<Graph, Item>::ItemIt {
64    public:
65     
66      typedef typename ItemSetTraits<Graph, Item>::ItemIt Parent;
67
68      typedef typename Map::Value Value;
69     
70      MapIt(Map& _map) : Parent(*_map.getGraph()), map(_map) {}
71     
72      typename MapTraits<Map>::ConstReturnValue operator*() const {
73        return map[*this];
74      }
75
76      typename MapTraits<Map>::ReturnValue operator*() {
77        return map[*this];
78      }
79     
80      void set(const Value& value) {
81        map.set(*this, value);
82      }
83     
84    protected:
85      Map& map;
86     
87    };
88
89    class ConstMapIt : public ItemSetTraits<Graph, Key>::ItemIt {
90    public:
91
92      typedef typename ItemSetTraits<Graph, Key>::ItemIt Parent;
93
94      typedef typename Map::Value Value;
95
96      ConstMapIt(const Map& _map) : Parent(*_map.getGraph()), map(_map) {}
97
98      typename MapTraits<Map>::ConstReturnValue operator*() const {
99        return map[*this];
100      }
101    protected:
102      const Map& map;
103    };
104
105    class ItemIt : public ItemSetTraits<Graph, Key>::ItemIt {
106    public:
107     
108      typedef typename ItemSetTraits<Graph, Key>::ItemIt Parent;
109
110      ItemIt(Map& _map) : Parent(*_map.getGraph()) {}
111     
112    };
113  };
114
115}
116
117#endif
Note: See TracBrowser for help on using the repository browser.