diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2016-10-28 21:55:12 -0700 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2016-11-07 09:39:46 -0800 |
commit | c2c5d42f36f4440aaddc4a64974a52fdb07af08b (patch) | |
tree | 121eb8fbd0c3fa2378c900bd411c3a6c0eb7d2ab | |
parent | 50e8a9ccd78c8c20c3eac6618da7293078446b58 (diff) |
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.
-rw-r--r-- | src/hash.h | 3 | ||||
-rw-r--r-- | src/script/bitcoinconsensus.cpp | 3 | ||||
-rw-r--r-- | src/serialize.h | 3 | ||||
-rw-r--r-- | src/streams.h | 25 |
4 files changed, 12 insertions, 22 deletions
diff --git a/src/hash.h b/src/hash.h index db4e130ae7..88926ab31f 100644 --- a/src/hash.h +++ b/src/hash.h @@ -138,9 +138,8 @@ public: CHashWriter(int nTypeIn, int nVersionIn) : nType(nTypeIn), nVersion(nVersionIn) {} - CHashWriter& write(const char *pch, size_t size) { + void write(const char *pch, size_t size) { ctx.Write((const unsigned char*)pch, size); - return (*this); } // invalidates the object diff --git a/src/script/bitcoinconsensus.cpp b/src/script/bitcoinconsensus.cpp index 1d0ca0c5ac..4e2358d9a2 100644 --- a/src/script/bitcoinconsensus.cpp +++ b/src/script/bitcoinconsensus.cpp @@ -23,7 +23,7 @@ public: m_remaining(txToLen) {} - TxInputStream& read(char* pch, size_t nSize) + void read(char* pch, size_t nSize) { if (nSize > m_remaining) throw std::ios_base::failure(std::string(__func__) + ": end of data"); @@ -37,7 +37,6 @@ public: memcpy(pch, m_data, nSize); m_remaining -= nSize; m_data += nSize; - return *this; } template<typename T> diff --git a/src/serialize.h b/src/serialize.h index 82870c45b3..f8e82edf8b 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -943,10 +943,9 @@ public: CSizeComputer(int nTypeIn, int nVersionIn) : nSize(0), nType(nTypeIn), nVersion(nVersionIn) {} - CSizeComputer& write(const char *psz, size_t nSize) + void write(const char *psz, size_t nSize) { this->nSize += nSize; - return *this; } template<typename T> diff --git a/src/streams.h b/src/streams.h index c66a996519..582443ab4f 100644 --- a/src/streams.h +++ b/src/streams.h @@ -255,7 +255,7 @@ public: void SetVersion(int n) { nVersion = n; } int GetVersion() { return nVersion; } - CDataStream& read(char* pch, size_t nSize) + void read(char* pch, size_t nSize) { // Read from the beginning of the buffer unsigned int nReadPosNext = nReadPos + nSize; @@ -268,14 +268,13 @@ public: memcpy(pch, &vch[nReadPos], nSize); nReadPos = 0; vch.clear(); - return (*this); + return; } memcpy(pch, &vch[nReadPos], nSize); nReadPos = nReadPosNext; - return (*this); } - CDataStream& ignore(int nSize) + void ignore(int nSize) { // Ignore from the beginning of the buffer if (nSize < 0) { @@ -288,17 +287,15 @@ public: throw std::ios_base::failure("CDataStream::ignore(): end of data"); nReadPos = 0; vch.clear(); - return (*this); + return; } nReadPos = nReadPosNext; - return (*this); } - CDataStream& write(const char* pch, size_t nSize) + void write(const char* pch, size_t nSize) { // Write to the end of the buffer vch.insert(vch.end(), pch, pch + nSize); - return (*this); } template<typename Stream> @@ -433,16 +430,15 @@ public: void SetVersion(int n) { nVersion = n; } int GetVersion() { return nVersion; } - CAutoFile& read(char* pch, size_t nSize) + void read(char* pch, size_t nSize) { if (!file) throw std::ios_base::failure("CAutoFile::read: file handle is NULL"); if (fread(pch, 1, nSize, file) != nSize) throw std::ios_base::failure(feof(file) ? "CAutoFile::read: end of file" : "CAutoFile::read: fread failed"); - return (*this); } - CAutoFile& ignore(size_t nSize) + void ignore(size_t nSize) { if (!file) throw std::ios_base::failure("CAutoFile::ignore: file handle is NULL"); @@ -453,16 +449,14 @@ public: throw std::ios_base::failure(feof(file) ? "CAutoFile::ignore: end of file" : "CAutoFile::read: fread failed"); nSize -= nNow; } - return (*this); } - CAutoFile& write(const char* pch, size_t nSize) + void write(const char* pch, size_t nSize) { if (!file) throw std::ios_base::failure("CAutoFile::write: file handle is NULL"); if (fwrite(pch, 1, nSize, file) != nSize) throw std::ios_base::failure("CAutoFile::write: write failed"); - return (*this); } template<typename T> @@ -563,7 +557,7 @@ public: } // read a number of bytes - CBufferedFile& read(char *pch, size_t nSize) { + void read(char *pch, size_t nSize) { if (nSize + nReadPos > nReadLimit) throw std::ios_base::failure("Read attempted past buffer limit"); if (nSize + nRewind > vchBuf.size()) @@ -582,7 +576,6 @@ public: pch += nNow; nSize -= nNow; } - return (*this); } // return the current reading position |