From 04653742243e4bb6452108cfd0fef2f4afd8f23b Mon Sep 17 00:00:00 2001 From: rtk0c Date: Mon, 6 Sep 2021 00:15:35 -0700 Subject: Fix all compile errors, remove OperateIOProxy requirement from DataStream api --- core/src/Utils/IO/DataStream.hpp | 70 +++++++++++----------------------------- 1 file changed, 19 insertions(+), 51 deletions(-) (limited to 'core/src/Utils/IO/DataStream.hpp') 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 void ReadObject(TObject& obj) { - if constexpr (requires(TObject t) { t.ReadFromDataStream(std::declval()); }) { - obj.ReadFromDataStream(*this); - } else if constexpr (requires(TObject t) { t.OperateIOProxy(std::declval()); }) { - 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 - 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 @@ -104,7 +82,7 @@ public: } public: - // Proxy functions for OperateIOProxy + // Proxy functions for writing templated IO functions template void Bytes(size_t byteCount, T* buffer) @@ -118,6 +96,12 @@ public: Read(t); } + template + void Enum(T& t) + { + ReadEnum(t); + } + template void Object(T& obj) { @@ -180,41 +164,19 @@ public: } template - void WriteObject(TObject& obj) - { - if constexpr (requires(TObject t) { t.WriteToDataStream(std::declval()); }) { - obj.WriteToDataStream(*this); - } else if constexpr (requires(TObject t) { t.OperateIOProxy(std::declval()); }) { - 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 - 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'."); - } + void WriteObject(const TObject& obj) + { + obj.WriteToDataStream(*this); } template - 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 void Bytes(size_t byteCount, T* buffer) @@ -228,6 +190,12 @@ public: Write(t); } + template + void Enum(T t) + { + WriteEnum(t); + } + template void Object(T& obj) { -- cgit v1.2.3-70-g09d2