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