32 namespace fable::schema {
45 using PrototypeSchema = P;
48 :
Passthru(ptr, PrototypeSchema(
nullptr,
""), std::move(desc)) {}
49 Passthru(
Type* ptr, PrototypeSchema prototype, std::string desc)
51 , prototype_(std::move(prototype))
53 prototype_.reset_ptr();
57 [[nodiscard]] std::string
type_string()
const override {
return prototype_.type_string(); }
60 Json j = prototype_.json_schema();
61 this->augment_schema(j);
65 bool validate(
const Conf& c, std::optional<SchemaError>& err)
const override {
68 return prototype_.validate(c, err);
73 assert(ptr_ !=
nullptr);
78 assert(ptr_ !=
nullptr);
79 *ptr_ = deserialize(c);
82 [[nodiscard]]
Json serialize(
const Type& x)
const {
return *x; }
84 [[nodiscard]] Type deserialize(
const Conf& c)
const {
return c; }
86 void serialize_into(Json& j,
const Type& x)
const { j = serialize(x); }
88 void deserialize_into(
const Conf& c, Type& x)
const { x = deserialize(c); }
93 PrototypeSchema prototype_;
97 inline Passthru<Ignore> make_schema(Conf* ptr, std::string desc) {
98 return {ptr, Ignore(), std::move(desc)};
101 template <
typename P>
102 Passthru<P> make_schema(Conf* ptr, P prototype, std::string desc) {
103 return {ptr, std::move(prototype), std::move(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:57
void from_conf(const Conf &c) override
Definition: passthru.hpp:77
void to_json(Json &j) const override
Definition: passthru.hpp:72
Json json_schema() const override
Definition: passthru.hpp:59
bool validate(const Conf &c, std::optional< SchemaError > &err) const override
Definition: passthru.hpp:65
void reset_ptr() override
Definition: passthru.hpp:90
nlohmann::json Json
Definition: fable_fwd.hpp:35