$darkmode
#include <string.hpp>
Public Types | |
| using | Type = std::string |
Public Member Functions | |
| String (Type *ptr, std::string desc) | |
| String | not_empty () && |
| size_t | min_length () const |
| String | min_length (size_t value) && |
| void | set_min_length (size_t value) |
| size_t | max_length () const |
| String | max_length (size_t value) && |
| void | set_max_length (size_t value) |
| const std::string & | pattern () const |
| String | pattern (const std::string &value) && |
| void | set_pattern (const std::string &value) |
| String | c_identifier () && |
| bool | interpolate () const |
| String | interpolate (bool value) && |
| void | set_interpolate (bool value) |
| Environment * | environment () const |
| String | environment (Environment *env) && |
| void | set_environment (Environment *env) |
| const std::vector< std::string > & | enum_of () const |
| String | enum_of (std::vector< std::string > &&init) |
| void | set_enum_of (std::vector< std::string > &&init) |
| 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< String > | |
| std::unique_ptr< Interface > | clone () const override |
| operator Box () const | |
| JsonType | type () const override |
| std::string | type_string () const override |
| Json | usage () const override |
| bool | is_required () const override |
| String | require () && |
| String | required (bool value) && |
| String | reset_pointer () && |
| bool | has_description () const |
| void | set_description (std::string s) override |
| const std::string & | description () const override |
| String | 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< SchemaError > | fail (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< String > | |
| Base (const Base< String > &)=default | |
| Base (Base< String > &&) noexcept=default | |
| Base (JsonType t, std::string desc) | |
| Base (JsonType t) | |
| Base (std::string desc) | |
| Base< String > & | operator= (const Base< String > &)=default |
| Base< String > & | operator= (Base< String > &&) 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 | |
| Interface & | operator= (const Interface &)=default |
| Interface & | operator= (Interface &&) noexcept=default |
Protected Attributes inherited from fable::schema::Base< String > | |
| JsonType | type_ |
| bool | required_ |
| std::string | desc_ |
String de-/serializes a string.
A string can have the following validation properties set:
The String schema type allows these properties to be specified and will validate them during deserialization.
| String fable::schema::String::c_identifier | ( | ) | && |
Ensure that the input matches an identifier as roughly specified by C.
This is shorthand for setting the pattern to FABLE_REGEX_C_IDENTIFIER.
| const std::vector< std::string > & fable::schema::String::enum_of | ( | ) | const |
Return the set of valid values for the string.
| String fable::schema::String::enum_of | ( | std::vector< std::string > && | init | ) |
Set the valid values for the string.
| init | list of valid values |
| Environment * fable::schema::String::environment | ( | ) | const |
Return the Environment used for variable interpolation.
| String fable::schema::String::environment | ( | Environment * | env | ) | && |
Set the Environment used for variable interpolation.
| environment |
|
overridevirtual |
Apply the input JSON configuration.
This does not validate the input.
Implements fable::schema::Interface.
| bool fable::schema::String::interpolate | ( | ) | const |
Return whether shell-style variable interpolation is enabled (default false).
| String fable::schema::String::interpolate | ( | bool | value | ) | && |
Set whether variable interpolation is enabled.
The following strings are then interpolated:
This uses the Environment set by the set_environment() method. If no environment is set, a default empty environment is used with OS environment fallback.
The string "${SHELL}" for example will evaluate to the current shell as defined in the OS environment, unless explicitely set in an Environment that is passed to set_environment().
Alternatives can be provided, such as with "${NOT_EXIST-alternate string}".
| value | true to enable |
|
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.
| size_t fable::schema::String::max_length | ( | ) | const |
Return the current maximum length (max size_t value if unset).
| String fable::schema::String::max_length | ( | size_t | value | ) | && |
Set the maximum string length in bytes.
| value | max bytes |
| size_t fable::schema::String::min_length | ( | ) | const |
Return the current minimum length (0 if unset).
| String fable::schema::String::min_length | ( | size_t | value | ) | && |
Set the minimum string length in bytes.
| value | min bytes |
| String fable::schema::String::not_empty | ( | ) | && |
Ensure input is not empty if present.
This is effectively an alias for min_length(1).
| const std::string & fable::schema::String::pattern | ( | ) | const |
Return the regular expression pattern the string should match.
| String fable::schema::String::pattern | ( | const std::string & | value | ) | && |
Set the string regular expression pattern.
| value | regex pattern |
|
overridevirtual |
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.
| void fable::schema::String::set_enum_of | ( | std::vector< std::string > && | init | ) |
Set the valid values for the string.
| init | list of valid values |
| void fable::schema::String::set_environment | ( | Environment * | env | ) |
Set the Environment used for variable interpolation.
| environment |
| void fable::schema::String::set_interpolate | ( | bool | value | ) |
Set whether variable interpolation is enabled.
The following strings are then interpolated:
This uses the Environment set by the set_environment() method. If no environment is set, a default empty environment is used with OS environment fallback.
The string "${SHELL}" for example will evaluate to the current shell as defined in the OS environment, unless explicitely set in an Environment that is passed to set_environment().
Alternatives can be provided, such as with "${NOT_EXIST-alternate string}".
| value | true to enable |
| void fable::schema::String::set_max_length | ( | size_t | value | ) |
Set the maximum string length in bytes.
| value | maximum string length in bytes |
| void fable::schema::String::set_min_length | ( | size_t | value | ) |
Set the minimum string length in bytes.
| value | min bytes |
| void fable::schema::String::set_pattern | ( | const std::string & | value | ) |
Set the string regular expression pattern.
| value | regex pattern |
|
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.
| 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.
|
overridevirtual |
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.
|
overridevirtual |
Validate the input JSON configuration for correctness.
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.| c | JSON to check |
| error | reference to store error if occurred |
Implements fable::schema::Interface.