src/work/deba/node_map_registry.h
author marci
Tue, 20 Apr 2004 12:10:36 +0000
changeset 353 eeae2f4a0d74
parent 337 6e1b7efa577f
child 377 33fe0ee01dc5
permissions -rw-r--r--
template first goes to comment...
     1 #ifndef NODE_MAP_REGISTRY_H
     2 #define NODE_MAP_REGISTRY_H
     3 
     4 #include <vector>
     5 
     6 #include "node_map_base.h"
     7 
     8 template <typename G, typename E>
     9 class NodeMapRegistry {
    10 public:
    11 	typedef G Graph;
    12 	typedef E Node
    13 	
    14 	typedef NodeMapBase<Graph, Node> NodeMapBase;
    15 
    16 protected:
    17 	typedef std::vector<NodeMapBase*> Container; 
    18 	
    19 	Container container;
    20 	
    21 	void add(NodeMapBase& map_base) {
    22 		if (map_base.graph) {
    23 			map_base.graph->node_maps.erase(map_base);
    24 		}
    25 		container.push_back(&map_base);
    26 		map_base.graph = this;
    27 		map_base.graph_index = container.size()-1;
    28 	} 
    29 	
    30 	void erase(NodeMapBase& map_base) {
    31 		if (map_base.graph != this) return;
    32 		container.back()->graph_index = map_base.graph_index; 
    33 		container[map_base.graph_index] = container.back();
    34 		container.pop_back();
    35 		map_base.graph = 0;
    36 	}
    37 	
    38 	void add(Node& node) {
    39 		typename Container::iterator it;
    40 		for (it = container.begin(); it != container.end(); ++it) {
    41 			(*it)->add(node);
    42 		}
    43 	}
    44 	
    45 	void erase(Node& node) {
    46 		typename Container::iterator it;
    47 		for (it = container.begin(); it != container.end(); ++it) {
    48 			(*it)->erase(node);
    49 		}
    50 	}
    51 
    52 	friend class NodeMapBase;
    53 };
    54 
    55 #endif