diff options
author | fanquake <fanquake@gmail.com> | 2023-09-14 09:39:37 +0100 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2023-09-14 09:56:10 +0100 |
commit | 8209e86eeb4ceb6dd0e06c45fb3c799bb42834ab (patch) | |
tree | d4d5c617a8c742e3cd79dd75d6bc7f2ea9499a11 /src/streams.h | |
parent | f1a9fd627b1a669c4dfab797da42825230708f2a (diff) | |
parent | fa19c914f7fe7be127c0fb330b41ff7c091f40aa (diff) |
Merge bitcoin/bitcoin#28458: refactor: Remove unused GetType() from CBufferedFile and CAutoFile
fa19c914f7fe7be127c0fb330b41ff7c091f40aa scripted-diff: Rename CBufferedFile to BufferedFile (MarcoFalke)
fa2f2413b87f5fc1e5c92bf510beebdcd0091714 Remove unused GetType() from CBufferedFile and CAutoFile (MarcoFalke)
5c2b3cd4b856f1bb536daaf7f576b1b1b42293ca dbwrapper: Use DataStream for batch operations (TheCharlatan)
Pull request description:
This refactor is required for https://github.com/bitcoin/bitcoin/pull/28052 and https://github.com/bitcoin/bitcoin/pull/28451
Thus, split it out.
ACKs for top commit:
ajtowns:
utACK fa19c914f7fe7be127c0fb330b41ff7c091f40aa
TheCharlatan:
ACK fa19c914f7fe7be127c0fb330b41ff7c091f40aa
Tree-SHA512: d9c232324702512e45fd73ec3e3170f1e8a8c8f9c49cb613a6b693a9f83358914155527ace2517a2cd626a0cedcada56ef70a2a7812edafb1888fd6765eebba2
Diffstat (limited to 'src/streams.h')
-rw-r--r-- | src/streams.h | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/src/streams.h b/src/streams.h index 5ff952be76..f9a817c9b6 100644 --- a/src/streams.h +++ b/src/streams.h @@ -550,12 +550,10 @@ public: class CAutoFile : public AutoFile { private: - const int nType; const int nVersion; public: - explicit CAutoFile(std::FILE* file, int type, int version, std::vector<std::byte> data_xor = {}) : AutoFile{file, std::move(data_xor)}, nType{type}, nVersion{version} {} - int GetType() const { return nType; } + explicit CAutoFile(std::FILE* file, int version, std::vector<std::byte> data_xor = {}) : AutoFile{file, std::move(data_xor)}, nVersion{version} {} int GetVersion() const { return nVersion; } template<typename T> @@ -579,10 +577,9 @@ public: * Will automatically close the file when it goes out of scope if not null. * If you need to close the file early, use file.fclose() instead of fclose(file). */ -class CBufferedFile +class BufferedFile { private: - const int nType; const int nVersion; FILE *src; //!< source file @@ -603,7 +600,7 @@ private: return false; size_t nBytes = fread((void*)&vchBuf[pos], 1, readNow, src); if (nBytes == 0) { - throw std::ios_base::failure(feof(src) ? "CBufferedFile::Fill: end of file" : "CBufferedFile::Fill: fread failed"); + throw std::ios_base::failure(feof(src) ? "BufferedFile::Fill: end of file" : "BufferedFile::Fill: fread failed"); } nSrcPos += nBytes; return true; @@ -632,25 +629,24 @@ private: } public: - CBufferedFile(FILE* fileIn, uint64_t nBufSize, uint64_t nRewindIn, int nTypeIn, int nVersionIn) - : nType(nTypeIn), nVersion(nVersionIn), nReadLimit(std::numeric_limits<uint64_t>::max()), nRewind(nRewindIn), vchBuf(nBufSize, std::byte{0}) + BufferedFile(FILE* fileIn, uint64_t nBufSize, uint64_t nRewindIn, int nVersionIn) + : nVersion{nVersionIn}, nReadLimit{std::numeric_limits<uint64_t>::max()}, nRewind{nRewindIn}, vchBuf(nBufSize, std::byte{0}) { if (nRewindIn >= nBufSize) throw std::ios_base::failure("Rewind limit must be less than buffer size"); src = fileIn; } - ~CBufferedFile() + ~BufferedFile() { fclose(); } // Disallow copies - CBufferedFile(const CBufferedFile&) = delete; - CBufferedFile& operator=(const CBufferedFile&) = delete; + BufferedFile(const BufferedFile&) = delete; + BufferedFile& operator=(const BufferedFile&) = delete; int GetVersion() const { return nVersion; } - int GetType() const { return nType; } void fclose() { @@ -715,7 +711,7 @@ public: } template<typename T> - CBufferedFile& operator>>(T&& obj) { + BufferedFile& operator>>(T&& obj) { ::Unserialize(*this, obj); return (*this); } |