$darkmode
fable::schema::Path Class Reference

#include <path.hpp>

Inheritance diagram for fable::schema::Path:
[legend]
Collaboration diagram for fable::schema::Path:
[legend]

Public Types

enum  State {
  Any, State::Absent, State::Exists, State::Executable,
  State::FileExists, State::DirExists, State::NotFile, State::NotDir
}
 
using Type = boost::filesystem::path
 

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
 
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< Path >
 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
 
Path require () &&
 
Path required (bool value) &&
 
Path 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
 
Path 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< Path >
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< Path >
JsonType type_
 
bool required_
 
std::string desc_
 

Detailed Description

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.

Member Enumeration Documentation

◆ State

State represents valid states a path can be in relative to the filesystem.

Enumerator
Absent 

any valid path

Exists 

path does not exist

Executable 

path exists

FileExists 

path exists in search path or locally and has executable permission

DirExists 

path exists and is a file

NotFile 

path exists and is a directory

NotDir 

path does not exist or is a directory

Member Function Documentation

◆ absolute()

Path fable::schema::Path::absolute ( ) &&
inline

Require the input path to be absolute.

◆ from_conf()

void fable::schema::Path::from_conf ( const Conf )
inlineoverridevirtual

Apply the input JSON configuration.

This does not validate the input.

Implements fable::schema::Interface.

◆ json_schema()

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

Here is the caller graph for this function:

◆ reset_ptr()

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

bool fable::schema::Path::resolve ( ) const
inline

Return whether path resolution is active.

By default this is true.

◆ resolve() [2/2]

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

Here is the call graph for this function:

◆ state() [1/2]

State fable::schema::Path::state ( ) const
inline

Return the required state of the path in the filesystem.

Here is the caller graph for this function:

◆ state() [2/2]

Path fable::schema::Path::state ( State  s) &&
inline

Set the required state of the path in the filesystem.

Here is the call graph for this function:

◆ to_json()

void fable::schema::Path::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()

void fable::schema::Path::validate ( const Conf c) const
overridevirtual

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:
Here is the caller graph for this function:

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