src/work/deba/vector_map_factory.h
changeset 571 9632ea8be6ca
child 595 e10b5e9419ef
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/work/deba/vector_map_factory.h	Fri May 07 08:18:30 2004 +0000
     1.3 @@ -0,0 +1,71 @@
     1.4 +#ifndef VECTOR_MAP_H
     1.5 +#define VECTOR_MAP_H
     1.6 +
     1.7 +#include <vector>
     1.8 +#include <iostream>
     1.9 +
    1.10 +#include "map_base.h"
    1.11 +
    1.12 +namespace hugo {
    1.13 +	
    1.14 +	template <typename G, typename K, typename KIt>
    1.15 +	class VectorMapFactory {
    1.16 +	
    1.17 +	
    1.18 +	public:
    1.19 +		
    1.20 +		typedef G Graph;
    1.21 +		typedef K Key;
    1.22 +		typedef KIt KeyIt;
    1.23 +		
    1.24 +		template <typename V> 
    1.25 +		class VectorMap : public MapBase<G, K, KIt> {
    1.26 +		public:
    1.27 +			typedef V ValueType;
    1.28 +	
    1.29 +			VectorMap() {}
    1.30 +			
    1.31 +			VectorMap(Graph& g, MapRegistry<G, K, KIt>& r) 
    1.32 +				: MapBase<G, K, KIt>(g, r) {}
    1.33 +	
    1.34 +	
    1.35 +			ValueType& operator[](const K& key) {
    1.36 +				int id = graph->id(key);
    1.37 +				return container[id];
    1.38 +			} 
    1.39 +		
    1.40 +			const ValueType& operator[](const K& key) const {
    1.41 +				int id = graph->id(key);
    1.42 +				return container[id];
    1.43 +			}
    1.44 +	
    1.45 +			const ValueType& get(const K& key) const {
    1.46 +				int id = graph->id(key);
    1.47 +				return container[id];
    1.48 +			} 
    1.49 +		
    1.50 +			void set(const K& key, const ValueType& val) {
    1.51 +				int id = graph->id(key);
    1.52 +				container[id] = val;
    1.53 +			}
    1.54 +		
    1.55 +			void add(const K& key) {
    1.56 +				int id = graph->id(key);
    1.57 +				std::cerr << id << std::endl;
    1.58 +				if (id >= container.size()) {
    1.59 +					container.resize(id + 1);
    1.60 +				}
    1.61 +			}
    1.62 +		
    1.63 +			void erase(const K& key) {}
    1.64 +	
    1.65 +		private:
    1.66 +			typedef std::vector<ValueType> Container;
    1.67 +		
    1.68 +			Container container;
    1.69 +		};
    1.70 +		
    1.71 +	};
    1.72 +}
    1.73 +
    1.74 +#endif