cli11
Loading...
Searching...
No Matches
cli::config_base_t Class Referenceexport
module cli11

A configuration converter for INI and TOML files. More...

Inheritance diagram for cli::config_base_t:
cli::config_t cli::config_ini_t

Public Member Functions

auto to_config (const app_t *app, config_output_mode_t mode, bool write_description, std::string prefix) const -> std::string override
 Writes an application out as configuration text.
auto to_config (const app_t *app, bool default_also, bool write_description, std::string prefix) const -> std::string override
 Writes an application out as configuration text.
auto from_config (std::istream &input) const -> std::vector< config_item_t > override
 Reads configuration text into a list of entries.
auto comment (char cchar) -> config_base_t *
 Sets the character introducing a comment.
auto array_bounds (char a_start, char a_end) -> config_base_t *
 Sets the characters delimiting an array.
auto array_delimiter (char a_sep) -> config_base_t *
 Sets the character separating array elements.
auto value_separator (char v_sep) -> config_base_t *
 Sets the character separating a name from its value.
auto quote_character (char q_string, char literal_char) -> config_base_t *
 Sets the quote characters.
auto max_layers (std::uint8_t layers) -> config_base_t *
 Sets how many nested sections to descend into.
auto parent_separator (char sep) -> config_base_t *
 Sets the character separating nested section names.
auto comment_defaults (bool com_def=true) -> config_base_t *
 Sets whether default values are written out commented.
auto section_ref () -> std::string &
 Returns a mutable reference to the selected section name.
auto section () const -> const std::string &
 Returns the selected section name.
auto section (const std::string &section_name) -> config_base_t *
 Selects a particular section of the file.
auto index_ref () -> std::int16_t &
 Returns a mutable reference to the selected section index.
auto index () const -> std::int16_t
 Returns the selected section index.
auto index (std::int16_t section_index) -> config_base_t *
 Selects a particular index within an arrayed section.
auto allow_duplicate_fields (bool value=true) -> config_base_t *
 Sets whether non-sequential duplicate fields are merged.
Public Member Functions inherited from cli::config_t
 config_t (const config_t &)=default
 config_t (config_t &&)=default
auto operator= (const config_t &) -> config_t &=default
auto operator= (config_t &&) -> config_t &=default
virtual auto to_flag (const config_item_t &item) const -> std::string
 Reduces an entry to a single flag value.
auto from_file (const std::string &name) const -> std::vector< config_item_t >
 Reads a configuration file into a list of entries.

Protected Attributes

char comment_char_ {'#'}
 The character introducing a comment.
char array_start_ {'['}
 The character opening an array; '\0' disables arrays.
char array_end_ {']'}
 The character closing an array; '\0' disables arrays.
char array_separator_ {','}
 The character separating elements within an array.
char value_delimiter_ {'='}
 The character separating a name from its value.
char string_quote_ {'"'}
 The character quoting escaped strings.
char literal_quote_ {'\''}
 The character quoting literal strings and single characters.
std::uint8_t maximum_layers_ {255}
 The maximum number of nested sections to descend into.
char parent_separator_char_ {'.'}
 The character separating nested section names.
bool comment_defaults_bool_ {false}
 Whether default values are written out commented.
bool allow_multiple_duplicate_fields_ {false}
 Whether repeated field names collapse into a single vector.
std::int16_t config_index_ {-1}
 Which index of an arrayed section to use; -1 means all.
std::string config_section_ {}
 Which section of the file to use; empty means the whole file.
Protected Attributes inherited from cli::config_t
std::vector< config_item_titems {}
 Entries accumulated while reading.

Detailed Description

A configuration converter for INI and TOML files.

Every piece of punctuation is a setting, so the same reader handles both dialects. cli::config_ini_t is this class with INI characters preset.

Member Function Documentation

◆ allow_duplicate_fields()

auto cli::config_base_t::allow_duplicate_fields ( bool value = true) -> config_base_t *
inline

Sets whether non-sequential duplicate fields are merged.

Parameters
valueWhether to merge duplicates.
Returns
A pointer to this converter, for chaining.

◆ array_bounds()

auto cli::config_base_t::array_bounds ( char a_start,
char a_end ) -> config_base_t *
inline

Sets the characters delimiting an array.

