Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

FaceArray.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/Array.h>
36 
37 
38 namespace ogdf {
39 
40 
42 
53 
54 public:
56 
58  FaceArrayBase() : m_pEmbedding(nullptr) { }
59 
61  explicit FaceArrayBase(const ConstCombinatorialEmbedding *pE) : m_pEmbedding(pE) {
62  if(pE) m_it = pE->registerArray(this);
63  }
64 
66  FaceArrayBase(FaceArrayBase &base) : m_it(base.m_it), m_pEmbedding(base.m_pEmbedding) {
67  if(m_pEmbedding) m_pEmbedding->moveRegisterArray(m_it, this);
68  base.m_pEmbedding = nullptr;
70  }
71 
72  // destructor, unregisters the array
73  virtual ~FaceArrayBase() {
74  if (m_pEmbedding) m_pEmbedding->unregisterArray(m_it);
75  }
76 
77  // event interface used by CombinatorialEmbedding
79  virtual void enlargeTable(int newTableSize) = 0;
81  virtual void reinit(int initTableSize) = 0;
82 
85  if (m_pEmbedding) m_pEmbedding->unregisterArray(m_it);
86  if ((m_pEmbedding = pE) != nullptr) m_it = pE->registerArray(this);
87  }
88 
91  if (m_pEmbedding) m_pEmbedding->unregisterArray(m_it);
92  m_pEmbedding = base.m_pEmbedding;
93  m_it = base.m_it;
94  base.m_pEmbedding = nullptr;
96  if (m_pEmbedding != nullptr)
97  m_pEmbedding->moveRegisterArray(m_it, this);
98  }
99 
100 }; // class FaceArrayBase
101 
102 
104 
113 template<class T> class FaceArray : private Array<T>, protected FaceArrayBase {
114  T m_x;
115 
116 public:
118  using key_type = face;
120  using value_type = T;
121 
126 
127 
129  FaceArray() : Array<T>(), FaceArrayBase() { }
130 
133  Array<T>(E.faceArrayTableSize()), FaceArrayBase(&E) { }
134 
136 
140  FaceArray(const ConstCombinatorialEmbedding &E, const T &x) :
141  Array<T>(0,E.faceArrayTableSize()-1,x), FaceArrayBase(&E), m_x(x) { }
142 
144 
148  FaceArray(const FaceArray<T> &A) : Array<T>(A), FaceArrayBase(A.m_pEmbedding), m_x(A.m_x) { }
149 
151 
154  FaceArray(FaceArray<T> &&A) : Array<T>(std::move(A)), FaceArrayBase(A), m_x(A.m_x) { }
155 
156 
162 
164  bool valid() const { return Array<T>::low() <= Array<T>::high(); }
165 
168  return m_pEmbedding;
169  }
170 
172  const T &operator[](face f) const {
173  OGDF_ASSERT(f != nullptr);
174  OGDF_ASSERT(f->embeddingOf() == m_pEmbedding);
175  return Array<T>::operator [](f->index());
176  }
177 
179  T &operator[](face f) {
180  OGDF_ASSERT(f != nullptr);
181  OGDF_ASSERT(f->embeddingOf() == m_pEmbedding);
182  return Array<T>::operator [](f->index());
183  }
184 
186  const T &operator()(face f) const {
187  OGDF_ASSERT(f != nullptr);
188  OGDF_ASSERT(f->embeddingOf() == m_pEmbedding);
189  return Array<T>::operator [](f->index());
190  }
191 
193  T &operator()(face f) {
194  OGDF_ASSERT(f != nullptr);
195  OGDF_ASSERT(f->embeddingOf() == m_pEmbedding);
196  return Array<T>::operator [](f->index());
197  }
198 
199 
201 
206 
208 
211  iterator begin() { return iterator(m_pEmbedding->firstFace(), this); }
212 
214 
218 
220 
224 
226 
229  iterator end() { return iterator(nullptr, this); }
230 
232 
235  const_iterator end() const { return const_iterator(nullptr, this); }
236 
238 
241  const_iterator cend() const { return const_iterator(nullptr, this); }
242 
244 
247  iterator rbegin() { return iterator(m_pEmbedding->lastFace(), this); }
248 
250 
254 
256 
260 
262 
265  iterator rend() { return iterator(nullptr, this); }
266 
268 
271  const_iterator rend() const { return const_iterator(nullptr, this); }
272 
274 
277  const_iterator crend() const { return const_iterator(nullptr, this); }
278 
279 
281 
286 
288  void init() {
289  Array<T>::init(); reregister(nullptr);
290  }
291 
295  }
296 
298 
302  void init(const ConstCombinatorialEmbedding &E, const T &x) {
303  Array<T>::init(0,E.faceArrayTableSize()-1, m_x = x); reregister(&E);
304  }
305 
307  void fill(const T &x) {
308  int high = m_pEmbedding->maxFaceIndex();
309  if(high >= 0)
310  Array<T>::fill(0,high,x);
311  }
312 
316  m_x = a.m_x;
318  return *this;
319  }
320 
322 
327  m_x = a.m_x;
328  moveRegister(a);
329  return *this;
330  }
331 
332 
334 
339 
340  static key_type findSuccKey(key_type key) { return key->succ(); }
341  static key_type findPredKey(key_type key) { return key->pred(); }
342 
344 
345 private:
346  virtual void enlargeTable(int newTableSize) {
347  Array<T>::resize(newTableSize,m_x);
348  }
349 
350  virtual void reinit(int initTableSize) {
351  Array<T>::init(0,initTableSize-1,m_x);
352  }
353 
355 
356 }; // class FaceArray<T>
357 
358 
359 } // end namespace ogdf
face lastFace() const
Returns the last face in the list of all faces.
const_iterator end() const
Returns a const iterator to one-past-last entry in the face array.
Definition: FaceArray.h:235
The parameterized class Array implements dynamic arrays of type E.
Definition: Array.h:56
static key_type findSuccKey(key_type key)
Definition: FaceArray.h:340
void init()
Reinitializes the array. Associates the array with no combinatorial embedding.
Definition: FaceArray.h:288
void fill(const T &x)
Sets all array elements to x.
Definition: FaceArray.h:307
FaceArrayBase()
Initializes a face array not associated with a combinatorial embedding.
Definition: FaceArray.h:58
void init()
Reinitializes the array to an array with empty index set.
Definition: Array.h:206
void init(const ConstCombinatorialEmbedding &E)
Reinitializes the array. Associates the array with E.
Definition: FaceArray.h:293
void moveRegister(FaceArrayBase &base)
Moves array registration from base to this array.
Definition: FaceArray.h:90
const_iterator cend() const
Returns a const iterator to one-past-last entry in the face array.
Definition: FaceArray.h:241
INDEX high() const
Returns the maximal array index.
Definition: Array.h:131
Combinatorial embeddings of planar graphs.
const T & operator[](face f) const
Returns a reference to the element with index f.
Definition: FaceArray.h:172
face pred() const
Returns the predecessor in the list of all faces.
FaceArray(const ConstCombinatorialEmbedding &E, const T &x)
Constructs a face array associated with E.
Definition: FaceArray.h:140
const_iterator crend() const
Returns a const iterator to one-before-first entry in the face array.
Definition: FaceArray.h:277
void init(const ConstCombinatorialEmbedding &E, const T &x)
Reinitializes the array. Associates the array with E.
Definition: FaceArray.h:302
Declaration of CombinatorialEmbedding and face.
const T & operator()(face f) const
Returns a reference to the element with index f.
Definition: FaceArray.h:186
bool * iterator
Provides a random-access iterator that can read or modify any element in an array.
Definition: Array.h:71
const bool * const_iterator
Provides a random-access iterator that can read a const element in an array.
Definition: Array.h:69
ListIterator< FaceArrayBase * > registerArray(FaceArrayBase *pFaceArray) const
Registers the face array pFaceArray.
FaceArray(const FaceArray< T > &A)
Constructs an face array that is a copy of A.
Definition: FaceArray.h:148
Declaration and implementation of Array class and Array algorithms.
bool valid() const
Returns true iff the array is associated with a combinatorial embedding.
Definition: FaceArray.h:164
virtual void enlargeTable(int newTableSize)=0
Virtual function called when table size has to be enlarged.
void moveRegisterArray(ListIterator< FaceArrayBase *> it, FaceArrayBase *pFaceArray) const
Move the registration it of a node array to pFaceArray (used with move semantics for face arrays)...
const_iterator crbegin() const
Returns a const iterator to the last entry in the face array.
Definition: FaceArray.h:259
const_iterator rbegin() const
Returns a const iterator to the last entry in the face array.
Definition: FaceArray.h:253
Dynamic arrays indexed with faces of a combinatorial embedding.
bool value_type
Represents the data type stored in an array element.
Definition: Array.h:63
T & operator()(face f)
Returns a reference to the element with index f.
Definition: FaceArray.h:193
T m_x
The default value for array elements.
Definition: FaceArray.h:114
const_iterator rend() const
Returns a const iterator to one-before-first entry in the face array.
Definition: FaceArray.h:271
void reregister(const ConstCombinatorialEmbedding *pE)
Associates the array with a new combinatorial embedding.
Definition: FaceArray.h:84
FaceElement * face
int faceArrayTableSize() const
Returns the table size of face arrays associated with this embedding.
Faces in a combinatorial embedding.
const ConstCombinatorialEmbedding * embeddingOf() const
Returns a pointer to the associated combinatorial embedding.
Definition: FaceArray.h:167
FaceArray< T > & operator=(FaceArray< T > &&a)
Assignment operator (move semantics).
Definition: FaceArray.h:325
Encapsulates a pointer to a list element.
Definition: List.h:41
#define OGDF_NEW_DELETE
Makes the class use OGDF&#39;s memory allocator.
Definition: memory.h:84
FaceArray(FaceArray< T > &&A)
Constructs a face array containing the elements of A (move semantics).
Definition: FaceArray.h:154
const T & move(const T &v)
Definition: backward.hpp:243
virtual void reinit(int initTableSize)
Virtual function called when table has to be reinitialized.
Definition: FaceArray.h:350
FaceArray()
Constructs an empty face array associated with no combinatorial embedding.
Definition: FaceArray.h:129
void unregisterArray(ListIterator< FaceArrayBase *> it) const
Unregisters the face array identified by it.
static key_type findPredKey(key_type key)
Definition: FaceArray.h:341
iterator rend()
Returns an iterator to one-before-first entry in the face array.
Definition: FaceArray.h:265
void resize(INDEX newSize, const E &x)
Resizes (enlarges or shrinks) the array to hold newSize elements and sets new elements to x...
Definition: Array.h:274
FaceArrayBase(FaceArrayBase &base)
Moves face array base to this face array.
Definition: FaceArray.h:66
const_iterator cbegin() const
Returns a const iterator to the first entry in the face array.
Definition: FaceArray.h:223
iterator rbegin()
Returns an iterator to the last entry in the face array.
Definition: FaceArray.h:247
ListIterator< FaceArrayBase * > m_it
Pointer to list element in the list of all registered face arrays which references this array...
Definition: FaceArray.h:52
T & operator[](face f)
Returns a reference to the element with index f.
Definition: FaceArray.h:179
FaceArray(const ConstCombinatorialEmbedding &E)
Constructs a face array associated with E.
Definition: FaceArray.h:132
virtual void reinit(int initTableSize)=0
Virtual function called when table has to be reinitialized.
Array< E, INDEX > & operator=(const Array< E, INDEX > &A)
Assignment operator.
Definition: Array.h:284
const_reference operator[](INDEX i) const
Returns a reference to the element at position i.
Definition: Array.h:140
const ConstCombinatorialEmbedding * m_pEmbedding
The associated combinatorial embedding.
Definition: FaceArray.h:55
void fill(const E &x)
Sets all elements to x.
Definition: Array.h:235
int index() const
Returns the index of the face.
The namespace for all OGDF objects.
virtual void enlargeTable(int newTableSize)
Virtual function called when table size has to be enlarged.
Definition: FaceArray.h:346
const_iterator begin() const
Returns a const iterator to the first entry in the face array.
Definition: FaceArray.h:217
virtual ~FaceArrayBase()
Definition: FaceArray.h:73
int maxFaceIndex() const
Returns the largest used face index.
face firstFace() const
Returns the first face in the list of all faces.
INDEX low() const
Returns the minimal array index.
Definition: Array.h:128
FaceArray< T > & operator=(const FaceArray< T > &a)
Assignment operator.
Definition: FaceArray.h:314
FaceArrayBase(const ConstCombinatorialEmbedding *pE)
Initializes a face array associated with pE.
Definition: FaceArray.h:61
face succ() const
Returns the successor in the list of all faces.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:41
iterator begin()
Returns an iterator to the first entry in the face array.
Definition: FaceArray.h:211
iterator end()
Returns an iterator to one-past-last entry in the face array.
Definition: FaceArray.h:229
Abstract base class for face arrays.
Definition: FaceArray.h:47