mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-04 01:06:19 +08:00
Added a to_schema method to the CustomParser
This commit is contained in:
@@ -7,15 +7,14 @@
|
||||
#include "../internal/has_to_class_method_v.hpp"
|
||||
#include "../internal/to_ptr_field_tuple.hpp"
|
||||
#include "Parser.hpp"
|
||||
#include "schema/Type.hpp"
|
||||
|
||||
namespace rfl {
|
||||
namespace parsing {
|
||||
|
||||
template <class ReaderType, class WriterType, class OriginalClass,
|
||||
class HelperStruct>
|
||||
template <class R, class W, class OriginalClass, class HelperStruct>
|
||||
struct CustomParser {
|
||||
static Result<OriginalClass> read(const ReaderType& _r,
|
||||
const auto& _var) noexcept {
|
||||
static Result<OriginalClass> read(const R& _r, const auto& _var) noexcept {
|
||||
const auto to_class = [](auto&& _h) -> Result<OriginalClass> {
|
||||
try {
|
||||
if constexpr (internal::has_to_class_method_v<HelperStruct>) {
|
||||
@@ -31,15 +30,20 @@ struct CustomParser {
|
||||
return Error(e.what());
|
||||
}
|
||||
};
|
||||
return Parser<ReaderType, WriterType, HelperStruct>::read(_r, _var)
|
||||
.and_then(to_class);
|
||||
return Parser<R, W, HelperStruct>::read(_r, _var).and_then(to_class);
|
||||
}
|
||||
|
||||
template <class P>
|
||||
static auto write(const WriterType& _w, const OriginalClass& _p,
|
||||
static auto write(const W& _w, const OriginalClass& _p,
|
||||
const P& _parent) noexcept {
|
||||
Parser<ReaderType, WriterType, HelperStruct>::write(
|
||||
_w, HelperStruct::from_class(_p), _parent);
|
||||
Parser<R, W, HelperStruct>::write(_w, HelperStruct::from_class(_p),
|
||||
_parent);
|
||||
}
|
||||
|
||||
static schema::Type to_schema(
|
||||
std::map<std::string, schema::Type>* _definitions) {
|
||||
return Parser<R, W, std::remove_cvref_t<HelperStruct>>::to_schema(
|
||||
_definitions);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user