Open
Graph Drawing
Framework

 v.2012.07
 

AdjEntryArray.h
Go to the documentation of this file.
1 /*
2  * $Revision: 2615 $
3  *
4  * last checkin:
5  * $Author: gutwenger $
6  * $Date: 2012-07-16 14:23:36 +0200 (Mo, 16. Jul 2012) $
7  ***************************************************************/
8 
44 #ifdef _MSC_VER
45 #pragma once
46 #endif
47 
48 #ifndef OGDF_ADJ_ENTRY_ARRAY_H
49 #define OGDF_ADJ_ENTRY_ARRAY_H
50 
51 
52 #include <ogdf/basic/Graph.h>
53 
54 
55 namespace ogdf {
56 
57 
59 
69 
70 public:
71  const Graph *m_pGraph;
72 
76  AdjEntryArrayBase(const Graph *pG) : m_pGraph(pG) {
77  if(pG) m_it = pG->registerArray(this);
78  }
79 
80  // destructor, unregisters the array
81  virtual ~AdjEntryArrayBase() {
83  }
84 
85  // event interface used by Graph
87  virtual void enlargeTable(int newTableSize) = 0;
89  virtual void reinit(int initTableSize) = 0;
91  virtual void disconnect() = 0;
93  virtual void resetIndex(int newIndex, int oldIndex) = 0;
94 
96  void reregister(const Graph *pG) {
98  if ((m_pGraph = pG) != 0) m_it = pG->registerArray(this);
99  }
100 }; // class AdjEntryArrayBase
101 
102 
104 
110 template<class T> class AdjEntryArray : private Array<T>, protected AdjEntryArrayBase {
111  T m_x;
112 
113 public:
117  AdjEntryArray(const Graph &G) : Array<T>(G.adjEntryArrayTableSize()), AdjEntryArrayBase(&G) { }
119 
123  AdjEntryArray(const Graph &G, const T &x) :
124  Array<T>(0,G.adjEntryArrayTableSize()-1,x), AdjEntryArrayBase(&G), m_x(x) { }
126 
130 
132  bool valid() const { return (Array<T>::low() <= Array<T>::high()); }
133 
135  const T &operator[](adjEntry adj) const {
136  OGDF_ASSERT(adj != 0 && adj->graphOf() == m_pGraph)
137  return Array<T>::operator [](adj->index());
138  }
139 
142  OGDF_ASSERT(adj != 0 && adj->graphOf() == m_pGraph)
143  return Array<T>::operator [](adj->index());
144  }
145 
147 
151  const T &operator[](int index) const {
152  return Array<T>::operator [](index);
153  }
154 
156 
160  T &operator[](int index) {
161  return Array<T>::operator [](index);
162  }
163 
167  m_x = A.m_x;
168  reregister(A.m_pGraph);
169  return *this;
170  }
171 
173  void init() {
175  }
176 
178  void init(const Graph &G) {
180  }
181 
183 
187  void init(const Graph &G, const T &x) {
189  }
190 
192  void fill(const T &x) {
193  int high = m_pGraph->maxAdjEntryIndex();
194  if(high >= 0)
195  Array<T>::fill(0,high,x);
196  }
197 
198 private:
199  virtual void enlargeTable(int newTableSize) {
200  Array<T>::grow(newTableSize-Array<T>::size(),m_x);
201  }
202 
203  virtual void reinit(int initTableSize) {
204  Array<T>::init(0,initTableSize-1,m_x);
205  }
206 
207  virtual void resetIndex(int newIndex, int oldIndex) {
208  Array<T>::operator [](newIndex) = Array<T>::operator [](oldIndex);
209  }
210 
211  virtual void disconnect() {
212  Array<T>::init();
213  m_pGraph = 0;
214  }
215 
217 
218 }; // class AdjEntryArray<T>
219 
220 
221 } // end namespace ogdf
222 
223 
224 #endif