Open
Graph Drawing
Framework

 v.2010.10
 

FaceArray.h

Go to the documentation of this file.
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  
00053 #ifdef _MSC_VER
00054 #pragma once
00055 #endif
00056 
00057 #ifndef OGDF_FACE_ARRAY_H
00058 #define OGDF_FACE_ARRAY_H
00059 
00060 
00061 #include <ogdf/basic/Array.h>
00062 #include <ogdf/basic/CombinatorialEmbedding.h>
00063 
00064 
00065 namespace ogdf {
00066 
00067 
00069 
00074 class FaceArrayBase {
00079     ListIterator<FaceArrayBase*> m_it;
00080 
00081 public:
00082     const ConstCombinatorialEmbedding *m_pEmbedding; 
00083 
00085     FaceArrayBase() : m_pEmbedding(0) { }
00087     FaceArrayBase(const ConstCombinatorialEmbedding *pE) : m_pEmbedding(pE) {
00088         if(pE) m_it = pE->registerArray(this);
00089     }
00090 
00091     // destructor, unregisters the array
00092     virtual ~FaceArrayBase() {
00093         if (m_pEmbedding) m_pEmbedding->unregisterArray(m_it);
00094     }
00095 
00096     // event interface used by CombinatorialEmbedding
00098     virtual void enlargeTable(int newTableSize) = 0;
00100     virtual void reinit(int initTableSize) = 0;
00101 
00103     void reregister(const ConstCombinatorialEmbedding *pE) {
00104         if (m_pEmbedding) m_pEmbedding->unregisterArray(m_it);
00105         if ((m_pEmbedding = pE) != 0) m_it = pE->registerArray(this);
00106     }
00107 }; // class FaceArrayBase
00108 
00109 
00110 //---------------------------------------------------------
00111 // FaceArray<T>
00112 // associative arrays for edges (with table doubling)
00113 //---------------------------------------------------------
00115 
00119 template<class T> class FaceArray : private Array<T>, protected FaceArrayBase {
00120     T m_x; 
00121 
00122 public:
00124     FaceArray() : Array<T>(), FaceArrayBase() { }
00126     FaceArray(const ConstCombinatorialEmbedding &E) :
00127         Array<T>(E.faceArrayTableSize()), FaceArrayBase(&E) { }
00129 
00133     FaceArray(const ConstCombinatorialEmbedding &E, const T &x) :
00134         Array<T>(0,E.faceArrayTableSize()-1,x), FaceArrayBase(&E), m_x(x) { }
00136 
00140     FaceArray(const FaceArray<T> &A) : Array<T>(A), FaceArrayBase(A.m_pEmbedding), m_x(A.m_x) { }
00141 
00143     bool valid() const { return (Array<T>::low() <= Array<T>::high()); }
00144 
00146     const ConstCombinatorialEmbedding *embeddingOf() const {
00147         return m_pEmbedding;
00148     }
00149 
00151     const T &operator[](face f) const {
00152         OGDF_ASSERT(f != 0 && f->embeddingOf() == m_pEmbedding)
00153         return Array<T>::operator [](f->index());
00154     }
00155 
00157     T &operator[](face f) {
00158         OGDF_ASSERT(f != 0 && f->embeddingOf() == m_pEmbedding)
00159         return Array<T>::operator [](f->index());
00160     }
00161 
00163 
00167     const T &operator[](int index) const {
00168         return Array<T>::operator [](index);
00169     }
00170 
00172 
00176     T &operator[](int index) {
00177         return Array<T>::operator [](index);
00178     }
00179 
00181     FaceArray<T> &operator=(const FaceArray<T> &a) {
00182         Array<T>::operator =(a);
00183         m_x = a.m_x;
00184         reregister(a.m_pEmbedding);
00185         return *this;
00186     }
00187 
00189     void init() {
00190         Array<T>::init(); reregister(0);
00191     }
00192 
00194     void init(const ConstCombinatorialEmbedding &E) {
00195         Array<T>::init(E.faceArrayTableSize()); reregister(&E);
00196     }
00197 
00199 
00203     void init(const ConstCombinatorialEmbedding &E, const T &x) {
00204         Array<T>::init(0,E.faceArrayTableSize()-1, m_x = x); reregister(&E);
00205     }
00206 
00208     void fill(const T &x) {
00209         int high = m_pEmbedding->maxFaceIndex();
00210         if(high >= 0)
00211             Array<T>::fill(0,high,x);
00212     }
00213 
00214 private:
00215     virtual void enlargeTable(int newTableSize) {
00216         Array<T>::grow(newTableSize-Array<T>::size(),m_x);
00217     }
00218 
00219     virtual void reinit(int initTableSize) {
00220         Array<T>::init(0,initTableSize-1,m_x);
00221     }
00222 
00223     OGDF_NEW_DELETE
00224 
00225 }; // class FaceArray<T>
00226 
00227 
00228 } // end namespace ogdf
00229 
00230 
00231 #endif