I'm not sure it's desirable, I know multiple inheritance can be a bit of a mess, and frankly I'm too unfamiliar with it to assess whether or not this is a better approach. Just thought I'd share since it does lead to a fair amount of code deduplication. Since it's a transitory phase, I think it might make sense. Compiles and unit tests are fine:
<details>
<summary>git diff</summary>
diff --git a/src/hash.h b/src/hash.h
index b2ef29fcd..05d72dbab 100644
--- a/src/hash.h
+++ b/src/hash.h
@@ -145,7 +145,7 @@ public:
}
};
-class CHashWriter : public HashWriter
+class CHashWriter : virtual public HashWriter
{
private:
const int nType;
@@ -167,7 +167,7 @@ public:
/** Reads data from an underlying stream, while hashing the read data. */
template <typename Source>
-class HashVerifier : public HashWriter
+class HashVerifier : virtual public HashWriter
{
private:
Source& m_source;
@@ -200,29 +200,10 @@ public:
};
template<typename Source>
-class CHashVerifier : public CHashWriter
+class CHashVerifier : public CHashWriter, public HashVerifier<Source>
{
-private:
- Source* source;
-
public:
- explicit CHashVerifier(Source* source_) : CHashWriter(source_->GetType(), source_->GetVersion()), source(source_) {}
-
- void read(Span<std::byte> dst)
- {
- source->read(dst);
- this->write(dst);
- }
-
- void ignore(size_t nSize)
- {
- std::byte data[1024];
- while (nSize > 0) {
- size_t now = std::min<size_t>(nSize, 1024);
- read({data, now});
- nSize -= now;
- }
- }
+ explicit CHashVerifier(Source* source) : CHashWriter(source->GetType(), source->GetVersion()), HashVerifier<Source>(*source) {}
template<typename T>
CHashVerifier<Source>& operator>>(T&& obj)
</details>