2024-05-31 22:59:00 -04:00
|
|
|
#ifndef RFL_PARSING_PARSER_SKIP_HPP_
|
|
|
|
#define RFL_PARSING_PARSER_SKIP_HPP_
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <type_traits>
|
|
|
|
|
|
|
|
#include "../Result.hpp"
|
|
|
|
#include "../always_false.hpp"
|
|
|
|
#include "../internal/Skip.hpp"
|
|
|
|
#include "Parser_base.hpp"
|
|
|
|
#include "schema/Type.hpp"
|
|
|
|
|
|
|
|
namespace rfl {
|
2024-06-08 14:10:59 -04:00
|
|
|
namespace parsing {
|
2024-05-31 22:59:00 -04:00
|
|
|
|
2024-06-08 15:53:06 -04:00
|
|
|
template <
|
2024-06-16 00:13:15 -04:00
|
|
|
class R,
|
|
|
|
class W,
|
|
|
|
class T,
|
|
|
|
bool _skip_serialization,
|
|
|
|
bool _skip_deserialization,
|
|
|
|
class ProcessorsType>
|
2024-06-08 14:10:59 -04:00
|
|
|
requires AreReaderAndWriter<
|
2024-06-08 15:53:06 -04:00
|
|
|
R,
|
|
|
|
W,
|
2024-06-16 00:13:15 -04:00
|
|
|
internal::Skip<T, _skip_serialization, _skip_deserialization>>
|
|
|
|
struct Parser<
|
|
|
|
R,
|
|
|
|
W,
|
|
|
|
internal::Skip<T, _skip_serialization, _skip_deserialization>,
|
|
|
|
ProcessorsType> {
|
2024-06-08 14:10:59 -04:00
|
|
|
using InputVarType = typename R::InputVarType;
|
|
|
|
using OutputVarType = typename W::OutputVarType;
|
2024-05-31 22:59:00 -04:00
|
|
|
|
2024-06-16 00:13:15 -04:00
|
|
|
static Result<internal::Skip<T, _skip_serialization, _skip_deserialization>>
|
2024-06-08 14:10:59 -04:00
|
|
|
read(const R& _r, const InputVarType& _var) noexcept {
|
|
|
|
if constexpr (_skip_deserialization) {
|
|
|
|
return internal::Skip<T, _skip_serialization, _skip_deserialization>(
|
2024-06-16 00:13:15 -04:00
|
|
|
std::remove_cvref_t<T>()
|
2024-06-08 15:53:06 -04:00
|
|
|
);
|
2024-06-08 14:10:59 -04:00
|
|
|
} else {
|
|
|
|
const auto to_skip = [&](auto&& _t) {
|
2024-06-16 00:13:15 -04:00
|
|
|
return internal::Skip<T, _skip_serialization, _skip_deserialization>(std::move(_t));
|
2024-06-08 14:10:59 -04:00
|
|
|
};
|
2024-06-16 00:13:15 -04:00
|
|
|
return Parser<R, W, std::remove_cvref_t<T>, ProcessorsType>::read(_r, _var).transform(
|
|
|
|
to_skip
|
|
|
|
);
|
2024-06-08 14:10:59 -04:00
|
|
|
}
|
|
|
|
}
|
2024-05-31 22:59:00 -04:00
|
|
|
|
2024-06-08 14:10:59 -04:00
|
|
|
template <class P>
|
|
|
|
static void write(
|
2024-06-16 00:13:15 -04:00
|
|
|
const W& _w,
|
|
|
|
const internal::Skip<T, _skip_serialization, _skip_deserialization>& _skip,
|
|
|
|
const P& _parent
|
2024-06-08 15:53:06 -04:00
|
|
|
) noexcept {
|
2024-06-08 14:10:59 -04:00
|
|
|
if constexpr (_skip_serialization) {
|
2024-06-16 00:13:15 -04:00
|
|
|
using ReflectionType = std::remove_cvref_t<
|
|
|
|
typename internal::Skip<T, _skip_serialization, _skip_deserialization>::ReflectionType>;
|
|
|
|
Parser<R, W, ReflectionType, ProcessorsType>::write(_w, ReflectionType(), _parent);
|
2024-06-08 14:10:59 -04:00
|
|
|
} else {
|
2024-06-16 00:13:15 -04:00
|
|
|
Parser<R, W, std::remove_cvref_t<T>, ProcessorsType>::write(_w, _skip.value(), _parent);
|
2024-06-08 14:10:59 -04:00
|
|
|
}
|
|
|
|
}
|
2024-05-31 22:59:00 -04:00
|
|
|
|
2024-06-16 00:13:15 -04:00
|
|
|
static schema::Type to_schema(std::map<std::string, schema::Type>* _definitions) {
|
|
|
|
return Parser<R, W, std::remove_cvref_t<T>, ProcessorsType>::to_schema(_definitions);
|
2024-06-08 14:10:59 -04:00
|
|
|
}
|
|
|
|
};
|
2024-05-31 22:59:00 -04:00
|
|
|
|
2024-06-08 14:10:59 -04:00
|
|
|
} // namespace parsing
|
|
|
|
} // namespace rfl
|
2024-05-31 22:59:00 -04:00
|
|
|
|
|
|
|
#endif
|