draconisplusplus/include/rfl/parsing/Parser_skip.hpp

87 lines
2.5 KiB
C++
Raw Normal View History

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 <
class R,
class W,
class T,
bool _skip_serialization,
bool _skip_deserialization,
class ProcessorsType>
2024-06-08 14:10:59 -04:00
requires AreReaderAndWriter<
R,
W,
internal::Skip<T, _skip_serialization, _skip_deserialization>>
2024-06-08 15:53:06 -04:00
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-08 14:10:59 -04:00
static Result<
internal::Skip<T, _skip_serialization, _skip_deserialization>>
read(const R& _r, const InputVarType& _var) noexcept {
if constexpr (_skip_deserialization) {
return internal::Skip<T, _skip_serialization, _skip_deserialization>(
2024-06-08 15:53:06 -04:00
std::remove_cvref_t<T>()
);
2024-06-08 14:10:59 -04:00
} else {
const auto to_skip = [&](auto&& _t) {
2024-06-08 15:53:06 -04:00
return internal::Skip<
T, _skip_serialization, _skip_deserialization>(std::move(_t));
2024-06-08 14:10:59 -04:00
};
return Parser<R, W, std::remove_cvref_t<T>, ProcessorsType>::read(
2024-06-08 15:53:06 -04:00
_r, _var
)
2024-06-08 14:10:59 -04:00
.transform(to_skip);
}
}
2024-05-31 22:59:00 -04:00
2024-06-08 14:10:59 -04:00
template <class P>
static void write(
const W& _w,
const internal::Skip<T, _skip_serialization, _skip_deserialization>&
2024-06-08 15:53:06 -04:00
_skip,
const P& _parent
) noexcept {
2024-06-08 14:10:59 -04:00
if constexpr (_skip_serialization) {
using ReflectionType = std::remove_cvref_t<typename internal::Skip<
T, _skip_serialization, _skip_deserialization>::ReflectionType>;
Parser<R, W, ReflectionType, ProcessorsType>::write(
2024-06-08 15:53:06 -04:00
_w, ReflectionType(), _parent
);
2024-06-08 14:10:59 -04:00
} else {
Parser<R, W, std::remove_cvref_t<T>, ProcessorsType>::write(
2024-06-08 15:53:06 -04:00
_w, _skip.value(), _parent
);
2024-06-08 14:10:59 -04:00
}
}
2024-05-31 22:59:00 -04:00
2024-06-08 14:10:59 -04:00
static schema::Type to_schema(
2024-06-08 15:53:06 -04:00
std::map<std::string, schema::Type>* _definitions
) {
2024-06-08 14:10:59 -04:00
return Parser<R, W, std::remove_cvref_t<T>, ProcessorsType>::to_schema(
2024-06-08 15:53:06 -04:00
_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