$darkmode
fable::schema::Duration< T, Period > Class Template Reference
Inheritance diagram for fable::schema::Duration< T, Period >:
Collaboration diagram for fable::schema::Duration< T, Period >:

Public Types

using Type = std::chrono::duration< T, Period >
 

Public Member Functions

template<typename X = T, std::enable_if_t< std::is_integral_v< X > &&std::is_unsigned_v< X >, int > = 0>
 Duration (Type *ptr, std::string desc)
 
template<typename X = T, std::enable_if_t< std::is_integral_v< X > &&std::is_signed_v< X >, int > = 0>
 Duration (Type *ptr, std::string desc)
 
template<typename X = T, std::enable_if_t< std::is_floating_point_v< X >, int > = 0>
 Duration (Type *ptr, std::string desc)
 
minimum () const
 
void set_minimum (T value)
 
Duration< T, Period > minimum (T value) &&
 
bool exclusive_minimum () const
 
void set_exclusive_minimum (T value)
 
Duration< T, Period > exclusive_minimum (T value) &&
 
maximum () const
 
void set_maximum (T value)
 
Duration< T, Period > maximum (T value) &&
 
bool exclusive_maximum () const
 
void set_exclusive_maximum (T value)
 
Duration< T, Period > exclusive_maximum (T value) &&
 
std::pair< T, T > bounds () const
 
void set_bounds (T min, T max)
 
Duration< T, Period > bounds (T min, T max) &&
 
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
 
Json serialize (const Type &x) const
 
Type deserialize (const Conf &c) const
 
void serialize_into (Json &j, const Type &x) const
 
void deserialize_into (const Conf &c, Type &x) const
 
void reset_ptr () override
 
virtual Json to_json () const
 
virtual void to_json (Json &) const=0
 
- Public Member Functions inherited from fable::schema::Base< Duration< T, Period > >
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
 
Duration< T, Period > require () &&
 
Duration< T, Period > required (bool value) &&
 
Duration< T, Period > reset_pointer () &&
 
bool has_description () const
 
void set_description (std::string s) override
 
const std::string & description () const override
 
Duration< T, Period > 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< SchemaErrorfail (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< Duration< T, Period > >
 Base (const Base< Duration< T, Period > > &)=default
 
 Base (Base< Duration< T, Period > > &&) noexcept=default
 
 Base (JsonType t, std::string desc)
 
 Base (JsonType t)
 
 Base (std::string desc)
 
Base< Duration< T, Period > > & operator= (const Base< Duration< T, Period > > &)=default
 
Base< Duration< T, Period > > & operator= (Base< Duration< T, Period > > &&) 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
 
Interfaceoperator= (const Interface &)=default
 
Interfaceoperator= (Interface &&) noexcept=default
 
- Protected Attributes inherited from fable::schema::Base< Duration< T, Period > >
JsonType type_
 
bool required_
 
std::string desc_
 

Member Function Documentation

◆ from_conf()

template<typename T , typename Period >
void fable::schema::Duration< T, Period >::from_conf ( const Conf )
inlineoverridevirtual

Apply the input JSON configuration.

This does not validate the input.

Implements fable::schema::Interface.

◆ json_schema()

template<typename T , typename Period >
Json fable::schema::Duration< T, Period >::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.

Here is the call graph for this function:

◆ reset_ptr()

template<typename T , typename Period >
void fable::schema::Duration< T, Period >::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.

◆ to_json() [1/3]

template<typename T , typename Period >
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.

◆ to_json() [2/3]

template<typename T , typename Period >
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]

template<typename T , typename Period >
void fable::schema::Duration< T, Period >::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.

◆ validate()

template<typename T , typename Period >
bool fable::schema::Duration< T, Period >::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.

Here is the call graph for this function:

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