Open
Graph Drawing
Framework

 v.2012.05
 

Queue.h
Go to the documentation of this file.
00001 /*
00002  * $Revision: 2299 $
00003  * 
00004  * last checkin:
00005  *   $Author: gutwenger $ 
00006  *   $Date: 2012-05-07 15:57:08 +0200 (Mon, 07 May 2012) $ 
00007  ***************************************************************/
00008  
00044 #ifdef _MSC_VER
00045 #pragma once
00046 #endif
00047 
00048 #ifndef OGDF_QUEUE_H
00049 #define OGDF_QUEUE_H
00050 
00051 
00052 #include <ogdf/basic/SList.h>
00053 
00054 
00055 namespace ogdf {
00056 
00057 
00059 
00063 template<class E> class QueuePure : private SListPure<E> {
00064 public:
00066     QueuePure() { }
00067 
00069     QueuePure(const QueuePure<E> &Q) : SListPure<E>(Q) { }
00070 
00071     // destruction
00072     ~QueuePure() { }
00073 
00075     bool empty() const { return SListPure<E>::empty(); }
00076 
00078     const E &top() const {
00079         return SListPure<E>::front();
00080     }
00081 
00083     E &top() {
00084         return SListPure<E>::front();
00085     }
00086 
00088     const E &bottom() const {
00089         return SListPure<E>::back();
00090     }
00091 
00093     E &bottom() {
00094         return SListPure<E>::back();
00095     }
00096 
00098     QueuePure<E> &operator=(const QueuePure<E> &Q) {
00099         SListPure<E>::operator=(Q);
00100         return *this;
00101     }
00102 
00104     SListIterator<E> append(const E &x) {
00105         return SListPure<E>::pushBack(x);
00106     }
00107 
00109     E pop() {
00110         E x = top();
00111         SListPure<E>::popFront();
00112         return x;
00113     }
00114 
00116     void clear() { SListPure<E>::clear(); }
00117 
00119     const SListPure<E> &getListPure() const { return *this; }
00120 
00121     OGDF_NEW_DELETE
00122 }; // class QueuePure
00123 
00124 
00126 
00130 template<class E> class Queue : private SList<E> {
00131 public:
00133     Queue() { }
00134 
00136     Queue(const Queue<E> &Q) : SList<E>(Q) { }
00137 
00138     // destruction
00139     ~Queue() { }
00140 
00142     bool empty() const { return SList<E>::empty(); }
00143 
00145     int size() const { return SList<E>::size(); }
00146 
00148     const E &top() const {
00149         return SList<E>::front();
00150     }
00151 
00153     E &top() {
00154         return SList<E>::front();
00155     }
00156 
00158     const E &bottom() const {
00159         return SListPure<E>::back();
00160     }
00161 
00163     E &bottom() {
00164         return SListPure<E>::back();
00165     }
00166 
00168     Queue<E> &operator=(const Queue<E> &Q) {
00169         SList<E>::operator=(Q);
00170         return *this;
00171     }
00172 
00174     SListIterator<E> append(const E &x) {
00175         return SList<E>::pushBack(x);
00176     }
00177 
00179     E pop() {
00180         E x = top();
00181         SList<E>::popFront();
00182         return x;
00183     }
00184 
00186     void clear() { SList<E>::clear(); }
00187 
00189     const SList<E> &getList() const { return *this; }
00191     const SListPure<E> &getListPure() const { return SList<E>::getListPure(); }
00192 
00193     OGDF_NEW_DELETE
00194 }; // class Queue
00195 
00196 
00197 // prints queue to output stream os using delimiter delim
00198 template<class E>
00199 void print(ostream &os, const QueuePure<E> &Q, char delim = ' ')
00200 { print(os,Q.getListPure(),delim); }
00201 
00202 // prints queue to output stream os using delimiter delim
00203 template<class E>
00204 void print(ostream &os, const Queue<E> &Q, char delim = ' ')
00205 { print(os,Q.getListPure(),delim); }
00206 
00207 
00208 // output operator
00209 template<class E>
00210 ostream &operator<<(ostream &os, const QueuePure<E> &Q)
00211 {
00212     print(os,Q); return os;
00213 }
00214 
00215 template<class E>
00216 ostream &operator<<(ostream &os, const Queue<E> &Q)
00217 {
00218     print(os,Q); return os;
00219 }
00220 
00221 
00222 } // end namespace ogdf
00223 
00224 
00225 #endif