diff options
Diffstat (limited to 'core/src/Utils/IO/DataStream.hpp')
-rw-r--r-- | core/src/Utils/IO/DataStream.hpp | 68 |
1 files changed, 18 insertions, 50 deletions
diff --git a/core/src/Utils/IO/DataStream.hpp b/core/src/Utils/IO/DataStream.hpp index 58fae7d..3c00f4c 100644 --- a/core/src/Utils/IO/DataStream.hpp +++ b/core/src/Utils/IO/DataStream.hpp @@ -72,29 +72,7 @@ public: template <class TObject> void ReadObject(TObject& obj) { - if constexpr (requires(TObject t) { t.ReadFromDataStream(std::declval<BaseDataStream>()); }) { - obj.ReadFromDataStream(*this); - } else if constexpr (requires(TObject t) { t.OperateIOProxy(std::declval<InputDataStream>()); }) { - obj.OperateIOProxy(*this); - } else { - static_assert(false && sizeof(TObject), "This type does not have integration with InputDataStream."); - } - } - - /// Helper to invoke either Read() or ReadObject(). Note that this function doesn't account for types that needs and adapter. - /// This is intended for writing IO adapters, users that's writing IO logic shouldn't using this - it increases compile time while reducing readability. - template <class T> - void ReadGeneric(T& t) - { - if constexpr (requires(T tt, InputDataStream ss) { ss.Read(tt); }) { - Read(t); - } else if constexpr (requires(T tt, InputDataStream ss) { ss.ReadEnum(tt); }) { - ReadEnum(t); - } else if constexpr (requires(T tt, InputDataStream ss) { ss.ReadObject(tt); }) { - ReadObject(t); - } else { - static_assert(false && sizeof(T), "This type is neither a 'value' nor an 'object'."); - } + obj.ReadFromDataStream(*this); } template <class TAdapter, class TObject> @@ -104,7 +82,7 @@ public: } public: - // Proxy functions for OperateIOProxy + // Proxy functions for writing templated IO functions template <class T> void Bytes(size_t byteCount, T* buffer) @@ -119,6 +97,12 @@ public: } template <class T> + void Enum(T& t) + { + ReadEnum(t); + } + + template <class T> void Object(T& obj) { ReadObject(obj); @@ -180,41 +164,19 @@ public: } template <class TObject> - void WriteObject(TObject& obj) + void WriteObject(const TObject& obj) { - if constexpr (requires(TObject t) { t.WriteToDataStream(std::declval<BaseDataStream>()); }) { - obj.WriteToDataStream(*this); - } else if constexpr (requires(TObject t) { t.OperateIOProxy(std::declval<OutputDataStream>()); }) { - obj.OperateIOProxy(*this); - } else { - static_assert(false && sizeof(TObject), "This type does not have integration with OutputDataStream."); - } - } - - /// Helper to invoke either Write() or WriteObject(). Note that this function doesn't account for types that needs and adapter. - /// This is intended for writing IO adapters, users that's writing IO logic shouldn't using this - it increases compile time while reducing readability. - template <class T> - void WriteGeneric(T& t) - { - if constexpr (requires(T tt, OutputDataStream ss) { ss.Write(tt); }) { - Write(t); - } else if constexpr (requires(T tt, OutputDataStream ss) { ss.WriteEnum(tt); }) { - WriteEnum(t); - } else if constexpr (requires(T tt, OutputDataStream ss) { ss.WriteObject(tt); }) { - WriteObject(t); - } else { - static_assert(false && sizeof(T), "This type is neither a 'value' nor an 'object'."); - } + obj.WriteToDataStream(*this); } template <class TAdapter, class TObject> - void WriteObjectAdapted(TObject& obj) + void WriteObjectAdapted(const TObject& obj) { TAdapter::WriteToDataStream(*this, obj); } public: - // Proxy functions for OperateIOProxy + // Proxy functions for writing templated IO functions template <class T> void Bytes(size_t byteCount, T* buffer) @@ -229,6 +191,12 @@ public: } template <class T> + void Enum(T t) + { + WriteEnum(t); + } + + template <class T> void Object(T& obj) { WriteObject(obj); |