Open
Graph Drawing
Framework

 v.2012.05
 

FaceArray.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  
00043 #ifdef _MSC_VER
00044 #pragma once
00045 #endif
00046 
00047 #ifndef OGDF_FACE_ARRAY_H
00048 #define OGDF_FACE_ARRAY_H
00049 
00050 
00051 #include <ogdf/basic/Array.h>
00052 #include <ogdf/basic/CombinatorialEmbedding.h>
00053 
00054 
00055 namespace ogdf {
00056 
00057 
00059 
00064 class FaceArrayBase {
00069     ListIterator<FaceArrayBase*> m_it;
00070 
00071 public:
00072     const ConstCombinatorialEmbedding *m_pEmbedding; 
00073 
00075     FaceArrayBase() : m_pEmbedding(0) { }
00077     FaceArrayBase(const ConstCombinatorialEmbedding *pE) : m_pEmbedding(pE) {
00078         if(pE) m_it = pE->registerArray(this);
00079     }
00080 
00081     // destructor, unregisters the array
00082     virtual ~FaceArrayBase() {
00083         if (m_pEmbedding) m_pEmbedding->unregisterArray(m_it);
00084     }
00085 
00086     // event interface used by CombinatorialEmbedding
00088     virtual void enlargeTable(int newTableSize) = 0;
00090     virtual void reinit(int initTableSize) = 0;
00091 
00093     void reregister(const ConstCombinatorialEmbedding *pE) {
00094         if (m_pEmbedding) m_pEmbedding->unregisterArray(m_it);
00095         if ((m_pEmbedding = pE) != 0) m_it = pE->registerArray(this);
00096     }
00097 }; // class FaceArrayBase
00098 
00099 
00100 //---------------------------------------------------------
00101 // FaceArray<T>
00102 // associative arrays for edges (with table doubling)
00103 //---------------------------------------------------------
00105 
00109 template<class T> class FaceArray : private Array<T>, protected FaceArrayBase {
00110     T m_x; 
00111 
00112 public:
00114     FaceArray() : Array<T>(), FaceArrayBase() { }
00116     FaceArray(const ConstCombinatorialEmbedding &E) :
00117         Array<T>(E.faceArrayTableSize()), FaceArrayBase(&E) { }
00119 
00123     FaceArray(const ConstCombinatorialEmbedding &E, const T &x) :
00124         Array<T>(0,E.faceArrayTableSize()-1,x), FaceArrayBase(&E), m_x(x) { }
00126 
00130     FaceArray(const FaceArray<T> &A) : Array<T>(A), FaceArrayBase(A.m_pEmbedding), m_x(A.m_x) { }
00131 
00133     bool valid() const { return (Array<T>::low() <= Array<T>::high()); }
00134 
00136     const ConstCombinatorialEmbedding *embeddingOf() const {
00137         return m_pEmbedding;
00138     }
00139 
00141     const T &operator[](face f) const {
00142         OGDF_ASSERT(f != 0 && f->embeddingOf() == m_pEmbedding)
00143         return Array<T>::operator [](f->index());
00144     }
00145 
00147     T &operator[](face f) {
00148         OGDF_ASSERT(f != 0 && f->embeddingOf() == m_pEmbedding)
00149         return Array<T>::operator [](f->index());
00150     }
00151 
00153 
00157     const T &operator[](int index) const {
00158         return Array<T>::operator [](index);
00159     }
00160 
00162 
00166     T &operator[](int index) {
00167         return Array<T>::operator [](index);
00168     }
00169 
00171     FaceArray<T> &operator=(const FaceArray<T> &a) {
00172         Array<T>::operator =(a);
00173         m_x = a.m_x;
00174         reregister(a.m_pEmbedding);
00175         return *this;
00176     }
00177 
00179     void init() {
00180         Array<T>::init(); reregister(0);
00181     }
00182 
00184     void init(const ConstCombinatorialEmbedding &E) {
00185         Array<T>::init(E.faceArrayTableSize()); reregister(&E);
00186     }
00187 
00189 
00193     void init(const ConstCombinatorialEmbedding &E, const T &x) {
00194         Array<T>::init(0,E.faceArrayTableSize()-1, m_x = x); reregister(&E);
00195     }
00196 
00198     void fill(const T &x) {
00199         int high = m_pEmbedding->maxFaceIndex();
00200         if(high >= 0)
00201             Array<T>::fill(0,high,x);
00202     }
00203 
00204 private:
00205     virtual void enlargeTable(int newTableSize) {
00206         Array<T>::grow(newTableSize-Array<T>::size(),m_x);
00207     }
00208 
00209     virtual void reinit(int initTableSize) {
00210         Array<T>::init(0,initTableSize-1,m_x);
00211     }
00212 
00213     OGDF_NEW_DELETE
00214 
00215 }; // class FaceArray<T>
00216 
00217 
00218 } // end namespace ogdf
00219 
00220 
00221 #endif