Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

mqueue.h

00001 #ifndef CRYPTOPP_MQUEUE_H
00002 #define CRYPTOPP_MQUEUE_H
00003 
00004 #include "queue.h"
00005 #include "filters.h"
00006 #include <deque>
00007 
00008 NAMESPACE_BEGIN(CryptoPP)
00009 
00011 class MessageQueue : public BufferedTransformationWithAutoSignal
00012 {
00013 public:
00014         MessageQueue(unsigned int nodeSize=256);
00015 
00016         void Put(byte inByte)
00017                 {m_queue.Put(inByte); m_lengths.back()++;}
00018         void Put(const byte *inString, unsigned int length)
00019                 {m_queue.Put(inString, length); m_lengths.back()+=length;}
00020 
00021         unsigned long MaxRetrievable() const
00022                 {return m_lengths.front();}
00023         bool AnyRetrievable() const
00024                 {return m_lengths.front() > 0;}
00025 
00026         unsigned long TransferTo(BufferedTransformation &target, unsigned long transferMax=ULONG_MAX)
00027                 {return Got(m_queue.TransferTo(target, STDMIN(MaxRetrievable(), transferMax)));}
00028         unsigned long CopyTo(BufferedTransformation &target, unsigned long copyMax=ULONG_MAX) const
00029                 {return m_queue.CopyTo(target, STDMIN(MaxRetrievable(), copyMax));}
00030 
00031         void MessageEnd(int=-1)
00032                 {m_lengths.push_back(0);}
00033 
00034         unsigned long TotalBytesRetrievable() const
00035                 {return m_queue.MaxRetrievable();}
00036         unsigned int NumberOfMessages() const
00037                 {return m_lengths.size()-1;}
00038         bool RetrieveNextMessage();
00039 
00040         unsigned int CopyMessagesTo(BufferedTransformation &target, unsigned int count=UINT_MAX) const;
00041 
00042         void swap(MessageQueue &rhs);
00043 
00044 private:
00045         unsigned long Got(unsigned long length)
00046                 {assert(m_lengths.front() >= length); m_lengths.front() -= length; return length;}
00047 
00048         ByteQueue m_queue;
00049         std::deque<unsigned long> m_lengths;
00050 };
00051 
00052 NAMESPACE_END
00053 
00054 NAMESPACE_BEGIN(std)
00055 template<> inline void swap(CryptoPP::MessageQueue &a, CryptoPP::MessageQueue &b)
00056 {
00057         a.swap(b);
00058 }
00059 NAMESPACE_END
00060 
00061 #endif

Generated at Mon Jan 15 01:16:34 2001 for Crypto++ by doxygen1.2.4 written by Dimitri van Heesch, © 1997-2000