Open
Graph Drawing
Framework

 v.2007.11
 

AdjEntryArray.h

Go to the documentation of this file.
00001 /*
00002  * $Revision: 1.7 $
00003  * 
00004  * last checkin:
00005  *   $Author: gutwenger $ 
00006  *   $Date: 2007-11-08 16:10:37 +0100 (Do, 08 Nov 2007) $ 
00007  ***************************************************************/
00008  
00051 #ifdef _MSC_VER
00052 #pragma once
00053 #endif
00054 
00055 #ifndef OGDF_ADJ_ENTRY_ARRAY_H
00056 #define OGDF_ADJ_ENTRY_ARRAY_H
00057 
00058 
00059 #include <ogdf/basic/Graph.h>
00060 
00061 
00062 namespace ogdf {
00063 
00064 
00066 
00070 class AdjEntryArrayBase {
00075     ListIterator<AdjEntryArrayBase*> m_it;
00076 
00077 public:
00078     const Graph *m_pGraph; 
00079 
00081     AdjEntryArrayBase() : m_pGraph(0) { }
00083     AdjEntryArrayBase(const Graph *pG) : m_pGraph(pG) {
00084         m_it = pG->registerArray(this);
00085     }
00086 
00087     // destructor, unregisters the array
00088     virtual ~AdjEntryArrayBase() {
00089         if (m_pGraph) m_pGraph->unregisterArray(m_it);
00090     }
00091 
00092     // event interface used by Graph
00094     virtual void enlargeTable(int newTableSize) = 0;
00096     virtual void reinit(int initTableSize) = 0;
00098     virtual void disconnect() = 0;
00100     virtual void resetIndex(int newIndex, int oldIndex) = 0;
00101 
00103     void reregister(const Graph *pG) {
00104         if (m_pGraph) m_pGraph->unregisterArray(m_it);
00105         if ((m_pGraph = pG) != 0) m_it = pG->registerArray(this);
00106     }
00107 }; // class AdjEntryArrayBase
00108 
00109 
00111 
00115 template<class T> class AdjEntryArray : private Array<T>, protected AdjEntryArrayBase {
00116     T m_x; 
00117 
00118 public:
00120     AdjEntryArray() : Array<T>(), AdjEntryArrayBase() { }
00122     AdjEntryArray(const Graph &G) : Array<T>(G.adjEntryArrayTableSize()), AdjEntryArrayBase(&G) { }
00124 
00128     AdjEntryArray(const Graph &G, const T &x) :
00129         Array<T>(0,G.adjEntryArrayTableSize()-1,x), AdjEntryArrayBase(&G), m_x(x) { }
00131 
00134     AdjEntryArray(const AdjEntryArray<T> &A) : Array<T>(A), AdjEntryArrayBase(A.m_pGraph), m_x(A.m_x) { }
00135 
00137     bool valid() const { return (Array<T>::low() <= Array<T>::high()); }
00138 
00140     const T &operator[](adjEntry adj) const {
00141         OGDF_ASSERT(adj != 0 && adj->graphOf() == m_pGraph)
00142         return Array<T>::operator [](adj->index());
00143     }
00144 
00146     T &operator[](adjEntry adj) {
00147         OGDF_ASSERT(adj != 0 && adj->graphOf() == m_pGraph)
00148         return Array<T>::operator [](adj->index());
00149     }
00150 
00152 
00156     const T &operator[](int index) const {
00157         return Array<T>::operator [](index);
00158     }
00159 
00161 
00165     T &operator[](int index) {
00166         return Array<T>::operator [](index);
00167     }
00168 
00170     AdjEntryArray<T> &operator=(const AdjEntryArray<T> &A) {
00171         Array<T>::operator =(A);
00172         m_x = A.m_x;
00173         reregister(A.m_pGraph);
00174         return *this;
00175     }
00176 
00178     void init() {
00179         Array<T>::init(); reregister(0);
00180     }
00181 
00183     void init(const Graph &G) {
00184         Array<T>::init(G.adjEntryArrayTableSize()); reregister(&G);
00185     }
00186 
00188 
00192     void init(const Graph &G, const T &x) {
00193         Array<T>::init(0,G.adjEntryArrayTableSize()-1, m_x = x); reregister(&G);
00194     }
00195 
00197     void fill(const T &x) {
00198         int high = m_pGraph->maxAdjEntryIndex();
00199         if(high >= 0)
00200             Array<T>::fill(0,high,x);
00201     }
00202 
00203 private:
00204     virtual void enlargeTable(int newTableSize) {
00205         Array<T>::grow(newTableSize-Array<T>::size(),m_x);
00206     }
00207 
00208     virtual void reinit(int initTableSize) {
00209         Array<T>::init(0,initTableSize-1,m_x);
00210     }
00211 
00212     virtual void resetIndex(int newIndex, int oldIndex) {
00213         Array<T>::operator [](newIndex) = Array<T>::operator [](oldIndex);
00214     }
00215 
00216     virtual void disconnect() {
00217         Array<T>::init();
00218         m_pGraph = 0;
00219     }
00220 
00221     OGDF_NEW_DELETE
00222 
00223 }; // class AdjEntryArray<T>
00224 
00225 
00226 } // end namespace ogdf
00227 
00228 
00229 #endif


© 1999-2007 by oreas GmbH, © 2005-2007 by University Dortmund and University Cologne.

Generated on Thu Nov 22 19:40:00 2007 by doxygen 1.5.4.