25 #ifndef FABLE_SCHEMA_STRUCT_HPP_ 26 #define FABLE_SCHEMA_STRUCT_HPP_ 31 #include <type_traits> 56 template <
typename S = Box>
57 using PropertyList = std::initializer_list<std::pair<std::string const, S>>;
59 template <
typename T,
typename S = Box>
60 using enable_if_property_list_t = std::enable_if_t<std::is_same<PropertyList<S>, T>::value>;
75 explicit Struct(std::string&& desc =
"") :
Base(JsonType::object, std::move(desc)) {}
77 Struct(std::string&& desc, PropertyList<Box> props) :
Base(JsonType::object, std::move(desc)) {
108 Struct(std::string&& desc,
const Box& base, PropertyList<Box> props)
110 desc_ = std::move(desc);
114 Struct(
const Box& base, PropertyList<Box> props) :
Struct(
"", base, props) {}
124 Struct property(
const std::string& key,
Box&& s) && {
126 return std::move(*
this);
145 template <
typename T,
typename = enable_if_confable_t<T>>
150 template <
typename T>
151 Struct properties_from(
const T x) {
153 return std::move(*
this);
162 void set_require(std::initializer_list<std::string> init);
163 Struct require(std::initializer_list<std::string> init) &&;
183 additional_properties_ = v;
184 return std::move(*
this);
187 template <
typename S,
typename = enable_if_schema_t<S>>
188 void set_additional_properties(
const S& s) {
189 additional_properties_ =
true;
190 additional_prototype_.reset(s.clone());
191 additional_prototype_->reset_ptr();
194 template <
typename S,
typename = enable_if_schema_t<S>>
196 set_additional_properties(s);
197 return std::move(*
this);
216 std::map<std::string, Box> properties_{};
217 std::vector<std::string> properties_required_{};
218 std::shared_ptr<Interface> additional_prototype_{};
219 bool additional_properties_{
false};
222 template <
typename T,
typename = enable_if_property_list_t<T>>
223 inline Struct make_schema(T&& props) {
224 return Struct(std::forward<T>(props));
227 template <
typename T,
typename = enable_if_property_list_t<T>>
228 inline Struct make_schema(std::string&& desc, T&& props) {
229 return Struct(std::move(desc), std::forward<T>(props));
232 template <
typename T,
typename = enable_if_property_list_t<T>>
233 inline Struct make_schema(std::string&& desc,
const Box& base, T&& props) {
234 return Struct(std::move(desc), base, std::forward<T>(props));
237 template <
typename T,
typename = enable_if_property_list_t<T>>
238 inline Struct make_schema(std::string&& desc,
const Struct& base, T&& props) {
239 return Struct(std::move(desc), base, std::forward<T>(props));
245 #endif // FABLE_SCHEMA_STRUCT_HPP_
Struct(std::string &&desc, const Box &base, PropertyList< Box > props)
Definition: struct.hpp:108
void from_conf(const Conf &c) override
Definition: struct.cpp:137
void reset_ptr() override
Definition: struct.cpp:172
Definition: interface.hpp:263
Struct additional_properties(bool v) &&
Definition: struct.hpp:182
nlohmann::json Json
Definition: json.hpp:62
void set_require(std::initializer_list< std::string > init)
Definition: struct.cpp:58
Json usage() const override
Definition: struct.cpp:84
void set_properties_from(const Struct &s)
Definition: struct.hpp:141
virtual Json to_json() const
Definition: interface.hpp:220
void validate(const Conf &c) const override
Definition: struct.cpp:112
Definition: struct.hpp:73
Definition: interface.hpp:354
void set_properties(PropertyList< Box > props)
Definition: struct.cpp:46
void set_require_all()
Definition: struct.cpp:72
void set_property(const std::string &key, Box &&s)
Definition: struct.cpp:32
Json json_schema() const override
Definition: struct.cpp:92