Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

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 
102 
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 
249 
251  void init() {
252  Array<T>::init(); reregister(nullptr);
253  }
254 
258  }
259 
261 
265  void init(const ConstCombinatorialEmbedding &E, const T &x) {
266  Array<T>::init(0,E.faceArrayTableSize()-1, m_x = x); reregister(&E);
267  }
268 
270  void fill(const T &x) {
271  int high = m_pEmbedding->maxFaceIndex();
272  if(high >= 0)
273  Array<T>::fill(0,high,x);
274  }
275 
279  m_x = a.m_x;
281  return *this;
282  }
283 
285 
290  m_x = a.m_x;
291  moveRegister(a);
292  return *this;
293  }
294 
295 
297 
302 
303  static key_type findSuccKey(key_type key) { return key->succ(); }
304  static key_type findPredKey(key_type key) { return key->pred(); }
305 
307 
308 private:
309  virtual void enlargeTable(int newTableSize) {
310  Array<T>::resize(newTableSize,m_x);
311  }
312 
313  virtual void reinit(int initTableSize) {
314  Array<T>::init(0,initTableSize-1,m_x);
315  }
316 
318 };
319 
320 }
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:200
static key_type findSuccKey(key_type key)
Definition: FaceArray.h:303
void init()
Reinitializes the array. Associates the array with no combinatorial embedding.
Definition: FaceArray.h:251
void fill(const T &x)
Sets all array elements to x.
Definition: FaceArray.h:270
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:354
void init(const ConstCombinatorialEmbedding &E)
Reinitializes the array. Associates the array with E.
Definition: FaceArray.h:256
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:279
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
Definition: GML.h:110
void init(const ConstCombinatorialEmbedding &E, const T &x)
Reinitializes the array. Associates the array with E.
Definition: FaceArray.h:265
Declaration of CombinatorialEmbedding and face.
const T & operator()(face f) const
Returns a reference to the element with index f.
Definition: FaceArray.h:186
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)...
Dynamic arrays indexed with faces of a combinatorial embedding.
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
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
ArrayIterator< ogdf::NodeElement > iterator
Provides a random-access iterator that can read or modify any element in an array.
Definition: Array.h:215
FaceArray< T > & operator=(FaceArray< T > &&a)
Assignment operator (move semantics).
Definition: FaceArray.h:288
Class for the representation of nodes.
Definition: Graph_d.h:169
Encapsulates a pointer to a list element.
Definition: List.h:42
#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:313
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:304
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:422
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
ArrayConstIterator< ogdf::NodeElement > const_iterator
Provides a random-access iterator that can read a const element in an array.
Definition: Array.h:213
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:432
const_reference operator[](INDEX i) const
Returns a reference to the element at position i.
Definition: Array.h:288
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:383
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:309
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:276
FaceArray< T > & operator=(const FaceArray< T > &a)
Assignment operator.
Definition: FaceArray.h:277
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