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