src/work/deba/edge_map_registry.h
author marci
Fri, 16 Apr 2004 13:05:08 +0000
changeset 338 e8725f30dd98
child 340 a2ce3c4780b7
permissions -rw-r--r--
kicsit takaritottam, es szepitettem es, es maga a csuda, de azer nem
teljesen mer' meg kell csinalni vele dolgokat.
     1 #ifndef EDGE_MAP_REGISTRY_H
     2 #define EDGE_MAP_REGISTRY_H
     3 
     4 #include <vector>
     5 
     6 template <typename G, typename E>
     7 class EdgeMapRegistry {
     8 public:
     9 	typedef G Graph;
    10 	typedef E Edge
    11 	
    12 	typedef EdgeMapBase<Graph, Edge> EdgeMapBase;
    13 
    14 protected:
    15 	typedef std::vector<EdgeMapBase*> Container; 
    16 	
    17 	Container container;
    18 	
    19 	void add(EdgeMapBase& map_base) {
    20 		if (map_base.graph) {
    21 			map_base.graph->edge_maps.erase(map_base);
    22 		}
    23 		container.push_back(&map_base);
    24 		map_base.graph = this;
    25 		map_base.graph_index = container.size()-1;
    26 	} 
    27 	
    28 	void erase(EdgeMapBase& map_base) {
    29 		if (map_base.graph != this) return;
    30 		container.back()->graph_index = map_base.graph_index; 
    31 		container[map_base.graph_index] = container.back();
    32 		container.pop_back();
    33 		map_base.graph = 0;
    34 	}
    35 	
    36 	void addEdge(Edge& edge) {
    37 		typename Container::iterator it;
    38 		for (it = container.begin(); it != container.end(); ++it) {
    39 			(*it)->add(edge);
    40 		}
    41 	}
    42 	
    43 	void eraseEdge(Edge& edge) {
    44 		typename Container::iterator it;
    45 		for (it = container.begin(); it != container.end(); ++it) {
    46 			(*it)->erase(edge);
    47 		}
    48 	}
    49 
    50 	friend class EdgeMapBase;
    51 };
    52 
    53 #endif