Rev | Line | |
---|
[571] | 1 | #ifndef VECTOR_MAP_H |
---|
| 2 | #define VECTOR_MAP_H |
---|
| 3 | |
---|
| 4 | #include <vector> |
---|
| 5 | |
---|
[627] | 6 | #include "map_registry.h" |
---|
[571] | 7 | |
---|
| 8 | namespace hugo { |
---|
| 9 | |
---|
[627] | 10 | template <typename MapRegistry> |
---|
| 11 | class VectorMapFactory { |
---|
| 12 | public: |
---|
| 13 | |
---|
| 14 | typedef typename MapRegistry::Graph Graph; |
---|
| 15 | typedef typename MapRegistry::Key Key; |
---|
| 16 | typedef typename MapRegistry::KeyIt KeyIt; |
---|
| 17 | |
---|
| 18 | typedef typename MapRegistry::MapBase MapBase; |
---|
| 19 | |
---|
| 20 | template <typename V> |
---|
| 21 | class Map : public MapBase { |
---|
| 22 | public: |
---|
| 23 | typedef V Value; |
---|
[571] | 24 | |
---|
[627] | 25 | Map() {} |
---|
| 26 | |
---|
| 27 | Map(Graph& g, MapRegistry& r) : MapBase(g, r) { |
---|
| 28 | init(); |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | |
---|
| 32 | virtual ~Map() { |
---|
| 33 | destroy(); |
---|
| 34 | } |
---|
[571] | 35 | |
---|
[627] | 36 | |
---|
| 37 | Value& operator[](const Key& key) { |
---|
| 38 | int id = graph->id(key); |
---|
| 39 | return container[id]; |
---|
| 40 | } |
---|
[571] | 41 | |
---|
[627] | 42 | const Value& operator[](const Key& key) const { |
---|
| 43 | int id = graph->id(key); |
---|
| 44 | return container[id]; |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | const Value& get(const Key& key) const { |
---|
| 48 | int id = graph->id(key); |
---|
| 49 | return container[id]; |
---|
| 50 | } |
---|
[571] | 51 | |
---|
[627] | 52 | void set(const Key& key, const Value& val) { |
---|
| 53 | int id = graph->id(key); |
---|
| 54 | container[id] = val; |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | void add(const Key& key) { |
---|
| 58 | int id = graph->id(key); |
---|
| 59 | if (id >= container.size()) { |
---|
| 60 | container.resize(id + 1); |
---|
| 61 | } |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | void erase(const Key& key) {} |
---|
[571] | 65 | |
---|
[627] | 66 | private: |
---|
| 67 | typedef std::vector<Value> Container; |
---|
[571] | 68 | |
---|
[627] | 69 | Container container; |
---|
| 70 | }; |
---|
[571] | 71 | |
---|
[627] | 72 | }; |
---|
[571] | 73 | } |
---|
| 74 | |
---|
| 75 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.