#pragma once #include "Utils/IO/DataStream.hpp" namespace DataStreamAdapters { /// Helper to invoke either Read() or ReadObject(). /// 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 ReadHelper(InputDataStream& stream, T& t) { if constexpr (!std::is_same_v) { stream.ReadObjectAdapted(t); } else if constexpr (requires(T tt, InputDataStream ss) { ss.Read(tt); }) { stream.Read(t); } else if constexpr (requires(T tt, InputDataStream ss) { ss.ReadEnum(tt); }) { stream.ReadEnum(t); } else if constexpr (requires(T tt, InputDataStream ss) { ss.ReadObject(tt); }) { stream.ReadObject(t); } else { static_assert(false && sizeof(T), "This type is neither a 'value' nor an 'object'."); } } /// Helper to invoke either Write() or WriteObject(). /// 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 WriteHelper(OutputDataStream& stream, T& t) { if constexpr (!std::is_same_v) { stream.WriteObjectAdapted(t); } else if constexpr (requires(T tt, OutputDataStream ss) { ss.Write(tt); }) { stream.Write(t); } else if constexpr (requires(T tt, OutputDataStream ss) { ss.WriteEnum(tt); }) { stream.WriteEnum(t); } else if constexpr (requires(T tt, OutputDataStream ss) { ss.WriteObject(tt); }) { stream.WriteObject(t); } else { static_assert(false && sizeof(T), "This type is neither a 'value' nor an 'object'."); } } } // namespace DataStreamAdapters