Don't import ogdf namespace
[TortoiseGit.git] / ext / OGDF / ogdf / basic / GraphObserver.h
blob0d39ef5de0bd58776a83e625ba8da7c5343fb452
1 /*
2 * $Revision: 2615 $
4 * last checkin:
5 * $Author: gutwenger $
6 * $Date: 2012-07-16 14:23:36 +0200 (Mo, 16. Jul 2012) $
7 ***************************************************************/
9 /** \file
10 * \brief Abstract base class for structures on graphs, that need
11 * to be informed about graph changes (e.g. cluster graphs).
13 * Follows the observer pattern: graphs are observable
14 * objects that can inform observers on changes made to their
15 * structure.
17 * \author Karsten Klein
19 * \par License:
20 * This file is part of the Open Graph Drawing Framework (OGDF).
22 * \par
23 * Copyright (C)<br>
24 * See README.txt in the root directory of the OGDF installation for details.
26 * \par
27 * This program is free software; you can redistribute it and/or
28 * modify it under the terms of the GNU General Public License
29 * Version 2 or 3 as published by the Free Software Foundation;
30 * see the file LICENSE.txt included in the packaging of this file
31 * for details.
33 * \par
34 * This program is distributed in the hope that it will be useful,
35 * but WITHOUT ANY WARRANTY; without even the implied warranty of
36 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 * GNU General Public License for more details.
39 * \par
40 * You should have received a copy of the GNU General Public
41 * License along with this program; if not, write to the Free
42 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
43 * Boston, MA 02110-1301, USA.
45 * \see http://www.gnu.org/copyleft/gpl.html
46 ***************************************************************/
49 #ifdef _MSC_VER
50 #pragma once
51 #endif
53 #ifndef OGDF_GRAPH_STRUCTURE_H
54 #define OGDF_GRAPH_STRUCTURE_H
57 #include <ogdf/basic/List.h>
58 #include <ogdf/basic/Graph.h>
60 namespace ogdf {
63 // in embedded graphs, adjacency lists are given in clockwise order.
67 //----------------------------------------------------------
68 // GraphObserver
69 //----------------------------------------------------------
70 /**
71 * \brief Abstract Base class for classes that need to keep track
72 * of changes in the graph like addition/deletion of nodes
73 * or edges.
74 * derived classes have to overload nodeDeleted, nodeAdded
75 * edgeDeleted, edgeAdded
76 * these functions should be called by Graph before (delete)
80 class OGDF_EXPORT GraphObserver {
81 friend class Graph;
83 public:
84 //! Constructs instance of GraphObserver class
85 GraphObserver() : m_pGraph(0) { }
87 /**
88 *\brief Constructs instance of GraphObserver class
89 * \param G is the graph to be watched
91 GraphObserver(const Graph* G) : m_pGraph(G)
93 m_itGList = G->registerStructure(this);
94 }//constructor
96 //! Destroys the instance, unregisters it from watched graph
97 virtual ~GraphObserver()
99 if (m_pGraph) m_pGraph->unregisterStructure(m_itGList);
100 }//destructor
102 //! Associates observer instance with graph \a G
103 void reregister(const Graph *pG) {
104 //small speedup: check if == m_pGraph
105 if (m_pGraph) m_pGraph->unregisterStructure(m_itGList);
106 if ((m_pGraph = pG) != 0) m_itGList = pG->registerStructure(this);
109 //! Called by watched graph when a node is deleted
110 //! Has to be implemented by derived classes
111 virtual void nodeDeleted(node v) = 0;
113 //! Called by watched graph when a node is added
114 //! Has to be implemented by derived classes
115 virtual void nodeAdded(node v) = 0;
117 //! Called by watched graph when an edge is deleted
118 //! Has to be implemented by derived classes
119 virtual void edgeDeleted(edge e) = 0;
121 //! Called by watched graph when an edge is added
122 //! Has to be implemented by derived classes
123 virtual void edgeAdded(edge e) = 0;
125 //! Called by watched graph when it is reinitialized
126 //! Has to be implemented by derived classes
127 virtual void reInit() = 0;
129 //! Called by watched graph when its clear function is called
130 //! Has to be implemented by derived classes
131 virtual void cleared() = 0;
133 const Graph* getGraph() const { return m_pGraph; }
135 protected:
136 const Graph* m_pGraph; //! watched graph
137 ListIterator<GraphObserver*> m_itGList; //! List entry in graphs list of all registered graphobservers
142 } //end namespace ogdf
144 #endif