$darkmode
fable::schema::Factory< T > Class Template Reference

#include <factory.hpp>

Inheritance diagram for fable::schema::Factory< T >:
Collaboration diagram for fable::schema::Factory< T >:

Public Types

using Type = typename FactoryBase< T, Factory< T > >::Type
 
using MakeFunc = typename FactoryBase< T, Factory< T > >::MakeFunc
 
using TypeFactory = typename FactoryBase< T, Factory< T > >::TypeFactory
 
using FactoryMap = typename FactoryBase< T, Factory< T > >::FactoryMap
 
using FactoryPairList = typename FactoryBase< T, Factory< T > >::FactoryPairList
 
- Public Types inherited from fable::schema::FactoryBase< T, Factory< T > >
using Type = T
 
using MakeFunc = std::function< T(const Conf &c)>
 
using TransformFunc = std::function< Box(Struct &&)>
 
using FactoryMap = std::map< std::string, TypeFactory >
 
using FactoryPairList = std::initializer_list< std::pair< std::string, TypeFactory > >
 

Public Member Functions

 Factory (const Factory< T > &other)=default
 
 Factory (Factory< T > &&other) noexcept=default
 
Factory< T > & operator= (const Factory< T > &other)=default
 
Factory< T > & operator= (Factory< T > &&other) noexcept=default
 
 Factory (Type *ptr, std::string desc)
 
 Factory (Type *ptr, std::string desc, FactoryMap &&fs)
 
 Factory (Type *ptr, std::string desc, FactoryPairList fs)
 
void from_conf (const Conf &c) override
 
void to_json (Json &j) const override
 
void reset_ptr () override
 
- Public Member Functions inherited from fable::schema::FactoryBase< T, Factory< T > >
 FactoryBase (std::string desc="")
 
 FactoryBase (std::string desc, FactoryPairList fs)
 
 FactoryBase (std::string desc, FactoryMap &&fs)
 
Factory< T > factory_key (const std::string &keyword) &&
 
Factory< T > args_key (const std::string &keyword) &&
 
Factory< T > args_subset (bool value) &&
 
Factory< T > transform_schema (TransformFunc f) &&
 
void set_factory_key (const std::string &keyword)
 
void set_args_key (const std::string &keyword)
 
void set_args_subset (bool value)
 
void set_transform_schema (TransformFunc f)
 
const TypeFactory & get_factory (const std::string &key) const
 
bool has_factory (const std::string &key) const
 
bool add_factory (const std::string &key, Box &&s, MakeFunc f)
 
void set_factory (const std::string &key, Box &&s, MakeFunc f)
 
void add_default_factory (const std::string &key)
 
Json json_schema () const override
 
bool validate (const Conf &c, std::optional< SchemaError > &err) const override
 
Type make (const Conf &c) const
 
Type deserialize (const Conf &c) const
 
Json serialize (const Type &x) const
 
void serialize_into (Json &j, const Type &x) const
 
void deserialize_into (const Conf &c, Type &x) const
 
void from_conf (const Conf &) override
 
void to_json (Json &) const override
 
virtual Json to_json () const
 
virtual void to_json (Json &) const =0
 
void reset_ptr () override
 
- Public Member Functions inherited from fable::schema::Base< Factory< T > >
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
 
Factory< T > require () &&
 
Factory< T > required (bool value) &&
 
Factory< T > reset_pointer () &&
 
bool has_description () const
 
void set_description (std::string s) override
 
const std::string & description () const override
 
Factory< 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< 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::FactoryBase< T, Factory< T > >
 FactoryBase (const FactoryBase &other)
 
 FactoryBase (FactoryBase &&) noexcept=default
 
FactoryBaseoperator= (const FactoryBase &other)
 
FactoryBaseoperator= (FactoryBase &&) noexcept=default
 
void reset_schema ()
 
std::vector< Boxfactory_schemas () const
 
std::vector< Jsonfactory_json_schemas () const
 
- Protected Member Functions inherited from fable::schema::Base< Factory< T > >
 Base (const Base< Factory< T > > &)=default
 
 Base (Base< Factory< T > > &&) noexcept=default
 
 Base (JsonType t, std::string desc)
 
 Base (JsonType t)
 
 Base (std::string desc)
 
Base< Factory< T > > & operator= (const Base< Factory< T > > &)=default
 
Base< Factory< T > > & operator= (Base< Factory< 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
 
Interfaceoperator= (const Interface &)=default
 
Interfaceoperator= (Interface &&) noexcept=default
 
- Protected Attributes inherited from fable::schema::FactoryBase< T, Factory< T > >
std::unique_ptr< Variantschema_
 
TransformFunc transform_func_
 
FactoryMap available_
 
std::string factory_key_
 
std::string args_key_
 
bool args_subset_
 
- Protected Attributes inherited from fable::schema::Base< Factory< T > >
JsonType type_
 
bool required_
 
std::string desc_
 

Detailed Description

template<typename T>
class fable::schema::Factory< T >

Factory is a factory schema that extends FactoryPointerless in that it can deserialize into a variable through a pointer.

Apart from the added constructors, the interface is otherwise identical to FactoryPointerless.

Member Function Documentation

◆ from_conf()

template<typename T >
void fable::schema::Factory< T >::from_conf ( const Conf )
inlineoverridevirtual

Apply the input JSON configuration.

This does not validate the input.

Implements fable::schema::Interface.

◆ reset_ptr()

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


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