monotone

monotone Mtn Source Tree

Root/cryptopp/queue.h

1// specification file for an unlimited queue for storing bytes
2
3#ifndef CRYPTOPP_QUEUE_H
4#define CRYPTOPP_QUEUE_H
5
6#include "simple.h"
7//#include <algorithm>
8
9NAMESPACE_BEGIN(CryptoPP)
10
11/** The queue is implemented as a linked list of byte arrays, but you don't need to
12 know about that. So just ignore this next line. :) */
13class ByteQueueNode;
14
15//! Byte Queue
16class ByteQueue : public Bufferless<BufferedTransformation>
17{
18public:
19ByteQueue(unsigned int m_nodeSize=256);
20ByteQueue(const ByteQueue &copy);
21~ByteQueue();
22
23unsigned long MaxRetrievable() const
24{return CurrentSize();}
25bool AnyRetrievable() const
26{return !IsEmpty();}
27
28void IsolatedInitialize(const NameValuePairs &parameters);
29byte * CreatePutSpace(unsigned int &size);
30unsigned int Put2(const byte *inString, unsigned int length, int messageEnd, bool blocking);
31
32unsigned int Get(byte &outByte);
33unsigned int Get(byte *outString, unsigned int getMax);
34
35unsigned int Peek(byte &outByte) const;
36unsigned int Peek(byte *outString, unsigned int peekMax) const;
37
38unsigned int TransferTo2(BufferedTransformation &target, unsigned long &transferBytes, const std::string &channel=NULL_CHANNEL, bool blocking=true);
39unsigned int CopyRangeTo2(BufferedTransformation &target, unsigned long &begin, unsigned long end=ULONG_MAX, const std::string &channel=NULL_CHANNEL, bool blocking=true) const;
40
41// these member functions are not inherited
42void SetNodeSize(unsigned int nodeSize) {m_nodeSize = nodeSize;}
43
44unsigned long CurrentSize() const;
45bool IsEmpty() const;
46
47void Clear();
48
49void Unget(byte inByte);
50void Unget(const byte *inString, unsigned int length);
51
52const byte * Spy(unsigned int &contiguousSize) const;
53
54void LazyPut(const byte *inString, unsigned int size);
55void UndoLazyPut(unsigned int size);
56void FinalizeLazyPut();
57
58ByteQueue & operator=(const ByteQueue &rhs);
59bool operator==(const ByteQueue &rhs) const;
60byte operator[](unsigned long i) const;
61void swap(ByteQueue &rhs);
62
63class Walker : public InputRejecting<BufferedTransformation>
64{
65public:
66Walker(const ByteQueue &queue)
67: m_queue(queue) {Initialize();}
68
69unsigned long GetCurrentPosition() {return m_position;}
70
71unsigned long MaxRetrievable() const
72{return m_queue.CurrentSize() - m_position;}
73
74void IsolatedInitialize(const NameValuePairs &parameters);
75
76unsigned int Get(byte &outByte);
77unsigned int Get(byte *outString, unsigned int getMax);
78
79unsigned int Peek(byte &outByte) const;
80unsigned int Peek(byte *outString, unsigned int peekMax) const;
81
82unsigned int TransferTo2(BufferedTransformation &target, unsigned long &transferBytes, const std::string &channel=NULL_CHANNEL, bool blocking=true);
83unsigned int CopyRangeTo2(BufferedTransformation &target, unsigned long &begin, unsigned long end=ULONG_MAX, const std::string &channel=NULL_CHANNEL, bool blocking=true) const;
84
85private:
86const ByteQueue &m_queue;
87const ByteQueueNode *m_node;
88unsigned long m_position;
89unsigned int m_offset;
90const byte *m_lazyString;
91unsigned int m_lazyLength;
92};
93
94friend class Walker;
95
96private:
97void CleanupUsedNodes();
98void CopyFrom(const ByteQueue &copy);
99void Destroy();
100
101unsigned int m_nodeSize;
102ByteQueueNode *m_head, *m_tail;
103const byte *m_lazyString;
104unsigned int m_lazyLength;
105};
106
107//! use this to make sure LazyPut is finalized in event of exception
108class LazyPutter
109{
110public:
111LazyPutter(ByteQueue &bq, const byte *inString, unsigned int size)
112: m_bq(bq) {bq.LazyPut(inString, size);}
113~LazyPutter()
114{try {m_bq.FinalizeLazyPut();} catch(...) {}}
115private:
116ByteQueue &m_bq;
117};
118
119NAMESPACE_END
120
121NAMESPACE_BEGIN(std)
122template<> inline void swap(CryptoPP::ByteQueue &a, CryptoPP::ByteQueue &b)
123{
124a.swap(b);
125}
126NAMESPACE_END
127
128#endif

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status