|
qxLib
|
A singleton that manages layered configuration variables. More...
#include <layered_configs_manager.h>
Public Types | |
| enum class | get_error |
| Errors returned when reading a registered variable. | |
| enum class | set_error |
| Errors returned when writing a variable; failed writes preserve the current value. | |
Public Member Functions | |
| void | set_app_description (string sAppDescription) noexcept |
| Set app description. It will be shown in help message. More... | |
| void | set_args (int argc, char *argv[]) noexcept |
| Copy command line arguments, converting narrow input with to_string(). More... | |
| bool | show_help () const noexcept |
| Show help message if "--help" or "-h" argument is present in command line arguments. More... | |
| bool | parse () noexcept |
| Parse command line arguments, environment variables, and default values. More... | |
| template<class T > | |
| std::expected< T, get_error > | get (string_view svRuntimeName) const noexcept |
| Get variable value by runtime name. More... | |
| template<class T > | |
| std::expected< void, set_error > | set (string_view svRuntimeName, T value) noexcept |
| Set variable value by runtime name. Only set if the variable type matches. More... | |
| std::expected< std::reference_wrapper< const std::any >, get_error > | get (string_view svRuntimeName) const noexcept |
| Read the current value without knowing its C++ type. More... | |
| std::expected< void, set_error > | set (string_view svRuntimeName, std::any value) noexcept |
| Set a type-erased value using the variable's exact registered C++ type. More... | |
| std::expected< string, get_error > | get_string (string_view svRuntimeName) const noexcept |
| Read a value through its registered string formatter without knowing its C++ type. More... | |
| std::expected< void, set_error > | set_string (string_view svRuntimeName, string_view svValue) noexcept |
| Set a variable from text using its existing registered parser. More... | |
| std::vector< layered_config_variable_info > | get_variables () const noexcept |
| Enumerate registered variables without exposing converters or stored values. More... | |
| void | reset () noexcept |
| Clear all variables and command line arguments. You should call parse() after that to set variables again. | |
A singleton that manages layered configuration variables.
Doesn't support multithreading
Definition at line 65 of file layered_configs_manager.h.
|
inlinenoexcept |
Get variable value by runtime name.
| T | - type of variable |
| svRuntimeName | - runtime name of variable |
Definition at line 279 of file layered_configs_manager.inl.
|
inlinenoexcept |
Read the current value without knowing its C++ type.
The reference is valid until the stored value is removed or the manager is reset. Setting or parsing values may change which value is current.
| svRuntimeName | - registered runtime name, matched exactly |
Definition at line 303 of file layered_configs_manager.inl.
|
inlinenoexcept |
Read a value through its registered string formatter without knowing its C++ type.
| svRuntimeName | - registered runtime name, matched exactly |
Definition at line 332 of file layered_configs_manager.inl.
|
inlinenoexcept |
Enumerate registered variables without exposing converters or stored values.
Definition at line 357 of file layered_configs_manager.inl.
|
inlinenoexcept |
Parse command line arguments, environment variables, and default values.
Should be called after set_args() and before get()/set() of any variable. You can call it multiple times during the app lifetime, for example, to load variables from different DLLs.
Definition at line 155 of file layered_configs_manager.inl.
|
inlinenoexcept |
Set a type-erased value using the variable's exact registered C++ type.
| svRuntimeName | - registered runtime name |
| value | - owned value; a mismatched type leaves the variable unchanged |
Definition at line 316 of file layered_configs_manager.inl.
|
inlinenoexcept |
Set variable value by runtime name. Only set if the variable type matches.
| T | - type of variable |
| svRuntimeName | - runtime name of variable |
| value | - new variable value |
Definition at line 294 of file layered_configs_manager.inl.
|
inlinenoexcept |
Set app description. It will be shown in help message.
| sAppDescription | - app description |
Definition at line 30 of file layered_configs_manager.inl.
|
inlinenoexcept |
Copy command line arguments, converting narrow input with to_string().
Should be called once at the beginning of the app before the first parse(). Non-positive argc or null argv clears the command line arguments.
| argc | - number of command line arguments |
| argv | - array of command line arguments |
Definition at line 35 of file layered_configs_manager.inl.
|
inlinenoexcept |
Set a variable from text using its existing registered parser.
Every registered variable is writable. Conversion rules match environment and command-line parsing. On success this uses the same runtime storage as set<T>(); no file is written. Failure leaves the previous value unchanged. Call only on the manager's owning thread.
| svRuntimeName | - registered runtime name, matched exactly |
| svValue | - text to convert to the variable's declared type |
Definition at line 342 of file layered_configs_manager.inl.
|
inlinenoexcept |
Show help message if "--help" or "-h" argument is present in command line arguments.
Should be called after set_args().
Definition at line 49 of file layered_configs_manager.inl.