src/work/deba/map_registry.h
author alpar
Mon, 26 Apr 2004 17:39:38 +0000
changeset 428 3544872b38c2
child 571 9632ea8be6ca
permissions -rw-r--r--
time_measure.h went to src/include.
     1 #ifndef MAP_REGISTRY_H
     2 #define MAP_REGISTRY_H
     3 
     4 #include <vector>
     5 
     6 
     7 namespace hugo {
     8 	template <typename G, typename K, typename KIt>
     9 	class MapRegistry;
    10 }
    11 
    12 #include "map_base.h"
    13 
    14 namespace hugo {
    15 
    16 	template <typename G, typename K, typename KIt>
    17 	class MapRegistry {
    18 	public:
    19 		typedef G Graph;
    20 		typedef K Key;
    21 		typedef KIt KeyIt;
    22 	
    23 		typedef MapBase<Graph, Key, KIt> Map;
    24 		friend class Base;
    25 	
    26 	protected:
    27 	
    28 		typedef std::vector<Map*> Container; 
    29 	  Container container;
    30 
    31 		Graph* graph;		
    32 		
    33 		
    34 	public:
    35 	
    36 		MapRegistry(Graph& g) : container(0), graph(&g) {}
    37 				
    38 		~MapRegistry() {
    39 			typename Container::iterator it;
    40 			for (it = container.begin(); it != container.end(); ++it) {
    41 				(*it)->destroy(*graph);
    42 				(*it)->registry = 0;
    43 			}
    44 		}
    45 	
    46 	private:
    47 		MapRegistry(const MapRegistry& ) {}
    48 		MapRegistry& operator=(const MapRegistry& ) {}
    49 	
    50 	public:
    51 	
    52 		void add(Map& map) {
    53 			if (map.registry) {
    54 				map.registry->erase(map);
    55 			}
    56 			container.push_back(&map);
    57 			map.registry = this;
    58 			map.registry_index = container.size()-1;
    59 			map.init(*graph);
    60 		} 
    61 	
    62 		void erase(Map& map_base) {
    63 			map_base.destroy(*graph);
    64 			container.back()->registry_index = map_base.registry_index; 
    65 			container[map_base.registry_index] = container.back();
    66 			container.pop_back();
    67 			map_base.registry = 0;
    68 		}
    69 	
    70 		
    71 		void add(Key& key) {
    72 			typename Container::iterator it;
    73 			for (it = container.begin(); it != container.end(); ++it) {
    74 				(*it)->add(key);
    75 			}
    76 		}	
    77 		
    78 		void erase(Key& key) {
    79 			typename Container::iterator it;
    80 			for (it = container.begin(); it != container.end(); ++it) {
    81 				(*it)->erase(key);
    82 			}
    83 		}
    84 
    85 		Graph& getGraph() {
    86 			return *graph;
    87 		}
    88 
    89 
    90 	};
    91 
    92 }
    93 
    94 #endif