Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00043 #ifdef _MSC_VER
00044 #pragma once
00045 #endif
00046
00047 #ifndef OGDF_ADJ_ENTRY_ARRAY_H
00048 #define OGDF_ADJ_ENTRY_ARRAY_H
00049
00050
00051 #include <ogdf/basic/Graph.h>
00052
00053
00054 namespace ogdf {
00055
00056
00058
00062 class AdjEntryArrayBase {
00067 ListIterator<AdjEntryArrayBase*> m_it;
00068
00069 public:
00070 const Graph *m_pGraph;
00071
00073 AdjEntryArrayBase() : m_pGraph(0) { }
00075 AdjEntryArrayBase(const Graph *pG) : m_pGraph(pG) {
00076 if(pG) m_it = pG->registerArray(this);
00077 }
00078
00079
00080 virtual ~AdjEntryArrayBase() {
00081 if (m_pGraph) m_pGraph->unregisterArray(m_it);
00082 }
00083
00084
00086 virtual void enlargeTable(int newTableSize) = 0;
00088 virtual void reinit(int initTableSize) = 0;
00090 virtual void disconnect() = 0;
00092 virtual void resetIndex(int newIndex, int oldIndex) = 0;
00093
00095 void reregister(const Graph *pG) {
00096 if (m_pGraph) m_pGraph->unregisterArray(m_it);
00097 if ((m_pGraph = pG) != 0) m_it = pG->registerArray(this);
00098 }
00099 };
00100
00101
00103
00107 template<class T> class AdjEntryArray : private Array<T>, protected AdjEntryArrayBase {
00108 T m_x;
00109
00110 public:
00112 AdjEntryArray() : Array<T>(), AdjEntryArrayBase() { }
00114 AdjEntryArray(const Graph &G) : Array<T>(G.adjEntryArrayTableSize()), AdjEntryArrayBase(&G) { }
00116
00120 AdjEntryArray(const Graph &G, const T &x) :
00121 Array<T>(0,G.adjEntryArrayTableSize()-1,x), AdjEntryArrayBase(&G), m_x(x) { }
00123
00126 AdjEntryArray(const AdjEntryArray<T> &A) : Array<T>(A), AdjEntryArrayBase(A.m_pGraph), m_x(A.m_x) { }
00127
00129 bool valid() const { return (Array<T>::low() <= Array<T>::high()); }
00130
00132 const T &operator[](adjEntry adj) const {
00133 OGDF_ASSERT(adj != 0 && adj->graphOf() == m_pGraph)
00134 return Array<T>::operator [](adj->index());
00135 }
00136
00138 T &operator[](adjEntry adj) {
00139 OGDF_ASSERT(adj != 0 && adj->graphOf() == m_pGraph)
00140 return Array<T>::operator [](adj->index());
00141 }
00142
00144
00148 const T &operator[](int index) const {
00149 return Array<T>::operator [](index);
00150 }
00151
00153
00157 T &operator[](int index) {
00158 return Array<T>::operator [](index);
00159 }
00160
00162 AdjEntryArray<T> &operator=(const AdjEntryArray<T> &A) {
00163 Array<T>::operator =(A);
00164 m_x = A.m_x;
00165 reregister(A.m_pGraph);
00166 return *this;
00167 }
00168
00170 void init() {
00171 Array<T>::init(); reregister(0);
00172 }
00173
00175 void init(const Graph &G) {
00176 Array<T>::init(G.adjEntryArrayTableSize()); reregister(&G);
00177 }
00178
00180
00184 void init(const Graph &G, const T &x) {
00185 Array<T>::init(0,G.adjEntryArrayTableSize()-1, m_x = x); reregister(&G);
00186 }
00187
00189 void fill(const T &x) {
00190 int high = m_pGraph->maxAdjEntryIndex();
00191 if(high >= 0)
00192 Array<T>::fill(0,high,x);
00193 }
00194
00195 private:
00196 virtual void enlargeTable(int newTableSize) {
00197 Array<T>::grow(newTableSize-Array<T>::size(),m_x);
00198 }
00199
00200 virtual void reinit(int initTableSize) {
00201 Array<T>::init(0,initTableSize-1,m_x);
00202 }
00203
00204 virtual void resetIndex(int newIndex, int oldIndex) {
00205 Array<T>::operator [](newIndex) = Array<T>::operator [](oldIndex);
00206 }
00207
00208 virtual void disconnect() {
00209 Array<T>::init();
00210 m_pGraph = 0;
00211 }
00212
00213 OGDF_NEW_DELETE
00214
00215 };
00216
00217
00218 }
00219
00220
00221 #endif