$darkmode
fable::schema::Base< CRTP > Class Template Reference

#include <interface.hpp>

Inheritance diagram for fable::schema::Base< CRTP >:
Collaboration diagram for fable::schema::Base< CRTP >:

Public Member Functions

std::unique_ptr< Interfaceclone () const override
 
 operator Box () const
 
JsonType type () const override
 
std::string type_string () const override
 
Json usage () const override
 
bool is_required () const override
 
CRTP require () &&
 
CRTP required (bool value) &&
 
CRTP reset_pointer () &&
 
bool has_description () const
 
void set_description (std::string s) override
 
const std::string & description () const override
 
CRTP description (std::string desc) &&
 
- Public Member Functions inherited from fable::schema::Interface
virtual bool is_variant () const
 
virtual Json json_schema () const =0
 
virtual bool validate (const Conf &c, std::optional< SchemaError > &error) const =0
 
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
 
virtual void to_json (Json &) const =0
 
virtual void from_conf (const Conf &)=0
 
virtual void reset_ptr ()=0
 

Protected Member Functions

 Base (const Base< CRTP > &)=default
 
 Base (Base< CRTP > &&) noexcept=default
 
Base< CRTP > & operator= (const Base< CRTP > &)=default
 
Base< CRTP > & operator= (Base< CRTP > &&) noexcept=default
 
 Base (JsonType t, std::string desc)
 
 Base (JsonType t)
 
 Base (std::string desc)
 
bool validate_type (const Conf &c, std::optional< SchemaError > &err) const
 
template<typename... Args>
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
 
template<typename... Args>
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
 
Interfaceoperator= (const Interface &)=default
 
Interfaceoperator= (Interface &&) noexcept=default
 

Protected Attributes

JsonType type_ {JsonType::null}
 
bool required_ {false}
 
std::string desc_ {}
 

Detailed Description

template<typename CRTP>
class fable::schema::Base< CRTP >

The Base class implements the Interface partially and is meant to cover the most commonly used types.

See most of the other schema types for how it is used.

Member Function Documentation

◆ clone()

template<typename CRTP >
std::unique_ptr<Interface> fable::schema::Base< CRTP >::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()

template<typename CRTP >
const std::string& fable::schema::Base< CRTP >::description ( ) const
inlineoverridevirtual

◆ is_required()

template<typename CRTP >
bool fable::schema::Base< CRTP >::is_required ( ) const
inlineoverridevirtual

◆ set_description()

template<typename CRTP >
void fable::schema::Base< CRTP >::set_description ( std::string  s)
inlineoverridevirtual

◆ type()

template<typename CRTP >
JsonType fable::schema::Base< CRTP >::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()

template<typename CRTP >
std::string fable::schema::Base< CRTP >::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.
Here is the caller graph for this function:

◆ usage()

template<typename CRTP >
Json fable::schema::Base< CRTP >::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.
Here is the call graph for this function:

◆ validate_type()

template<typename CRTP >
bool fable::schema::Base< CRTP >::validate_type ( const Conf c,
std::optional< SchemaError > &  err 
) const
inlineprotected

Validate whether c is of the correct type.

This method is provided for an implementation to call in its fail() implementation. It is not called automatically.

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:

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