Open
Graph Drawing
Framework

 v.2012.05
 

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