src/work/deba/pac_map_factory.h
changeset 678 a6bfd3346245
child 921 818510fa3d99
equal deleted inserted replaced
-1:000000000000 0:94bc99acdd01
       
     1 #ifndef PAC_MAP_FACTORY_H
       
     2 #define PAC_MAP_FACTORY_H
       
     3 
       
     4 #include "map_base.h"
       
     5 
       
     6 /**
       
     7 	Converter class to use the standard template
       
     8 	libary's pair associative containers as a graph map.
       
     9 */
       
    10 
       
    11 namespace hugo {
       
    12 	
       
    13 	template <typename G, typename K, typename KIt, template <typename, typename> class PAC>
       
    14 	class PacMapFactory {
       
    15 	
       
    16 	
       
    17 	public:
       
    18 		
       
    19 		typedef G Graph;
       
    20 		typedef K Key;
       
    21 		typedef KIt KeyIt;
       
    22 		
       
    23 		template <typename V> 
       
    24 		class Map : public MapBase<G, K, KIt> {
       
    25 		public:
       
    26 			typedef V Value;
       
    27 	
       
    28 			Map() {}
       
    29 			
       
    30 			Map(Graph& g, MapRegistry<G, K, KIt>& r) 
       
    31 				: MapBase<G, K, KIt>(g, r) {
       
    32 				init();
       
    33 			}
       
    34 				
       
    35 			virtual ~Map() {
       
    36 				destroy();
       
    37 			}
       
    38 	
       
    39 	
       
    40 			V& operator[](const K& key) {
       
    41 				return container.find(key)->second;
       
    42 			} 
       
    43 		
       
    44 			const V& operator[](const K& key) const {
       
    45 				return container.find(key)->second;
       
    46 			}
       
    47 	
       
    48 			const V& get(const K& key) const {
       
    49 				return container.find(key)->second;
       
    50 			} 
       
    51 		
       
    52 			void set(const K& key, const V& value) {
       
    53 				container.find(key)->second = value;
       
    54 			}
       
    55 		
       
    56 			void add(const K& key) {
       
    57 				container.insert(key);
       
    58 			}
       
    59 		
       
    60 			void erase(const K& key) {
       
    61 				container.erase(key);
       
    62 			}
       
    63 	
       
    64 		private:
       
    65 			typedef PAC<K, V> Container;
       
    66 		
       
    67 			Container container;
       
    68 		};
       
    69 		
       
    70 	};
       
    71 }
       
    72 
       
    73 #endif