Fabcoin Core  0.16.2
P2P Digital Currency
queue.h
Go to the documentation of this file.
1 // queue.h - written and placed in the public domain by Wei Dai
2 
6 
7 #ifndef CRYPTOPP_QUEUE_H
8 #define CRYPTOPP_QUEUE_H
9 
10 #include "cryptlib.h"
11 #include "simple.h"
12 
14 
15 class ByteQueueNode;
16 
21 {
22 public:
28  ByteQueue(size_t nodeSize=0);
29 
32  ByteQueue(const ByteQueue &copy);
33  ~ByteQueue();
34 
36  {return CurrentSize();}
37  bool AnyRetrievable() const
38  {return !IsEmpty();}
39 
40  void IsolatedInitialize(const NameValuePairs &parameters);
41  byte * CreatePutSpace(size_t &size);
42  size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking);
43 
44  size_t Get(byte &outByte);
45  size_t Get(byte *outString, size_t getMax);
46 
47  size_t Peek(byte &outByte) const;
48  size_t Peek(byte *outString, size_t peekMax) const;
49 
50  size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true);
51  size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const;
52 
53  // these member functions are not inherited
54  void SetNodeSize(size_t nodeSize);
55 
56  lword CurrentSize() const;
57  bool IsEmpty() const;
58 
59  void Clear();
60 
61  void Unget(byte inByte);
62  void Unget(const byte *inString, size_t length);
63 
64  const byte * Spy(size_t &contiguousSize) const;
65 
66  void LazyPut(const byte *inString, size_t size);
67  void LazyPutModifiable(byte *inString, size_t size);
68  void UndoLazyPut(size_t size);
69  void FinalizeLazyPut();
70 
71  ByteQueue & operator=(const ByteQueue &rhs);
72  bool operator==(const ByteQueue &rhs) const;
73  bool operator!=(const ByteQueue &rhs) const {return !operator==(rhs);}
74  byte operator[](lword i) const;
75  void swap(ByteQueue &rhs);
76 
79  class Walker : public InputRejecting<BufferedTransformation>
80  {
81  public:
84  Walker(const ByteQueue &queue)
85  : m_queue(queue), m_node(NULL), m_position(0), m_offset(0), m_lazyString(NULL), m_lazyLength(0)
86  {Initialize();}
87 
88  lword GetCurrentPosition() {return m_position;}
89 
91  {return m_queue.CurrentSize() - m_position;}
92 
93  void IsolatedInitialize(const NameValuePairs &parameters);
94 
95  size_t Get(byte &outByte);
96  size_t Get(byte *outString, size_t getMax);
97 
98  size_t Peek(byte &outByte) const;
99  size_t Peek(byte *outString, size_t peekMax) const;
100 
101  size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true);
102  size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const;
103 
104  private:
106  const ByteQueueNode *m_node;
108  size_t m_offset;
110  size_t m_lazyLength;
111  };
112 
113  friend class Walker;
114 
115 private:
116  void CleanupUsedNodes();
117  void CopyFrom(const ByteQueue &copy);
118  void Destroy();
119 
121  size_t m_nodeSize;
122  ByteQueueNode *m_head, *m_tail;
124  size_t m_lazyLength;
126 };
127 
130 {
131 public:
132  LazyPutter(ByteQueue &bq, const byte *inString, size_t size)
133  : m_bq(bq) {bq.LazyPut(inString, size);}
135  {try {m_bq.FinalizeLazyPut();} catch(const Exception&) {CRYPTOPP_ASSERT(0);}}
136 protected:
137  LazyPutter(ByteQueue &bq) : m_bq(bq) {}
138 private:
140 };
141 
144 {
145 public:
146  LazyPutterModifiable(ByteQueue &bq, byte *inString, size_t size)
147  : LazyPutter(bq) {bq.LazyPutModifiable(inString, size);}
148 };
149 
151 
152 #ifndef __BORLANDC__
154 template<> inline void swap(CryptoPP::ByteQueue &a, CryptoPP::ByteQueue &b)
155 {
156  a.swap(b);
157 }
159 #endif
160 
161 #endif
Base class for all exceptions thrown by the library.
Definition: cryptlib.h:140
LazyPutter(ByteQueue &bq, const byte *inString, size_t size)
Definition: queue.h:132
const byte * m_lazyString
Definition: queue.h:109
void LazyPutModifiable(byte *inString, size_t size)
Definition: queue.cpp:275
uint8_t byte
Definition: Common.h:57
use this to make sure LazyPut is finalized in event of exception
Definition: queue.h:129
~LazyPutter()
Definition: queue.h:134
const lword LWORD_MAX
Definition: config.h:246
Classes providing basic library services.
ByteQueue & m_bq
Definition: queue.h:139
#define NAMESPACE_BEGIN(x)
Definition: config.h:200
Abstract base classes that provide a uniform interface to this library.
std::hash for asio::adress
Definition: Common.h:323
Base class for input rejecting filters.
Definition: simple.h:121
like LazyPutter, but does a LazyPutModifiable instead
Definition: queue.h:143
size_t m_lazyLength
Definition: queue.h:124
Interface for buffered transformations.
Definition: cryptlib.h:1352
lword MaxRetrievable() const
Provides the number of bytes ready for retrieval.
Definition: queue.h:35
concurrent_queue< JitTask > m_queue
Definition: SmartVM.cpp:60
lword m_position
Definition: queue.h:107
bool operator==(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
Definition: asn.h:558
ByteQueueNode * m_tail
Definition: queue.h:122
const std::string DEFAULT_CHANNEL
Default channel for BufferedTransformation.
Definition: cryptlib.cpp:59
byte * m_lazyString
Definition: queue.h:123
#define a(i)
const ByteQueue & m_queue
Definition: queue.h:105
LazyPutterModifiable(ByteQueue &bq, byte *inString, size_t size)
Definition: queue.h:146
bool operator!=(const ByteQueue &rhs) const
Definition: queue.h:73
bool m_autoNodeSize
Definition: queue.h:120
lword MaxRetrievable() const
Provides the number of bytes ready for retrieval.
Definition: queue.h:90
const ByteQueueNode * m_node
Definition: queue.h:106
size_t m_lazyLength
Definition: queue.h:110
#define b(i, j)
#define CRYPTOPP_ASSERT(exp)
Definition: trap.h:92
Data structure used to store byte strings.
Definition: queue.h:20
bool AnyRetrievable() const
Determines whether bytes are ready for retrieval.
Definition: queue.h:37
uint8_t const size_t const size
Definition: sha3.h:20
LazyPutter(ByteQueue &bq)
Definition: queue.h:137
#define NAMESPACE_END
Definition: config.h:201
std::vector< char * > parameters
Definition: boostTest.cpp:46
void LazyPut(const byte *inString, size_t size)
Definition: queue.cpp:260
word64 lword
Definition: config.h:245
A ByteQueue iterator.
Definition: queue.h:79
#define CRYPTOPP_DLL
Definition: config.h:704
lword GetCurrentPosition()
Definition: queue.h:88
bool m_lazyStringModifiable
Definition: queue.h:125
size_t m_nodeSize
Definition: queue.h:121
Walker(const ByteQueue &queue)
Construct a ByteQueue Walker.
Definition: queue.h:84
size_t m_offset
Definition: queue.h:108
Base class for bufferless filters.
Definition: simple.h:83
Interface for retrieving values given their names.
Definition: cryptlib.h:279
NAMESPACE_END void swap(CryptoPP::ByteQueue &a, CryptoPP::ByteQueue &b)
Definition: queue.h:154