Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
FaceArray.h
Go to the documentation of this file.
1
32#pragma once
33
34#include <ogdf/basic/Array.h>
36
37namespace ogdf {
38
39
41
52
53public:
55
58
61 if (pE) {
62 m_it = pE->registerArray(this);
63 }
64 }
65
74
75 // destructor, unregisters the array
76 virtual ~FaceArrayBase() {
77 if (m_pEmbedding) {
79 }
80 }
81
82 // event interface used by CombinatorialEmbedding
84 virtual void enlargeTable(int newTableSize) = 0;
86 virtual void reinit(int initTableSize) = 0;
87
90 if (m_pEmbedding) {
92 }
93 if ((m_pEmbedding = pE) != nullptr) {
94 m_it = pE->registerArray(this);
95 }
96 }
97
100 if (m_pEmbedding) {
102 }
103 m_pEmbedding = base.m_pEmbedding;
104 m_it = base.m_it;
105 base.m_pEmbedding = nullptr;
107 if (m_pEmbedding != nullptr) {
109 }
110 }
111};
112
114
125template<class T>
126class FaceArray : private Array<T>, protected FaceArrayBase {
127 T m_x;
128
129public:
131 using key_type = face;
133 using value_type = T;
134
139
142
145 : Array<T>(E.faceArrayTableSize()), FaceArrayBase(&E) { }
146
148
153 : Array<T>(0, E.faceArrayTableSize() - 1, x), FaceArrayBase(&E), m_x(x) { }
154
156
161
163
167
173
175 bool valid() const { return Array<T>::low() <= Array<T>::high(); }
176
179
181 const T& operator[](face f) const {
182 OGDF_ASSERT(f != nullptr);
183 OGDF_ASSERT(f->embeddingOf() == m_pEmbedding);
184 return Array<T>::operator[](f->index());
185 }
186
189 OGDF_ASSERT(f != nullptr);
190 OGDF_ASSERT(f->embeddingOf() == m_pEmbedding);
191 return Array<T>::operator[](f->index());
192 }
193
195 const T& operator()(face f) const {
196 OGDF_ASSERT(f != nullptr);
197 OGDF_ASSERT(f->embeddingOf() == m_pEmbedding);
198 return Array<T>::operator[](f->index());
199 }
200
203 OGDF_ASSERT(f != nullptr);
204 OGDF_ASSERT(f->embeddingOf() == m_pEmbedding);
205 return Array<T>::operator[](f->index());
206 }
207
209
214
216
220
222
226
228
232
234
237 iterator end() { return iterator(nullptr, this); }
238
240
243 const_iterator end() const { return const_iterator(nullptr, this); }
244
246
249 const_iterator cend() const { return const_iterator(nullptr, this); }
250
252
257
259 void init() {
261 reregister(nullptr);
262 }
263
269
271
275 void init(const ConstCombinatorialEmbedding& E, const T& x) {
276 Array<T>::init(0, E.faceArrayTableSize() - 1, m_x = x);
277 reregister(&E);
278 }
279
281 void fill(const T& x) {
283 if (high >= 0) {
284 Array<T>::fill(0, high, x);
285 }
286 }
287
291 m_x = a.m_x;
293 return *this;
294 }
295
297
301 Array<T>::operator=(std::move(a));
302 m_x = a.m_x;
303 moveRegister(a);
304 return *this;
305 }
306
308
313
314 static key_type findSuccKey(key_type key) { return key->succ(); }
315
316 static key_type findPredKey(key_type key) { return key->pred(); }
317
319
320private:
322
323 virtual void reinit(int initTableSize) { Array<T>::init(0, initTableSize - 1, m_x); }
324
326};
327
328}
Declaration and implementation of Array class and Array algorithms.
Declaration of CombinatorialEmbedding and face.
The parameterized class Array implements dynamic arrays of type E.
Definition Array.h:214
const_reference operator[](INDEX i) const
Returns a reference to the element at position i.
Definition Array.h:303
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:437
INDEX high() const
Returns the maximal array index.
Definition Array.h:294
void init()
Reinitializes the array to an array with empty index set.
Definition Array.h:367
void fill(const E &x)
Sets all elements to x.
Definition Array.h:396
Array< E, INDEX > & operator=(const Array< E, INDEX > &A)
Assignment operator.
Definition Array.h:447
INDEX low() const
Returns the minimal array index.
Definition Array.h:291
Combinatorial embeddings of planar graphs.
face firstFace() const
Returns the first face in the list of all faces.
int faceArrayTableSize() const
Returns the table size of face arrays associated with this embedding.
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).
ListIterator< FaceArrayBase * > registerArray(FaceArrayBase *pFaceArray) const
Registers the face array pFaceArray.
int maxFaceIndex() const
Returns the largest used face index.
void unregisterArray(ListIterator< FaceArrayBase * > it) const
Unregisters the face array identified by it.
Abstract base class for face arrays.
Definition FaceArray.h:46
virtual void reinit(int initTableSize)=0
Virtual function called when table has to be reinitialized.
virtual void enlargeTable(int newTableSize)=0
Virtual function called when table size has to be enlarged.
void moveRegister(FaceArrayBase &base)
Moves array registration from base to this array.
Definition FaceArray.h:99
virtual ~FaceArrayBase()
Definition FaceArray.h:76
ListIterator< FaceArrayBase * > m_it
Pointer to list element in the list of all registered face arrays which references this array.
Definition FaceArray.h:51
FaceArrayBase(const ConstCombinatorialEmbedding *pE)
Initializes a face array associated with pE.
Definition FaceArray.h:60
FaceArrayBase(FaceArrayBase &base)
Moves face array base to this face array.
Definition FaceArray.h:67
const ConstCombinatorialEmbedding * m_pEmbedding
The associated combinatorial embedding.
Definition FaceArray.h:54
FaceArrayBase()
Initializes a face array not associated with a combinatorial embedding.
Definition FaceArray.h:57
void reregister(const ConstCombinatorialEmbedding *pE)
Associates the array with a new combinatorial embedding.
Definition FaceArray.h:89
Dynamic arrays indexed with faces of a combinatorial embedding.
Definition FaceArray.h:126
FaceArray(const FaceArray< T > &A)
Constructs an face array that is a copy of A.
Definition FaceArray.h:160
T & operator[](face f)
Returns a reference to the element with index f.
Definition FaceArray.h:188
virtual void enlargeTable(int newTableSize)
Virtual function called when table size has to be enlarged.
Definition FaceArray.h:321
FaceArray(const ConstCombinatorialEmbedding &E, const T &x)
Constructs a face array associated with E.
Definition FaceArray.h:152
const_iterator begin() const
Returns a const iterator to the first entry in the face array.
Definition FaceArray.h:225
FaceArray(FaceArray< T > &&A)
Constructs a face array containing the elements of A (move semantics).
Definition FaceArray.h:166
FaceArray< T > & operator=(const FaceArray< T > &a)
Assignment operator.
Definition FaceArray.h:289
void init(const ConstCombinatorialEmbedding &E, const T &x)
Reinitializes the array. Associates the array with E.
Definition FaceArray.h:275
const ConstCombinatorialEmbedding * embeddingOf() const
Returns a pointer to the associated combinatorial embedding.
Definition FaceArray.h:178
const T & operator()(face f) const
Returns a reference to the element with index f.
Definition FaceArray.h:195
static key_type findPredKey(key_type key)
Definition FaceArray.h:316
bool valid() const
Returns true iff the array is associated with a combinatorial embedding.
Definition FaceArray.h:175
void init(const ConstCombinatorialEmbedding &E)
Reinitializes the array. Associates the array with E.
Definition FaceArray.h:265
iterator end()
Returns an iterator to one-past-last entry in the face array.
Definition FaceArray.h:237
internal::GraphArrayConstIterator< FaceArray< T > > const_iterator
The type for face array const iterators.
Definition FaceArray.h:138
iterator begin()
Returns an iterator to the first entry in the face array.
Definition FaceArray.h:219
const T & operator[](face f) const
Returns a reference to the element with index f.
Definition FaceArray.h:181
internal::GraphArrayIterator< FaceArray< T > > iterator
The type for face array iterators.
Definition FaceArray.h:136
T value_type
The type for array entries.
Definition FaceArray.h:133
FaceArray(const ConstCombinatorialEmbedding &E)
Constructs a face array associated with E.
Definition FaceArray.h:144
const_iterator end() const
Returns a const iterator to one-past-last entry in the face array.
Definition FaceArray.h:243
virtual void reinit(int initTableSize)
Virtual function called when table has to be reinitialized.
Definition FaceArray.h:323
const_iterator cend() const
Returns a const iterator to one-past-last entry in the face array.
Definition FaceArray.h:249
FaceArray()
Constructs an empty face array associated with no combinatorial embedding.
Definition FaceArray.h:141
FaceArray< T > & operator=(FaceArray< T > &&a)
Assignment operator (move semantics).
Definition FaceArray.h:300
static key_type findSuccKey(key_type key)
Definition FaceArray.h:314
void init()
Reinitializes the array. Associates the array with no combinatorial embedding.
Definition FaceArray.h:259
T & operator()(face f)
Returns a reference to the element with index f.
Definition FaceArray.h:202
T m_x
The default value for array elements.
Definition FaceArray.h:127
void fill(const T &x)
Sets all array elements to x.
Definition FaceArray.h:281
const_iterator cbegin() const
Returns a const iterator to the first entry in the face array.
Definition FaceArray.h:231
Faces in a combinatorial embedding.
face pred() const
Returns the predecessor in the list of all faces.
face succ() const
Returns the successor in the list of all faces.
Encapsulates a pointer to a list element.
Definition List.h:103
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:41
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
Definition memory.h:84
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.
FaceElement * face
Definition GML.h:110