From df26f6df6ca8e97d919f188addd484be8a78242a Mon Sep 17 00:00:00 2001 From: hazby2002 <1094501217@qq.com> Date: Wed, 27 Dec 2023 01:26:00 +0800 Subject: [PATCH] Implement write operation of Parser for c-arrays. --- include/rfl/Result.hpp | 5 ++++ include/rfl/parsing/Parser.hpp | 1 + include/rfl/parsing/Parser_c_array.hpp | 40 ++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 include/rfl/parsing/Parser_c_array.hpp diff --git a/include/rfl/Result.hpp b/include/rfl/Result.hpp index a6d564fc..096f517d 100644 --- a/include/rfl/Result.hpp +++ b/include/rfl/Result.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -339,6 +340,10 @@ class Result { std::variant t_or_err_; }; +/// This is simply to get the compilation to pass. +template +class Result : public Result> {}; + } // namespace rfl #endif diff --git a/include/rfl/parsing/Parser.hpp b/include/rfl/parsing/Parser.hpp index 71624a33..607356b7 100644 --- a/include/rfl/parsing/Parser.hpp +++ b/include/rfl/parsing/Parser.hpp @@ -4,6 +4,7 @@ #include "Parser_array.hpp" #include "Parser_base.hpp" #include "Parser_box.hpp" +#include "Parser_c_array.hpp" #include "Parser_default.hpp" #include "Parser_map_like.hpp" #include "Parser_named_tuple.hpp" diff --git a/include/rfl/parsing/Parser_c_array.hpp b/include/rfl/parsing/Parser_c_array.hpp new file mode 100644 index 00000000..0755e495 --- /dev/null +++ b/include/rfl/parsing/Parser_c_array.hpp @@ -0,0 +1,40 @@ +#ifndef RFL_PARSING_PARSER_C_ARRAY_HPP_ +#define RFL_PARSING_PARSER_C_ARRAY_HPP_ + +#include + +#include "../Result.hpp" +#include "../always_false.hpp" +#include "Parser_base.hpp" + +namespace rfl { +namespace parsing { + +template + requires AreReaderAndWriter +struct Parser { + public: + using InputArrayType = typename R::InputArrayType; + using InputVarType = typename R::InputVarType; + + using OutputArrayType = typename W::OutputArrayType; + using OutputVarType = typename W::OutputVarType; + + using CArray = T[_size]; + static Result read(const R& _r, const InputVarType& _var) noexcept { + static_assert(always_false_v, "Unimplemented"); + } + + static OutputVarType write(const W& _w, const CArray& _arr) noexcept { + auto arr = _w.new_array(); + for (const auto& e : _arr) { + _w.add(Parser>::write(_w, e), &arr); + } + return OutputVarType(arr); + } +}; + +} // namespace parsing +} // namespace rfl + +#endif