00001
00002
00003 #ifndef CRYPTOPP_QUEUE_H
00004 #define CRYPTOPP_QUEUE_H
00005
00006 #include "simple.h"
00007
00008
00009 NAMESPACE_BEGIN(CryptoPP)
00010
00011
00012
00013 class ByteQueueNode;
00014
00015
00016 class CRYPTOPP_DLL ByteQueue : public Bufferless<BufferedTransformation>
00017 {
00018 public:
00019 ByteQueue(size_t nodeSize=0);
00020 ByteQueue(const ByteQueue ©);
00021 ~ByteQueue();
00022
00023 lword MaxRetrievable() const
00024 {return CurrentSize();}
00025 bool AnyRetrievable() const
00026 {return !IsEmpty();}
00027
00028 void IsolatedInitialize(const NameValuePairs ¶meters);
00029 byte * CreatePutSpace(size_t &size);
00030 size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking);
00031
00032 size_t Get(byte &outByte);
00033 size_t Get(byte *outString, size_t getMax);
00034
00035 size_t Peek(byte &outByte) const;
00036 size_t Peek(byte *outString, size_t peekMax) const;
00037
00038 size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true);
00039 size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const;
00040
00041
00042 void SetNodeSize(size_t nodeSize);
00043
00044 lword CurrentSize() const;
00045 bool IsEmpty() const;
00046
00047 void Clear();
00048
00049 void Unget(byte inByte);
00050 void Unget(const byte *inString, size_t length);
00051
00052 const byte * Spy(size_t &contiguousSize) const;
00053
00054 void LazyPut(const byte *inString, size_t size);
00055 void LazyPutModifiable(byte *inString, size_t size);
00056 void UndoLazyPut(size_t size);
00057 void FinalizeLazyPut();
00058
00059 ByteQueue & operator=(const ByteQueue &rhs);
00060 bool operator==(const ByteQueue &rhs) const;
00061 bool operator!=(const ByteQueue &rhs) const {return !operator==(rhs);}
00062 byte operator[](lword i) const;
00063 void swap(ByteQueue &rhs);
00064
00065 class Walker : public InputRejecting<BufferedTransformation>
00066 {
00067 public:
00068 Walker(const ByteQueue &queue)
00069 : m_queue(queue) {Initialize();}
00070
00071 lword GetCurrentPosition() {return m_position;}
00072
00073 lword MaxRetrievable() const
00074 {return m_queue.CurrentSize() - m_position;}
00075
00076 void IsolatedInitialize(const NameValuePairs ¶meters);
00077
00078 size_t Get(byte &outByte);
00079 size_t Get(byte *outString, size_t getMax);
00080
00081 size_t Peek(byte &outByte) const;
00082 size_t Peek(byte *outString, size_t peekMax) const;
00083
00084 size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true);
00085 size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const;
00086
00087 private:
00088 const ByteQueue &m_queue;
00089 const ByteQueueNode *m_node;
00090 lword m_position;
00091 size_t m_offset;
00092 const byte *m_lazyString;
00093 size_t m_lazyLength;
00094 };
00095
00096 friend class Walker;
00097
00098 private:
00099 void CleanupUsedNodes();
00100 void CopyFrom(const ByteQueue ©);
00101 void Destroy();
00102
00103 bool m_autoNodeSize;
00104 size_t m_nodeSize;
00105 ByteQueueNode *m_head, *m_tail;
00106 byte *m_lazyString;
00107 size_t m_lazyLength;
00108 bool m_lazyStringModifiable;
00109 };
00110
00111
00112 class CRYPTOPP_DLL LazyPutter
00113 {
00114 public:
00115 LazyPutter(ByteQueue &bq, const byte *inString, size_t size)
00116 : m_bq(bq) {bq.LazyPut(inString, size);}
00117 ~LazyPutter()
00118 {try {m_bq.FinalizeLazyPut();} catch(...) {}}
00119 protected:
00120 LazyPutter(ByteQueue &bq) : m_bq(bq) {}
00121 private:
00122 ByteQueue &m_bq;
00123 };
00124
00125
00126 class LazyPutterModifiable : public LazyPutter
00127 {
00128 public:
00129 LazyPutterModifiable(ByteQueue &bq, byte *inString, size_t size)
00130 : LazyPutter(bq) {bq.LazyPutModifiable(inString, size);}
00131 };
00132
00133 NAMESPACE_END
00134
00135 #ifndef __BORLANDC__
00136 NAMESPACE_BEGIN(std)
00137 template<> inline void swap(CryptoPP::ByteQueue &a, CryptoPP::ByteQueue &b)
00138 {
00139 a.swap(b);
00140 }
00141 NAMESPACE_END
00142 #endif
00143
00144 #endif