PRCYCoin  2.0.0.7rc1
P2P Digital Currency
streams.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2013 The Bitcoin developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef BITCOIN_STREAMS_H
7 #define BITCOIN_STREAMS_H
8 
9 #include "allocators.h"
10 #include "serialize.h"
11 
12 #include <algorithm>
13 #include <assert.h>
14 #include <ios>
15 #include <limits>
16 #include <map>
17 #include <set>
18 #include <stdint.h>
19 #include <stdio.h>
20 #include <string.h>
21 #include <string>
22 #include <utility>
23 #include <vector>
24 
25 #define HEX_DATA_STREAM CDataStream ser(SER_NETWORK, PROTOCOL_VERSION); ser
26 #define HEX_DATA_STREAM_PROTOCOL(protocolVersion) CDataStream ser(SER_NETWORK, protocolVersion); ser
27 #define HEX_STR(a) HexStr(a.begin(), a.end())
28 
35 {
36 protected:
39  unsigned int nReadPos;
40 
41 public:
42  int nType;
43  int nVersion;
44 
45  typedef vector_type::allocator_type allocator_type;
46  typedef vector_type::size_type size_type;
47  typedef vector_type::difference_type difference_type;
48  typedef vector_type::reference reference;
49  typedef vector_type::const_reference const_reference;
50  typedef vector_type::value_type value_type;
51  typedef vector_type::iterator iterator;
52  typedef vector_type::const_iterator const_iterator;
53  typedef vector_type::reverse_iterator reverse_iterator;
54 
55  explicit CDataStream(int nTypeIn, int nVersionIn)
56  {
57  Init(nTypeIn, nVersionIn);
58  }
59 
60  CDataStream(const_iterator pbegin, const_iterator pend, int nTypeIn, int nVersionIn) : vch(pbegin, pend)
61  {
62  Init(nTypeIn, nVersionIn);
63  }
64 
65 #if !defined(_MSC_VER) || _MSC_VER >= 1300
66  CDataStream(const char* pbegin, const char* pend, int nTypeIn, int nVersionIn) : vch(pbegin, pend)
67  {
68  Init(nTypeIn, nVersionIn);
69  }
70 #endif
71 
72  CDataStream(const vector_type& vchIn, int nTypeIn, int nVersionIn) : vch(vchIn.begin(), vchIn.end())
73  {
74  Init(nTypeIn, nVersionIn);
75  }
76 
77  CDataStream(const std::vector<char>& vchIn, int nTypeIn, int nVersionIn) : vch(vchIn.begin(), vchIn.end())
78  {
79  Init(nTypeIn, nVersionIn);
80  }
81 
82  CDataStream(const std::vector<unsigned char>& vchIn, int nTypeIn, int nVersionIn) : vch(vchIn.begin(), vchIn.end())
83  {
84  Init(nTypeIn, nVersionIn);
85  }
86 
87  void Init(int nTypeIn, int nVersionIn)
88  {
89  nReadPos = 0;
90  nType = nTypeIn;
91  nVersion = nVersionIn;
92  }
93 
95  {
96  vch.insert(vch.end(), b.begin(), b.end());
97  return *this;
98  }
99 
100  friend CDataStream operator+(const CDataStream& a, const CDataStream& b)
101  {
102  CDataStream ret = a;
103  ret += b;
104  return (ret);
105  }
106 
107  std::string str() const
108  {
109  return (std::string(begin(), end()));
110  }
111 
112 
113  //
114  // Vector subset
115  //
116  const_iterator begin() const { return vch.begin() + nReadPos; }
117  iterator begin() { return vch.begin() + nReadPos; }
118  const_iterator end() const { return vch.end(); }
119  iterator end() { return vch.end(); }
120  size_type size() const { return vch.size() - nReadPos; }
121  bool empty() const { return vch.size() == nReadPos; }
122  void resize(size_type n, value_type c = 0) { vch.resize(n + nReadPos, c); }
123  void reserve(size_type n) { vch.reserve(n + nReadPos); }
124  const_reference operator[](size_type pos) const { return vch[pos + nReadPos]; }
125  reference operator[](size_type pos) { return vch[pos + nReadPos]; }
126  void clear()
127  {
128  vch.clear();
129  nReadPos = 0;
130  }
131  iterator insert(iterator it, const char& x = char()) { return vch.insert(it, x); }
132  void insert(iterator it, size_type n, const char& x) { vch.insert(it, n, x); }
133 
134  void insert(iterator it, std::vector<char>::const_iterator first, std::vector<char>::const_iterator last)
135  {
136  assert(last - first >= 0);
137  if (it == vch.begin() + nReadPos && (unsigned int)(last - first) <= nReadPos) {
138  // special case for inserting at the front when there's room
139  nReadPos -= (last - first);
140  memcpy(&vch[nReadPos], &first[0], last - first);
141  } else
142  vch.insert(it, first, last);
143  }
144 
145 #if !defined(_MSC_VER) || _MSC_VER >= 1300
146  void insert(iterator it, const char* first, const char* last)
147  {
148  assert(last - first >= 0);
149  if (it == vch.begin() + nReadPos && (unsigned int)(last - first) <= nReadPos) {
150  // special case for inserting at the front when there's room
151  nReadPos -= (last - first);
152  memcpy(&vch[nReadPos], &first[0], last - first);
153  } else
154  vch.insert(it, first, last);
155  }
156 #endif
157 
159  {
160  if (it == vch.begin() + nReadPos) {
161  // special case for erasing from the front
162  if (++nReadPos >= vch.size()) {
163  // whenever we reach the end, we take the opportunity to clear the buffer
164  nReadPos = 0;
165  return vch.erase(vch.begin(), vch.end());
166  }
167  return vch.begin() + nReadPos;
168  } else
169  return vch.erase(it);
170  }
171 
173  {
174  if (first == vch.begin() + nReadPos) {
175  // special case for erasing from the front
176  if (last == vch.end()) {
177  nReadPos = 0;
178  return vch.erase(vch.begin(), vch.end());
179  } else {
180  nReadPos = (last - vch.begin());
181  return last;
182  }
183  } else
184  return vch.erase(first, last);
185  }
186 
187  inline void Compact()
188  {
189  vch.erase(vch.begin(), vch.begin() + nReadPos);
190  nReadPos = 0;
191  }
192 
194  {
195  // Rewind by n characters if the buffer hasn't been compacted yet
196  if (n > nReadPos)
197  return false;
198  nReadPos -= n;
199  return true;
200  }
201 
202 
203  //
204  // Stream subset
205  //
206  bool eof() const { return size() == 0; }
207  CDataStream* rdbuf() { return this; }
208  int in_avail() { return size(); }
209 
210  void SetType(int n) { nType = n; }
211  int GetType() { return nType; }
212  void SetVersion(int n) { nVersion = n; }
213  int GetVersion() { return nVersion; }
214  void ReadVersion() { *this >> nVersion; }
215  void WriteVersion() { *this << nVersion; }
216 
217  CDataStream& read(char* pch, size_t nSize)
218  {
219  // Read from the beginning of the buffer
220  unsigned int nReadPosNext = nReadPos + nSize;
221  if (nReadPosNext >= vch.size()) {
222  if (nReadPosNext > vch.size()) {
223  throw std::ios_base::failure("CDataStream::read() : end of data");
224  }
225  memcpy(pch, &vch[nReadPos], nSize);
226  nReadPos = 0;
227  vch.clear();
228  return (*this);
229  }
230  memcpy(pch, &vch[nReadPos], nSize);
231  nReadPos = nReadPosNext;
232  return (*this);
233  }
234 
235  CDataStream& ignore(int nSize)
236  {
237  // Ignore from the beginning of the buffer
238  assert(nSize >= 0);
239  unsigned int nReadPosNext = nReadPos + nSize;
240  if (nReadPosNext >= vch.size()) {
241  if (nReadPosNext > vch.size())
242  throw std::ios_base::failure("CDataStream::ignore() : end of data");
243  nReadPos = 0;
244  vch.clear();
245  return (*this);
246  }
247  nReadPos = nReadPosNext;
248  return (*this);
249  }
250 
251  CDataStream& write(const char* pch, size_t nSize)
252  {
253  // Write to the end of the buffer
254  vch.insert(vch.end(), pch, pch + nSize);
255  return (*this);
256  }
257 
258  template <typename Stream>
259  void Serialize(Stream& s, int nType, int nVersion) const
260  {
261  // Special case: stream << stream concatenates like stream += stream
262  if (!vch.empty())
263  s.write((char*)&vch[0], vch.size() * sizeof(vch[0]));
264  }
265 
266  template <typename T>
267  unsigned int GetSerializeSize(const T& obj)
268  {
269  // Tells the size of the object if serialized to this stream
271  }
272 
273  template <typename T>
274  CDataStream& operator<<(const T& obj)
275  {
276  // Serialize to this stream
277  ::Serialize(*this, obj, nType, nVersion);
278  return (*this);
279  }
280 
281  template <typename T>
283  {
284  // Unserialize from this stream
285  ::Unserialize(*this, obj, nType, nVersion);
286  return (*this);
287  }
288 
290  {
291  data.insert(data.end(), begin(), end());
292  clear();
293  }
294 };
295 
296 
304 {
305 private:
306  // Disallow copies
307  CAutoFile(const CAutoFile&);
308  CAutoFile& operator=(const CAutoFile&);
309 
310  int nType;
311  int nVersion;
312 
313  FILE* file;
314 
315 public:
316  CAutoFile(FILE* filenew, int nTypeIn, int nVersionIn)
317  {
318  file = filenew;
319  nType = nTypeIn;
320  nVersion = nVersionIn;
321  }
322 
324  {
325  fclose();
326  }
327 
328  void fclose()
329  {
330  if (file) {
331  ::fclose(file);
332  file = NULL;
333  }
334  }
335 
340  FILE* release()
341  {
342  FILE* ret = file;
343  file = NULL;
344  return ret;
345  }
346 
351  FILE* Get() const { return file; }
352 
355  bool IsNull() const { return (file == NULL); }
356 
357  //
358  // Stream subset
359  //
360  void SetType(int n) { nType = n; }
361  int GetType() { return nType; }
362  void SetVersion(int n) { nVersion = n; }
363  int GetVersion() { return nVersion; }
364  void ReadVersion() { *this >> nVersion; }
365  void WriteVersion() { *this << nVersion; }
366 
367  CAutoFile& read(char* pch, size_t nSize)
368  {
369  if (!file)
370  throw std::ios_base::failure("CAutoFile::read : file handle is NULL");
371  if (fread(pch, 1, nSize, file) != nSize)
372  throw std::ios_base::failure(feof(file) ? "CAutoFile::read : end of file" : "CAutoFile::read : fread failed");
373  return (*this);
374  }
375 
376  CAutoFile& ignore(size_t nSize)
377  {
378  if (!file)
379  throw std::ios_base::failure("CAutoFile::ignore: file handle is NULL");
380  unsigned char data[4096];
381  while (nSize > 0) {
382  size_t nNow = std::min<size_t>(nSize, sizeof(data));
383  if (fread(data, 1, nNow, file) != nNow)
384  throw std::ios_base::failure(feof(file) ? "CAutoFile::ignore: end of file" : "CAutoFile::read: fread failed");
385  nSize -= nNow;
386  }
387  return (*this);
388  }
389 
390  CAutoFile& write(const char* pch, size_t nSize)
391  {
392  if (!file)
393  throw std::ios_base::failure("CAutoFile::write : file handle is NULL");
394  if (fwrite(pch, 1, nSize, file) != nSize)
395  throw std::ios_base::failure("CAutoFile::write : write failed");
396  return (*this);
397  }
398 
399  template <typename T>
400  unsigned int GetSerializeSize(const T& obj)
401  {
402  // Tells the size of the object if serialized to this stream
404  }
405 
406  template <typename T>
407  CAutoFile& operator<<(const T& obj)
408  {
409  // Serialize to this stream
410  if (!file)
411  throw std::ios_base::failure("CAutoFile::operator<< : file handle is NULL");
412  ::Serialize(*this, obj, nType, nVersion);
413  return (*this);
414  }
415 
416  template <typename T>
418  {
419  // Unserialize from this stream
420  if (!file)
421  throw std::ios_base::failure("CAutoFile::operator>> : file handle is NULL");
422  ::Unserialize(*this, obj, nType, nVersion);
423  return (*this);
424  }
425 };
426 
434 {
435 private:
436  // Disallow copies
439 
440  int nType;
441  int nVersion;
442 
443  FILE* src; // source file
444  uint64_t nSrcPos; // how many bytes have been read from source
445  uint64_t nReadPos; // how many bytes have been read from this
446  uint64_t nReadLimit; // up to which position we're allowed to read
447  uint64_t nRewind; // how many bytes we guarantee to rewind
448  std::vector<char> vchBuf; // the buffer
449 
450 protected:
451  // read data from the source to fill the buffer
452  bool Fill()
453  {
454  unsigned int pos = nSrcPos % vchBuf.size();
455  unsigned int readNow = vchBuf.size() - pos;
456  unsigned int nAvail = vchBuf.size() - (nSrcPos - nReadPos) - nRewind;
457  if (nAvail < readNow)
458  readNow = nAvail;
459  if (readNow == 0)
460  return false;
461  size_t read = fread((void*)&vchBuf[pos], 1, readNow, src);
462  if (read == 0) {
463  throw std::ios_base::failure(feof(src) ? "CBufferedFile::Fill : end of file" : "CBufferedFile::Fill : fread failed");
464  } else {
465  nSrcPos += read;
466  return true;
467  }
468  }
469 
470 public:
471  CBufferedFile(FILE* fileIn, uint64_t nBufSize, uint64_t nRewindIn, int nTypeIn, int nVersionIn) : nSrcPos(0), nReadPos(0), nReadLimit((uint64_t)(-1)), nRewind(nRewindIn), vchBuf(nBufSize, 0)
472  {
473  src = fileIn;
474  nType = nTypeIn;
475  nVersion = nVersionIn;
476  }
477 
479  {
480  fclose();
481  }
482 
483  void fclose()
484  {
485  if (src) {
486  ::fclose(src);
487  src = NULL;
488  }
489  }
490 
491  // check whether we're at the end of the source file
492  bool eof() const
493  {
494  return nReadPos == nSrcPos && feof(src);
495  }
496 
497  // read a number of bytes
498  CBufferedFile& read(char* pch, size_t nSize)
499  {
500  if (nSize + nReadPos > nReadLimit)
501  throw std::ios_base::failure("Read attempted past buffer limit");
502  if (nSize + nRewind > vchBuf.size())
503  throw std::ios_base::failure("Read larger than buffer size");
504  while (nSize > 0) {
505  if (nReadPos == nSrcPos)
506  Fill();
507  unsigned int pos = nReadPos % vchBuf.size();
508  size_t nNow = nSize;
509  if (nNow + pos > vchBuf.size())
510  nNow = vchBuf.size() - pos;
511  if (nNow + nReadPos > nSrcPos)
512  nNow = nSrcPos - nReadPos;
513  memcpy(pch, &vchBuf[pos], nNow);
514  nReadPos += nNow;
515  pch += nNow;
516  nSize -= nNow;
517  }
518  return (*this);
519  }
520 
521  // return the current reading position
522  uint64_t GetPos()
523  {
524  return nReadPos;
525  }
526 
527  // rewind to a given reading position
528  bool SetPos(uint64_t nPos)
529  {
530  nReadPos = nPos;
531  if (nReadPos + nRewind < nSrcPos) {
533  return false;
534  } else if (nReadPos > nSrcPos) {
535  nReadPos = nSrcPos;
536  return false;
537  } else {
538  return true;
539  }
540  }
541 
542  bool Seek(uint64_t nPos)
543  {
544  long nLongPos = nPos;
545  if (nPos != (uint64_t)nLongPos)
546  return false;
547  if (fseek(src, nLongPos, SEEK_SET))
548  return false;
549  nLongPos = ftell(src);
550  nSrcPos = nLongPos;
551  nReadPos = nLongPos;
552  return true;
553  }
554 
555  // prevent reading beyond a certain position
556  // no argument removes the limit
557  bool SetLimit(uint64_t nPos = (uint64_t)(-1))
558  {
559  if (nPos < nReadPos)
560  return false;
561  nReadLimit = nPos;
562  return true;
563  }
564 
565  template <typename T>
567  {
568  // Unserialize from this stream
569  ::Unserialize(*this, obj, nType, nVersion);
570  return (*this);
571  }
572 
573  // search for a given byte in the stream, and remain positioned on it
574  void FindByte(char ch)
575  {
576  while (true) {
577  if (nReadPos == nSrcPos)
578  Fill();
579  if (vchBuf[nReadPos % vchBuf.size()] == ch)
580  break;
581  nReadPos++;
582  }
583  }
584 };
585 
586 #endif // BITCOIN_STREAMS_H
CAutoFile::operator<<
CAutoFile & operator<<(const T &obj)
Definition: streams.h:407
CDataStream::end
iterator end()
Definition: streams.h:119
CDataStream::value_type
vector_type::value_type value_type
Definition: streams.h:50
CBufferedFile::GetPos
uint64_t GetPos()
Definition: streams.h:522
CDataStream::size_type
vector_type::size_type size_type
Definition: streams.h:46
CAutoFile::operator=
CAutoFile & operator=(const CAutoFile &)
CAutoFile::file
FILE * file
Definition: streams.h:313
CAutoFile::nType
int nType
Definition: streams.h:310
CAutoFile::WriteVersion
void WriteVersion()
Definition: streams.h:365
CAutoFile::read
CAutoFile & read(char *pch, size_t nSize)
Definition: streams.h:367
CDataStream::erase
iterator erase(iterator first, iterator last)
Definition: streams.h:172
CDataStream::vch
vector_type vch
Definition: streams.h:38
CAutoFile::SetVersion
void SetVersion(int n)
Definition: streams.h:362
CDataStream::operator+
friend CDataStream operator+(const CDataStream &a, const CDataStream &b)
Definition: streams.h:100
b
void const uint64_t * b
Definition: field_5x52_asm_impl.h:10
CDataStream::begin
const_iterator begin() const
Definition: streams.h:116
CBufferedFile::SetPos
bool SetPos(uint64_t nPos)
Definition: streams.h:528
CAutoFile::Get
FILE * Get() const
Get wrapped FILE* without transfer of ownership.
Definition: streams.h:351
CDataStream::CDataStream
CDataStream(const std::vector< unsigned char > &vchIn, int nTypeIn, int nVersionIn)
Definition: streams.h:82
CDataStream::CDataStream
CDataStream(const char *pbegin, const char *pend, int nTypeIn, int nVersionIn)
Definition: streams.h:66
CAutoFile::ReadVersion
void ReadVersion()
Definition: streams.h:364
CDataStream::operator>>
CDataStream & operator>>(T &obj)
Definition: streams.h:282
CDataStream::Init
void Init(int nTypeIn, int nVersionIn)
Definition: streams.h:87
CDataStream::CDataStream
CDataStream(const vector_type &vchIn, int nTypeIn, int nVersionIn)
Definition: streams.h:72
CAutoFile::operator>>
CAutoFile & operator>>(T &obj)
Definition: streams.h:417
CDataStream::insert
void insert(iterator it, std::vector< char >::const_iterator first, std::vector< char >::const_iterator last)
Definition: streams.h:134
CDataStream::reference
vector_type::reference reference
Definition: streams.h:48
memcpy
void * memcpy(void *a, const void *b, size_t c)
Definition: glibc_compat.cpp:15
CBufferedFile::fclose
void fclose()
Definition: streams.h:483
GetSerializeSize
unsigned int GetSerializeSize(char a, int, int=0)
Definition: serialize.h:194
Unserialize
void Unserialize(Stream &s, char &a, int, int=0)
Definition: serialize.h:218
CBufferedFile::Seek
bool Seek(uint64_t nPos)
Definition: streams.h:542
CDataStream::Compact
void Compact()
Definition: streams.h:187
CDataStream::begin
iterator begin()
Definition: streams.h:117
CBufferedFile::FindByte
void FindByte(char ch)
Definition: streams.h:574
CAutoFile::~CAutoFile
~CAutoFile()
Definition: streams.h:323
CDataStream::insert
iterator insert(iterator it, const char &x=char())
Definition: streams.h:131
CDataStream::vector_type
CSerializeData vector_type
Definition: streams.h:37
CDataStream::CDataStream
CDataStream(const std::vector< char > &vchIn, int nTypeIn, int nVersionIn)
Definition: streams.h:77
CBufferedFile::src
FILE * src
Definition: streams.h:443
CBufferedFile::nRewind
uint64_t nRewind
Definition: streams.h:447
CDataStream::insert
void insert(iterator it, size_type n, const char &x)
Definition: streams.h:132
CAutoFile
Non-refcounted RAII wrapper for FILE*.
Definition: streams.h:303
CDataStream::const_reference
vector_type::const_reference const_reference
Definition: streams.h:49
CDataStream::nVersion
int nVersion
Definition: streams.h:43
CBufferedFile::~CBufferedFile
~CBufferedFile()
Definition: streams.h:478
CDataStream::operator+=
CDataStream & operator+=(const CDataStream &b)
Definition: streams.h:94
CBufferedFile::Fill
bool Fill()
Definition: streams.h:452
CDataStream::allocator_type
vector_type::allocator_type allocator_type
Definition: streams.h:45
CBufferedFile
Non-refcounted RAII wrapper around a FILE* that implements a ring buffer to deserialize from.
Definition: streams.h:433
CBufferedFile::eof
bool eof() const
Definition: streams.h:492
CDataStream::CDataStream
CDataStream(int nTypeIn, int nVersionIn)
Definition: streams.h:55
CDataStream::ignore
CDataStream & ignore(int nSize)
Definition: streams.h:235
CDataStream::operator[]
const_reference operator[](size_type pos) const
Definition: streams.h:124
CAutoFile::write
CAutoFile & write(const char *pch, size_t nSize)
Definition: streams.h:390
CBufferedFile::nSrcPos
uint64_t nSrcPos
Definition: streams.h:444
CBufferedFile::nReadPos
uint64_t nReadPos
Definition: streams.h:445
CDataStream::end
const_iterator end() const
Definition: streams.h:118
CDataStream::nType
int nType
Definition: streams.h:42
CBufferedFile::vchBuf
std::vector< char > vchBuf
Definition: streams.h:448
CAutoFile::CAutoFile
CAutoFile(FILE *filenew, int nTypeIn, int nVersionIn)
Definition: streams.h:316
allocators.h
CDataStream::erase
iterator erase(iterator it)
Definition: streams.h:158
CDataStream::GetAndClear
void GetAndClear(CSerializeData &data)
Definition: streams.h:289
CDataStream::WriteVersion
void WriteVersion()
Definition: streams.h:215
CAutoFile::IsNull
bool IsNull() const
Return true if the wrapped FILE* is NULL, false otherwise.
Definition: streams.h:355
CSerializeData
std::vector< char, zero_after_free_allocator< char > > CSerializeData
Definition: allocators.h:265
CBufferedFile::operator>>
CBufferedFile & operator>>(T &obj)
Definition: streams.h:566
CAutoFile::nVersion
int nVersion
Definition: streams.h:311
CAutoFile::ignore
CAutoFile & ignore(size_t nSize)
Definition: streams.h:376
CDataStream::GetType
int GetType()
Definition: streams.h:211
CBufferedFile::operator=
CBufferedFile & operator=(const CBufferedFile &)
CAutoFile::GetVersion
int GetVersion()
Definition: streams.h:363
CAutoFile::CAutoFile
CAutoFile(const CAutoFile &)
CAutoFile::fclose
void fclose()
Definition: streams.h:328
CDataStream::reverse_iterator
vector_type::reverse_iterator reverse_iterator
Definition: streams.h:53
CDataStream::reserve
void reserve(size_type n)
Definition: streams.h:123
CDataStream::size
size_type size() const
Definition: streams.h:120
CBufferedFile::nType
int nType
Definition: streams.h:440
CDataStream::SetVersion
void SetVersion(int n)
Definition: streams.h:212
CBufferedFile::CBufferedFile
CBufferedFile(const CBufferedFile &)
CDataStream::operator[]
reference operator[](size_type pos)
Definition: streams.h:125
CDataStream::Serialize
void Serialize(Stream &s, int nType, int nVersion) const
Definition: streams.h:259
CAutoFile::GetSerializeSize
unsigned int GetSerializeSize(const T &obj)
Definition: streams.h:400
CDataStream::clear
void clear()
Definition: streams.h:126
CDataStream::difference_type
vector_type::difference_type difference_type
Definition: streams.h:47
CDataStream::ReadVersion
void ReadVersion()
Definition: streams.h:214
CDataStream::operator<<
CDataStream & operator<<(const T &obj)
Definition: streams.h:274
CDataStream::const_iterator
vector_type::const_iterator const_iterator
Definition: streams.h:52
Serialize
void Serialize(Stream &s, char a, int, int=0)
Definition: serialize.h:206
CDataStream::resize
void resize(size_type n, value_type c=0)
Definition: streams.h:122
CBufferedFile::read
CBufferedFile & read(char *pch, size_t nSize)
Definition: streams.h:498
CDataStream::in_avail
int in_avail()
Definition: streams.h:208
serialize.h
CDataStream::nReadPos
unsigned int nReadPos
Definition: streams.h:39
CDataStream
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:34
CDataStream::insert
void insert(iterator it, const char *first, const char *last)
Definition: streams.h:146
CDataStream::CDataStream
CDataStream(const_iterator pbegin, const_iterator pend, int nTypeIn, int nVersionIn)
Definition: streams.h:60
CDataStream::empty
bool empty() const
Definition: streams.h:121
CAutoFile::release
FILE * release()
Get wrapped FILE* with transfer of ownership.
Definition: streams.h:340
CDataStream::GetVersion
int GetVersion()
Definition: streams.h:213
CBufferedFile::nReadLimit
uint64_t nReadLimit
Definition: streams.h:446
CDataStream::Rewind
bool Rewind(size_type n)
Definition: streams.h:193
CDataStream::str
std::string str() const
Definition: streams.h:107
CBufferedFile::CBufferedFile
CBufferedFile(FILE *fileIn, uint64_t nBufSize, uint64_t nRewindIn, int nTypeIn, int nVersionIn)
Definition: streams.h:471
CDataStream::rdbuf
CDataStream * rdbuf()
Definition: streams.h:207
CDataStream::SetType
void SetType(int n)
Definition: streams.h:210
CDataStream::GetSerializeSize
unsigned int GetSerializeSize(const T &obj)
Definition: streams.h:267
CDataStream::read
CDataStream & read(char *pch, size_t nSize)
Definition: streams.h:217
CDataStream::eof
bool eof() const
Definition: streams.h:206
CBufferedFile::SetLimit
bool SetLimit(uint64_t nPos=(uint64_t)(-1))
Definition: streams.h:557
CDataStream::iterator
vector_type::iterator iterator
Definition: streams.h:51
CAutoFile::SetType
void SetType(int n)
Definition: streams.h:360
CDataStream::write
CDataStream & write(const char *pch, size_t nSize)
Definition: streams.h:251
CAutoFile::GetType
int GetType()
Definition: streams.h:361
CBufferedFile::nVersion
int nVersion
Definition: streams.h:441