Parameters
a_startThe opening character.
a_endThe closing character.
Returns
A pointer to this converter, for chaining.

◆ array_delimiter()

auto cli::config_base_t::array_delimiter ( char a_sep) -> config_base_t *
inline

Sets the character separating array elements.

Parameters
a_sepThe separator character.
Returns
A pointer to this converter, for chaining.

◆ comment()

auto cli::config_base_t::comment ( char cchar) -> config_base_t *
inline

Sets the character introducing a comment.

Parameters
ccharThe comment character.
Returns
A pointer to this converter, for chaining.

◆ comment_defaults()

auto cli::config_base_t::comment_defaults ( bool com_def = true) -> config_base_t *
inline

Sets whether default values are written out commented.

Parameters
com_defWhether to comment defaults.
Returns
A pointer to this converter, for chaining.

◆ from_config()

auto cli::config_base_t::from_config ( std::istream & input) const -> std::vector< config_item_t >
nodiscardoverridevirtual

Reads configuration text into a list of entries.

Parameters
inputThe stream to read from.
Returns
The entries that were read.

Implements cli::config_t.

◆ index() [1/2]

auto cli::config_base_t::index ( ) const -> std::int16_t
inlinenodiscard

Returns the selected section index.

Returns
The index, or -1 if every section is used.

◆ index() [2/2]

auto cli::config_base_t::index ( std::int16_t section_index) -> config_base_t *
inline

Selects a particular index within an arrayed section.

Parameters
section_indexThe index to use, or -1 for all sections.
Returns
A pointer to this converter, for chaining.

◆ index_ref()

auto cli::config_base_t::index_ref ( ) -> std::int16_t &
inlinenodiscard

Returns a mutable reference to the selected section index.

Returns
A reference to the section index.

◆ max_layers()

auto cli::config_base_t::max_layers ( std::uint8_t layers) -> config_base_t *
inline

Sets how many nested sections to descend into.

Parameters
layersThe maximum depth.
Returns
A pointer to this converter, for chaining.

◆ parent_separator()

auto cli::config_base_t::parent_separator ( char sep) -> config_base_t *
inline

Sets the character separating nested section names.

Parameters
sepThe separator character.
Returns
A pointer to this converter, for chaining.

◆ quote_character()

auto cli::config_base_t::quote_character ( char q_string,
char literal_char ) -> config_base_t *
inline

Sets the quote characters.

Parameters
q_stringThe character quoting escaped strings.
literal_charThe character quoting literal strings.
Returns
A pointer to this converter, for chaining.

◆ section() [1/2]

auto cli::config_base_t::section ( ) const -> const std::string &
inlinenodiscard

Returns the selected section name.

Returns
The section name, empty if the whole file is used.

◆ section() [2/2]

auto cli::config_base_t::section ( const std::string & section_name) -> config_base_t *
inline

Selects a particular section of the file.

Parameters
section_nameThe section to use.
Returns
A pointer to this converter, for chaining.

◆ section_ref()

auto cli::config_base_t::section_ref ( ) -> std::string &
inlinenodiscard

Returns a mutable reference to the selected section name.

Returns
A reference to the section name.

◆ to_config() [1/2]

auto cli::config_base_t::to_config ( const app_t * app,
bool default_also,
bool write_description,
std::string prefix ) const -> std::string
nodiscardoverridevirtual

Writes an application out as configuration text.

Parameters
appThe application to describe.
default_alsoInclude options left at their defaults.
write_descriptionInclude descriptions as comments.
prefixSection prefix to write entries under.
Returns
The configuration text.

Implements cli::config_t.

◆ to_config() [2/2]

auto cli::config_base_t::to_config ( const app_t * app,
config_output_mode_t mode,
bool write_description,
std::string prefix ) const -> std::string
nodiscardoverridevirtual

Writes an application out as configuration text.

Parameters
appThe application to describe.
modeHow much of the application to write.
write_descriptionInclude descriptions as comments.
prefixSection prefix to write entries under.
Returns
The configuration text.

Reimplemented from cli::config_t.

◆ value_separator()

auto cli::config_base_t::value_separator ( char v_sep) -> config_base_t *
inline

Sets the character separating a name from its value.

Parameters
v_sepThe separator character.
Returns
A pointer to this converter, for chaining.

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