diff options
author | rtk0c <[email protected]> | 2021-09-04 17:58:56 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2021-09-04 17:58:56 -0700 |
commit | 70e00f817e9596a746800ba4afec2b7c4ca25142 (patch) | |
tree | 52ca5f993034c6dcb7353805450e66cefc5a0481 /core/src/Utils/IO/VectorIntegration.hpp | |
parent | 500aa5130f3f5ad211749018d7be9b0ab46c12b4 (diff) |
Migrate Template and TableTemplate to use DataStream
Diffstat (limited to 'core/src/Utils/IO/VectorIntegration.hpp')
-rw-r--r-- | core/src/Utils/IO/VectorIntegration.hpp | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/core/src/Utils/IO/VectorIntegration.hpp b/core/src/Utils/IO/VectorIntegration.hpp index dedbf29..da663a4 100644 --- a/core/src/Utils/IO/VectorIntegration.hpp +++ b/core/src/Utils/IO/VectorIntegration.hpp @@ -2,31 +2,47 @@ #include "Utils/IO/DataStream.hpp" +#include <type_traits> #include <vector> namespace DataStreamAdapters { +template <class TAdapter = void> struct Vector { template <class TElement> - void ReadFromDataStream(InputDataStream& s, std::vecetor<TElement>& vec) + static void ReadFromDataStream(InputDataStream& s, std::vector<TElement>& vec) { - s.Write((uint64_t)vec.size()); - for (auto& element : vec) { - // TODO - } - } + static_assert(std::is_default_constructible_v<TElement>); + static_assert(std::is_move_constructible_v<TElement>); - template <class TElement> - void WriteToDataStream(OutputDataStream& s, const std::vecetor<TElement>& vec) - { uint64_t size; - s >> size; + s.Read(size); vec.clear(); vec.reserve(size); for (uint64_t i = 0; i < size; ++i) { - // TODO + TElement element; + if constexpr (std::is_same_v<TAdapter, void>) { + s.ReadGeneric(element); + } else { + s.ReadObjectAdapted<TAdapter>(element); + } + + vec.push_back(std::move(element)); + } + } + + template <class TElement> + static void WriteToDataStream(OutputDataStream& s, const std::vector<TElement>& vec) + { + s.Write((uint64_t)vec.size()); + for (auto& element : vec) { + if constexpr (std::is_same_v<TAdapter, void>) { + s.WriteGeneric(element); + } else { + s.WriteObjectAdapted<TAdapter>(element); + } } } }; |