author | alpar |
Sat, 17 Apr 2004 13:15:53 +0000 | |
changeset 348 | b63ea19e502e |
child 377 | 33fe0ee01dc5 |
permissions | -rw-r--r-- |
deba@340 | 1 |
#ifndef VECTOR_MAP_H |
deba@340 | 2 |
#define VECTOR_MAP_H |
deba@340 | 3 |
|
deba@340 | 4 |
#include <vector> |
deba@340 | 5 |
|
deba@340 | 6 |
template <typename G, typename K, typename V, template <typename, typename> class MapBase > |
deba@340 | 7 |
class VectorMap : public MapBase<G, K> { |
deba@340 | 8 |
public: |
deba@340 | 9 |
typedef V ValueType; |
deba@340 | 10 |
|
deba@340 | 11 |
VectorMap() {} |
deba@340 | 12 |
VectorMap(G& g) : MapBase<G, K>(g) { |
deba@340 | 13 |
init(); |
deba@340 | 14 |
} |
deba@340 | 15 |
|
deba@340 | 16 |
~VectorMap() { |
deba@340 | 17 |
// destroy(); |
deba@340 | 18 |
} |
deba@340 | 19 |
|
deba@340 | 20 |
ValueType& operator[](const K& key) { |
deba@340 | 21 |
return container[key->id]; |
deba@340 | 22 |
} |
deba@340 | 23 |
|
deba@340 | 24 |
const ValueType& operator[](const K& key) const { |
deba@340 | 25 |
return container[key->id]; |
deba@340 | 26 |
} |
deba@340 | 27 |
|
deba@340 | 28 |
const ValueType& get(const K& key) const { |
deba@340 | 29 |
return container[key->id]; |
deba@340 | 30 |
} |
deba@340 | 31 |
|
deba@340 | 32 |
void set(const K& key, const ValueType& val) { |
deba@340 | 33 |
container[key->id] = val; |
deba@340 | 34 |
} |
deba@340 | 35 |
|
deba@340 | 36 |
void add(const K& key) { |
deba@340 | 37 |
container.resize(key->id); |
deba@340 | 38 |
} |
deba@340 | 39 |
|
deba@340 | 40 |
void erase(const K& key) {} |
deba@340 | 41 |
|
deba@340 | 42 |
private: |
deba@340 | 43 |
typedef std::vector<ValueType> Container; |
deba@340 | 44 |
|
deba@340 | 45 |
Container container; |
deba@340 | 46 |
} |
deba@340 | 47 |
|
deba@340 | 48 |
#endif |