$darkmode
#include <struct.hpp>
Public Member Functions | |
| Struct (std::string &&desc="") | |
| Struct (std::string &&desc, PropertyList< Box > props) | |
| Struct (PropertyList< Box > props) | |
| Struct (std::string &&desc, const Box &base, PropertyList< Box > props) | |
| Struct (const Box &base, PropertyList< Box > props) | |
| void | set_property (const std::string &key, Box &&s) |
| Struct | property (const std::string &key, Box &&s) && |
| void | set_properties (PropertyList< Box > props) |
| void | set_properties_from (const Struct &s) |
| void | set_properties_from (const Box &s) |
| template<typename T , typename = enable_if_confable_t<T>> | |
| void | set_properties_from (const T *x) |
| template<typename T > | |
| Struct | properties_from (const T x) |
| void | set_require (std::initializer_list< std::string > init) |
| Struct | require (std::initializer_list< std::string > init) && |
| void | set_require_all () |
| Struct | require_all () && |
| Struct | additional_properties (bool v) && |
| template<typename S , typename = enable_if_schema_t<S>> | |
| void | set_additional_properties (const S &s) |
| template<typename S , typename = enable_if_schema_t<S>> | |
| Struct | additional_properties (const S &s) && |
| bool | additional_properties () const |
| void | reset_ptr () override |
| Json | usage () const override |
| Json | json_schema () const override |
| void | validate (const Conf &c) const override |
| void | to_json (Json &j) const override |
| void | from_conf (const Conf &c) override |
Public Member Functions inherited from fable::schema::Base< Struct > | |
| Base (JsonType t, std::string &&desc) | |
| Base (JsonType t) | |
| Base (std::string &&desc) | |
| Interface * | clone () const override |
| operator Box () const | |
| JsonType | type () const override |
| std::string | type_string () const override |
| Json | usage () const override |
| bool | is_required () const override |
| Struct | require () && |
| Struct | required (bool value) && |
| Struct | reset_pointer () && |
| bool | has_description () const |
| void | set_description (const std::string &s) override |
| void | set_description (std::string &&s) |
| const std::string & | description () const override |
| Struct | description (std::string &&desc) && |
Public Member Functions inherited from fable::schema::Interface | |
| virtual bool | is_variant () const |
| virtual bool | is_valid (const Conf &c) const |
| virtual Json | to_json () const |
Additional Inherited Members | |
Protected Member Functions inherited from fable::schema::Base< Struct > | |
| void | validate_type (const Conf &c) const |
| void | throw_error (const Conf &c, const char *format, Args... args) const |
| void | throw_error (const ConfError &e) const |
| void | throw_wrong_type (const Conf &c) const |
| void | augment_schema (Json &j) const |
Protected Attributes inherited from fable::schema::Base< Struct > | |
| JsonType | type_ |
| bool | required_ |
| std::string | desc_ |
Struct maintains a key-value mapping, where the list of keys is usually known and the values can have different types (schemas).
This is usually the basis of any schema, since most start with a JSON object.
This should not be confused with the Map type.
|
inline |
Instantiate a Struct with a base Schema, which should also be a Struct, then extend it with the property list.
This is particularly useful when the Confable is inheriting from a base class:
struct Sub : public Base {
std::string member;
CONFABLE_SCHEMA(Sub) {
return Struct{
Base::schema_impl(),
{
{"member", make_schema(&member, "important addition")},
}
};
}
};
Warning: When implementing schema_impl, for example with CONFABLE_SCHEMA, it is absolutely important that you not call Base::schema(), as this will internally call this->schema_impl(), which will lead to an infinite recursion! Instead, call Base::schema_impl().
|
inline |
Set whether to tolerate unknown fields in this entry.
|
overridevirtual |
Apply the input JSON configuration.
This does not validate the input.
Implements fable::schema::Interface.
|
overridevirtual |
Return the JSON schema.
Example output:
{ "$schema": "http://json-schema.org/draft-07/schema#", "description": "stand-in no-operation simulator", "properties": { "vehicles": { "description": "list of vehicle names to make available", "items": { "type": "string" }, "type": "array" } }, "title": "nop", "additionalProperties": false, "type": "object" }
See the following links for the specification:
Implements fable::schema::Interface.
|
overridevirtual |
Reset the internal pointer to nullptr, protecting against invalid access.
This should be used when a schema is used after the backing data has been deleted.
Implements fable::schema::Interface.
| void fable::schema::Struct::set_properties | ( | PropertyList< Box > | props | ) |
Set all properties.
|
inline |
Add the properties from s to this schema.
| void fable::schema::Struct::set_property | ( | const std::string & | key, |
| Box && | s | ||
| ) |
Set the property to this schema.
| void fable::schema::Struct::set_require | ( | std::initializer_list< std::string > | init | ) |
Set which entries are required.
| void fable::schema::Struct::set_require_all | ( | ) |
Set whether all entries are required.
|
overridevirtual |
Return the current value of the destination.
Warning: This is NOT an efficient operation, but it can be useful for cases where speed is not important.
Implements fable::schema::Interface.
|
overridevirtual |
Return a compact JSON description of the schema. This is useful for human-readable error output.
Example output:
{ "field1": "boolean! :: lorem ipsum dolor sit amet", "field2": { "field2.1": "integer :: lorem ipsum dolor sit amet" "field2.2": "boolean :: lorem ipsum dolor sit amet" }, "field3": "array of integer :: lorem ipsum dolor sit amet", "field4": [{ "field4.1": "string :: lorem ipsum dolor sit amet" "field4.2": "boolean :: lorem ipsum dolor sit amet" }] }
When describing the schema of a primitive array, we can represent that as a single string. But when the array contains an object, we wrap a single object in an array. This isn't awfully consistent, but it's the best we can do.
Implements fable::schema::Interface.
|
overridevirtual |
Validate the input JSON configuration.
If you don't have a Conf but would like to validate a Json type, then construct a Conf on the fly:
s.validate(Conf{j});
This function is not provided inline to prevent incorrect use.
Implements fable::schema::Interface.