Main Page | Class List | File List | Class Members

UnboundedQueue.hpp

00001 /*
00002  * Copyright (C) 2003-2004
00003  * Slawomir Lisznianski <slisznianski@asyncnet.com>
00004  *
00005  * Permission to use, copy, modify, distribute and sell this software
00006  * and its documentation for any purpose is hereby granted without fee,
00007  * provided that the above copyright notice appear in all copies and
00008  * that both that copyright notice and this permission notice appear
00009  * in supporting documentation. Slawomir Lisznianski makes no
00010  * representations about the suitability of this software for any
00011  * purpose. It is provided "as is" without express or implied warranty.
00012  *
00013  */
00014 
00015 #ifndef RHA_UNBOUNDEDQUEUE_HPP
00016 #define RHA_UNBOUNDEDQUEUE_HPP
00017 
00018 #include <deque>
00019 
00020 namespace Rha
00021 {
00029     template<class T,
00030              class C = std::deque<T> >
00031     class UnboundedQueue
00032     {
00033     public:
00034       typedef UnboundedQueue<T, C> OfType;
00035       typedef C                    Container;
00036       typedef T                    Task;
00037 
00044       struct Configurator
00045       { };
00046 
00048       UnboundedQueue();
00049 
00055       ~UnboundedQueue();
00056 
00062       inline void setUp();
00063 
00069       inline bool empty() const;
00070 
00076       inline bool full() const;
00077 
00083       inline void flush();
00084 
00089       inline Task& front();
00090       inline const Task& front() const;
00091 
00096       inline void push(const Task& val);
00097 
00102       inline void pop();
00103     private:
00104       Container M_container;
00105     };
00106 }
00107 
00108 template<class T,
00109          class C>
00110 Rha::UnboundedQueue<T,
00111                     C>::UnboundedQueue()
00112 { }
00113 
00114 template<class T,
00115          class C>
00116 Rha::UnboundedQueue<T,
00117                     C>::~UnboundedQueue()
00118 { }
00119 
00120 template<class T,
00121          class C>
00122 void
00123 Rha::UnboundedQueue<T,
00124                     C>::setUp()
00125 { }
00126 
00127 template<class T,
00128          class C>
00129 bool
00130 Rha::UnboundedQueue<T,
00131                     C>::empty() const
00132 {
00133   return (M_container.empty());
00134 }
00135 
00136 template<class T,
00137          class C>
00138 bool
00139 Rha::UnboundedQueue<T,
00140                     C>::full() const
00141 {
00142   // Unbounded queue has no upper limit.
00143   //
00144   return (false);
00145 }
00146 
00147 template<class T,
00148          class C>
00149 void
00150 Rha::UnboundedQueue<T,
00151                     C>::flush()
00152 {
00153   M_container.clear();
00154 }
00155 
00156 template<class T,
00157          class C>
00158 typename Rha::UnboundedQueue<T,
00159                              C>::Task&
00160 Rha::UnboundedQueue<T,
00161                     C>::front()
00162 {
00163   return (M_container.front());
00164 }
00165 
00166 template<class T,
00167          class C>
00168 const typename Rha::UnboundedQueue<T,
00169                                    C>::Task&
00170 Rha::UnboundedQueue<T,
00171                     C>::front() const
00172 {
00173   return (M_container.front());
00174 }
00175 
00176 template<class T,
00177          class C>
00178 void
00179 Rha::UnboundedQueue<T,
00180                     C>::push(const Task& val)
00181 {
00182   M_container.push_back(val);
00183 }
00184 
00185 template<class T,
00186          class C>
00187 void
00188 Rha::UnboundedQueue<T,
00189                     C>::pop()
00190 {
00191   M_container.pop_front();
00192 }
00193 
00194 #endif // RHA_UNBOUNDEDQUEUE_HPP