deba@595
|
1 |
#ifndef PAC_MAP_FACTORY_H
|
deba@595
|
2 |
#define PAC_MAP_FACTORY_H
|
deba@595
|
3 |
|
deba@595
|
4 |
#include "map_base.h"
|
deba@595
|
5 |
|
deba@595
|
6 |
/**
|
deba@595
|
7 |
Converter class to use the standard template
|
deba@595
|
8 |
libary's pair associative containers as a graph map.
|
deba@595
|
9 |
*/
|
deba@595
|
10 |
|
deba@595
|
11 |
namespace hugo {
|
deba@595
|
12 |
|
deba@595
|
13 |
template <typename G, typename K, typename KIt, template <typename, typename> class PAC>
|
deba@595
|
14 |
class PacMapFactory {
|
deba@595
|
15 |
|
deba@595
|
16 |
|
deba@595
|
17 |
public:
|
deba@595
|
18 |
|
deba@595
|
19 |
typedef G Graph;
|
deba@595
|
20 |
typedef K Key;
|
deba@595
|
21 |
typedef KIt KeyIt;
|
deba@595
|
22 |
|
deba@595
|
23 |
template <typename V>
|
deba@595
|
24 |
class Map : public MapBase<G, K, KIt> {
|
deba@595
|
25 |
public:
|
deba@595
|
26 |
typedef V Value;
|
deba@595
|
27 |
|
deba@595
|
28 |
Map() {}
|
deba@595
|
29 |
|
deba@595
|
30 |
Map(Graph& g, MapRegistry<G, K, KIt>& r)
|
deba@595
|
31 |
: MapBase<G, K, KIt>(g, r) {
|
deba@595
|
32 |
init();
|
deba@595
|
33 |
}
|
deba@595
|
34 |
|
deba@595
|
35 |
virtual ~Map() {
|
deba@595
|
36 |
destroy();
|
deba@595
|
37 |
}
|
deba@595
|
38 |
|
deba@595
|
39 |
|
deba@595
|
40 |
V& operator[](const K& key) {
|
deba@595
|
41 |
return container.find(key)->second;
|
deba@595
|
42 |
}
|
deba@595
|
43 |
|
deba@595
|
44 |
const V& operator[](const K& key) const {
|
deba@595
|
45 |
return container.find(key)->second;
|
deba@595
|
46 |
}
|
deba@595
|
47 |
|
deba@595
|
48 |
const V& get(const K& key) const {
|
deba@595
|
49 |
return container.find(key)->second;
|
deba@595
|
50 |
}
|
deba@595
|
51 |
|
deba@595
|
52 |
void set(const K& key, const V& value) {
|
deba@595
|
53 |
container.find(key)->second = value;
|
deba@595
|
54 |
}
|
deba@595
|
55 |
|
deba@595
|
56 |
void add(const K& key) {
|
deba@595
|
57 |
container.insert(key);
|
deba@595
|
58 |
}
|
deba@595
|
59 |
|
deba@595
|
60 |
void erase(const K& key) {
|
deba@595
|
61 |
container.erase(key);
|
deba@595
|
62 |
}
|
deba@595
|
63 |
|
deba@595
|
64 |
private:
|
deba@595
|
65 |
typedef PAC<K, V> Container;
|
deba@595
|
66 |
|
deba@595
|
67 |
Container container;
|
deba@595
|
68 |
};
|
deba@595
|
69 |
|
deba@595
|
70 |
};
|
deba@595
|
71 |
}
|
deba@595
|
72 |
|
deba@595
|
73 |
#endif |