src/work/deba/edge_map_registry.h
changeset 340 a2ce3c4780b7
parent 337 6e1b7efa577f
child 377 33fe0ee01dc5
equal deleted inserted replaced
0:6fd577b3b22d 1:780fa494d8cf
     1 #ifndef EDGE_MAP_REGISTRY_H
     1 #ifndef EDGE_MAP_REGISTRY_H
     2 #define EDGE_MAP_REGISTRY_H
     2 #define EDGE_MAP_REGISTRY_H
     3 
     3 
     4 #include <vector>
     4 #include <vector>
       
     5 
       
     6 #include "edge_map_base.h"
     5 
     7 
     6 template <typename G, typename E>
     8 template <typename G, typename E>
     7 class EdgeMapRegistry {
     9 class EdgeMapRegistry {
     8 public:
    10 public:
     9 	typedef G Graph;
    11 	typedef G Graph;
    10 	typedef E Edge
    12 	typedef E Edge
    11 	
    13 	
    12 	typedef EdgeMapBase<Graph, Edge> EdgeMapBase;
    14 	typedef EdgeMapBase<Graph, Edge> MapBase;
    13 
    15 
    14 protected:
    16 protected:
    15 	typedef std::vector<EdgeMapBase*> Container; 
    17 	typedef std::vector<EdgeMapBase*> Container; 
    16 	
    18 	
    17 	Container container;
    19 	Container container;
    18 	
    20 	
    19 	void add(EdgeMapBase& map_base) {
    21 	void add(MapBase& map_base) {
    20 		if (map_base.graph) {
    22 		if (map_base.graph) {
    21 			map_base.graph->edge_maps.erase(map_base);
    23 			map_base.graph->edge_maps.erase(map_base);
    22 		}
    24 		}
    23 		container.push_back(&map_base);
    25 		container.push_back(&map_base);
    24 		map_base.graph = this;
    26 		map_base.graph = this;
    25 		map_base.graph_index = container.size()-1;
    27 		map_base.graph_index = container.size()-1;
    26 	} 
    28 	} 
    27 	
    29 	
    28 	void erase(EdgeMapBase& map_base) {
    30 	void erase(MapBase& map_base) {
    29 		if (map_base.graph != this) return;
    31 		if (map_base.graph != this) return;
    30 		container.back()->graph_index = map_base.graph_index; 
    32 		container.back()->graph_index = map_base.graph_index; 
    31 		container[map_base.graph_index] = container.back();
    33 		container[map_base.graph_index] = container.back();
    32 		container.pop_back();
    34 		container.pop_back();
    33 		map_base.graph = 0;
    35 		map_base.graph = 0;
    34 	}
    36 	}
    35 	
    37 	
    36 	void addEdge(Edge& edge) {
    38 	void add(Edge& edge) {
    37 		typename Container::iterator it;
    39 		typename Container::iterator it;
    38 		for (it = container.begin(); it != container.end(); ++it) {
    40 		for (it = container.begin(); it != container.end(); ++it) {
    39 			(*it)->add(edge);
    41 			(*it)->add(edge);
    40 		}
    42 		}
    41 	}
    43 	}
    42 	
    44 	
    43 	void eraseEdge(Edge& edge) {
    45 	void erase(Edge& edge) {
    44 		typename Container::iterator it;
    46 		typename Container::iterator it;
    45 		for (it = container.begin(); it != container.end(); ++it) {
    47 		for (it = container.begin(); it != container.end(); ++it) {
    46 			(*it)->erase(edge);
    48 			(*it)->erase(edge);
    47 		}
    49 		}
    48 	}
    50 	}
    49 
    51 
    50 	friend class EdgeMapBase;
    52 	friend class MapBase;
    51 };
    53 };
    52 
    54 
    53 #endif
    55 #endif