$darkmode
#include <json.hpp>
Public Types | |
| using | Type = T |
Public Member Functions | |
| FromJson (Type *ptr, JsonType t, std::string desc) | |
| Json | json_schema () const override |
| bool | validate (const Conf &c, std::optional< SchemaError > &err) const override |
| void | to_json (Json &j) const override |
| void | from_conf (const Conf &c) override |
| void | reset_ptr () override |
| Json | serialize (const Type &x) const |
| void | serialize_into (Json &j, const Type &x) const |
| template<typename = std::enable_if<std::is_default_constructible_v<Type>>> | |
| Type | deserialize (const Conf &c) const |
| void | deserialize_into (const Conf &c, Type &x) const |
| virtual Json | to_json () const |
| virtual void | to_json (Json &) const=0 |
Public Member Functions inherited from fable::schema::Base< FromJson< T > > | |
| std::unique_ptr< 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 |
| FromJson< T > | require () && |
| FromJson< T > | required (bool value) && |
| FromJson< T > | reset_pointer () && |
| bool | has_description () const |
| void | set_description (std::string s) override |
| const std::string & | description () const override |
| FromJson< T > | description (std::string desc) && |
Public Member Functions inherited from fable::schema::Interface | |
| virtual bool | is_variant () const |
| virtual void | validate_or_throw (const Conf &c) const final |
| virtual std::optional< SchemaError > | fail (const Conf &c) const final |
| virtual bool | is_valid (const Conf &c) const final |
| virtual Json | to_json () const |
Additional Inherited Members | |
Protected Member Functions inherited from fable::schema::Base< FromJson< T > > | |
| Base (const Base< FromJson< T > > &)=default | |
| Base (Base< FromJson< T > > &&) noexcept=default | |
| Base (JsonType t, std::string desc) | |
| Base (JsonType t) | |
| Base (std::string desc) | |
| Base< FromJson< T > > & | operator= (const Base< FromJson< T > > &)=default |
| Base< FromJson< T > > & | operator= (Base< FromJson< T > > &&) noexcept=default |
| bool | validate_type (const Conf &c, std::optional< SchemaError > &err) const |
| SchemaError | error (const Conf &c, std::string_view format, Args &&... args) const |
| SchemaError | error (const ConfError &e) const |
| SchemaError | wrong_type (const Conf &c) const |
| bool | set_error (std::optional< SchemaError > &err, const Conf &c, std::string_view format, Args &&... args) const |
| bool | set_error (std::optional< SchemaError > &err, const ConfError &e) const |
| bool | set_error (std::optional< SchemaError > &err, SchemaError &&e) const |
| bool | set_wrong_type (std::optional< SchemaError > &err, const Conf &c) const |
| void | augment_schema (Json &j) const |
Protected Member Functions inherited from fable::schema::Interface | |
| Interface (const Interface &)=default | |
| Interface (Interface &&) noexcept=default | |
| Interface & | operator= (const Interface &)=default |
| Interface & | operator= (Interface &&) noexcept=default |
Protected Attributes inherited from fable::schema::Base< FromJson< T > > | |
| JsonType | type_ |
| bool | required_ |
| std::string | desc_ |
FromJson uses the from_json and to_json methods for deserializing and deserializing data to the type.
This provides only minimal validation, and its use is not recommended. It is only included because sometimes we have little choice but to work with what is laid before us.
Note that the constructor is different to most other schema types: it requires you to specify the expected JSON type. This incidentally means that it is also very hard to use this schema type by accident.
|
inlineoverridevirtual |
Apply the input JSON configuration.
This does not validate the input.
Implements fable::schema::Interface.
|
inlineoverridevirtual |
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.
|
inlineoverridevirtual |
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.
|
inline |
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.
| virtual void fable::schema::Interface::to_json |
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.
|
inlineoverridevirtual |
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.
|
inlineoverridevirtual |
Validate the input JSON configuration for correctness.
error if there is an error. This method should not reset error if there is no error. Therefore, the content of error is only valid if the method returns false. This allows you to chain validates and check at the end if there was an error.| c | JSON to check |
| error | reference to store error if occurred |
Implements fable::schema::Interface.