mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-03 00:26:19 +08:00
Some more adaptations
This commit is contained in:
@@ -51,8 +51,8 @@ struct Parser<R, W, std::array<T, _size>> {
|
||||
const P& _parent) noexcept {
|
||||
auto arr = ParentType::add_array(_w, _size, _parent);
|
||||
const auto new_parent = typename ParentType::Array{&arr};
|
||||
for (auto it = _arr.begin(); it != _arr.end(); ++it) {
|
||||
Parser<R, W, std::remove_cvref_t<T>>::write(_w, *it, new_parent);
|
||||
for (const auto& e : _arr) {
|
||||
Parser<R, W, std::remove_cvref_t<T>>::write(_w, e, new_parent);
|
||||
}
|
||||
_w.end_array(&arr);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "../Result.hpp"
|
||||
#include "../always_false.hpp"
|
||||
#include "../internal/to_std_array.hpp"
|
||||
#include "Parent.hpp"
|
||||
#include "Parser_array.hpp"
|
||||
#include "Parser_base.hpp"
|
||||
|
||||
@@ -14,7 +15,7 @@ namespace rfl {
|
||||
namespace parsing {
|
||||
|
||||
template <class R, class W, class T, size_t _size>
|
||||
requires AreReaderAndWriter<R, W, T[_size]>
|
||||
requires AreReaderAndWriter<R, W, T[_size]>
|
||||
struct Parser<R, W, T[_size]> {
|
||||
public:
|
||||
using InputArrayType = typename R::InputArrayType;
|
||||
@@ -23,20 +24,24 @@ struct Parser<R, W, T[_size]> {
|
||||
using OutputArrayType = typename W::OutputArrayType;
|
||||
using OutputVarType = typename W::OutputVarType;
|
||||
|
||||
using ParentType = Parent<W>;
|
||||
using CArray = T[_size];
|
||||
using StdArray = internal::to_std_array_t<T[_size]>;
|
||||
|
||||
static Result<Array<T[_size]>> read(const R& _r,
|
||||
const InputVarType& _var) noexcept {
|
||||
using StdArray = internal::to_std_array_t<T[_size]>;
|
||||
return Parser<R, W, StdArray>::read(_r, _var);
|
||||
}
|
||||
|
||||
static OutputVarType write(const W& _w, const CArray& _arr) noexcept {
|
||||
auto arr = _w.new_array();
|
||||
template <class P>
|
||||
static void write(const W& _w, const CArray& _arr,
|
||||
const P& _parent) noexcept {
|
||||
auto arr = ParentType::add_array(_w, _size, _parent);
|
||||
const auto new_parent = typename ParentType::Array{&arr};
|
||||
for (const auto& e : _arr) {
|
||||
_w.add(Parser<R, W, std::remove_cvref_t<T>>::write(_w, e), &arr);
|
||||
Parser<R, W, std::remove_cvref_t<T>>::write(_w, e, new_parent);
|
||||
}
|
||||
return OutputVarType(arr);
|
||||
_w.end_array(&arr);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -39,9 +39,12 @@ struct Parser<R, W, Result<T>> {
|
||||
Parser<R, W, VariantType>::read(_r, _var).transform(to_res));
|
||||
}
|
||||
|
||||
static OutputVarType write(const W& _w, const Result<T>& _r) noexcept {
|
||||
const auto write_t = [&](const auto& _t) -> OutputVarType {
|
||||
return Parser<R, W, std::remove_cvref_t<T>>::write(_w, _t);
|
||||
template <class P>
|
||||
static void write(const W& _w, const Result<T>& _r,
|
||||
const P& _parent) noexcept {
|
||||
const auto write_t = [&](const auto& _t) -> Nothing {
|
||||
Parser<R, W, std::remove_cvref_t<T>>::write(_w, _t, _parent);
|
||||
return Nothing{};
|
||||
};
|
||||
|
||||
const auto write_err = [&](const auto& _err) -> Nothing {
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace rfl {
|
||||
namespace parsing {
|
||||
|
||||
template <class R, class W, class T>
|
||||
requires AreReaderAndWriter<R, W, Array<T>>
|
||||
requires AreReaderAndWriter<R, W, Array<T>>
|
||||
struct Parser<R, W, Array<T>> {
|
||||
public:
|
||||
using InputArrayType = typename R::InputArrayType;
|
||||
@@ -23,15 +23,16 @@ struct Parser<R, W, Array<T>> {
|
||||
using OutputArrayType = typename W::OutputArrayType;
|
||||
using OutputVarType = typename W::OutputVarType;
|
||||
|
||||
using RflArray = Array<T>;
|
||||
using StdArray = internal::to_std_array_t<T>;
|
||||
|
||||
static Result<RflArray> read(const R& _r, const InputVarType& _var) noexcept {
|
||||
static Result<Array<T>> read(const R& _r, const InputVarType& _var) noexcept {
|
||||
return Parser<R, W, StdArray>::read(_r, _var);
|
||||
}
|
||||
|
||||
static OutputVarType write(const W& _w, const RflArray& _arr) noexcept {
|
||||
return Parser<R, W, StdArray>::write(_w, _arr);
|
||||
template <class P>
|
||||
static void write(const W& _w, const Array<T>& _arr,
|
||||
const P& _parent) noexcept {
|
||||
Parser<R, W, StdArray>::write(_w, _arr, _parent);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ struct Parser<R, W, std::variant<FieldTypes...>> {
|
||||
} else {
|
||||
const auto handle = [&](const auto& _v) {
|
||||
using Type = std::remove_cvref_t<decltype(_v)>;
|
||||
return Parser<R, W, Type>::write(_w, _v);
|
||||
Parser<R, W, Type>::write(_w, _v, _parent);
|
||||
};
|
||||
return std::visit(handle, _variant);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user