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 
37 namespace ogdf {
38 
39 
41 
49 template<class E>
50 class QueuePure : private SListPure<E> {
51 public:
53  using value_type = E;
55  using reference = E&;
57  using const_reference = const E&;
62 
64  QueuePure() { }
65 
67  QueuePure(std::initializer_list<E> initList) : SListPure<E>(initList) { }
68 
70  QueuePure(const QueuePure<E>& Q) : SListPure<E>(Q) { }
71 
73 
77 
79  ~QueuePure() { }
80 
85 
88  bool empty() const { return SListPure<E>::empty(); }
89 
91  const_reference top() const { return SListPure<E>::front(); }
92 
95 
98 
101 
103 
107 
111 
114 
117 
120 
122  const_iterator end() const { return SListPure<E>::end(); }
123 
125  const_iterator cend() const { return SListPure<E>::cend(); }
126 
129 
132 
134 
138 
143  return *this;
144  }
145 
147 
152  return *this;
153  }
154 
156  const SListPure<E>& getListPure() const { return *this; }
157 
159 
163 
166  iterator append(const E& x) { return SListPure<E>::pushBack(x); }
167 
169 
172  template<class... Args>
173  iterator emplace(Args&&... args) {
174  return SListPure<E>::emplaceBack(std::forward<Args>(args)...);
175  }
176 
178  E pop() {
179  E x = top();
181  return x;
182  }
183 
186 
188 };
189 
191 
199 template<class E>
200 class Queue : private SList<E> {
201 public:
203  using value_type = E;
205  using reference = E&;
207  using const_reference = const E&;
212 
214  Queue() { }
215 
217  Queue(std::initializer_list<E> initList) : SList<E>(initList) { }
218 
220  Queue(const Queue<E>& Q) : SList<E>(Q) { }
221 
223 
226  Queue(Queue<E>&& Q) : SList<E>(std::move(Q)) { }
227 
229  ~Queue() { }
230 
235 
238  bool empty() const { return SList<E>::empty(); }
239 
241  int size() const { return SList<E>::size(); }
242 
244  const_reference top() const { return SList<E>::front(); }
245 
247  reference top() { return SList<E>::front(); }
248 
251 
254 
256 
260 
264 
266  const_iterator begin() const { return SList<E>::begin(); }
267 
269  const_iterator cbegin() const { return SList<E>::cbegin(); }
270 
272  iterator end() { return SList<E>::end(); }
273 
275  const_iterator end() const { return SList<E>::end(); }
276 
278  const_iterator cend() const { return SList<E>::cend(); }
279 
282 
285 
287 
291 
296  return *this;
297  }
298 
300 
305  return *this;
306  }
307 
309  const SList<E>& getList() const { return *this; }
310 
312 
316 
319  iterator append(const E& x) { return SList<E>::pushBack(x); }
320 
322 
325  template<class... Args>
326  iterator emplace(Args&&... args) {
327  return SList<E>::emplaceBack(std::forward<Args>(args)...);
328  }
329 
331  E pop() {
332  E x = top();
334  return x;
335  }
336 
338  void clear() { SList<E>::clear(); }
339 
341 
343 };
344 
345 // prints queue to output stream os using delimiter delim
346 template<class E>
347 void print(std::ostream& os, const QueuePure<E>& Q, char delim = ' ') {
348  print(os, Q.getListPure(), delim);
349 }
350 
351 // prints queue to output stream os using delimiter delim
352 template<class E>
353 void print(std::ostream& os, const Queue<E>& Q, char delim = ' ') {
354  print(os, Q.getList(), delim);
355 }
356 
357 // output operator
358 template<class E>
359 std::ostream& operator<<(std::ostream& os, const QueuePure<E>& Q) {
360  print(os, Q);
361  return os;
362 }
363 
364 template<class E>
365 std::ostream& operator<<(std::ostream& os, const Queue<E>& Q) {
366  print(os, Q);
367  return os;
368 }
369 
370 }
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ogdf::Queue::bottom
reference bottom()
Returns a reference to the back element.
Definition: Queue.h:253
ogdf::Queue::append
iterator append(const E &x)
Adds x at the end of queue.
Definition: Queue.h:319
ogdf::Queue::operator=
Queue< E > & operator=(Queue< E > &&Q)
Assignment operator (move semantics).
Definition: Queue.h:303
ogdf::Queue::clear
void clear()
Makes the queue empty.
Definition: Queue.h:338
ogdf::SListPure::backIterator
iterator backIterator()
Returns an iterator to the last element of the list.
Definition: SList.h:368
ogdf::Queue::emplace
iterator emplace(Args &&... args)
Adds a new element at the end of the queue.
Definition: Queue.h:326
ogdf::SListPure::front
const_reference front() const
Returns a reference to the first element.
Definition: SList.h:245
ogdf::Queue::top
reference top()
Returns a reference to the front element.
Definition: Queue.h:247
ogdf::SList::operator=
SList< E > & operator=(const SList< E > &L)
Assignment operator.
Definition: SList.h:881
ogdf::SListIteratorBase
Encapsulates a pointer to an ogdf::SList element.
Definition: SList.h:41
ogdf::SList
Singly linked lists (maintaining the length of the list).
Definition: SList.h:833
ogdf::Queue::cbegin
const_iterator cbegin() const
Returns a const iterator to the first element of the queue.
Definition: Queue.h:269
ogdf::QueuePure::operator=
QueuePure< E > & operator=(const QueuePure< E > &Q)
Assignment operator.
Definition: Queue.h:141
ogdf::Queue::top
const_reference top() const
Returns a reference to the front element.
Definition: Queue.h:244
ogdf::QueuePure::getListPure
const SListPure< E > & getListPure() const
Conversion to const SListPure.
Definition: Queue.h:156
ogdf::SListPure::clear
void clear()
Removes all elements from the list.
Definition: SList.h:555
ogdf::Queue::Queue
Queue(const Queue< E > &Q)
Constructs a queue that is a copy of Q.
Definition: Queue.h:220
ogdf::QueuePure::empty
bool empty() const
Returns true iff the queue is empty.
Definition: Queue.h:88
ogdf::Queue::end
iterator end()
Returns an iterator to one-past-last element of the queue.
Definition: Queue.h:272
OGDF_NEW_DELETE
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
Definition: memory.h:84
ogdf::QueuePure::emplace
iterator emplace(Args &&... args)
Adds a new element at the end of the queue.
Definition: Queue.h:173
ogdf::QueuePure::~QueuePure
~QueuePure()
Destruction.
Definition: Queue.h:79
ogdf::SListPure::begin
iterator begin()
Returns an iterator to the first element of the list.
Definition: SList.h:332
ogdf::SListPure::cend
const_iterator cend() const
Returns a const iterator to one-past-last element of the list.
Definition: SList.h:362
ogdf::SListPure::back
const_reference back() const
Returns a reference to the last element.
Definition: SList.h:263
ogdf::SListPure::empty
bool empty() const
Returns true iff the list is empty.
Definition: SList.h:226
ogdf::SListPure::emplaceBack
iterator emplaceBack(Args &&... args)
Adds a new element at the end of the list.
Definition: SList.h:484
ogdf::QueuePure::clear
void clear()
Makes the queue empty.
Definition: Queue.h:185
ogdf::QueuePure::operator=
QueuePure< E > & operator=(QueuePure< E > &&Q)
Assignment operator (move semantics).
Definition: Queue.h:150
ogdf::QueuePure::QueuePure
QueuePure()
Constructs an empty queue.
Definition: Queue.h:64
ogdf::QueuePure::append
iterator append(const E &x)
Adds x at the end of queue.
Definition: Queue.h:166
ogdf::QueuePure::bottom
const_reference bottom() const
Returns a reference to the back element.
Definition: Queue.h:97
ogdf::SListPure::end
iterator end()
Returns an iterator to one-past-last element of the list.
Definition: SList.h:350
ogdf::QueuePure::QueuePure
QueuePure(const QueuePure< E > &Q)
Constructs a queue that is a copy of Q.
Definition: Queue.h:70
ogdf::Queue::pop
E pop()
Removes front element and returns it.
Definition: Queue.h:331
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:868
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:241
ogdf::QueuePure::reference
E & reference
Provides a reference to an element stored in a queue.
Definition: Queue.h:55
ogdf::QueuePure::end
iterator end()
Returns an iterator to one-past-last element of the queue.
Definition: Queue.h:119
ogdf::SListPure
Singly linked lists.
Definition: SList.h:39
ogdf::QueuePure::value_type
E value_type
Represents the data type stored in a queue element.
Definition: Queue.h:53
ogdf::QueuePure::end
const_iterator end() const
Returns a const iterator to one-past-last element of the queue.
Definition: Queue.h:122
ogdf::operator<<
std::ostream & operator<<(std::ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
Definition: Array.h:978
ogdf::Queue::bottom
const_reference bottom() const
Returns a reference to the back element.
Definition: Queue.h:250
ogdf::Queue
The parameterized class Queue<E> implements list-based queues.
Definition: Queue.h:200
ogdf::Queue::Queue
Queue()
Constructs an empty queue.
Definition: Queue.h:214
ogdf::Queue::Queue
Queue(std::initializer_list< E > initList)
Constructs a queue and appends the elements in initList to it.
Definition: Queue.h:217
ogdf::Queue::begin
const_iterator begin() const
Returns a const iterator to the first element of the queue.
Definition: Queue.h:266
ogdf::SList::clear
void clear()
Removes all elements from the list.
Definition: SList.h:972
ogdf::Queue::cend
const_iterator cend() const
Returns a const iterator to one-past-last element of the queue.
Definition: Queue.h:278
ogdf::Queue::empty
bool empty() const
Returns true iff the queue is empty.
Definition: Queue.h:238
ogdf::Queue::begin
iterator begin()
Returns an iterator to the first element of the queue.
Definition: Queue.h:263
ogdf::QueuePure::top
reference top()
Returns a reference to the front element.
Definition: Queue.h:94
ogdf::SListPure::cbegin
const_iterator cbegin() const
Returns a const iterator to the first element of the list.
Definition: SList.h:344
ogdf::QueuePure::begin
const_iterator begin() const
Returns a const iterator to the first element of the queue.
Definition: Queue.h:113
ogdf::QueuePure::QueuePure
QueuePure(QueuePure< E > &&Q)
Constructs a queue containing the elements of Q (move semantics).
Definition: Queue.h:76
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:57
ogdf::QueuePure::cbegin
const_iterator cbegin() const
Returns a const iterator to the first element of the queue.
Definition: Queue.h:116
ogdf::QueuePure
Implementation of list-based queues.
Definition: Queue.h:50
std
Definition: GML.h:110
ogdf::QueuePure::bottom
reference bottom()
Returns a reference to the back element.
Definition: Queue.h:100
ogdf::SList::emplaceBack
iterator emplaceBack(Args &&... args)
Adds a new element at the end of the list.
Definition: SList.h:934
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:967
ogdf::QueuePure::cend
const_iterator cend() const
Returns a const iterator to one-past-last element of the queue.
Definition: Queue.h:125
ogdf::QueuePure::QueuePure
QueuePure(std::initializer_list< E > initList)
Constructs a queue and appends the elements in initList to it.
Definition: Queue.h:67
ogdf::SListPure::pushBack
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition: SList.h:469
ogdf::Queue::~Queue
~Queue()
Destruction.
Definition: Queue.h:229
ogdf::Queue::end
const_iterator end() const
Returns a const iterator to one-past-last element of the queue.
Definition: Queue.h:275
ogdf::QueuePure::begin
iterator begin()
Returns an iterator to the first element of the queue.
Definition: Queue.h:110
ogdf::Queue::backIterator
iterator backIterator()
Returns an iterator to the last element of the queue.
Definition: Queue.h:281
ogdf::Queue::operator=
Queue< E > & operator=(const Queue< E > &Q)
Assignment operator.
Definition: Queue.h:294
ogdf::QueuePure::pop
E pop()
Removes front element and returns it.
Definition: Queue.h:178
ogdf::QueuePure::backIterator
const_iterator backIterator() const
Returns a const iterator to the last element of the queue.
Definition: Queue.h:131
ogdf::QueuePure::top
const_reference top() const
Returns a reference to the front element.
Definition: Queue.h:91
ogdf::Queue::backIterator
const_iterator backIterator() const
Returns a const iterator to the last element of the queue.
Definition: Queue.h:284
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:233
ogdf::SListPure::popFront
void popFront()
Removes the first element from the list.
Definition: SList.h:519
ogdf::SListPure::operator=
SListPure< E > & operator=(const SListPure< E > &L)
Assignment operator.
Definition: SList.h:404
ogdf::SList::pushBack
SListIterator< E > pushBack(const E &x)
Adds element x at the end of the list.
Definition: SList.h:927
ogdf::Queue::getList
const SList< E > & getList() const
Conversion to const SList.
Definition: Queue.h:309
ogdf::QueuePure::backIterator
iterator backIterator()
Returns an iterator to the last element of the queue.
Definition: Queue.h:128
ogdf::Queue::Queue
Queue(Queue< E > &&Q)
Constructs a queue containing the elements of Q (move semantics).
Definition: Queue.h:226
ogdf::SList::popFront
void popFront()
Removes the first element from the list.
Definition: SList.h:953