COIN-OR::LEMON - Graph Library

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

Last change on this file since 377:33fe0ee01dc5 was 377:33fe0ee01dc5, checked in by Balazs Dezso, 20 years ago
File size: 2.0 KB
RevLine 
[262]1#ifndef NODE_MAP_BASE_H
2#define NODE_MAP_BASE_H
3
[340]4/**
5        Template base class for implementing mapping on nodes.
6        \param The first template parameter is the Graph class. The Graph
7                must have an \emp node_maps member with \emp NodeMapRegistry class.
8        \param The second template parameter is the Node type of the class.
9       
10*/
11
12template <typename G, typename K>
[262]13class NodeMapBase {
[377]14
15#include "node_map_registry.h"
16
[262]17public:
18        typedef G Graph;
[377]19        friend class NodeMapRegistry<G, K>;
[262]20
21        typedef K KeyType;
22       
[340]23        /**
24                Default constructor.
25        */     
26       
[336]27        NodeMapBase() : graph(0) {}
[340]28
29        /**
30                Simple constructor to register into a graph.
31        */
32       
[336]33        NodeMapBase(Graph& g) : graph(&g) {
34                graph->node_maps.add(*this);
35        }
[262]36
[340]37        /**
38                Copy constructor with registering into the map.
39        */     
40       
41        NodeMapBase(const NodeMapBase& copy) : graph(copy.graph) {
42                if (graph) {
43                        graph->node_maps.add(*this);
44                }
45        }
46       
47        /**
48                Assign operator.
49        */     
50
51        const NodeMapBase& operator=(const NodeMapBase& copy) {
52                if (graph) {
53                        graph.node_maps.erase(*this);
54                }
55                graph = copy.graph;
56                if (graph) {
57                        graph->node_maps.add(*this);
58                }
59               
60        }
61       
62
63        /**
64                Destructor.
65        */     
66
[336]67        virtual ~NodeMapBase() {
68                if (graph) {
[377]69                        graph->node_maps.erase(*this);
[336]70                }
71        }
72       
[262]73protected:
74       
75        Graph* graph;
76
77        int graph_index;
78       
[340]79        /**
80                Helper function to implement the default constructor in the subclasses.
81        */
82       
[336]83        void init() {
[377]84                for (typename Graph::NodeIt it(g); g.valid(it); g.next(it)) {
[336]85                        add(it);
86                }
87        }
88       
[340]89        /**
90                Helper function to implement the destructor in the subclasses.
91        */
92       
[336]93        void destroy() {
[377]94                for (typename Graph::NodeIt it(g); g.valid(it); g.next(it)) {
[336]95                        erase(it);
96                }
97        }
[262]98       
[340]99        /**
100                The add member function should be overloaded in the subclasses.
101                \e Add extends the map with the new node.
102        */
103       
[262]104        virtual void add(const KeyType&) = 0;
[340]105       
106        /**
107                The erase member function should be overloaded in the subclasses.
108                \e Erase removes the node from the map.
109        */
110       
[262]111        virtual void erase(const KeyType&) = 0;
[340]112       
113        /**
114                Exception class to throw at unsupported operation.
115        */
116       
117        class NotSupportedOperationException {};
[262]118
119};
120
121#endif
Note: See TracBrowser for help on using the repository browser.