src/work/deba/vector_map_factory.h
author jacint
Fri, 07 May 2004 10:34:36 +0000
changeset 575 bdf7fb750e0e
child 595 e10b5e9419ef
permissions -rw-r--r--
Docs added
     1 #ifndef VECTOR_MAP_H
     2 #define VECTOR_MAP_H
     3 
     4 #include <vector>
     5 #include <iostream>
     6 
     7 #include "map_base.h"
     8 
     9 namespace hugo {
    10 	
    11 	template <typename G, typename K, typename KIt>
    12 	class VectorMapFactory {
    13 	
    14 	
    15 	public:
    16 		
    17 		typedef G Graph;
    18 		typedef K Key;
    19 		typedef KIt KeyIt;
    20 		
    21 		template <typename V> 
    22 		class VectorMap : public MapBase<G, K, KIt> {
    23 		public:
    24 			typedef V ValueType;
    25 	
    26 			VectorMap() {}
    27 			
    28 			VectorMap(Graph& g, MapRegistry<G, K, KIt>& r) 
    29 				: MapBase<G, K, KIt>(g, r) {}
    30 	
    31 	
    32 			ValueType& operator[](const K& key) {
    33 				int id = graph->id(key);
    34 				return container[id];
    35 			} 
    36 		
    37 			const ValueType& operator[](const K& key) const {
    38 				int id = graph->id(key);
    39 				return container[id];
    40 			}
    41 	
    42 			const ValueType& get(const K& key) const {
    43 				int id = graph->id(key);
    44 				return container[id];
    45 			} 
    46 		
    47 			void set(const K& key, const ValueType& val) {
    48 				int id = graph->id(key);
    49 				container[id] = val;
    50 			}
    51 		
    52 			void add(const K& key) {
    53 				int id = graph->id(key);
    54 				std::cerr << id << std::endl;
    55 				if (id >= container.size()) {
    56 					container.resize(id + 1);
    57 				}
    58 			}
    59 		
    60 			void erase(const K& key) {}
    61 	
    62 		private:
    63 			typedef std::vector<ValueType> Container;
    64 		
    65 			Container container;
    66 		};
    67 		
    68 	};
    69 }
    70 
    71 #endif