32 namespace fable::schema {
45 using PrototypeSchema = std::remove_cv_t<std::remove_reference_t<P>>;
48 :
Passthru(ptr, PrototypeSchema(
nullptr,
""), std::move(desc)) {}
49 Passthru(
Type* ptr, PrototypeSchema prototype, std::string desc)
50 :
Base<Passthru<P>>(prototype.type(), std::move(desc)), prototype_(std::move(prototype)), ptr_(ptr) {
51 prototype_.reset_ptr();
55 [[nodiscard]] std::string
type_string()
const override {
return prototype_.type_string(); }
58 Json j = prototype_.json_schema();
59 this->augment_schema(j);
63 bool validate(
const Conf& c, std::optional<SchemaError>& err)
const override {
66 return prototype_.validate(c, err);
71 assert(ptr_ !=
nullptr);
76 assert(ptr_ !=
nullptr);
77 *ptr_ = deserialize(c);
80 [[nodiscard]]
Json serialize(
const Type& x)
const {
return *x; }
82 [[nodiscard]] Type deserialize(
const Conf& c)
const {
return c; }
84 void serialize_into(Json& j,
const Type& x)
const { j = serialize(x); }
86 void deserialize_into(
const Conf& c, Type& x)
const { x = deserialize(c); }
91 PrototypeSchema prototype_;
96 Passthru<Ignore> make_schema(Conf* ptr, S&& desc) {
97 return {ptr, Ignore(), std::forward<S>(desc)};
100 template <
typename P,
typename S>
101 Passthru<P> make_schema(Conf* ptr, P&& prototype, S&& desc) {
102 return {ptr, std::forward<P>(prototype), std::forward<S>(desc)};
Definition: interface.hpp:398
virtual Json to_json() const
Definition: interface.hpp:254
Definition: passthru.hpp:42
std::string type_string() const override
Definition: passthru.hpp:55
void from_conf(const Conf &c) override
Definition: passthru.hpp:75
void to_json(Json &j) const override
Definition: passthru.hpp:70
Json json_schema() const override
Definition: passthru.hpp:57
bool validate(const Conf &c, std::optional< SchemaError > &err) const override
Definition: passthru.hpp:63
void reset_ptr() override
Definition: passthru.hpp:88
nlohmann::json Json
Definition: fable_fwd.hpp:35