diff options
author | Jeffrey Walton <noloader@gmail.com> | 2015-11-05 01:59:46 -0500 |
---|---|---|
committer | Jeffrey Walton <noloader@gmail.com> | 2015-11-05 01:59:46 -0500 |
commit | 48809d4e85c125814425c621d8d0d89f95405924 (patch) | |
tree | 1010fd16c4b1199f3d27dd726dda241a2bd29f83 /queue.h | |
parent | 025337a94aceb75d188149db70c2094673772816 (diff) | |
download | cryptopp-git-48809d4e85c125814425c621d8d0d89f95405924.tar.gz |
CRYPTOPP 5.6.3 RC6 checkin
Diffstat (limited to 'queue.h')
-rw-r--r-- | queue.h | 288 |
1 files changed, 144 insertions, 144 deletions
@@ -1,144 +1,144 @@ -// specification file for an unlimited queue for storing bytes - -#ifndef CRYPTOPP_QUEUE_H -#define CRYPTOPP_QUEUE_H - -#include "simple.h" -//#include <algorithm> - -NAMESPACE_BEGIN(CryptoPP) - -/** The queue is implemented as a linked list of byte arrays, but you don't need to - know about that. So just ignore this next line. :) */ -class ByteQueueNode; - -//! Byte Queue -class CRYPTOPP_DLL ByteQueue : public Bufferless<BufferedTransformation> -{ -public: - ByteQueue(size_t nodeSize=0); - ByteQueue(const ByteQueue ©); - ~ByteQueue(); - - lword MaxRetrievable() const - {return CurrentSize();} - bool AnyRetrievable() const - {return !IsEmpty();} - - void IsolatedInitialize(const NameValuePairs ¶meters); - byte * CreatePutSpace(size_t &size); - size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking); - - size_t Get(byte &outByte); - size_t Get(byte *outString, size_t getMax); - - size_t Peek(byte &outByte) const; - size_t Peek(byte *outString, size_t peekMax) const; - - size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true); - size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const; - - // these member functions are not inherited - void SetNodeSize(size_t nodeSize); - - lword CurrentSize() const; - bool IsEmpty() const; - - void Clear(); - - void Unget(byte inByte); - void Unget(const byte *inString, size_t length); - - const byte * Spy(size_t &contiguousSize) const; - - void LazyPut(const byte *inString, size_t size); - void LazyPutModifiable(byte *inString, size_t size); - void UndoLazyPut(size_t size); - void FinalizeLazyPut(); - - ByteQueue & operator=(const ByteQueue &rhs); - bool operator==(const ByteQueue &rhs) const; - bool operator!=(const ByteQueue &rhs) const {return !operator==(rhs);} - byte operator[](lword i) const; - void swap(ByteQueue &rhs); - - class Walker : public InputRejecting<BufferedTransformation> - { - public: - Walker(const ByteQueue &queue) - : m_queue(queue) {Initialize();} - - lword GetCurrentPosition() {return m_position;} - - lword MaxRetrievable() const - {return m_queue.CurrentSize() - m_position;} - - void IsolatedInitialize(const NameValuePairs ¶meters); - - size_t Get(byte &outByte); - size_t Get(byte *outString, size_t getMax); - - size_t Peek(byte &outByte) const; - size_t Peek(byte *outString, size_t peekMax) const; - - size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true); - size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const; - - private: - const ByteQueue &m_queue; - const ByteQueueNode *m_node; - lword m_position; - size_t m_offset; - const byte *m_lazyString; - size_t m_lazyLength; - }; - - friend class Walker; - -private: - void CleanupUsedNodes(); - void CopyFrom(const ByteQueue ©); - void Destroy(); - - bool m_autoNodeSize; - size_t m_nodeSize; - ByteQueueNode *m_head, *m_tail; - byte *m_lazyString; - size_t m_lazyLength; - bool m_lazyStringModifiable; -}; - -//! use this to make sure LazyPut is finalized in event of exception -class CRYPTOPP_DLL LazyPutter -{ -public: - LazyPutter(ByteQueue &bq, const byte *inString, size_t size) - : m_bq(bq) {bq.LazyPut(inString, size);} - ~LazyPutter() - {try {m_bq.FinalizeLazyPut();} catch(...) {}} -protected: - LazyPutter(ByteQueue &bq) : m_bq(bq) {} -private: - ByteQueue &m_bq; -}; - -//! like LazyPutter, but does a LazyPutModifiable instead -class LazyPutterModifiable : public LazyPutter -{ -public: - LazyPutterModifiable(ByteQueue &bq, byte *inString, size_t size) - : LazyPutter(bq) {bq.LazyPutModifiable(inString, size);} -}; - -NAMESPACE_END - -#ifndef __BORLANDC__ -NAMESPACE_BEGIN(std) -template<> inline void swap(CryptoPP::ByteQueue &a, CryptoPP::ByteQueue &b) -{ - a.swap(b); -} -NAMESPACE_END -#endif - -#endif +// specification file for an unlimited queue for storing bytes
+
+#ifndef CRYPTOPP_QUEUE_H
+#define CRYPTOPP_QUEUE_H
+
+#include "cryptlib.h"
+#include "simple.h"
+
+NAMESPACE_BEGIN(CryptoPP)
+
+/** The queue is implemented as a linked list of byte arrays, but you don't need to
+ know about that. So just ignore this next line. :) */
+class ByteQueueNode;
+
+//! Byte Queue
+class CRYPTOPP_DLL ByteQueue : public Bufferless<BufferedTransformation>
+{
+public:
+ ByteQueue(size_t nodeSize=0);
+ ByteQueue(const ByteQueue ©);
+ ~ByteQueue();
+
+ lword MaxRetrievable() const
+ {return CurrentSize();}
+ bool AnyRetrievable() const
+ {return !IsEmpty();}
+
+ void IsolatedInitialize(const NameValuePairs ¶meters);
+ byte * CreatePutSpace(size_t &size);
+ size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking);
+
+ size_t Get(byte &outByte);
+ size_t Get(byte *outString, size_t getMax);
+
+ size_t Peek(byte &outByte) const;
+ size_t Peek(byte *outString, size_t peekMax) const;
+
+ size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true);
+ size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const;
+
+ // these member functions are not inherited
+ void SetNodeSize(size_t nodeSize);
+
+ lword CurrentSize() const;
+ bool IsEmpty() const;
+
+ void Clear();
+
+ void Unget(byte inByte);
+ void Unget(const byte *inString, size_t length);
+
+ const byte * Spy(size_t &contiguousSize) const;
+
+ void LazyPut(const byte *inString, size_t size);
+ void LazyPutModifiable(byte *inString, size_t size);
+ void UndoLazyPut(size_t size);
+ void FinalizeLazyPut();
+
+ ByteQueue & operator=(const ByteQueue &rhs);
+ bool operator==(const ByteQueue &rhs) const;
+ bool operator!=(const ByteQueue &rhs) const {return !operator==(rhs);}
+ byte operator[](lword i) const;
+ void swap(ByteQueue &rhs);
+
+ class Walker : public InputRejecting<BufferedTransformation>
+ {
+ public:
+ Walker(const ByteQueue &queue)
+ : m_queue(queue) {Initialize();}
+
+ lword GetCurrentPosition() {return m_position;}
+
+ lword MaxRetrievable() const
+ {return m_queue.CurrentSize() - m_position;}
+
+ void IsolatedInitialize(const NameValuePairs ¶meters);
+
+ size_t Get(byte &outByte);
+ size_t Get(byte *outString, size_t getMax);
+
+ size_t Peek(byte &outByte) const;
+ size_t Peek(byte *outString, size_t peekMax) const;
+
+ size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true);
+ size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const;
+
+ private:
+ const ByteQueue &m_queue;
+ const ByteQueueNode *m_node;
+ lword m_position;
+ size_t m_offset;
+ const byte *m_lazyString;
+ size_t m_lazyLength;
+ };
+
+ friend class Walker;
+
+private:
+ void CleanupUsedNodes();
+ void CopyFrom(const ByteQueue ©);
+ void Destroy();
+
+ bool m_autoNodeSize;
+ size_t m_nodeSize;
+ ByteQueueNode *m_head, *m_tail;
+ byte *m_lazyString;
+ size_t m_lazyLength;
+ bool m_lazyStringModifiable;
+};
+
+//! use this to make sure LazyPut is finalized in event of exception
+class CRYPTOPP_DLL LazyPutter
+{
+public:
+ LazyPutter(ByteQueue &bq, const byte *inString, size_t size)
+ : m_bq(bq) {bq.LazyPut(inString, size);}
+ ~LazyPutter()
+ {try {m_bq.FinalizeLazyPut();} catch(const Exception&) {assert(0);}}
+protected:
+ LazyPutter(ByteQueue &bq) : m_bq(bq) {}
+private:
+ ByteQueue &m_bq;
+};
+
+//! like LazyPutter, but does a LazyPutModifiable instead
+class LazyPutterModifiable : public LazyPutter
+{
+public:
+ LazyPutterModifiable(ByteQueue &bq, byte *inString, size_t size)
+ : LazyPutter(bq) {bq.LazyPutModifiable(inString, size);}
+};
+
+NAMESPACE_END
+
+#ifndef __BORLANDC__
+NAMESPACE_BEGIN(std)
+template<> inline void swap(CryptoPP::ByteQueue &a, CryptoPP::ByteQueue &b)
+{
+ a.swap(b);
+}
+NAMESPACE_END
+#endif
+
+#endif
|