Rev | Line | |
---|
[262] | 1 | #ifndef NODE_MAP_BASE_H |
---|
| 2 | #define NODE_MAP_BASE_H |
---|
| 3 | |
---|
| 4 | template <class G, class K> |
---|
| 5 | class NodeMapBase { |
---|
| 6 | public: |
---|
| 7 | typedef G Graph; |
---|
| 8 | |
---|
| 9 | typedef K KeyType; |
---|
| 10 | |
---|
[336] | 11 | NodeMapBase() : graph(0) {} |
---|
| 12 | NodeMapBase(Graph& g) : graph(&g) { |
---|
| 13 | graph->node_maps.add(*this); |
---|
| 14 | } |
---|
[262] | 15 | |
---|
[336] | 16 | virtual ~NodeMapBase() { |
---|
| 17 | if (graph) { |
---|
| 18 | graph.node_maps.erase(*this); |
---|
| 19 | } |
---|
| 20 | } |
---|
| 21 | |
---|
[262] | 22 | protected: |
---|
| 23 | |
---|
| 24 | Graph* graph; |
---|
| 25 | |
---|
| 26 | int graph_index; |
---|
| 27 | |
---|
[336] | 28 | void init() { |
---|
| 29 | for (Graph::NodeIt it(g); g.valid(it); g.next(it)) { |
---|
| 30 | add(it); |
---|
| 31 | } |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | void destroy() { |
---|
| 35 | for (Graph::NodeIt it(g); g.valid(it); g.next(it)) { |
---|
| 36 | erase(it); |
---|
| 37 | } |
---|
| 38 | } |
---|
[262] | 39 | |
---|
| 40 | virtual void add(const KeyType&) = 0; |
---|
| 41 | virtual void erase(const KeyType&) = 0; |
---|
| 42 | |
---|
| 43 | friend class Graph; |
---|
| 44 | }; |
---|
| 45 | |
---|
| 46 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.