Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

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 
76  QueuePure(QueuePure<E> &&Q) : SListPure<E>(std::move(Q)) { }
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 
143 
145 
150 
154  return *this;
155  }
156 
158 
163  return *this;
164  }
165 
167  const SListPure<E> &getListPure() const { return *this; }
168 
170 
175 
177  iterator append(const E &x) {
178  return SListPure<E>::pushBack(x);
179  }
180 
182 
185  template<class ... Args>
186  iterator emplace(Args && ... args) {
187  return SListPure<E>::emplaceBack(std::forward<Args>(args)...);
188  }
189 
191  E pop() {
192  E x = top();
194  return x;
195  }
196 
199 
201 }; // class QueuePure
202 
203 
205 
213 template<class E> class Queue : private SList<E> {
214 public:
216  using value_type = E;
218  using reference = E&;
220  using const_reference = const E &;
225 
227  Queue() { }
228 
230  Queue(std::initializer_list<E> initList) : SList<E>(initList) { }
231 
233  Queue(const Queue<E> &Q) : SList<E>(Q) { }
234 
236 
239  Queue(Queue<E> &&Q) : SList<E>(std::move(Q)) { }
240 
242  ~Queue() { }
243 
249 
251  bool empty() const { return SList<E>::empty(); }
252 
254  int size() const { return SList<E>::size(); }
255 
258  return SList<E>::front();
259  }
260 
263  return SList<E>::front();
264  }
265 
268  return SListPure<E>::back();
269  }
270 
273  return SListPure<E>::back();
274  }
275 
277 
282 
285 
287  const_iterator begin() const { return SList<E>::begin(); }
288 
290  const_iterator cbegin() const { return SList<E>::cbegin(); }
291 
293  iterator end() { return SList<E>::end(); }
294 
296  const_iterator end() const { return SList<E>::end(); }
297 
299  const_iterator cend() const { return SList<E>::cend(); }
300 
303 
305  const_iterator rbegin() const { return SList<E>::rbegin(); }
306 
309 
311 
316 
320  return *this;
321  }
322 
324 
329  return *this;
330  }
331 
333  const SList<E> &getList() const { return *this; }
334 
336 
341 
343  iterator append(const E &x) {
344  return SList<E>::pushBack(x);
345  }
346 
348 
351  template<class ... Args>
352  iterator emplace(Args && ... args) {
353  return SList<E>::emplaceBack(std::forward<Args>(args)...);
354  }
355 
357  E pop() {
358  E x = top();
360  return x;
361  }
362 
364  void clear() { SList<E>::clear(); }
365 
367 
369 }; // class Queue
370 
371 
372 // prints queue to output stream os using delimiter delim
373 template<class E>
374 void print(ostream &os, const QueuePure<E> &Q, char delim = ' ')
375 { print(os,Q.getListPure(),delim); }
376 
377 // prints queue to output stream os using delimiter delim
378 template<class E>
379 void print(ostream &os, const Queue<E> &Q, char delim = ' ')
380 { print(os,Q.getList(),delim); }
381 
382 
383 // output operator
384 template<class E>
385 ostream &operator<<(ostream &os, const QueuePure<E> &Q)
386 {
387  print(os,Q); return os;
388 }
389 
390 template<class E>
391 ostream &operator<<(ostream &os, const Queue<E> &Q)
392 {
393  print(os,Q); return os;
394 }
395 
396 
397 } // end namespace ogdf
Declaration of singly linked lists and iterators.
int size() const
Returns the number of elements in the queue.
Definition: Queue.h:254
const_iterator begin() const
Returns a const iterator to the first element of the queue.
Definition: Queue.h:287
const_iterator cbegin() const
Returns a const iterator to the first element of the list.
Definition: SList.h:328
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:213
iterator append(const E &x)
Adds x at the end of queue.
Definition: Queue.h:343
const_iterator crbegin() const
Returns a const iterator to the last element of the queue.
Definition: Queue.h:142
const_reference back() const
Returns a reference to the last element.
Definition: SList.h:256
bool empty() const
Returns true iff the list is empty.
Definition: SList.h:220
const_iterator rbegin() const
Returns a const iterator to the last element of the queue.
Definition: Queue.h:305
Queue< E > & operator=(const Queue< E > &Q)
Assignment operator.
Definition: Queue.h:318
iterator append(const E &x)
Adds x at the end of queue.
Definition: Queue.h:177
int size() const
Returns the number of elements in the list.
Definition: SList.h:815
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:230
const_iterator end() const
Returns a const iterator to one-past-last element of the queue.
Definition: Queue.h:130
const_iterator crbegin() const
Returns a const iterator to the last element of the list.
Definition: SList.h:364
const_iterator rbegin() const
Returns a const iterator to the last element of the queue.
Definition: Queue.h:139
Implementation of list-based queues.
Definition: Queue.h:50
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:198
Encapsulates a pointer to an ogdf::SList element.
Definition: SList.h:40
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:191
iterator emplaceBack(Args &&... args)
Adds a new element at the end of the list.
Definition: SList.h:883
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:220
Singly linked lists (maintaining the length of the list).
Definition: SList.h:777
iterator rbegin()
Returns an iterator to the last element of the queue.
Definition: Queue.h:302
Queue()
Constructs an empty queue.
Definition: Queue.h:227
QueuePure< E > & operator=(const QueuePure< E > &Q)
Assignment operator.
Definition: Queue.h:152
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:316
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:828
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition: SList.h:455
Queue(const Queue< E > &Q)
Constructs a queue that is a copy of Q.
Definition: Queue.h:233
iterator emplace(Args &&... args)
Adds a new element at the end of the queue.
Definition: Queue.h:352
~Queue()
Destruction.
Definition: Queue.h:242
Queue< E > & operator=(Queue< E > &&Q)
Assignment operator (move semantics).
Definition: Queue.h:327
iterator emplaceBack(Args &&... args)
Adds a new element at the end of the list.
Definition: SList.h:469
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:333
iterator rbegin()
Returns an iterator to the last element of the queue.
Definition: Queue.h:136
void popFront()
Removes the first element from the list.
Definition: SList.h:501
bool empty() const
Returns true iff the queue is empty.
Definition: Queue.h:251
const_reference front() const
Returns a reference to the first element.
Definition: SList.h:238
#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:296
const T & move(const T &v)
Definition: backward.hpp:243
reference bottom()
Returns a reference to the back element.
Definition: Queue.h:272
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:876
E value_type
Represents the data type stored in a queue element.
Definition: Queue.h:216
const_reference bottom() const
Returns a reference to the back element.
Definition: Queue.h:267
const_iterator crbegin() const
Returns a const iterator to the last element of the queue.
Definition: Queue.h:308
const_iterator cend() const
Returns a const iterator to one-past-last element of the list.
Definition: SList.h:346
SListPure< E > & operator=(const SListPure< E > &L)
Assignment operator.
Definition: SList.h:394
void clear()
Removes all elements from the list.
Definition: SList.h:533
iterator emplace(Args &&... args)
Adds a new element at the end of the queue.
Definition: Queue.h:186
const SListPure< E > & getListPure() const
Conversion to const SListPure.
Definition: Queue.h:167
QueuePure(const QueuePure< E > &Q)
Constructs a queue that is a copy of Q.
Definition: Queue.h:70
const_iterator cend() const
Returns a const iterator to one-past-last element of the queue.
Definition: Queue.h:299
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 clear()
Removes all elements from the list.
Definition: SList.h:921
E pop()
Removes front element and returns it.
Definition: Queue.h:357
iterator rbegin()
Returns an iterator to the last element of the list.
Definition: SList.h:352
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:293
E & reference
Provides a reference to an element stored in a queue.
Definition: Queue.h:218
void print(ostream &os, const Array< E, INDEX > &a, char delim=' ')
Prints array a to output stream os using delimiter delim.
Definition: Array.h:753
QueuePure< E > & operator=(QueuePure< E > &&Q)
Assignment operator (move semantics).
Definition: Queue.h:161
iterator begin()
Returns an iterator to the first element of the queue.
Definition: Queue.h:284
reference top()
Returns a reference to the front element.
Definition: Queue.h:262
void clear()
Makes the queue empty.
Definition: Queue.h:364
void popFront()
Removes the first element from the list.
Definition: SList.h:902
iterator end()
Returns an iterator to one-past-last element of the list.
Definition: SList.h:334
const_iterator cbegin() const
Returns a const iterator to the first element of the queue.
Definition: Queue.h:290
Queue(Queue< E > &&Q)
Constructs a queue containing the elements of Q (move semantics).
Definition: Queue.h:239
const_reference top() const
Returns a reference to the front element.
Definition: Queue.h:257