Skip to content

Commit c2c5d42

Browse files
committed
Make streams' read and write return void
The stream implementations had two cascading layers (the upper one with operator<< and operator>>, and a lower one with read and write). The lower layer's functions are never cascaded (nor should they, as they should only be used from the higher layer), so make them return void instead.
1 parent 50e8a9c commit c2c5d42

File tree

4 files changed

+12
-22
lines changed

4 files changed

+12
-22
lines changed

src/hash.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,8 @@ class CHashWriter
138138

139139
CHashWriter(int nTypeIn, int nVersionIn) : nType(nTypeIn), nVersion(nVersionIn) {}
140140

141-
CHashWriter& write(const char *pch, size_t size) {
141+
void write(const char *pch, size_t size) {
142142
ctx.Write((const unsigned char*)pch, size);
143-
return (*this);
144143
}
145144

146145
// invalidates the object

src/script/bitcoinconsensus.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class TxInputStream
2323
m_remaining(txToLen)
2424
{}
2525

26-
TxInputStream& read(char* pch, size_t nSize)
26+
void read(char* pch, size_t nSize)
2727
{
2828
if (nSize > m_remaining)
2929
throw std::ios_base::failure(std::string(__func__) + ": end of data");
@@ -37,7 +37,6 @@ class TxInputStream
3737
memcpy(pch, m_data, nSize);
3838
m_remaining -= nSize;
3939
m_data += nSize;
40-
return *this;
4140
}
4241

4342
template<typename T>

src/serialize.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -943,10 +943,9 @@ class CSizeComputer
943943

944944
CSizeComputer(int nTypeIn, int nVersionIn) : nSize(0), nType(nTypeIn), nVersion(nVersionIn) {}
945945

946-
CSizeComputer& write(const char *psz, size_t nSize)
946+
void write(const char *psz, size_t nSize)
947947
{
948948
this->nSize += nSize;
949-
return *this;
950949
}
951950

952951
template<typename T>

src/streams.h

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ class CDataStream
255255
void SetVersion(int n) { nVersion = n; }
256256
int GetVersion() { return nVersion; }
257257

258-
CDataStream& read(char* pch, size_t nSize)
258+
void read(char* pch, size_t nSize)
259259
{
260260
// Read from the beginning of the buffer
261261
unsigned int nReadPosNext = nReadPos + nSize;
@@ -268,14 +268,13 @@ class CDataStream
268268
memcpy(pch, &vch[nReadPos], nSize);
269269
nReadPos = 0;
270270
vch.clear();
271-
return (*this);
271+
return;
272272
}
273273
memcpy(pch, &vch[nReadPos], nSize);
274274
nReadPos = nReadPosNext;
275-
return (*this);
276275
}
277276

278-
CDataStream& ignore(int nSize)
277+
void ignore(int nSize)
279278
{
280279
// Ignore from the beginning of the buffer
281280
if (nSize < 0) {
@@ -288,17 +287,15 @@ class CDataStream
288287
throw std::ios_base::failure("CDataStream::ignore(): end of data");
289288
nReadPos = 0;
290289
vch.clear();
291-
return (*this);
290+
return;
292291
}
293292
nReadPos = nReadPosNext;
294-
return (*this);
295293
}
296294

297-
CDataStream& write(const char* pch, size_t nSize)
295+
void write(const char* pch, size_t nSize)
298296
{
299297
// Write to the end of the buffer
300298
vch.insert(vch.end(), pch, pch + nSize);
301-
return (*this);
302299
}
303300

304301
template<typename Stream>
@@ -433,16 +430,15 @@ class CAutoFile
433430
void SetVersion(int n) { nVersion = n; }
434431
int GetVersion() { return nVersion; }
435432

436-
CAutoFile& read(char* pch, size_t nSize)
433+
void read(char* pch, size_t nSize)
437434
{
438435
if (!file)
439436
throw std::ios_base::failure("CAutoFile::read: file handle is NULL");
440437
if (fread(pch, 1, nSize, file) != nSize)
441438
throw std::ios_base::failure(feof(file) ? "CAutoFile::read: end of file" : "CAutoFile::read: fread failed");
442-
return (*this);
443439
}
444440

445-
CAutoFile& ignore(size_t nSize)
441+
void ignore(size_t nSize)
446442
{
447443
if (!file)
448444
throw std::ios_base::failure("CAutoFile::ignore: file handle is NULL");
@@ -453,16 +449,14 @@ class CAutoFile
453449
throw std::ios_base::failure(feof(file) ? "CAutoFile::ignore: end of file" : "CAutoFile::read: fread failed");
454450
nSize -= nNow;
455451
}
456-
return (*this);
457452
}
458453

459-
CAutoFile& write(const char* pch, size_t nSize)
454+
void write(const char* pch, size_t nSize)
460455
{
461456
if (!file)
462457
throw std::ios_base::failure("CAutoFile::write: file handle is NULL");
463458
if (fwrite(pch, 1, nSize, file) != nSize)
464459
throw std::ios_base::failure("CAutoFile::write: write failed");
465-
return (*this);
466460
}
467461

468462
template<typename T>
@@ -563,7 +557,7 @@ class CBufferedFile
563557
}
564558

565559
// read a number of bytes
566-
CBufferedFile& read(char *pch, size_t nSize) {
560+
void read(char *pch, size_t nSize) {
567561
if (nSize + nReadPos > nReadLimit)
568562
throw std::ios_base::failure("Read attempted past buffer limit");
569563
if (nSize + nRewind > vchBuf.size())
@@ -582,7 +576,6 @@ class CBufferedFile
582576
pch += nNow;
583577
nSize -= nNow;
584578
}
585-
return (*this);
586579
}
587580

588581
// return the current reading position

0 commit comments

Comments
 (0)