diff options
Diffstat (limited to 'modules/codec/c++')
-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_)...}} |