MySQL 8.0.39
Source Code Documentation
|
Configuration. More...
#include <config_parser.h>
Public Types | |
using | SectionKey = std::pair< std::string, std::string > |
using | OptionMap = ConfigSection::OptionMap |
using | SectionList = std::list< ConfigSection * > |
using | ConstSectionList = std::list< const ConfigSection * > |
using | ConfigOverwrites = std::map< std::pair< std::string, std::string >, std::map< std::string, std::string > > |
Public Member Functions | |
Config (unsigned int flags=0U, const ConfigOverwrites &config_overwrites={}) | |
Construct a configuration. More... | |
template<class AssocT > | |
Config (const AssocT ¶meters, unsigned int flags=0U, const ConfigOverwrites &config_overwrites={}) | |
Construct a configuration. More... | |
template<class AssocT , class SeqT > | |
Config (const AssocT ¶meters, const SeqT &reserved, unsigned int flags=0U, const ConfigOverwrites &config_overwrites={}) | |
Construct a configuration. More... | |
Config (const Config &)=default | |
Config & | operator= (const Config &)=default |
virtual | ~Config ()=default |
template<class SeqT > | |
void | set_reserved (const SeqT &reserved) |
void | read (std::istream &input) |
Read configuration file from file, directory, or input stream. More... | |
void | read (const Path &path) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
void | read (const Path &path, const std::string &pattern) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
bool | empty () const |
Check if the configuration is empty. More... | |
void | clear () |
Clear the configuration. More... | |
bool | remove (const SectionKey §ion_key) noexcept |
Remove section from configuration. More... | |
bool | remove (const std::string §ion, const std::string &key=std::string()) noexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
void | update (const Config &other) |
Update configuration using another configuration. More... | |
ConstSectionList | get (const std::string §ion) const |
Get a list of sections having a name. More... | |
SectionList | get (const std::string §ion) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
ConfigSection & | get_default_section () const |
ConfigSection & | get (const std::string §ion, const std::string &key) |
Get a section by name and key. More... | |
const ConfigSection & | get (const std::string §ion, const std::string &key) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
ConfigSection & | add (const std::string §ion, const std::string &key=std::string()) |
Add a new section to the configuration. More... | |
bool | has (const std::string §ion, const std::string &key=std::string()) const |
bool | has_any (const std::string §ion) const |
std::string | get_default (const std::string &option) const |
bool | has_default (const std::string &option) const |
void | set_default (const std::string &option, const std::string &value) |
bool | is_reserved (const std::string &word) const |
std::list< Config::SectionKey > | section_names () const |
ConstSectionList | sections () const |
Get a list of all sections in the configuration. More... | |
Public Attributes | |
bool | error_on_unsupported_option {false} |
Static Public Attributes | |
static constexpr const char * | DEFAULT_PATTERN = "*.cfg" |
Default pattern to used to identify configuration files. More... | |
static constexpr unsigned int | allow_keys = 1U |
Flags for construction of configurations. More... | |
Protected Types | |
using | SectionMap = std::map< SectionKey, ConfigSection > |
using | ReservedList = std::vector< std::string > |
Protected Member Functions | |
void | copy_guts (const Config &source) noexcept |
Copy the guts of another configuration. More... | |
virtual void | do_read_file (const Path &path) |
Function to read single file. More... | |
virtual void | do_read_stream (std::istream &input) |
Function to read the configuration from a stream. More... | |
void | apply_overwrites () |
Protected Attributes | |
SectionMap | sections_ |
ReservedList | reserved_ |
std::shared_ptr< ConfigSection > | defaults_ |
unsigned int | flags_ |
ConfigOverwrites | config_overwrites_ |
Configuration.
A configuration consisting of named configuration sections.
There are three different constructors that are available with different kind of parameters.
using mysql_harness::Config::ConfigOverwrites = std::map<std::pair<std::string, std::string>, std::map<std::string, std::string> > |
using mysql_harness::Config::ConstSectionList = std::list<const ConfigSection *> |
|
protected |
using mysql_harness::Config::SectionKey = std::pair<std::string, std::string> |
using mysql_harness::Config::SectionList = std::list<ConfigSection *> |
|
protected |
|
explicit |
Construct a configuration.
flags | flags. |
config_overwrites | overwrites for selected configuration options. |
|
inlineexplicit |
Construct a configuration.
AssocT | Associate container type
|
bad_option | on bad options |
|
inlineexplicit |
Construct a configuration.
Construct a configuration instance by reading a configuration file and overriding the values read from a list of supplied parameters.
AssocT | Associate container type |
SeqT | Sequence container type
|
bad_option | on bad options |
|
default |
|
virtualdefault |
ConfigSection & mysql_harness::Config::add | ( | const std::string & | section, |
const std::string & | key = std::string() |
||
) |
Add a new section to the configuration.
section | Name of section to add. |
key | Optional key of section to add. |
|
protected |
void mysql_harness::Config::clear | ( | ) |
Clear the configuration.
This will remove all configuration information from the configuration, including the default section, but not the reserved words nor the flags set.
|
protectednoexcept |
Copy the guts of another configuration.
This member function is used to copy configuration state (the "guts") but not the sections and options, including not copying the default section.
|
protectedvirtual |
Function to read single file.
std::runtime_error,syntax_error |
|
protectedvirtual |
Function to read the configuration from a stream.
syntax_error,maybe | bad_section (not sure if it can happen) |
bool mysql_harness::Config::empty | ( | ) | const |
Check if the configuration is empty.
true
if there are any sections in the configuration (not counting the default section), false
otherwise. Config::SectionList mysql_harness::Config::get | ( | const std::string & | section | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Config::ConstSectionList mysql_harness::Config::get | ( | const std::string & | section | ) | const |
Get a list of sections having a name.
There can be several sections under the same name, but they will have different keys.
section | Section name of sections to fetch. |
ConfigSection & mysql_harness::Config::get | ( | const std::string & | section, |
const std::string & | key | ||
) |
Get a section by name and key.
Get a section given a name and a key. Since there can be several sections with the same name (but different keys) this will always return a unique section.
section | Name of section to fetch. |
key | Key for section to fetch. |
bad_section | Thrown if the section do not exist or if a key were used but is not allowed. |
const ConfigSection & mysql_harness::Config::get | ( | const std::string & | section, |
const std::string & | key | ||
) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std::string mysql_harness::Config::get_default | ( | const std::string & | option | ) | const |
ConfigSection & mysql_harness::Config::get_default_section | ( | ) | const |
bool mysql_harness::Config::has | ( | const std::string & | section, |
const std::string & | key = std::string() |
||
) | const |
bool mysql_harness::Config::has_any | ( | const std::string & | section | ) | const |
bool mysql_harness::Config::has_default | ( | const std::string & | option | ) | const |
bool mysql_harness::Config::is_reserved | ( | const std::string & | word | ) | const |
void mysql_harness::Config::read | ( | const Path & | path | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void mysql_harness::Config::read | ( | const Path & | path, |
const std::string & | pattern | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void mysql_harness::Config::read | ( | std::istream & | input | ) |
Read configuration file from file, directory, or input stream.
If there are conflicting sections (several instance sections with identical name and key) or conflicting options (several instances of an option in the same section) in the input, an exception will be thrown.
If the input is a stream, the contents of the stream will be added to the configuration, but if the input is either a file or a directory, the exisisting contents of the configuration will be removed.
If a pattern
is given, the path is assumed to be a directory and all files matching the pattern will be read into the the configuration object. The files together will be treated as if it is a single file, that is, no conflicting option values or sections are allowed and will raise an exception.
input | Input stream to read from. |
syntax_error | Raised if there is a syntax error in the configuration file and the configuration file have to be corrected. |
bad_section | Raised if there is a duplicate section (section with the same name and key) in the input stream. |
bad_option | Raised if there is a duplicate definition of an option (same option is given twice in a section). |
|
noexcept |
Remove section from configuration.
section_key | section+key to remove. |
|
noexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
Config::ConstSectionList mysql_harness::Config::sections | ( | ) | const |
Get a list of all sections in the configuration.
void mysql_harness::Config::set_default | ( | const std::string & | option, |
const std::string & | value | ||
) |
|
inline |
void mysql_harness::Config::update | ( | const Config & | other | ) |
Update configuration using another configuration.
This will incorporate all the sections and options from the other
configuration by adding sections that are missing and overwriting option values for sections that exist in the current configuration.
other | Configuration to read section, options, and values from. |
|
staticconstexpr |
Flags for construction of configurations.
|
protected |
|
staticconstexpr |
Default pattern to used to identify configuration files.
|
protected |
bool mysql_harness::Config::error_on_unsupported_option {false} |
|
protected |
|
protected |
|
protected |