mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-03 00:26:19 +08:00
33 lines
865 B
C++
33 lines
865 B
C++
#ifndef RFL_PARSING_PARSER_BOX_HPP_
|
|
#define RFL_PARSING_PARSER_BOX_HPP_
|
|
|
|
#include <type_traits>
|
|
|
|
#include "rfl/Box.hpp"
|
|
#include "rfl/Result.hpp"
|
|
#include "rfl/parsing/Parser_base.hpp"
|
|
|
|
namespace rfl {
|
|
namespace parsing {
|
|
|
|
template <class R, class W, class T>
|
|
requires AreReaderAndWriter<R, W, Box<T>>
|
|
struct Parser<R, W, Box<T>> {
|
|
using InputVarType = typename R::InputVarType;
|
|
using OutputVarType = typename W::OutputVarType;
|
|
|
|
static Result<Box<T>> read(const R& _r, const InputVarType& _var) noexcept {
|
|
const auto to_box = [](auto&& _t) { return Box<T>::make(std::move(_t)); };
|
|
return Parser<R, W, std::decay_t<T>>::read(_r, _var).transform(to_box);
|
|
}
|
|
|
|
static OutputVarType write(const W& _w, const Box<T>& _box) noexcept {
|
|
return Parser<R, W, std::decay_t<T>>::write(_w, *_box);
|
|
}
|
|
};
|
|
|
|
} // namespace parsing
|
|
} // namespace rfl
|
|
|
|
#endif
|