$darkmode
fable::schema::Box Class Referencefinal
Inheritance diagram for fable::schema::Box:
Collaboration diagram for fable::schema::Box:

Public Member Functions

 Box (const Box &)=default
 
 Box (Box &&) noexcept=default
 
Boxoperator= (const Box &)=default
 
Boxoperator= (Box &&) noexcept=default
 
 Box (std::unique_ptr< Interface > i)
 
 Box (std::shared_ptr< Interface > i)
 
std::shared_ptr< Interfaceget ()
 
template<typename T >
std::shared_ptr< T > as () const
 
template<typename T >
std::shared_ptr< T > as_unsafe () const
 
Box reset_pointer () &&
 
std::unique_ptr< Interfaceclone () const override
 
JsonType type () const override
 
std::string type_string () const override
 
bool is_required () const override
 
const std::string & description () const override
 
void set_description (std::string s) override
 
Json usage () const override
 
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
 
virtual Json to_json () const
 
virtual void to_json (Json &) const=0
 
- 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< SchemaErrorfail (const Conf &c) const final
 
virtual bool is_valid (const Conf &c) const final
 
virtual Json to_json () const
 

Friends

void to_json (Json &j, const Box &b)
 

Additional Inherited Members

- Protected Member Functions inherited from fable::schema::Interface
 Interface (const Interface &)=default
 
 Interface (Interface &&) noexcept=default
 
Interfaceoperator= (const Interface &)=default
 
Interfaceoperator= (Interface &&) noexcept=default
 

Member Function Documentation

◆ as()

template<typename T >
std::shared_ptr<T> fable::schema::Box::as ( ) const
inline

Return this type as a pointer to T.

This method can be used like so:

// In this example, we want a Struct.
auto ptr = s.template as<Struct>();
Examples
/home/docs/checkouts/readthedocs.org/user_builds/cloe/checkouts/latest/fable/include/fable/schema/interface.hpp.
Here is the call graph for this function:

◆ as_unsafe()

template<typename T >
std::shared_ptr<T> fable::schema::Box::as_unsafe ( ) const
inline

Return this type as a pointer to T.

This is unsafe in that you need to check the resulting shared pointer yourself for whether the dynamic cast was successful or not.

Examples
/home/docs/checkouts/readthedocs.org/user_builds/cloe/checkouts/latest/fable/include/fable/schema/interface.hpp.

◆ clone()

std::unique_ptr<Interface> fable::schema::Box::clone ( ) const
inlineoverridevirtual

Return a new instance of the object.

This is implemented by Base and allows us to wrap implementors of Interface with Schema.

Implements fable::schema::Interface.

Examples
/home/docs/checkouts/readthedocs.org/user_builds/cloe/checkouts/latest/fable/include/fable/schema/interface.hpp.

◆ description()

const std::string& fable::schema::Box::description ( ) const
inlineoverridevirtual

◆ from_conf()

void fable::schema::Box::from_conf ( const Conf )
inlineoverridevirtual

Apply the input JSON configuration.

This does not validate the input.

Implements fable::schema::Interface.

Examples
/home/docs/checkouts/readthedocs.org/user_builds/cloe/checkouts/latest/fable/include/fable/schema/interface.hpp.

◆ get()

std::shared_ptr<Interface> fable::schema::Box::get ( )
inline

◆ is_required()

bool fable::schema::Box::is_required ( ) const
inlineoverridevirtual

◆ json_schema()

Json fable::schema::Box::json_schema ( ) const
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.

Examples
/home/docs/checkouts/readthedocs.org/user_builds/cloe/checkouts/latest/fable/include/fable/schema/interface.hpp.
Here is the caller graph for this function:

◆ reset_ptr()

void fable::schema::Box::reset_ptr ( )
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.

Examples
/home/docs/checkouts/readthedocs.org/user_builds/cloe/checkouts/latest/fable/include/fable/schema/interface.hpp.
Here is the caller graph for this function:

◆ set_description()

void fable::schema::Box::set_description ( std::string  s)
inlineoverridevirtual

◆ to_json() [1/3]

virtual Json fable::schema::Interface::to_json
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.

Examples
/home/docs/checkouts/readthedocs.org/user_builds/cloe/checkouts/latest/fable/include/fable/schema/interface.hpp.

◆ to_json() [2/3]

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.

◆ to_json() [3/3]

void fable::schema::Box::to_json ( Json ) const
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.

◆ type()

JsonType fable::schema::Box::type ( ) const
inlineoverridevirtual

Return the JSON type.

If this is a variant type of differing types, then null should be returned. Otherwise, the type remains unique and can be returned. A type that is null is almost always a variant type of some sort, if even only an optional type.

Implements fable::schema::Interface.

Examples
/home/docs/checkouts/readthedocs.org/user_builds/cloe/checkouts/latest/fable/include/fable/schema/interface.hpp.

◆ type_string()

std::string fable::schema::Box::type_string ( ) const
inlineoverridevirtual

Return the type as a string.

The format of the string is:

"[array of] TYPE"

where TYPE is one of: null, object, boolean, float, integer, unsigned, string, and unknown.

Example output:

"object"
"array of boolean"
"array of object"

Implements fable::schema::Interface.

Examples
/home/docs/checkouts/readthedocs.org/user_builds/cloe/checkouts/latest/fable/include/fable/schema/interface.hpp.

◆ usage()

Json fable::schema::Box::usage ( ) const
inlineoverridevirtual

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.

Examples
/home/docs/checkouts/readthedocs.org/user_builds/cloe/checkouts/latest/fable/include/fable/schema/interface.hpp.

◆ validate()

bool fable::schema::Box::validate ( const Conf c,
std::optional< SchemaError > &  error 
) const
inlineoverridevirtual

Validate the input JSON configuration for correctness.

  • This method should only set 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.
  • This method should not throw if there is a schema error!
Parameters
cJSON to check
errorreference to store error if occurred
Returns
true if valid

Implements fable::schema::Interface.

Examples
/home/docs/checkouts/readthedocs.org/user_builds/cloe/checkouts/latest/fable/include/fable/schema/interface.hpp.
Here is the caller graph for this function:

The documentation for this class was generated from the following file: