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