mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-03 00:26:19 +08:00
Implement write operation of Parser for c-arrays.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <optional>
|
||||
#include <ranges>
|
||||
#include <span>
|
||||
#include <stdexcept>
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
@@ -339,6 +340,10 @@ class Result {
|
||||
std::variant<T, Error> t_or_err_;
|
||||
};
|
||||
|
||||
/// This is simply to get the compilation to pass.
|
||||
template <class T, std::size_t _n>
|
||||
class Result<T[_n]> : public Result<std::span<T, _n>> {};
|
||||
|
||||
} // namespace rfl
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
#ifndef RFL_PARSING_PARSER_C_ARRAY_HPP_
|
||||
#define RFL_PARSING_PARSER_C_ARRAY_HPP_
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#include "../Result.hpp"
|
||||
#include "../always_false.hpp"
|
||||
#include "Parser_base.hpp"
|
||||
|
||||
namespace rfl {
|
||||
namespace parsing {
|
||||
|
||||
template <class R, class W, class T, size_t _size>
|
||||
requires AreReaderAndWriter<R, W, T[_size]>
|
||||
struct Parser<R, W, T[_size]> {
|
||||
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<CArray> read(const R& _r, const InputVarType& _var) noexcept {
|
||||
static_assert(always_false_v<T>, "Unimplemented");
|
||||
}
|
||||
|
||||
static OutputVarType write(const W& _w, const CArray& _arr) noexcept {
|
||||
auto arr = _w.new_array();
|
||||
for (const auto& e : _arr) {
|
||||
_w.add(Parser<R, W, std::remove_cvref_t<T>>::write(_w, e), &arr);
|
||||
}
|
||||
return OutputVarType(arr);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace parsing
|
||||
} // namespace rfl
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user