Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

Queue.h
Go to the documentation of this file.
1 
33 #pragma once
34 
35 #include <ogdf/basic/SList.h>
36 
37 
38 namespace ogdf {
39 
40 
42 
50 template<class E> 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 
86 
88  bool empty() const { return SListPure<E>::empty(); }
89 
91  const_reference top() const {
92  return SListPure<E>::front();
93  }
94 
97  return SListPure<E>::front();
98  }
99 
102  return SListPure<E>::back();
103  }
104 
107  return SListPure<E>::back();
108  }
109 
111 
116 
119 
122 
125 
128 
130  const_iterator end() const { return SListPure<E>::end(); }
131 
133  const_iterator cend() const { return SListPure<E>::cend(); }
134 
137 
140 
142 
147 
151  return *this;
152  }
153 
155 
160  return *this;
161  }
162 
164  const SListPure<E> &getListPure() const { return *this; }
165 
167 
172 
174  iterator append(const E &x) {
175  return SListPure<E>::pushBack(x);
176  }
177 
179 
182  template<class ... Args>
183  iterator emplace(Args && ... args) {
184  return SListPure<E>::emplaceBack(std::forward<Args>(args)...);
185  }
186 
188  E pop() {
189  E x = top();
191  return x;
192  }
193 
196 
198 };
199 
201 
209 template<class E> class Queue : private SList<E> {
210 public:
212  using value_type = E;
214  using reference = E&;
216  using const_reference = const E &;
221 
223  Queue() { }
224 
226  Queue(std::initializer_list<E> initList) : SList<E>(initList) { }
227 
229  Queue(const Queue<E> &Q) : SList<E>(Q) { }
230 
232 
235  Queue(Queue<E> &&Q) : SList<E>(std::move(Q)) { }
236 
238  ~Queue() { }
239 
245 
247  bool empty() const { return SList<E>::empty(); }
248 
250  int size() const { return SList<E>::size(); }
251 
254  return SList<E>::front();
255  }
256 
259  return SList<E>::front();
260  }
261 
264  return SListPure<E>::back();
265  }
266 
269  return SListPure<E>::back();
270  }
271 
273 
278 
281 
283  const_iterator begin() const { return SList<E>::begin(); }
284 
286  const_iterator cbegin() const { return SList<E>::cbegin(); }
287 
289  iterator end() { return SList<E>::end(); }
290 
292  const_iterator end() const { return SList<E>::end(); }
293 
295  const_iterator cend() const { return SList<E>::cend(); }
296 
299 
302 
304 
309 
313  return *this;
314  }
315 
317 
322  return *this;
323  }
324 
326  const SList<E> &getList() const { return *this; }
327 
329 
334 
336  iterator append(const E &x) {
337  return SList<E>::pushBack(x);
338  }
339 
341 
344  template<class ... Args>
345  iterator emplace(Args && ... args) {
346  return SList<E>::emplaceBack(std::forward<Args>(args)...);
347  }
348 
350  E pop() {
351  E x = top();
353  return x;
354  }
355 
357  void clear() { SList<E>::clear(); }
358 
360 
362 };
363 
364 // prints queue to output stream os using delimiter delim
365 template<class E>
366 void print(std::ostream &os, const QueuePure<E> &Q, char delim = ' ')
367 { print(os,Q.getListPure(),delim); }
368 
369 // prints queue to output stream os using delimiter delim
370 template<class E>
371 void print(std::ostream &os, const Queue<E> &Q, char delim = ' ')
372 { print(os,Q.getList(),delim); }
373 
374 
375 // output operator
376 template<class E>
377 std::ostream &operator<<(std::ostream &os, const QueuePure<E> &Q)
378 {
379  print(os,Q); return os;
380 }
381 
382 template<class E>
383 std::ostream &operator<<(std::ostream &os, const Queue<E> &Q)
384 {
385  print(os,Q); return os;
386 }
387 
388 }
Declaration of singly linked lists and iterators.
int size() const
Returns the number of elements in the queue.
Definition: Queue.h:250
const_iterator begin() const
Returns a const iterator to the first element of the queue.
Definition: Queue.h:283
const_iterator cbegin() const
Returns a const iterator to the first element of the list.
Definition: SList.h:330
const_iterator cend() const
Returns a const iterator to one-past-last element of the queue.
Definition: Queue.h:133
The parameterized class Queue<E> implements list-based queues.
Definition: Queue.h:209
iterator append(const E &x)
Adds x at the end of queue.
Definition: Queue.h:336
const_reference back() const
Returns a reference to the last element.
Definition: SList.h:258
bool empty() const
Returns true iff the list is empty.
Definition: SList.h:222
Queue< E > & operator=(const Queue< E > &Q)
Assignment operator.
Definition: Queue.h:311
iterator append(const E &x)
Adds x at the end of queue.
Definition: Queue.h:174
int size() const
Returns the number of elements in the list.
Definition: SList.h:811
const_reference bottom() const
Returns a reference to the back element.
Definition: Queue.h:101
Singly linked lists.
Definition: SList.h:38
QueuePure()
Constructs an empty queue.
Definition: Queue.h:64
Queue(std::initializer_list< E > initList)
Constructs a queue and appends the elements in initList to it.
Definition: Queue.h:226
const_iterator backIterator() const
Returns a const iterator to the last element of the queue.
Definition: Queue.h:139
const_iterator end() const
Returns a const iterator to one-past-last element of the queue.
Definition: Queue.h:130
Implementation of list-based queues.
Definition: Queue.h:50
Definition: GML.h:110
E & reference
Provides a reference to an element stored in a queue.
Definition: Queue.h:55
void clear()
Makes the queue empty.
Definition: Queue.h:195
Encapsulates a pointer to an ogdf::SList element.
Definition: SList.h:39
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
QueuePure(std::initializer_list< E > initList)
Constructs a queue and appends the elements in initList to it.
Definition: Queue.h:67
E value_type
Represents the data type stored in a queue element.
Definition: Queue.h:53
E pop()
Removes front element and returns it.
Definition: Queue.h:188
iterator emplaceBack(Args &&... args)
Adds a new element at the end of the list.
Definition: SList.h:879
reference top()
Returns a reference to the front element.
Definition: Queue.h:96
const E & const_reference
Provides a reference to a const element stored in a queue for reading and performing const operations...
Definition: Queue.h:216
Singly linked lists (maintaining the length of the list).
Definition: SList.h:773
Queue()
Constructs an empty queue.
Definition: Queue.h:223
QueuePure< E > & operator=(const QueuePure< E > &Q)
Assignment operator.
Definition: Queue.h:149
iterator begin()
Returns an iterator to the first element of the queue.
Definition: Queue.h:118
~QueuePure()
Destruction.
Definition: Queue.h:79
iterator begin()
Returns an iterator to the first element of the list.
Definition: SList.h:318
bool empty() const
Returns true iff the queue is empty.
Definition: Queue.h:88
SList< E > & operator=(const SList< E > &L)
Assignment operator.
Definition: SList.h:824
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition: SList.h:451
Queue(const Queue< E > &Q)
Constructs a queue that is a copy of Q.
Definition: Queue.h:229
iterator emplace(Args &&... args)
Adds a new element at the end of the queue.
Definition: Queue.h:345
~Queue()
Destruction.
Definition: Queue.h:238
Queue< E > & operator=(Queue< E > &&Q)
Assignment operator (move semantics).
Definition: Queue.h:320
iterator emplaceBack(Args &&... args)
Adds a new element at the end of the list.
Definition: SList.h:465
const_iterator begin() const
Returns a const iterator to the first element of the queue.
Definition: Queue.h:121
const SList< E > & getList() const
Conversion to const SList.
Definition: Queue.h:326
void popFront()
Removes the first element from the list.
Definition: SList.h:497
bool empty() const
Returns true iff the queue is empty.
Definition: Queue.h:247
const_reference front() const
Returns a reference to the first element.
Definition: SList.h:240
iterator backIterator()
Returns an iterator to the last element of the list.
Definition: SList.h:354
#define OGDF_NEW_DELETE
Makes the class use OGDF&#39;s memory allocator.
Definition: memory.h:84
const_iterator end() const
Returns a const iterator to one-past-last element of the queue.
Definition: Queue.h:292
const T & move(const T &v)
Definition: backward.hpp:243
reference bottom()
Returns a reference to the back element.
Definition: Queue.h:268
const_iterator cbegin() const
Returns a const iterator to the first element of the queue.
Definition: Queue.h:124
reference bottom()
Returns a reference to the back element.
Definition: Queue.h:106
const_reference top() const
Returns a reference to the front element.
Definition: Queue.h:91
SListIterator< E > pushBack(const E &x)
Adds element x at the end of the list.
Definition: SList.h:872
E value_type
Represents the data type stored in a queue element.
Definition: Queue.h:212
iterator backIterator()
Returns an iterator to the last element of the queue.
Definition: Queue.h:298
const_reference bottom() const
Returns a reference to the back element.
Definition: Queue.h:263
const_iterator cend() const
Returns a const iterator to one-past-last element of the list.
Definition: SList.h:348
SListPure< E > & operator=(const SListPure< E > &L)
Assignment operator.
Definition: SList.h:390
void clear()
Removes all elements from the list.
Definition: SList.h:529
iterator emplace(Args &&... args)
Adds a new element at the end of the queue.
Definition: Queue.h:183
const SListPure< E > & getListPure() const
Conversion to const SListPure.
Definition: Queue.h:164
QueuePure(const QueuePure< E > &Q)
Constructs a queue that is a copy of Q.
Definition: Queue.h:70
const_iterator backIterator() const
Returns a const iterator to the last element of the queue.
Definition: Queue.h:301
const_iterator cend() const
Returns a const iterator to one-past-last element of the queue.
Definition: Queue.h:295
The namespace for all OGDF objects.
QueuePure(QueuePure< E > &&Q)
Constructs a queue containing the elements of Q (move semantics).
Definition: Queue.h:76
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:931
void clear()
Removes all elements from the list.
Definition: SList.h:917
iterator backIterator()
Returns an iterator to the last element of the queue.
Definition: Queue.h:136
E pop()
Removes front element and returns it.
Definition: Queue.h:350
iterator end()
Returns an iterator to one-past-last element of the queue.
Definition: Queue.h:127
iterator end()
Returns an iterator to one-past-last element of the queue.
Definition: Queue.h:289
E & reference
Provides a reference to an element stored in a queue.
Definition: Queue.h:214
QueuePure< E > & operator=(QueuePure< E > &&Q)
Assignment operator (move semantics).
Definition: Queue.h:158
iterator begin()
Returns an iterator to the first element of the queue.
Definition: Queue.h:280
reference top()
Returns a reference to the front element.
Definition: Queue.h:258
void clear()
Makes the queue empty.
Definition: Queue.h:357
void popFront()
Removes the first element from the list.
Definition: SList.h:898
iterator end()
Returns an iterator to one-past-last element of the list.
Definition: SList.h:336
const_iterator cbegin() const
Returns a const iterator to the first element of the queue.
Definition: Queue.h:286
Queue(Queue< E > &&Q)
Constructs a queue containing the elements of Q (move semantics).
Definition: Queue.h:235
const_reference top() const
Returns a reference to the front element.
Definition: Queue.h:253