aboutsummaryrefslogtreecommitdiff
path: root/app/source/Cplt/Utils/IO/TslArrayIntegration.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'app/source/Cplt/Utils/IO/TslArrayIntegration.hpp')
-rw-r--r--app/source/Cplt/Utils/IO/TslArrayIntegration.hpp50
1 files changed, 50 insertions, 0 deletions
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 <Cplt/Utils/IO/DataStream.hpp>
+#include <Cplt/Utils/IO/Helper.hpp>
+#include <Cplt/Utils/IO/StringIntegration.hpp>
+
+#include <tsl/array_map.h>
+#include <tsl/array_set.h>
+#include <string>
+#include <type_traits>
+
+// TODO support custom key types
+
+namespace DataStreamAdapters {
+template <class TAdapter = void>
+struct TslArrayMap
+{
+ template <class TValue>
+ static void ReadFromDataStream(InputDataStream& stream, tsl::array_map<char, TValue>& map)
+ {
+ static_assert(std::is_default_constructible_v<TValue>);
+ static_assert(std::is_move_constructible_v<TValue>);
+
+ uint64_t size;
+ stream.Read(size);
+ map.reserve(size);
+
+ for (uint64_t i = 0; i < size; ++i) {
+ std::string key;
+ stream.ReadObjectAdapted<DataStreamAdapters::String>(key);
+
+ TValue value;
+ ReadHelper<TAdapter>(stream, value);
+
+ map.insert(key, std::move(value));
+ }
+ }
+
+ template <class TValue>
+ static void WriteToDataStream(OutputDataStream& stream, const tsl::array_map<char, TValue>& map)
+ {
+ stream.Write((uint64_t)map.size());
+
+ for (auto it = map.begin(); it != map.end(); ++it) {
+ stream.WriteObjectAdapted<DataStreamAdapters::StringView>(it.key_sv());
+ WriteHelper<TAdapter>(stream, it.value());
+ }
+ }
+};
+} // namespace DataStreamAdapters