Skip to content

Commit

Permalink
streams: backport OverrideStream class
Browse files Browse the repository at this point in the history
  • Loading branch information
furszy committed Aug 10, 2021
1 parent acdbcf8 commit 6921f42
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/streams.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,34 @@
#include <utility>
#include <vector>

template<typename Stream>
class OverrideStream
{
Stream* stream;

const int nType;
const int nVersion;

public:
OverrideStream(Stream* stream_, int nType_, int nVersion_) : stream(stream_), nType(nType_), nVersion(nVersion_) {}

template<typename T>
OverrideStream<Stream>& operator<<(const T& obj)
{
// Serialize to this stream
::Serialize(*this->stream, obj, nType, nVersion);
return (*this);
}

template<typename T>
OverrideStream<Stream>& operator>>(T&& obj)
{
// Unserialize from this stream
::Unserialize(*this->stream, obj, nType, nVersion);
return (*this);
}
};

/** Double ended buffer combining vector and stream-like interfaces.
*
* >> and << read and write unformatted data using the above serialization templates.
Expand Down

0 comments on commit 6921f42

Please sign in to comment.