From 70a3abcb3aad4c5e74b4b9fa6ac76508ac157f55 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Fri, 5 Jan 2024 05:58:49 +0100 Subject: codec: Adding a basic csv decoder. Unfinished --- modules/codec/c++/csv.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'modules/codec/c++/csv.h') diff --git a/modules/codec/c++/csv.h b/modules/codec/c++/csv.h index 67c2c1d..3727829 100644 --- a/modules/codec/c++/csv.h +++ b/modules/codec/c++/csv.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "data.h" namespace saw { @@ -7,8 +9,53 @@ namespace encode { struct Csv {}; } +namespace impl { +template +struct csv_encode { + static_assert(always_false, "Case not supported"); +}; + +template +struct csv_encode, FromDecode> { + static_assert(Dim == 1, "Only one dimension is allowed."); + static_assert(!is_array::value, "Array of an array is not allowed."); + static_assert(is_tuple::value || is_struct::value, "Only struct or tuples allowed inside a csv array"); + + using Schema = schema::Array; + + static error_or encode(const data& from, data& to){ + if constexpr (is_struct::value){ + auto eov = csv_encode::encode_header(to); + if(eov.is_error()){ + return eov; + } + } + + for(std::size_t i = 0; i < from.size(); ++i){ + auto eov = csv_encode::encode(from.at(i), to); + if(eov.is_error()){ + return eov; + } + } + + return void_t{}; + } +}; + +template<> +struct csv_encode { + using Schema = schema::String; + + static error_or encode(const data& from, data& to){ + + return void_t{}; + } +}; +} + template class codec { + static_assert(is_array::value, "Only an Array is allowed as a base value"); public: template static error_or encode(const data& from, data& to){ -- cgit v1.2.3