BoundedQueue.h++

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------
00002    commonc++ - A C++ Common Class Library
00003    Copyright (C) 2005-2009  Mark A Lindner
00004 
00005    This file is part of commonc++.
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public
00018    License along with this library; if not, write to the Free
00019    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00020    ---------------------------------------------------------------------------
00021 */
00022 
00023 #ifndef __ccxx_BoundedQueue_hxx
00024 #define __ccxx_BoundedQueue_hxx
00025 
00026 #include <commonc++/Common.h++>
00027 #include <commonc++/CondVar.h++>
00028 #include <commonc++/InterruptedException.h++>
00029 #include <commonc++/Mutex.h++>
00030 #include <commonc++/ScopedLock.h++>
00031 #include <commonc++/System.h++>
00032 #include <commonc++/IOException.h++>
00033 
00034 #include <deque>
00035 
00036 namespace ccxx {
00037 
00044 template <typename T> class BoundedQueue
00045 {
00046   public:
00047 
00053   BoundedQueue(uint_t capacity);
00054 
00056   virtual ~BoundedQueue();
00057 
00059   void clear();
00060 
00065   void reset();
00066 
00074   void put(T item) throw(InterruptedException);
00075 
00086   void tryPut(T item, uint_t timeout = 0) throw(TimeoutException,
00087                                                 InterruptedException);
00088 
00096   T take() throw(InterruptedException);
00097 
00108   T tryTake(uint_t timeout = 0) throw(TimeoutException,
00109                                       InterruptedException);
00110 
00114   uint_t getSize() const throw();
00115 
00119   inline uint_t getCapacity() const throw()
00120   { return(_capacity); }
00121 
00130   void setCapacity(uint_t capacity) throw();
00131 
00135   void interrupt() throw();
00136 
00140   void shutdown() throw();
00141 
00143   inline bool isShutdown() const throw()
00144   { return(_terminated); }
00145 
00146   private:
00147 
00148   uint_t _capacity;
00149   std::deque<T> _queue;
00150   mutable Mutex _mutex;
00151   CondVar _condP;
00152   CondVar _condC;
00153   bool _terminated;
00154 };
00155 
00156 #include <commonc++/BoundedQueueImpl.h++>
00157 
00158 }; // namespace ccxx
00159 
00160 #endif // __ccxx_BoundedQueue_hxx
00161 
00162 /* end of header file */

Generated on Sat Apr 17 23:03:05 2010 for libcommonc++ by  doxygen 1.5.9