From 7fe47a9d5b1727a61dc724523b530762f6d6ba19 Mon Sep 17 00:00:00 2001 From: rtk0c Date: Thu, 30 Jun 2022 21:38:53 -0700 Subject: Restructure project --- app/source/Cplt/Utils/IO/TslArrayIntegration.hpp | 50 ++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 app/source/Cplt/Utils/IO/TslArrayIntegration.hpp (limited to 'app/source/Cplt/Utils/IO/TslArrayIntegration.hpp') diff --git a/app/source/Cplt/Utils/IO/TslArrayIntegration.hpp b/app/source/Cplt/Utils/IO/TslArrayIntegration.hpp new file mode 100644 index 0000000..b585bee --- /dev/null +++ b/app/source/Cplt/Utils/IO/TslArrayIntegration.hpp @@ -0,0 +1,50 @@ +#pragma once + +#include +#include +#include + +#include +#include +#include +#include + +// TODO support custom key types + +namespace DataStreamAdapters { +template +struct TslArrayMap +{ + template + static void ReadFromDataStream(InputDataStream& stream, tsl::array_map& map) + { + static_assert(std::is_default_constructible_v); + static_assert(std::is_move_constructible_v); + + uint64_t size; + stream.Read(size); + map.reserve(size); + + for (uint64_t i = 0; i < size; ++i) { + std::string key; + stream.ReadObjectAdapted(key); + + TValue value; + ReadHelper(stream, value); + + map.insert(key, std::move(value)); + } + } + + template + static void WriteToDataStream(OutputDataStream& stream, const tsl::array_map& map) + { + stream.Write((uint64_t)map.size()); + + for (auto it = map.begin(); it != map.end(); ++it) { + stream.WriteObjectAdapted(it.key_sv()); + WriteHelper(stream, it.value()); + } + } +}; +} // namespace DataStreamAdapters -- cgit v1.2.3-70-g09d2