$darkmode
fable::schema::Passthru< P > Class Template Reference

#include <passthru.hpp>

Inheritance diagram for fable::schema::Passthru< P >:
[legend]
Collaboration diagram for fable::schema::Passthru< P >:
[legend]

Public Types

using Type = Conf
 
using PrototypeSchema = P
 

Public Member Functions

 Passthru (Type *ptr, std::string &&desc)
 
 Passthru (Type *ptr, const PrototypeSchema &prototype, std::string &&desc)
 
std::string type_string () 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
 
Json serialize (const Type &x) const
 
Type deserialize (const Conf &c) const
 
void reset_ptr () override
 
- Public Member Functions inherited from fable::schema::Base< Passthru< P > >
 Base (JsonType t, std::string &&desc)
 
 Base (JsonType t)
 
 Base (std::string &&desc)
 
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
 
Passthru< P > require () &&
 
Passthru< P > required (bool value) &&
 
Passthru< P > 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
 
Passthru< P > 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< Passthru< P > >
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< Passthru< P > >
JsonType type_
 
bool required_
 
std::string desc_
 

Detailed Description

template<typename P>
class fable::schema::Passthru< P >

Passthru stores JSON data and optionally validates it.

This is in particular useful when you don't know exactly how the data will be validated, and you want to hold onto the original location metadata for better future error reporting.

Member Function Documentation

◆ from_conf()

template<typename P>
void fable::schema::Passthru< P >::from_conf ( const Conf )
inlineoverridevirtual

Apply the input JSON configuration.

This does not validate the input.

Implements fable::schema::Interface.

◆ json_schema()

template<typename P>
Json fable::schema::Passthru< P >::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.

◆ reset_ptr()

template<typename P>
void fable::schema::Passthru< P >::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()

template<typename P>
void fable::schema::Passthru< P >::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_string()

template<typename P>
std::string fable::schema::Passthru< P >::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.

◆ validate()

template<typename P>
void fable::schema::Passthru< P >::validate ( const Conf c) const
inlineoverridevirtual

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.

Here is the call graph for this function:

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