aboutsummaryrefslogtreecommitdiff
path: root/app/source/Cplt/Utils/IO/VectorIntegration.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'app/source/Cplt/Utils/IO/VectorIntegration.hpp')
-rw-r--r--app/source/Cplt/Utils/IO/VectorIntegration.hpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/app/source/Cplt/Utils/IO/VectorIntegration.hpp b/app/source/Cplt/Utils/IO/VectorIntegration.hpp
new file mode 100644
index 0000000..93967f6
--- /dev/null
+++ b/app/source/Cplt/Utils/IO/VectorIntegration.hpp
@@ -0,0 +1,42 @@
+#pragma once
+
+#include <Cplt/Utils/IO/DataStream.hpp>
+#include <Cplt/Utils/IO/Helper.hpp>
+
+#include <type_traits>
+#include <vector>
+
+namespace DataStreamAdapters {
+template <class TAdapter = void>
+struct Vector
+{
+ template <class TElement>
+ static void ReadFromDataStream(InputDataStream& stream, std::vector<TElement>& vec)
+ {
+ static_assert(std::is_default_constructible_v<TElement>);
+ static_assert(std::is_move_constructible_v<TElement>);
+
+ uint64_t size;
+ stream.Read(size);
+
+ vec.clear();
+ vec.reserve(size);
+
+ for (uint64_t i = 0; i < size; ++i) {
+ TElement element;
+ ReadHelper<TAdapter>(stream, element);
+
+ vec.push_back(std::move(element));
+ }
+ }
+
+ template <class TElement>
+ static void WriteToDataStream(OutputDataStream& stream, const std::vector<TElement>& vec)
+ {
+ stream.Write((uint64_t)vec.size());
+ for (auto& element : vec) {
+ WriteHelper<TAdapter>(stream, element);
+ }
+ }
+};
+} // namespace DataStreamAdapters