Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

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 
42 namespace ogdf {
43 
44 
46 
54 template<class E>
55 class QueuePure : private SListPure<E> {
56 public:
58  using value_type = E;
60  using reference = E&;
62  using const_reference = const E&;
67 
69  QueuePure() { }
70 
72  QueuePure(std::initializer_list<E> initList) : SListPure<E>(initList) { }
73 
75  QueuePure(const QueuePure<E>& Q) : SListPure<E>(Q) { }
76 
78 
82 
84  ~QueuePure() { }
85 
90 
93  bool empty() const { return SListPure<E>::empty(); }
94 
96  const_reference top() const { return SListPure<E>::front(); }
97 
100 
103 
106 
108 
112 
116 
119 
122 
125 
127  const_iterator end() const { return SListPure<E>::end(); }
128 
130  const_iterator cend() const { return SListPure<E>::cend(); }
131 
134 
137 
139 
143 
148  return *this;
149  }
150 
152 
157  return *this;
158  }
159 
161  const SListPure<E>& getListPure() const { return *this; }
162 
164 
168 
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 
204 template<class E>
205 class Queue : private SList<E> {
206 public:
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 
240 
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 
252  reference top() { return SList<E>::front(); }
253 
256 
259 
261 
265 
269 
271  const_iterator begin() const { return SList<E>::begin(); }
272 
274  const_iterator cbegin() const { return SList<E>::cbegin(); }
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 
296 
301  return *this;
302  }
303 
305 
310  return *this;
311  }
312 
314  const SList<E>& getList() const { return *this; }
315 
317 
321 
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
351 template<class E>
352 void 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
357 template<class E>
358 void print(std::ostream& os, const Queue<E>& Q, char delim = ' ') {
359  print(os, Q.getList(), delim);
360 }
361 
362 // output operator
363 template<class E>
364 std::ostream& operator<<(std::ostream& os, const QueuePure<E>& Q) {
365  print(os, Q);
366  return os;
367 }
368 
369 template<class E>
370 std::ostream& operator<<(std::ostream& os, const Queue<E>& Q) {
371  print(os, Q);
372  return os;
373 }
374 
375 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::Queue::bottom
reference bottom()
Returns a reference to the back element.
Definition: Queue.h:258
ogdf::Queue::append
iterator append(const E &x)
Adds x at the end of queue.
Definition: Queue.h:324
ogdf::Queue::operator=
Queue< E > & operator=(Queue< E > &&Q)
Assignment operator (move semantics).
Definition: Queue.h:308
ogdf::Queue::clear
void clear()
Makes the queue empty.
Definition: Queue.h:343
ogdf::SListPure::backIterator
iterator backIterator()
Returns an iterator to the last element of the list.
Definition: SList.h:380
ogdf::Queue::emplace
iterator emplace(Args &&... args)
Adds a new element at the end of the queue.
Definition: Queue.h:331
ogdf::SListPure::front
const_reference front() const
Returns a reference to the first element.
Definition: SList.h:257
ogdf::Queue::top
reference top()
Returns a reference to the front element.
Definition: Queue.h:252
ogdf::SList::operator=
SList< E > & operator=(const SList< E > &L)
Assignment operator.
Definition: SList.h:893
ogdf::SListIteratorBase
Encapsulates a pointer to an ogdf::SList element.
Definition: SList.h:50
ogdf::SList
Singly linked lists (maintaining the length of the list).
Definition: SList.h:845
ogdf::Queue::cbegin
const_iterator cbegin() const
Returns a const iterator to the first element of the queue.
Definition: Queue.h:274
ogdf::QueuePure::operator=
QueuePure< E > & operator=(const QueuePure< E > &Q)
Assignment operator.
Definition: Queue.h:146
ogdf::Queue::top
const_reference top() const
Returns a reference to the front element.
Definition: Queue.h:249
ogdf::QueuePure::getListPure
const SListPure< E > & getListPure() const
Conversion to const SListPure.
Definition: Queue.h:161
ogdf::SListPure::clear
void clear()
Removes all elements from the list.
Definition: SList.h:567
ogdf::Queue::Queue
Queue(const Queue< E > &Q)
Constructs a queue that is a copy of Q.
Definition: Queue.h:225
ogdf::QueuePure::empty
bool empty() const
Returns true iff the queue is empty.
Definition: Queue.h:93
ogdf::Queue::end
iterator end()
Returns an iterator to one-past-last element of the queue.
Definition: Queue.h:277
OGDF_NEW_DELETE
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
Definition: memory.h:85
ogdf::QueuePure::emplace
iterator emplace(Args &&... args)
Adds a new element at the end of the queue.
Definition: Queue.h:178
ogdf::QueuePure::~QueuePure
~QueuePure()
Destruction.
Definition: Queue.h:84
ogdf::SListPure::begin
iterator begin()
Returns an iterator to the first element of the list.
Definition: SList.h:344
ogdf::SListPure::cend
const_iterator cend() const
Returns a const iterator to one-past-last element of the list.
Definition: SList.h:374
ogdf::SListPure::back
const_reference back() const
Returns a reference to the last element.
Definition: SList.h:275
ogdf::SListPure::empty
bool empty() const
Returns true iff the list is empty.
Definition: SList.h:238
ogdf::SListPure::emplaceBack
iterator emplaceBack(Args &&... args)
Adds a new element at the end of the list.
Definition: SList.h:496
ogdf::QueuePure::clear
void clear()
Makes the queue empty.
Definition: Queue.h:190
ogdf::QueuePure::operator=
QueuePure< E > & operator=(QueuePure< E > &&Q)
Assignment operator (move semantics).
Definition: Queue.h:155
ogdf::QueuePure::QueuePure
QueuePure()
Constructs an empty queue.
Definition: Queue.h:69
ogdf::QueuePure::append
iterator append(const E &x)
Adds x at the end of queue.
Definition: Queue.h:171
ogdf::QueuePure::bottom
const_reference bottom() const
Returns a reference to the back element.
Definition: Queue.h:102
ogdf::SListPure::end
iterator end()
Returns an iterator to one-past-last element of the list.
Definition: SList.h:362
ogdf::QueuePure::QueuePure
QueuePure(const QueuePure< E > &Q)
Constructs a queue that is a copy of Q.
Definition: Queue.h:75
ogdf::Queue::pop
E pop()
Removes front element and returns it.
Definition: Queue.h:336
backward::details::move
const T & move(const T &v)
Definition: backward.hpp:243
ogdf::SList::size
int size() const
Returns the number of elements in the list.
Definition: SList.h:880
SList.h
Declaration of singly linked lists and iterators.
ogdf::Queue::size
int size() const
Returns the number of elements in the queue.
Definition: Queue.h:246
ogdf::QueuePure::reference
E & reference
Provides a reference to an element stored in a queue.
Definition: Queue.h:60
ogdf::QueuePure::end
iterator end()
Returns an iterator to one-past-last element of the queue.
Definition: Queue.h:124
ogdf::SListPure
Singly linked lists.
Definition: SList.h:52
ogdf::QueuePure::value_type
E value_type
Represents the data type stored in a queue element.
Definition: Queue.h:58
ogdf::QueuePure::end
const_iterator end() const
Returns a const iterator to one-past-last element of the queue.
Definition: Queue.h:127
ogdf::operator<<
std::ostream & operator<<(std::ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
Definition: Array.h:983
ogdf::Queue::bottom
const_reference bottom() const
Returns a reference to the back element.
Definition: Queue.h:255
ogdf::Queue
The parameterized class Queue<E> implements list-based queues.
Definition: Queue.h:205
ogdf::Queue::Queue
Queue()
Constructs an empty queue.
Definition: Queue.h:219
ogdf::Queue::Queue
Queue(std::initializer_list< E > initList)
Constructs a queue and appends the elements in initList to it.
Definition: Queue.h:222
ogdf::Queue::begin
const_iterator begin() const
Returns a const iterator to the first element of the queue.
Definition: Queue.h:271
ogdf::SList::clear
void clear()
Removes all elements from the list.
Definition: SList.h:984
ogdf::Queue::cend
const_iterator cend() const
Returns a const iterator to one-past-last element of the queue.
Definition: Queue.h:283
ogdf::Queue::empty
bool empty() const
Returns true iff the queue is empty.
Definition: Queue.h:243
ogdf::Queue::begin
iterator begin()
Returns an iterator to the first element of the queue.
Definition: Queue.h:268
ogdf::QueuePure::top
reference top()
Returns a reference to the front element.
Definition: Queue.h:99
ogdf::SListPure::cbegin
const_iterator cbegin() const
Returns a const iterator to the first element of the list.
Definition: SList.h:356
ogdf::QueuePure::begin
const_iterator begin() const
Returns a const iterator to the first element of the queue.
Definition: Queue.h:118
ogdf::QueuePure::QueuePure
QueuePure(QueuePure< E > &&Q)
Constructs a queue containing the elements of Q (move semantics).
Definition: Queue.h:81
ogdf::QueuePure::const_reference
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
ogdf::QueuePure::cbegin
const_iterator cbegin() const
Returns a const iterator to the first element of the queue.
Definition: Queue.h:121
ogdf::QueuePure
Implementation of list-based queues.
Definition: Queue.h:55
std
Definition: GML.h:111
ogdf::QueuePure::bottom
reference bottom()
Returns a reference to the back element.
Definition: Queue.h:105
ogdf::SList::emplaceBack
iterator emplaceBack(Args &&... args)
Adds a new element at the end of the list.
Definition: SList.h:946
ogdf::print
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
ogdf::QueuePure::cend
const_iterator cend() const
Returns a const iterator to one-past-last element of the queue.
Definition: Queue.h:130
ogdf::QueuePure::QueuePure
QueuePure(std::initializer_list< E > initList)
Constructs a queue and appends the elements in initList to it.
Definition: Queue.h:72
ogdf::SListPure::pushBack
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition: SList.h:481
ogdf::Queue::~Queue
~Queue()
Destruction.
Definition: Queue.h:234
ogdf::Queue::end
const_iterator end() const
Returns a const iterator to one-past-last element of the queue.
Definition: Queue.h:280
ogdf::QueuePure::begin
iterator begin()
Returns an iterator to the first element of the queue.
Definition: Queue.h:115
ogdf::Queue::backIterator
iterator backIterator()
Returns an iterator to the last element of the queue.
Definition: Queue.h:286
ogdf::Queue::operator=
Queue< E > & operator=(const Queue< E > &Q)
Assignment operator.
Definition: Queue.h:299
ogdf::QueuePure::pop
E pop()
Removes front element and returns it.
Definition: Queue.h:183
ogdf::QueuePure::backIterator
const_iterator backIterator() const
Returns a const iterator to the last element of the queue.
Definition: Queue.h:136
ogdf::QueuePure::top
const_reference top() const
Returns a reference to the front element.
Definition: Queue.h:96
ogdf::Queue::backIterator
const_iterator backIterator() const
Returns a const iterator to the last element of the queue.
Definition: Queue.h:289
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:240
ogdf::SListPure::popFront
void popFront()
Removes the first element from the list.
Definition: SList.h:531
memory.h
Declaration of memory manager for allocating small pieces of memory.
ogdf::SListPure::operator=
SListPure< E > & operator=(const SListPure< E > &L)
Assignment operator.
Definition: SList.h:416
ogdf::SList::pushBack
SListIterator< E > pushBack(const E &x)
Adds element x at the end of the list.
Definition: SList.h:939
ogdf::Queue::getList
const SList< E > & getList() const
Conversion to const SList.
Definition: Queue.h:314
ogdf::QueuePure::backIterator
iterator backIterator()
Returns an iterator to the last element of the queue.
Definition: Queue.h:133
ogdf::Queue::Queue
Queue(Queue< E > &&Q)
Constructs a queue containing the elements of Q (move semantics).
Definition: Queue.h:231
ogdf::SList::popFront
void popFront()
Removes the first element from the list.
Definition: SList.h:965