src/work/deba/map_registry.h
changeset 607 327f7cf13843
parent 571 9632ea8be6ca
child 627 6cc21a9c9fda
equal deleted inserted replaced
1:a3e16cac40ef 2:fa75bc25b7fe
     1 #ifndef MAP_REGISTRY_H
     1 #ifndef MAP_REGISTRY_H
     2 #define MAP_REGISTRY_H
     2 #define MAP_REGISTRY_H
     3 
     3 
     4 #include <vector>
     4 #include <vector>
       
     5 
       
     6 using namespace std;
     5 
     7 
     6 
     8 
     7 namespace hugo {
     9 namespace hugo {
     8 	template <typename G, typename K, typename KIt>
    10 	template <typename G, typename K, typename KIt>
     9 	class MapRegistry;
    11 	class MapRegistry;
    60 				map.registry->detach(map);
    62 				map.registry->detach(map);
    61 			}
    63 			}
    62 			container.push_back(&map);
    64 			container.push_back(&map);
    63 			map.registry = this;
    65 			map.registry = this;
    64 			map.registry_index = container.size()-1;
    66 			map.registry_index = container.size()-1;
    65 			map.init();
       
    66 		} 
    67 		} 
    67 	
    68 	
    68 		void detach(Map& map_base) {
    69 		void detach(Map& map) {
    69 			map_base.destroy();
    70 			container.back()->registry_index = map.registry_index; 
    70 			container.back()->registry_index = map_base.registry_index; 
    71 			container[map.registry_index] = container.back();
    71 			container[map_base.registry_index] = container.back();
       
    72 			container.pop_back();
    72 			container.pop_back();
    73 			map_base.registry = 0;
    73 			map.registry = 0;
    74 			map_base.graph = 0;
    74 			map.graph = 0;
    75 		}
    75 		}
    76 	
    76 	
    77 		
    77 		
    78 		void add(Key& key) {
    78 		virtual void add(Key& key) {
    79 			typename Container::iterator it;
    79 			typename Container::iterator it;
    80 			for (it = container.begin(); it != container.end(); ++it) {
    80 			for (it = container.begin(); it != container.end(); ++it) {
    81 				(*it)->add(key);
    81 				(*it)->add(key);
    82 			}
    82 			}
    83 		}	
    83 		}	
    84 		
    84 		
    85 		void erase(Key& key) {
    85 		virtual void erase(Key& key) {
    86 			typename Container::iterator it;
    86 			typename Container::iterator it;
    87 			for (it = container.begin(); it != container.end(); ++it) {
    87 			for (it = container.begin(); it != container.end(); ++it) {
    88 				(*it)->erase(key);
    88 				(*it)->erase(key);
    89 			}
    89 			}
    90 		}
    90 		}