00001 /* 00002 * $Revision: 2027 $ 00003 * 00004 * last checkin: 00005 * $Author: gutwenger $ 00006 * $Date: 2010-09-01 11:55:17 +0200 (Wed, 01 Sep 2010) $ 00007 ***************************************************************/ 00008 00058 #ifdef _MSC_VER 00059 #pragma once 00060 #endif 00061 00062 #ifndef OGDF_CLUSTER_GRAPH_OBSERVER_H 00063 #define OGDF_CLUSTER_GRAPH_OBSERVER_H 00064 00065 00066 #include <ogdf/basic/List.h> 00067 #include <ogdf/cluster/ClusterGraph.h> 00068 00069 namespace ogdf { 00070 00071 00072 //---------------------------------------------------------- 00073 // GraphObserver 00074 // abstract base class 00075 // derived classes have to overload nodeDeleted, nodeAdded 00076 // edgeDeleted, edgeAdded 00077 // these functions should be called by Graph before (delete) 00078 // and after (add) its structure 00079 //---------------------------------------------------------- 00080 class OGDF_EXPORT ClusterGraphObserver { 00081 friend class OGDF_EXPORT ClusterGraph; 00082 00083 public: 00084 ClusterGraphObserver() : m_pClusterGraph(0) {} 00085 00086 ClusterGraphObserver(const ClusterGraph* CG) : m_pClusterGraph(CG) 00087 { 00088 m_itCGList = CG->registerObserver(this); 00089 }//constructor 00090 00091 virtual ~ClusterGraphObserver() 00092 { 00093 if (m_pClusterGraph) m_pClusterGraph->unregisterObserver(m_itCGList); 00094 }//destructor 00095 00096 // associates structure with different graph 00097 void reregister(const ClusterGraph *pCG) { 00098 //small speedup: check if == m_pGraph 00099 if (m_pClusterGraph) m_pClusterGraph->unregisterObserver(m_itCGList); 00100 if ((m_pClusterGraph = pCG) != 0) m_itCGList = pCG->registerObserver(this); 00101 } 00102 00103 virtual void clusterDeleted(cluster v) = 0; 00104 virtual void clusterAdded(cluster v) = 0; 00105 //virtual void reInit() = 0; 00106 //virtual void cleared() = 0;//Graph cleared 00107 00108 const ClusterGraph* getGraph() const { return m_pClusterGraph;} 00109 00110 protected: 00111 const ClusterGraph* m_pClusterGraph; //underlying clustergraph 00112 00113 //List entry in cluster graphs list of all registered observers 00114 ListIterator<ClusterGraphObserver*> m_itCGList; 00115 }; 00116 00117 }; // end of namespace 00118 00119 #endif