deba@262: #ifndef EDGE_MAP_BASE_H deba@262: #define EDGE_MAP_BASE_H deba@262: deba@340: /** deba@340: Template base class for implementing mapping on edges. deba@340: \param The first template parameter is the Graph class. The Graph deba@340: must have an \emp edge_maps member with \emp EdgeMapRegistry class. deba@340: \param The second template parameter is the Edge type of the class. deba@340: deba@340: */ deba@340: deba@340: template deba@262: class EdgeMapBase { deba@262: public: deba@262: typedef G Graph; deba@336: deba@262: typedef K KeyType; deba@262: deba@340: /** deba@340: Default constructor. deba@340: */ deba@340: deba@336: EdgeMapBase() : graph(0) {} deba@340: deba@340: /** deba@340: Simple constructor to register into a graph. deba@340: */ deba@340: deba@336: EdgeMapBase(Graph& g) : graph(&g) { deba@336: graph->edge_maps.add(*this); deba@336: } deba@262: deba@340: /** deba@340: Copy constructor with registering into the map. deba@340: */ deba@340: deba@340: EdgeMapBase(const EdgeMapBase& copy) : graph(copy.graph) { deba@340: if (graph) { deba@340: graph->edge_maps.add(*this); deba@340: } deba@340: } deba@340: deba@340: /** deba@340: Assign operator. deba@340: */ deba@340: deba@340: const EdgeMapBase& operator=(const EdgeMapBase& copy) { deba@340: if (graph) { deba@340: graph.edge_maps.erase(*this); deba@340: } deba@340: graph = copy.graph; deba@340: if (graph) { deba@340: graph->edge_maps.add(*this); deba@340: } deba@340: deba@340: } deba@340: deba@340: deba@340: /** deba@340: Destructor. deba@340: */ deba@340: deba@336: virtual ~EdgeMapBase() { deba@336: if (graph) { deba@336: graph.edge_maps.erase(*this); deba@336: } deba@336: } deba@336: deba@262: protected: deba@262: deba@262: Graph* graph; deba@262: deba@262: int graph_index; deba@262: deba@340: /** deba@340: Helper function to implement the default constructor in the subclasses. deba@340: */ deba@340: deba@336: void init() { deba@336: for (Graph::EdgeIt it(g); g.valid(it); g.next(it)) { deba@336: add(it); deba@336: } deba@336: } deba@336: deba@340: /** deba@340: Helper function to implement the destructor in the subclasses. deba@340: */ deba@340: deba@336: void destroy() { deba@336: for (Graph::EdgeIt it(g); g.valid(it); g.next(it)) { deba@336: erase(it); deba@336: } deba@336: } deba@262: deba@340: /** deba@340: The add member function should be overloaded in the subclasses. deba@340: \e Add extends the map with the new edge. deba@340: */ deba@340: deba@262: virtual void add(const KeyType&) = 0; deba@340: deba@340: /** deba@340: The erase member function should be overloaded in the subclasses. deba@340: \e Erase removes the edge from the map. deba@340: */ deba@340: deba@262: virtual void erase(const KeyType&) = 0; deba@340: deba@340: /** deba@340: Exception class to throw at unsupported operation. deba@340: */ deba@340: deba@340: class NotSupportedOperationException {}; deba@262: deba@262: friend class Graph; deba@262: }; deba@262: deba@262: #endif