mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 14:38:29 +01:00
Support serialization as another type without casting
This adds a READWRITEAS(type, obj) macro which serializes obj as if it were casted to (const type&) when const, and to (type&) when non-const. This makes it usable in serialization code that uses a single implementation for both serialization and deserializing, which doesn't know the constness of the object involved.
This commit is contained in:
@@ -148,7 +148,12 @@ enum
|
||||
SER_GETHASH = (1 << 2),
|
||||
};
|
||||
|
||||
#define READWRITE(...) (::SerReadWriteMany(s, ser_action, __VA_ARGS__))
|
||||
//! Convert the reference base type to X, without changing constness or reference type.
|
||||
template<typename X> X& ReadWriteAsHelper(X& x) { return x; }
|
||||
template<typename X> const X& ReadWriteAsHelper(const X& x) { return x; }
|
||||
|
||||
#define READWRITE(...) (::SerReadWriteMany(s, ser_action, __VA_ARGS__))
|
||||
#define READWRITEAS(type, obj) (::SerReadWriteMany(s, ser_action, ReadWriteAsHelper<type>(obj)))
|
||||
|
||||
/**
|
||||
* Implement three methods for serializable objects. These are actually wrappers over
|
||||
|
||||
Reference in New Issue
Block a user