|
1 // -*- c++ -*- |
|
2 #ifndef SYM_MAP_FACTORY_H |
|
3 #define SYM_MAP_FACTORY_H |
|
4 |
|
5 namespace 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 |
|
17 SymEdgeIt(Invalid invalid) |
|
18 : EdgeIt(invalid) {} |
|
19 |
|
20 SymEdgeIt(const Graph& graph, Edge edge) |
|
21 : EdgeIt(graph, edge) {} |
|
22 |
|
23 SymEdgeIt& operator++() { |
|
24 EdgeIt::operator++(); |
|
25 while ( n != -1 && (n & 1)) { |
|
26 EdgeIt::operator++(); |
|
27 } |
|
28 return *this; |
|
29 } |
|
30 }; |
|
31 |
|
32 template <typename MapRegistry, template <typename> class MapFactory> |
|
33 class SymMapFactory { |
|
34 |
|
35 public: |
|
36 |
|
37 typedef typename MapRegistry::Graph Graph; |
|
38 typedef typename MapRegistry::Key Key; |
|
39 typedef typename MapRegistry::KeyIt KeyIt; |
|
40 |
|
41 typedef typename MapRegistry::MapBase MapBase; |
|
42 |
|
43 template <typename V> |
|
44 class Map : public MapFactory<MapRegistry>::template Map<V> { |
|
45 |
|
46 typedef typename MapFactory<MapRegistry>::template Map<V> MapImpl; |
|
47 public: |
|
48 |
|
49 typedef V Value; |
|
50 |
|
51 Map() : MapImpl() {} |
|
52 |
|
53 Map(const Graph& g, MapRegistry& r) : MapImpl(g, r) {} |
|
54 |
|
55 Map(const Graph& g, MapRegistry& r, const Value& v) : MapImpl(g, r, v) {} |
|
56 |
|
57 Map(const Map& copy) : MapImpl(static_cast<const MapImpl&>(copy)) {} |
|
58 |
|
59 template <typename CMap> Map(const CMap& copy) : MapImpl(copy) {} |
|
60 |
|
61 Map& operator=(const Map& copy) { |
|
62 MapImpl::operator=(static_cast<const MapImpl&>(copy)); |
|
63 return *this; |
|
64 } |
|
65 |
|
66 template <typename CMap> Map& operator=(const CMap& copy) { |
|
67 MapImpl::operator=(copy); |
|
68 return *this; |
|
69 } |
|
70 |
|
71 Value& operator[](const Key& key) { |
|
72 int id = MapBase::getGraph()->id(key); |
|
73 return MapImpl::operator[](id >> 1); |
|
74 } |
|
75 |
|
76 const Value& operator[](const Key& key) const { |
|
77 int id = MapBase::getGraph()->id(key); |
|
78 return MapImpl::operator[](id >> 1); |
|
79 } |
|
80 |
|
81 const Value& get(const Key& key) const { |
|
82 int id = MapBase::getGraph()->id(key); |
|
83 return MapImpl::operator[](id >> 1); |
|
84 } |
|
85 |
|
86 void set(const Key& key, const Value& val) { |
|
87 int id = MapBase::getGraph()->id(key); |
|
88 MapImpl::operator[](id >> 1) = val; |
|
89 } |
|
90 |
|
91 void add(const Key& key) { |
|
92 int id = MapBase::getGraph()->id(key); |
|
93 if (id & 1) return; |
|
94 MapImpl::add(key); |
|
95 } |
|
96 |
|
97 void erase(const Key& key) { |
|
98 int id = MapBase::getGraph()->id(key); |
|
99 if (id & 1) return; |
|
100 MapImpl::add(key); |
|
101 } |
|
102 |
|
103 |
|
104 }; |
|
105 }; |
|
106 } |
|
107 #endif |