diff options
author | Claudius "keldu" Holeksa <mail@keldu.de> | 2023-12-30 02:21:17 +0100 |
---|---|---|
committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2023-12-30 02:21:17 +0100 |
commit | 162e5c5da90f4316725086fa6a2ae13b3c22104e (patch) | |
tree | 7047b7afeaf95a2195e9f66182a783e831ac4ce4 /modules/codec/c++/data.h | |
parent | 55dd66d8dd773ed98580d1fac0e15da6244d35b8 (diff) |
codec: Added minor add functionality in common edge case
Diffstat (limited to 'modules/codec/c++/data.h')
-rw-r--r-- | modules/codec/c++/data.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/modules/codec/c++/data.h b/modules/codec/c++/data.h index 365405f..2dffdbe 100644 --- a/modules/codec/c++/data.h +++ b/modules/codec/c++/data.h @@ -1,6 +1,7 @@ #pragma once #include <forstio/common.h> +#include <forstio/error.h> #include <forstio/templates.h> #include <cassert> @@ -205,6 +206,35 @@ class data<schema::Array<T,Dim>, encode::Native> { value_.resize(get_full_size()); } + template<size_t i = 0> + error_or<void> add(saw::data<T,encode::Native> data){ + /** @todo + * Generally the last dimension can always accept a element so to say. + * Changing the others would require moving data due to the stride changing. + * Since the last dimension doesn't affect the stride, we don't need reordering there. + * But I want a quick solution for one dimension so here we are. + * + * I can always ignore strides and use a stacked std::vector + * std::vector<std::vector<...>> and so on. + * But for now I'm keeping the strides. Smaller chunks of memory aren't to bad either + * though. + * I'll probably change it to the smaller chunks + */ + static_assert(Dim == 1, "Currently can't deal with higher dims"); + static_assert(i < Dim, "Can't add to dimension. Index i larger than dimension size"); + + try { + value_.emplace_back(std::move(data)); + }catch(const std::exception& e){ + (void) e; + return make_error<err::out_of_memory>(); + } + + ++dims_.at(i); + + return void_t{}; + } + template<std::integral... Dims> data(Dims... size_): data{{static_cast<std::size_t>(size_)...}} |