src/work/deba/vector_map.h
author athos
Mon, 03 May 2004 14:43:49 +0000
changeset 514 fd991a24c857
parent 377 33fe0ee01dc5
permissions -rw-r--r--
An awful mistake found and corrected.
deba@340
     1
#ifndef VECTOR_MAP_H
deba@340
     2
#define VECTOR_MAP_H
deba@340
     3
deba@340
     4
#include <vector>
deba@378
     5
#include <iostream>
deba@340
     6
deba@378
     7
#include "map_base.h"
deba@378
     8
deba@378
     9
namespace hugo {
deba@378
    10
deba@378
    11
	template <typename G, typename K, typename KIt, typename V> 
deba@378
    12
	class VectorMap : public MapBase<G, K, KIt> {
deba@378
    13
	public:
deba@378
    14
		typedef V ValueType;
deba@340
    15
	
deba@378
    16
		VectorMap() {}
deba@378
    17
		VectorMap(typename MapBase<G, K, KIt>::Registry& r) : MapBase<G, K, KIt>(r) {}
deba@340
    18
	
deba@340
    19
	
deba@378
    20
		ValueType& operator[](const K& key) {
deba@378
    21
			int id = registry->getGraph().id(key);
deba@378
    22
			return container[id];
deba@378
    23
		} 
deba@340
    24
	
deba@378
    25
		const ValueType& operator[](const K& key) const {
deba@378
    26
			int id = registry->getGraph().id(key);
deba@378
    27
			return container[id];
deba@378
    28
		}
deba@340
    29
	
deba@378
    30
		const ValueType& get(const K& key) const {
deba@378
    31
			int id = registry->getGraph().id(key);
deba@378
    32
			return container[id];
deba@378
    33
		} 
deba@340
    34
	
deba@378
    35
		void set(const K& key, const ValueType& val) {
deba@378
    36
			int id = registry->getGraph().id(key);
deba@378
    37
			container[id] = val;
deba@378
    38
		}
deba@340
    39
	
deba@378
    40
		void add(const K& key) {
deba@378
    41
			int id = registry->getGraph().id(key);
deba@378
    42
			std::cerr << id << std::endl;
deba@378
    43
			if (id >= container.size()) {
deba@378
    44
				container.resize(id + 1);
deba@378
    45
			}
deba@377
    46
		}
deba@340
    47
	
deba@378
    48
		void erase(const K& key) {}
deba@340
    49
deba@378
    50
	private:
deba@378
    51
		typedef std::vector<ValueType> Container;
deba@340
    52
	
deba@378
    53
		Container container;
deba@378
    54
	};
deba@378
    55
deba@378
    56
}
deba@340
    57
deba@340
    58
#endif