26 #ifndef FABLE_SCHEMA_CONST_HPP_ 27 #define FABLE_SCHEMA_CONST_HPP_ 38 template <
typename T,
typename P>
42 using PrototypeSchema = P;
44 Const(
const Type& constant, std::string&& desc);
45 Const(
const Type& constant,
const PrototypeSchema& prototype, std::string&& desc)
47 , prototype_(prototype)
48 , constant_(constant) {
49 prototype_.reset_ptr();
54 Const(
const T& constant, std::string&& desc)
55 :
Const(constant, make_prototype<T>(), std::move(desc)) {}
63 this->augment_schema(j);
68 Type tmp = prototype_.deserialize(c);
69 if (tmp != constant_) {
70 this->throw_error(c,
"expected const value {}, got {}", constant_, tmp);
75 void to_json(
Json& j)
const override { j = serialize(constant_); }
79 Json serialize(
const Type& x)
const {
return prototype_.serialize(x); }
81 Type deserialize(
const Conf& c)
const {
89 PrototypeSchema prototype_;
93 template <
typename T,
typename P>
94 Const<T, P> make_const_schema(
const T& constant,
const P& prototype, std::string&& desc) {
95 return Const<T, P>(constant, prototype, std::move(desc));
109 #endif // FABLE_SCHEMA_CONST_HPP_
void to_json(Json &j) const override
Definition: const.hpp:75
void reset_ptr() override
Definition: const.hpp:86
nlohmann::json Json
Definition: json.hpp:62
Json json_schema() const override
Definition: const.hpp:59
void validate(const Conf &c) const override
Definition: const.hpp:67
virtual Json to_json() const
Definition: interface.hpp:220
void from_conf(const Conf &c) override
Definition: const.hpp:77
Definition: interface.hpp:354