src/work/deba/edge_map_registry.h
author deba
Thu, 22 Apr 2004 16:36:57 +0000
changeset 377 33fe0ee01dc5
parent 340 a2ce3c4780b7
permissions -rw-r--r--
(none)
     1 #ifndef EDGE_MAP_REGISTRY_H
     2 #define EDGE_MAP_REGISTRY_H
     3 
     4 #include <vector>
     5 
     6 template <typename G, typename K>
     7 class EdgeMapRegistry;
     8 
     9 #include "edge_map_base.h"
    10 
    11 template <typename G, typename K>
    12 class EdgeMapRegistry {
    13 public:
    14 	typedef G Graph;
    15 	typedef K Edge;
    16 	
    17 	typedef EdgeMapBase<Graph, Edge> MapBase;
    18 	friend class MapBase;
    19 
    20 protected:
    21 	
    22 	Graph* graph;
    23 
    24 	typedef std::vector<MapBase*> Container; 
    25 	
    26 	Container container;
    27 
    28 public:
    29 
    30 	EdgeMapRegistry(Graph g) : graph(&g) {}
    31 
    32 	void add(MapBase& map_base) {
    33 		if (map_base.graph) {
    34 			map_base.graph->edge_maps.erase(map_base);
    35 		}
    36 		container.push_back(&map_base);
    37 		map_base.graph = graph;
    38 		map_base.graph_index = container.size()-1;
    39 	} 
    40 	
    41 	void erase(MapBase& map_base) {
    42 		container.back()->graph_index = map_base.graph_index; 
    43 		container[map_base.graph_index] = container.back();
    44 		container.pop_back();
    45 		map_base.graph = 0;
    46 	}
    47 
    48 	
    49 	void add(Edge& edge) {
    50 		typename Container::iterator it;
    51 		for (it = container.begin(); it != container.end(); ++it) {
    52 			(*it)->add(edge);
    53 		}
    54 	}
    55 	
    56 	void erase(Edge& edge) {
    57 		typename Container::iterator it;
    58 		for (it = container.begin(); it != container.end(); ++it) {
    59 			(*it)->erase(edge);
    60 		}
    61 	}
    62 
    63 };
    64 
    65 #endif