COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/hugo/sym_map_factory.h @ 800:b70a494b4912

Last change on this file since 800:b70a494b4912 was 798:6d1abeb62dd3, checked in by Balazs Dezso, 20 years ago
File size: 2.5 KB
Line 
1// -*- c++ -*-
2#ifndef SYM_MAP_FACTORY_H
3#define SYM_MAP_FACTORY_H
4
5namespace hugo {
6
7  template <typename Graph, typename Edge, typename EdgeIt>
8  class SymEdgeIt : public EdgeIt {
9  public:
10
11    SymEdgeIt()
12      : EdgeIt() {}
13
14    SymEdgeIt(const Graph& graph)
15      : EdgeIt(graph) {
16      while ( n != -1 && (n & 1)) {
17        EdgeIt::operator++();
18      }
19    }
20
21    SymEdgeIt(Invalid invalid)
22      : EdgeIt(invalid) {}
23
24    SymEdgeIt(const Graph& graph, Edge edge)
25      : EdgeIt(graph, edge) {}
26
27    SymEdgeIt& operator++() {
28      EdgeIt::operator++();
29      while ( n != -1 && (n & 1)) {
30        EdgeIt::operator++();
31      }
32      return *this;
33    }
34  };
35
36  template <typename MapRegistry, template <typename> class MapFactory>
37  class SymMapFactory {
38
39  public:
40               
41    typedef typename MapRegistry::Graph Graph;
42    typedef typename MapRegistry::KeyType KeyType;
43    typedef typename MapRegistry::KeyIt KeyIt;
44
45    typedef typename MapRegistry::MapBase MapBase;
46
47    template <typename V>
48    class Map : public MapFactory<MapRegistry>::template Map<V> {
49
50      typedef typename MapFactory<MapRegistry>::template Map<V> MapImpl;
51    public:
52
53      typedef V Value;
54
55      Map() : MapImpl() {}
56
57      Map(const Graph& g, MapRegistry& r) : MapImpl(g, r) {}
58
59      Map(const Graph& g, MapRegistry& r, const Value& v)
60        : MapImpl(g, r, v) {}
61
62      Map(const Map& copy) : MapImpl(static_cast<const MapImpl&>(copy)) {}
63
64      template <typename CMap> Map(const CMap& copy) : MapImpl(copy) {}
65
66      Map& operator=(const Map& copy) {
67        MapImpl::operator=(static_cast<const MapImpl&>(copy));
68        return *this;
69      }
70
71      template <typename CMap> Map& operator=(const CMap& copy) {
72        MapImpl::operator=(copy);
73        return *this;
74      }
75   
76      Value& operator[](const KeyType& key) {
77        int id = MapBase::getGraph()->id(key); 
78        return MapImpl::operator[](id >> 1);
79      }
80               
81      const Value& operator[](const KeyType& key) const {
82        int id = MapBase::getGraph()->id(key);
83        return MapImpl::operator[](id >> 1);
84      }
85       
86      const Value& get(const KeyType& key) const {
87        int id = MapBase::getGraph()->id(key);
88        return MapImpl::operator[](id >> 1);
89      }
90               
91      void set(const KeyType& key, const Value& val) {
92        int id = MapBase::getGraph()->id(key);
93        MapImpl::operator[](id >> 1) = val;
94      }
95               
96      void add(const KeyType& key) {
97        int id = MapBase::getGraph()->id(key);
98        if (id & 1) return;
99        MapImpl::add(key);
100      }
101               
102      void erase(const KeyType& key) {
103        int id = MapBase::getGraph()->id(key);
104        if (id & 1) return;
105        MapImpl::add(key);
106      }
107
108
109    }; 
110  };
111}
112#endif
Note: See TracBrowser for help on using the repository browser.