Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

queue.h

00001 // specification file for an unlimited queue for storing bytes 00002 00003 #ifndef CRYPTOPP_QUEUE_H 00004 #define CRYPTOPP_QUEUE_H 00005 00006 #include "simple.h" 00007 //#include <algorithm> 00008 00009 NAMESPACE_BEGIN(CryptoPP) 00010 00011 /** The queue is implemented as a linked list of byte arrays, but you don't need to 00012 know about that. So just ignore this next line. :) */ 00013 class ByteQueueNode; 00014 00015 //! Byte Queue 00016 class ByteQueue : public Bufferless<BufferedTransformation> 00017 { 00018 public: 00019 ByteQueue(unsigned int m_nodeSize=256); 00020 ByteQueue(const ByteQueue &copy); 00021 ~ByteQueue(); 00022 00023 unsigned long MaxRetrievable() const 00024 {return CurrentSize();} 00025 bool AnyRetrievable() const 00026 {return !IsEmpty();} 00027 00028 void IsolatedInitialize(const NameValuePairs &parameters); 00029 byte * CreatePutSpace(unsigned int &size); 00030 unsigned int Put2(const byte *inString, unsigned int length, int messageEnd, bool blocking); 00031 00032 unsigned int Get(byte &outByte); 00033 unsigned int Get(byte *outString, unsigned int getMax); 00034 00035 unsigned int Peek(byte &outByte) const; 00036 unsigned int Peek(byte *outString, unsigned int peekMax) const; 00037 00038 unsigned int TransferTo2(BufferedTransformation &target, unsigned long &transferBytes, const std::string &channel=NULL_CHANNEL, bool blocking=true); 00039 unsigned int CopyRangeTo2(BufferedTransformation &target, unsigned long &begin, unsigned long end=ULONG_MAX, const std::string &channel=NULL_CHANNEL, bool blocking=true) const; 00040 00041 // these member functions are not inherited 00042 void SetNodeSize(unsigned int nodeSize) {m_nodeSize = nodeSize;} 00043 00044 unsigned long CurrentSize() const; 00045 bool IsEmpty() const; 00046 00047 void Clear(); 00048 00049 void Unget(byte inByte); 00050 void Unget(const byte *inString, unsigned int length); 00051 00052 const byte * Spy(unsigned int &contiguousSize) const; 00053 00054 void LazyPut(const byte *inString, unsigned int size); 00055 void UndoLazyPut(unsigned int size); 00056 void FinalizeLazyPut(); 00057 00058 ByteQueue & operator=(const ByteQueue &rhs); 00059 bool operator==(const ByteQueue &rhs) const; 00060 byte operator[](unsigned long i) const; 00061 void swap(ByteQueue &rhs); 00062 00063 class Walker : public InputRejecting<BufferedTransformation> 00064 { 00065 public: 00066 Walker(const ByteQueue &queue) 00067 : m_queue(queue) {Initialize();} 00068 00069 unsigned long GetCurrentPosition() {return m_position;} 00070 00071 unsigned long MaxRetrievable() const 00072 {return m_queue.CurrentSize() - m_position;} 00073 00074 void IsolatedInitialize(const NameValuePairs &parameters); 00075 00076 unsigned int Get(byte &outByte); 00077 unsigned int Get(byte *outString, unsigned int getMax); 00078 00079 unsigned int Peek(byte &outByte) const; 00080 unsigned int Peek(byte *outString, unsigned int peekMax) const; 00081 00082 unsigned int TransferTo2(BufferedTransformation &target, unsigned long &transferBytes, const std::string &channel=NULL_CHANNEL, bool blocking=true); 00083 unsigned int CopyRangeTo2(BufferedTransformation &target, unsigned long &begin, unsigned long end=ULONG_MAX, const std::string &channel=NULL_CHANNEL, bool blocking=true) const; 00084 00085 private: 00086 const ByteQueue &m_queue; 00087 const ByteQueueNode *m_node; 00088 unsigned long m_position; 00089 unsigned int m_offset; 00090 const byte *m_lazyString; 00091 unsigned int m_lazyLength; 00092 }; 00093 00094 friend class Walker; 00095 00096 private: 00097 void CleanupUsedNodes(); 00098 void CopyFrom(const ByteQueue &copy); 00099 void Destroy(); 00100 00101 unsigned int m_nodeSize; 00102 ByteQueueNode *m_head, *m_tail; 00103 const byte *m_lazyString; 00104 unsigned int m_lazyLength; 00105 }; 00106 00107 //! use this to make sure LazyPut is finalized in event of exception 00108 class LazyPutter 00109 { 00110 public: 00111 LazyPutter(ByteQueue &bq, const byte *inString, unsigned int size) 00112 : m_bq(bq) {bq.LazyPut(inString, size);} 00113 ~LazyPutter() 00114 {try {m_bq.FinalizeLazyPut();} catch(...) {}} 00115 private: 00116 ByteQueue &m_bq; 00117 }; 00118 00119 NAMESPACE_END 00120 00121 NAMESPACE_BEGIN(std) 00122 template<> inline void swap(CryptoPP::ByteQueue &a, CryptoPP::ByteQueue &b) 00123 { 00124 a.swap(b); 00125 } 00126 NAMESPACE_END 00127 00128 #endif

Generated on Fri Aug 13 09:56:54 2004 for Crypto++ by doxygen 1.3.7