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

#include <path.hpp>

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

Public Types

using Type = T
 
using State = PathState
 

Public Member Functions

 Path (Type *ptr, std::string desc)
 
State state () const
 
Path state (State s) &&
 
void set_state (State s)
 
Path absent () &&
 
Path exists () &&
 
Path executable () &&
 
Path file_exists () &&
 
Path dir_exists () &&
 
Path not_file () &&
 
Path not_dir () &&
 
Path not_empty () &&
 
Path absolute () &&
 
bool resolve () const
 
Path resolve (bool value) &&
 
void set_resolve (bool value)
 
bool normalize () const
 
Path normalize (bool value) &&
 
void set_normalize (bool value)
 
bool interpolate () const
 
void set_interpolate (bool value)
 
Path interpolate (bool value) &&
 
Environmentenvironment () const
 
void set_environment (Environment *env)
 
Path environment (Environment *env) &&
 
size_t min_length () const
 
void set_min_length (size_t value)
 
Path min_length (size_t value) &&
 
size_t max_length () const
 
void set_max_length (size_t value)
 
Path max_length (size_t value) &&
 
const std::string & pattern () const
 
void set_pattern (const std::string &value)
 
Path pattern (const std::string &value) &&
 
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< Path< 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
 
Path< T > require () &&
 
Path< T > required (bool value) &&
 
Path< T > reset_pointer () &&
 
bool has_description () const
 
void set_description (std::string s) override
 
const std::string & description () const override
 
Path< 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::Base< Path< T > >
 Base (const Base< Path< T > > &)=default
 
 Base (Base< Path< T > > &&) noexcept=default
 
 Base (JsonType t, std::string desc)
 
 Base (JsonType t)
 
 Base (std::string desc)
 
Base< Path< T > > & operator= (const Base< Path< T > > &)=default
 
Base< Path< T > > & operator= (Base< Path< 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::Base< Path< T > >
JsonType type_
 
bool required_
 
std::string desc_
 

Detailed Description

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

Path de-/serializes a string that represents a filesystem path.

Filesystem paths are special strings. We must take things into consideration such as:

  • how to interpret relative paths (as relative to current working directory or to the file containing the string)
  • whether the path indicated exists or not
  • whether the path refers to an executable
  • whether to normalize the path (by making absolute)

The Path schema type allows the user to specify these properties and will validate these during deserialization.

Path is a template class that supports both:

  • std::filesystem::path
  • boost::filesystem::path, if boost_path.hpp is included

Member Function Documentation

◆ absolute()

template<typename T >
Path fable::schema::Path< T >::absolute ( ) &&
inline

Require the input path to be absolute.

◆ from_conf()

template<typename T >
void fable::schema::Path< T >::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 >
Json fable::schema::Path< T >::json_schema ( ) const
overridevirtual

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 T >
void fable::schema::Path< 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.

◆ resolve() [1/2]

template<typename T >
bool fable::schema::Path< T >::resolve ( ) const
inline

Return whether path resolution is active.

By default this is true.

◆ resolve() [2/2]

template<typename T >
Path fable::schema::Path< T >::resolve ( bool  value) &&
inline

Set whether the configuration file location should be used to resolve the path being set.

This is particularly valuable when a configuration has references to other files. Instead of using the current-working-directory as the reference point, the file where the configuration value originates should be used as the reference point.

Resolve must be true if the search path should be used to resolve executables.

◆ state() [1/2]

template<typename T >
State fable::schema::Path< T >::state ( ) const
inline

Return the required state of the path in the filesystem.

◆ state() [2/2]

template<typename T >
Path fable::schema::Path< T >::state ( State  s) &&
inline

Set the required state of the path in the filesystem.

◆ to_json() [1/3]

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

◆ validate()

template<typename T >
bool fable::schema::Path< T >::validate ( const Conf c,
std::optional< SchemaError > &  error 
) const
overridevirtual

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 files: