COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/deba/node_map_registry.h @ 377:33fe0ee01dc5

Last change on this file since 377:33fe0ee01dc5 was 377:33fe0ee01dc5, checked in by Balazs Dezso, 17 years ago
File size: 1.2 KB
RevLine 
[337]1#ifndef NODE_MAP_REGISTRY_H
2#define NODE_MAP_REGISTRY_H
3
4#include <vector>
5
[377]6template <typename G, typename K>
7class NodeMapRegistry;
8
[340]9#include "node_map_base.h"
10
[377]11template <typename G, typename K>
[337]12class NodeMapRegistry {
13public:
14        typedef G Graph;
[377]15        typedef K Node;
[337]16       
[377]17        typedef NodeMapBase<Graph, Node> MapBase;
18        friend class MapBase;
[337]19
20protected:
[377]21       
22        Graph* graph;
23
24        typedef std::vector<MapBase*> Container;
[337]25       
26        Container container;
[377]27
28public:
29
30        NodeMapRegistry(Graph g) : graph(&g) {}
31
32        void add(MapBase& map_base) {
[337]33                if (map_base.graph) {
34                        map_base.graph->node_maps.erase(map_base);
35                }
36                container.push_back(&map_base);
[377]37                map_base.graph = graph;
[337]38                map_base.graph_index = container.size()-1;
39        }
40       
[377]41        void erase(MapBase& map_base) {
[337]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        }
[377]47
[337]48       
[340]49        void add(Node& node) {
[337]50                typename Container::iterator it;
51                for (it = container.begin(); it != container.end(); ++it) {
52                        (*it)->add(node);
53                }
54        }
55       
[340]56        void erase(Node& node) {
[337]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.