src/work/deba/map_registry.h
changeset 576 d00c33d07114
parent 378 c3f93631cd24
child 595 e10b5e9419ef
equal deleted inserted replaced
0:654e764f2834 1:a3e16cac40ef
    26 	protected:
    26 	protected:
    27 	
    27 	
    28 		typedef std::vector<Map*> Container; 
    28 		typedef std::vector<Map*> Container; 
    29 	  Container container;
    29 	  Container container;
    30 
    30 
    31 		Graph* graph;		
       
    32 		
       
    33 		
    31 		
    34 	public:
    32 	public:
    35 	
    33 	
    36 		MapRegistry(Graph& g) : container(0), graph(&g) {}
    34 		MapRegistry() {}
       
    35 	
       
    36 		MapRegistry(const MapRegistry&) {}
       
    37 		
       
    38 		MapRegistry& operator=(const MapRegistry&) {
       
    39 			for (it = container.begin(); it != container.end(); ++it) {
       
    40 				(*it)->destroy();
       
    41 				(*it)->graph = 0;
       
    42 				(*it)->registry = 0;
       
    43 			}
       
    44 		}
    37 				
    45 				
    38 		~MapRegistry() {
    46 		~MapRegistry() {
    39 			typename Container::iterator it;
    47 			typename Container::iterator it;
    40 			for (it = container.begin(); it != container.end(); ++it) {
    48 			for (it = container.begin(); it != container.end(); ++it) {
    41 				(*it)->destroy(*graph);
    49 				(*it)->destroy();
    42 				(*it)->registry = 0;
    50 				(*it)->registry = 0;
       
    51 				(*it)->graph = 0;
    43 			}
    52 			}
    44 		}
    53 		}
    45 	
    54 	
    46 	private:
       
    47 		MapRegistry(const MapRegistry& ) {}
       
    48 		MapRegistry& operator=(const MapRegistry& ) {}
       
    49 	
    55 	
    50 	public:
    56 	public:
    51 	
    57 	
    52 		void add(Map& map) {
    58 		void attach(Map& map) {
    53 			if (map.registry) {
    59 			if (map.registry) {
    54 				map.registry->erase(map);
    60 				map.registry->detach(map);
    55 			}
    61 			}
    56 			container.push_back(&map);
    62 			container.push_back(&map);
    57 			map.registry = this;
    63 			map.registry = this;
    58 			map.registry_index = container.size()-1;
    64 			map.registry_index = container.size()-1;
    59 			map.init(*graph);
    65 			map.init();
    60 		} 
    66 		} 
    61 	
    67 	
    62 		void erase(Map& map_base) {
    68 		void detach(Map& map_base) {
    63 			map_base.destroy(*graph);
    69 			map_base.destroy();
    64 			container.back()->registry_index = map_base.registry_index; 
    70 			container.back()->registry_index = map_base.registry_index; 
    65 			container[map_base.registry_index] = container.back();
    71 			container[map_base.registry_index] = container.back();
    66 			container.pop_back();
    72 			container.pop_back();
    67 			map_base.registry = 0;
    73 			map_base.registry = 0;
       
    74 			map_base.graph = 0;
    68 		}
    75 		}
    69 	
    76 	
    70 		
    77 		
    71 		void add(Key& key) {
    78 		void add(Key& key) {
    72 			typename Container::iterator it;
    79 			typename Container::iterator it;
    80 			for (it = container.begin(); it != container.end(); ++it) {
    87 			for (it = container.begin(); it != container.end(); ++it) {
    81 				(*it)->erase(key);
    88 				(*it)->erase(key);
    82 			}
    89 			}
    83 		}
    90 		}
    84 
    91 
    85 		Graph& getGraph() {
       
    86 			return *graph;
       
    87 		}
       
    88 
       
    89 
       
    90 	};
    92 	};
    91 
    93 
    92 }
    94 }
    93 
    95 
    94 #endif
    96 #endif