From 87b964591c9a93146bd43e8813387392f8520337 Mon Sep 17 00:00:00 2001 From: rtk0c Date: Sun, 15 Aug 2021 21:12:35 -0700 Subject: Turn IO adapter's mechanism from function overload into structs that are given by the user --- core/src/Utils/IO/StringIntegration.hpp | 42 +++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 18 deletions(-) (limited to 'core/src/Utils/IO/StringIntegration.hpp') diff --git a/core/src/Utils/IO/StringIntegration.hpp b/core/src/Utils/IO/StringIntegration.hpp index 35b1660..a90ea98 100644 --- a/core/src/Utils/IO/StringIntegration.hpp +++ b/core/src/Utils/IO/StringIntegration.hpp @@ -4,26 +4,32 @@ #include #include -namespace DataStreamIntegrations { -void ReadFromDataStream(DataStream& s, std::string& str) +namespace DataStreamAdapters { +struct String { - uint64_t size; - s.Read(size); + void ReadFromDataStream(DataStream& s, std::string& str) + { + uint64_t size; + s.Read(size); - str = {}; - str.reserve(size); - s.ReadBytes(size, std::back_inserter(str)); -} + str = {}; + str.reserve(size); + s.ReadBytes(size, std::back_inserter(str)); + } -void WriteToDataStream(DataStream& s, const std::string& str) -{ - s.Write((uint64_t)str.size()); - s.WriteBytes(str.size(), str.data()); -} + void WriteToDataStream(DataStream& s, const std::string& str) + { + s.Write((uint64_t)str.size()); + s.WriteBytes(str.size(), str.data()); + } +}; -void WriteToDataStream(DataStream& s, const std::string_view& str) +struct StringView { - s.Write((uint64_t)str.size()); - s.WriteBytes(str.size(), str.data()); -} -} // namespace DataStreamIntegrations + void WriteToDataStream(DataStream& s, const std::string_view& str) + { + s.Write((uint64_t)str.size()); + s.WriteBytes(str.size(), str.data()); + } +}; +} // namespace DataStreamAdapters -- cgit v1.2.3-70-g09d2