sharedQueue.h
Go to the documentation of this file.
00001 /******************************************************************************
00002 ** Copyright (c) 1992-2010 VT MAK
00003 ** All rights reserved.
00004 ******************************************************************************/
00005 
00008 
00009 #ifndef sharedQueue_H_
00010 #define sharedQueue_H_
00011 
00012 #include <deque>
00013 #include "threadSafe.h"
00014 #include "collectors.h"
00015 
00016 namespace MAKLogger
00017 {
00018 
00020    template <typename T>
00021    class DtSharedQueue
00022    {
00023    public:
00024 
00025       DtSharedQueue() : myDeque(std::deque<T> ())
00026       {
00027       }
00028 
00029       DtSharedQueue(const DtSharedQueue& original)
00030       {
00031          *myDeque = *original.myDeque;
00032       }
00033 
00034       int size() const
00035       {      
00036          return static_cast<int>(myDeque->size());
00037       }
00038 
00039       void clear()
00040       {
00041          myDeque->clear();
00042       }
00043 
00044       void push(const T& input)
00045       {
00046          myDeque->push_back(input);
00047       }
00048 
00049       void push_priority(const T& input)
00050       {
00051          myDeque->push_front(input);
00052       }
00053 
00054       bool pop(T& output)
00055       {
00056          DtScopedSequenceLock lock = myDeque.sequenceLock();
00057          if(myDeque->empty() == false)
00058          {      
00059             output = myDeque->front();
00060             myDeque->pop_front();
00061             return true;
00062          }
00063          return false;
00064       }
00065 
00066       void move(DtCollector<T>& output)
00067       {
00070          DtScopedSequenceLock lock     = myDeque.sequenceLock();        
00071          typename std::deque<T>::iterator startIter  = myDeque->begin();
00072          typename std::deque<T>::iterator endIter    = myDeque->end();
00073          for(;startIter != endIter;++startIter)
00074          {
00075             output.collect(*startIter);
00076          }
00077          myDeque->clear();
00078       }
00079 
00080    protected:
00081       DtThreadSafe<std::deque<T> > myDeque;
00082    };
00083 
00084 }
00085 
00086 #endif
00087 

Document ID: Generated on Tue Oct 11 19:41:03 EDT 2011 from SVN revision 107422
Copyright © 2005-2011 VT MÄK Inc. All Rights Reserved (www.mak.com)