Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
Queue.h
Go to the documentation of this file.
1
33#pragma once
34
35#include <ogdf/basic/SList.h>
36#include <ogdf/basic/memory.h>
37
38#include <initializer_list>
39#include <iosfwd>
40#include <utility>
41
42namespace ogdf {
43
44
46
54template<class E>
55class QueuePure : private SListPure<E> {
56public:
58 using value_type = E;
60 using reference = E&;
62 using const_reference = const E&;
67
70
72 QueuePure(std::initializer_list<E> initList) : SListPure<E>(initList) { }
73
75 QueuePure(const QueuePure<E>& Q) : SListPure<E>(Q) { }
76
78
81 QueuePure(QueuePure<E>&& Q) : SListPure<E>(std::move(Q)) { }
82
85
91
93 bool empty() const { return SListPure<E>::empty(); }
94
97
100
103
106
108
113
116
119
122
125
128
131
134
137
139
144
148 return *this;
149 }
150
152
156 SListPure<E>::operator=(std::move(Q));
157 return *this;
158 }
159
161 const SListPure<E>& getListPure() const { return *this; }
162
164
169
171 iterator append(const E& x) { return SListPure<E>::pushBack(x); }
172
174
177 template<class... Args>
178 iterator emplace(Args&&... args) {
179 return SListPure<E>::emplaceBack(std::forward<Args>(args)...);
180 }
181
183 E pop() {
184 E x = top();
186 return x;
187 }
188
191
193};
194
196
204template<class E>
205class Queue : private SList<E> {
206public:
208 using value_type = E;
210 using reference = E&;
212 using const_reference = const E&;
217
219 Queue() { }
220
222 Queue(std::initializer_list<E> initList) : SList<E>(initList) { }
223
225 Queue(const Queue<E>& Q) : SList<E>(Q) { }
226
228
231 Queue(Queue<E>&& Q) : SList<E>(std::move(Q)) { }
232
234 ~Queue() { }
235
241
243 bool empty() const { return SList<E>::empty(); }
244
246 int size() const { return SList<E>::size(); }
247
249 const_reference top() const { return SList<E>::front(); }
250
253
256
259
261
266
269
272
275
277 iterator end() { return SList<E>::end(); }
278
280 const_iterator end() const { return SList<E>::end(); }
281
283 const_iterator cend() const { return SList<E>::cend(); }
284
287
290
292
297
301 return *this;
302 }
303
305
309 SList<E>::operator=(std::move(Q));
310 return *this;
311 }
312
314 const SList<E>& getList() const { return *this; }
315
317
322
324 iterator append(const E& x) { return SList<E>::pushBack(x); }
325
327
330 template<class... Args>
331 iterator emplace(Args&&... args) {
332 return SList<E>::emplaceBack(std::forward<Args>(args)...);
333 }
334
336 E pop() {
337 E x = top();
339 return x;
340 }
341
343 void clear() { SList<E>::clear(); }
344
346
348};
349
350// prints queue to output stream os using delimiter delim
351template<class E>
352void print(std::ostream& os, const QueuePure<E>& Q, char delim = ' ') {
353 print(os, Q.getListPure(), delim);
354}
355
356// prints queue to output stream os using delimiter delim
357template<class E>
358void print(std::ostream& os, const Queue<E>& Q, char delim = ' ') {
359 print(os, Q.getList(), delim);
360}
361
362// output operator
363template<class E>
364std::ostream& operator<<(std::ostream& os, const QueuePure<E>& Q) {
365 print(os, Q);
366 return os;
367}
368
369template<class E>
370std::ostream& operator<<(std::ostream& os, const Queue<E>& Q) {
371 print(os, Q);
372 return os;
373}
374
375}
Declaration of singly linked lists and iterators.
The parameterized class Queue<E> implements list-based queues.
Definition Queue.h:205
Queue()
Constructs an empty queue.
Definition Queue.h:219
const_reference bottom() const
Returns a reference to the back element.
Definition Queue.h:255
Queue(const Queue< E > &Q)
Constructs a queue that is a copy of Q.
Definition Queue.h:225
iterator backIterator()
Returns an iterator to the last element of the queue.
Definition Queue.h:286
~Queue()
Destruction.
Definition Queue.h:234
const_iterator cbegin() const
Returns a const iterator to the first element of the queue.
Definition Queue.h:274
Queue(std::initializer_list< E > initList)
Constructs a queue and appends the elements in initList to it.
Definition Queue.h:222
const_iterator begin() const
Returns a const iterator to the first element of the queue.
Definition Queue.h:271
iterator end()
Returns an iterator to one-past-last element of the queue.
Definition Queue.h:277
iterator begin()
Returns an iterator to the first element of the queue.
Definition Queue.h:268
int size() const
Returns the number of elements in the queue.
Definition Queue.h:246
E & reference
Provides a reference to an element stored in a queue.
Definition Queue.h:210
const E & const_reference
Provides a reference to a const element stored in a queue for reading and performing const operations...
Definition Queue.h:212
void clear()
Makes the queue empty.
Definition Queue.h:343
const_iterator backIterator() const
Returns a const iterator to the last element of the queue.
Definition Queue.h:289
E pop()
Removes front element and returns it.
Definition Queue.h:336
iterator emplace(Args &&... args)
Adds a new element at the end of the queue.
Definition Queue.h:331
reference top()
Returns a reference to the front element.
Definition Queue.h:252
Queue(Queue< E > &&Q)
Constructs a queue containing the elements of Q (move semantics).
Definition Queue.h:231
const_iterator end() const
Returns a const iterator to one-past-last element of the queue.
Definition Queue.h:280
const_iterator cend() const
Returns a const iterator to one-past-last element of the queue.
Definition Queue.h:283
bool empty() const
Returns true iff the queue is empty.
Definition Queue.h:243
Queue< E > & operator=(const Queue< E > &Q)
Assignment operator.
Definition Queue.h:299
const_reference top() const
Returns a reference to the front element.
Definition Queue.h:249
iterator append(const E &x)
Adds x at the end of queue.
Definition Queue.h:324
reference bottom()
Returns a reference to the back element.
Definition Queue.h:258
Queue< E > & operator=(Queue< E > &&Q)
Assignment operator (move semantics).
Definition Queue.h:308
const SList< E > & getList() const
Conversion to const SList.
Definition Queue.h:314
E value_type
Represents the data type stored in a queue element.
Definition Queue.h:208
Implementation of list-based queues.
Definition Queue.h:55
void clear()
Makes the queue empty.
Definition Queue.h:190
reference top()
Returns a reference to the front element.
Definition Queue.h:99
~QueuePure()
Destruction.
Definition Queue.h:84
iterator end()
Returns an iterator to one-past-last element of the queue.
Definition Queue.h:124
const_iterator cend() const
Returns a const iterator to one-past-last element of the queue.
Definition Queue.h:130
iterator emplace(Args &&... args)
Adds a new element at the end of the queue.
Definition Queue.h:178
bool empty() const
Returns true iff the queue is empty.
Definition Queue.h:93
const E & const_reference
Provides a reference to a const element stored in a queue for reading and performing const operations...
Definition Queue.h:62
iterator append(const E &x)
Adds x at the end of queue.
Definition Queue.h:171
E pop()
Removes front element and returns it.
Definition Queue.h:183
iterator begin()
Returns an iterator to the first element of the queue.
Definition Queue.h:115
QueuePure(std::initializer_list< E > initList)
Constructs a queue and appends the elements in initList to it.
Definition Queue.h:72
reference bottom()
Returns a reference to the back element.
Definition Queue.h:105
E & reference
Provides a reference to an element stored in a queue.
Definition Queue.h:60
QueuePure()
Constructs an empty queue.
Definition Queue.h:69
QueuePure< E > & operator=(QueuePure< E > &&Q)
Assignment operator (move semantics).
Definition Queue.h:155
const_iterator end() const
Returns a const iterator to one-past-last element of the queue.
Definition Queue.h:127
QueuePure< E > & operator=(const QueuePure< E > &Q)
Assignment operator.
Definition Queue.h:146
const_iterator cbegin() const
Returns a const iterator to the first element of the queue.
Definition Queue.h:121
QueuePure(QueuePure< E > &&Q)
Constructs a queue containing the elements of Q (move semantics).
Definition Queue.h:81
const_reference bottom() const
Returns a reference to the back element.
Definition Queue.h:102
QueuePure(const QueuePure< E > &Q)
Constructs a queue that is a copy of Q.
Definition Queue.h:75
iterator backIterator()
Returns an iterator to the last element of the queue.
Definition Queue.h:133
E value_type
Represents the data type stored in a queue element.
Definition Queue.h:58
const SListPure< E > & getListPure() const
Conversion to const SListPure.
Definition Queue.h:161
const_iterator backIterator() const
Returns a const iterator to the last element of the queue.
Definition Queue.h:136
const_reference top() const
Returns a reference to the front element.
Definition Queue.h:96
const_iterator begin() const
Returns a const iterator to the first element of the queue.
Definition Queue.h:118
Singly linked lists (maintaining the length of the list).
Definition SList.h:845
iterator emplaceBack(Args &&... args)
Adds a new element at the end of the list.
Definition SList.h:946
void clear()
Removes all elements from the list.
Definition SList.h:984
int size() const
Returns the number of elements in the list.
Definition SList.h:880
void popFront()
Removes the first element from the list.
Definition SList.h:965
SList< E > & operator=(const SList< E > &L)
Assignment operator.
Definition SList.h:893
SListIterator< E > pushBack(const E &x)
Adds element x at the end of the list.
Definition SList.h:939
Encapsulates a pointer to an ogdf::SList element.
Definition SList.h:104
Singly linked lists.
Definition SList.h:191
iterator backIterator()
Returns an iterator to the last element of the list.
Definition SList.h:380
void clear()
Removes all elements from the list.
Definition SList.h:567
iterator end()
Returns an iterator to one-past-last element of the list.
Definition SList.h:362
const_iterator cbegin() const
Returns a const iterator to the first element of the list.
Definition SList.h:356
const_iterator cend() const
Returns a const iterator to one-past-last element of the list.
Definition SList.h:374
bool empty() const
Returns true iff the list is empty.
Definition SList.h:238
iterator emplaceBack(Args &&... args)
Adds a new element at the end of the list.
Definition SList.h:496
SListPure< E > & operator=(const SListPure< E > &L)
Assignment operator.
Definition SList.h:416
const_reference front() const
Returns a reference to the first element.
Definition SList.h:257
const_reference back() const
Returns a reference to the last element.
Definition SList.h:275
iterator begin()
Returns an iterator to the first element of the list.
Definition SList.h:344
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition SList.h:481
void popFront()
Removes the first element from the list.
Definition SList.h:531
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
Definition memory.h:85
Declaration of memory manager for allocating small pieces of memory.
The namespace for all OGDF objects.
std::ostream & operator<<(std::ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
Definition Array.h:983
void print(std::ostream &os, const Array< E, INDEX > &a, char delim=' ')
Prints array a to output stream os using delimiter delim.
Definition Array.h:972
Definition GML.h:111