diff options
author | rtk0c <[email protected]> | 2022-06-30 21:38:53 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2022-06-30 21:38:53 -0700 |
commit | 7fe47a9d5b1727a61dc724523b530762f6d6ba19 (patch) | |
tree | e95be6e66db504ed06d00b72c579565bab873277 /app/source/Cplt/Utils/IO/VectorIntegration.hpp | |
parent | 2cf952088d375ac8b2f45b144462af0953436cff (diff) |
Restructure project
Diffstat (limited to 'app/source/Cplt/Utils/IO/VectorIntegration.hpp')
-rw-r--r-- | app/source/Cplt/Utils/IO/VectorIntegration.hpp | 42 |
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 |