Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | 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 CRYPTOPP_DLL ByteQueue : public Bufferless<BufferedTransformation> 00017 { 00018 public: 00019 ByteQueue(unsigned int nodeSize=0); 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); 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 LazyPutModifiable(byte *inString, unsigned int size); 00056 void UndoLazyPut(unsigned int size); 00057 void FinalizeLazyPut(); 00058 00059 ByteQueue & operator=(const ByteQueue &rhs); 00060 bool operator==(const ByteQueue &rhs) const; 00061 byte operator[](unsigned long i) const; 00062 void swap(ByteQueue &rhs); 00063 00064 class Walker : public InputRejecting<BufferedTransformation> 00065 { 00066 public: 00067 Walker(const ByteQueue &queue) 00068 : m_queue(queue) {Initialize();} 00069 00070 unsigned long GetCurrentPosition() {return m_position;} 00071 00072 unsigned long MaxRetrievable() const 00073 {return m_queue.CurrentSize() - m_position;} 00074 00075 void IsolatedInitialize(const NameValuePairs &parameters); 00076 00077 unsigned int Get(byte &outByte); 00078 unsigned int Get(byte *outString, unsigned int getMax); 00079 00080 unsigned int Peek(byte &outByte) const; 00081 unsigned int Peek(byte *outString, unsigned int peekMax) const; 00082 00083 unsigned int TransferTo2(BufferedTransformation &target, unsigned long &transferBytes, const std::string &channel=NULL_CHANNEL, bool blocking=true); 00084 unsigned int CopyRangeTo2(BufferedTransformation &target, unsigned long &begin, unsigned long end=ULONG_MAX, const std::string &channel=NULL_CHANNEL, bool blocking=true) const; 00085 00086 private: 00087 const ByteQueue &m_queue; 00088 const ByteQueueNode *m_node; 00089 unsigned long m_position; 00090 unsigned int m_offset; 00091 const byte *m_lazyString; 00092 unsigned int m_lazyLength; 00093 }; 00094 00095 friend class Walker; 00096 00097 private: 00098 void CleanupUsedNodes(); 00099 void CopyFrom(const ByteQueue &copy); 00100 void Destroy(); 00101 00102 bool m_autoNodeSize; 00103 unsigned int m_nodeSize; 00104 ByteQueueNode *m_head, *m_tail; 00105 byte *m_lazyString; 00106 unsigned int m_lazyLength; 00107 bool m_lazyStringModifiable; 00108 }; 00109 00110 //! use this to make sure LazyPut is finalized in event of exception 00111 class CRYPTOPP_DLL LazyPutter 00112 { 00113 public: 00114 LazyPutter(ByteQueue &bq, const byte *inString, unsigned int size) 00115 : m_bq(bq) {bq.LazyPut(inString, size);} 00116 ~LazyPutter() 00117 {try {m_bq.FinalizeLazyPut();} catch(...) {}} 00118 protected: 00119 LazyPutter(ByteQueue &bq) : m_bq(bq) {} 00120 private: 00121 ByteQueue &m_bq; 00122 }; 00123 00124 //! like LazyPutter, but does a LazyPutModifiable instead 00125 class LazyPutterModifiable : public LazyPutter 00126 { 00127 public: 00128 LazyPutterModifiable(ByteQueue &bq, byte *inString, unsigned int size) 00129 : LazyPutter(bq) {bq.LazyPutModifiable(inString, size);} 00130 }; 00131 00132 NAMESPACE_END 00133 00134 NAMESPACE_BEGIN(std) 00135 template<> inline void swap(CryptoPP::ByteQueue &a, CryptoPP::ByteQueue &b) 00136 { 00137 a.swap(b); 00138 } 00139 NAMESPACE_END 00140 00141 #endif

Generated on Wed Jul 21 19:15:31 2004 for Crypto++ by doxygen 1.3.7-20040704