| Line | |
|---|
| 1 | #ifndef NODE_MAP_REGISTRY_H |
|---|
| 2 | #define NODE_MAP_REGISTRY_H |
|---|
| 3 | |
|---|
| 4 | #include <vector> |
|---|
| 5 | |
|---|
| 6 | template <typename G, typename K> |
|---|
| 7 | class NodeMapRegistry; |
|---|
| 8 | |
|---|
| 9 | #include "node_map_base.h" |
|---|
| 10 | |
|---|
| 11 | template <typename G, typename K> |
|---|
| 12 | class NodeMapRegistry { |
|---|
| 13 | public: |
|---|
| 14 | typedef G Graph; |
|---|
| 15 | typedef K Node; |
|---|
| 16 | |
|---|
| 17 | typedef NodeMapBase<Graph, Node> 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 | NodeMapRegistry(Graph g) : graph(&g) {} |
|---|
| 31 | |
|---|
| 32 | void add(MapBase& map_base) { |
|---|
| 33 | if (map_base.graph) { |
|---|
| 34 | map_base.graph->node_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(Node& node) { |
|---|
| 50 | typename Container::iterator it; |
|---|
| 51 | for (it = container.begin(); it != container.end(); ++it) { |
|---|
| 52 | (*it)->add(node); |
|---|
| 53 | } |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | void erase(Node& node) { |
|---|
| 57 | typename Container::iterator it; |
|---|
| 58 | for (it = container.begin(); it != container.end(); ++it) { |
|---|
| 59 | (*it)->erase(node); |
|---|
| 60 | } |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | }; |
|---|
| 64 | |
|---|
| 65 | #endif |
|---|
Note: See
TracBrowser
for help on using the repository browser.