summaryrefslogtreecommitdiff
path: root/modules/codec/c++/csv.h
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2024-01-05 05:58:49 +0100
committerClaudius "keldu" Holeksa <mail@keldu.de>2024-01-05 05:58:49 +0100
commit70a3abcb3aad4c5e74b4b9fa6ac76508ac157f55 (patch)
tree07f6516c19fd4f5eda0c7a5c8cb440570eafccfb /modules/codec/c++/csv.h
parent162e5c5da90f4316725086fa6a2ae13b3c22104e (diff)
codec: Adding a basic csv decoder. Unfinished
Diffstat (limited to 'modules/codec/c++/csv.h')
-rw-r--r--modules/codec/c++/csv.h47
1 files changed, 47 insertions, 0 deletions
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 <forstio/error.h>
+
#include "data.h"
namespace saw {
@@ -7,8 +9,53 @@ namespace encode {
struct Csv {};
}
+namespace impl {
+template<typename Schema, typename FromDecode>
+struct csv_encode {
+ static_assert(always_false<T>, "Case not supported");
+};
+
+template<typename T, size_t Dim>
+struct csv_encode<schema::Array<T,Dim>, FromDecode> {
+ static_assert(Dim == 1, "Only one dimension is allowed.");
+ static_assert(!is_array<T>::value, "Array of an array is not allowed.");
+ static_assert(is_tuple<T>::value || is_struct<T>::value, "Only struct or tuples allowed inside a csv array");
+
+ using Schema = schema::Array<T,Dim>;
+
+ static error_or<void> encode(const data<Schema, FromDecode>& from, data<Schema, encode::Csv>& to){
+ if constexpr (is_struct<T>::value){
+ auto eov = csv_encode<T>::encode_header(to);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+
+ for(std::size_t i = 0; i < from.size(); ++i){
+ auto eov = csv_encode<T>::encode(from.at(i), to);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+
+ return void_t{};
+ }
+};
+
+template<>
+struct csv_encode<schema::String, FromDecode> {
+ using Schema = schema::String;
+
+ static error_or<void> encode(const data<Schema, FromDecode>& from, data<Schema, encode::Csv>& to){
+
+ return void_t{};
+ }
+};
+}
+
template<typename Schema>
class codec<Schema, encode::Csv> {
+ static_assert(is_array<Schema>::value, "Only an Array is allowed as a base value");
public:
template<typename FromEncode>
static error_or<void> encode(const data<Schema, FromEncode>& from, data<Schema,encode::Csv>& to){