qxLib
Public Member Functions | List of all members
qx::layered_configs_manager Class Referencefinal

A singleton that manages layered configuration variables. More...

#include <layered_configs_manager.h>

Inheritance diagram for qx::layered_configs_manager:
singleton< layered_configs_manager >

Public Member Functions

void set_app_description (cstring sAppDescription) noexcept
 Set app description. It will be shown in help message. More...
 
void set_args (int argc, char *argv[]) noexcept
 Set command line arguments. 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::optional< T > get (cstring_view svRuntimeName) const noexcept
 Get variable value by runtime name. More...
 
template<class T >
bool set (cstring_view svRuntimeName, T value) noexcept
 Set variable value by runtime name. Only set if the variable type matches. More...
 
void reset () noexcept
 Clear all variables and command line arguments. You should call parse() after that to set variables again.
 

Detailed Description

A singleton that manages layered configuration variables.

Doesn't support multithreading

Author
Khrapov
Date
17.05.2026

Definition at line 51 of file layered_configs_manager.h.

Member Function Documentation

◆ get()

template<class T >
std::optional< T > qx::layered_configs_manager::get ( cstring_view  svRuntimeName) const
inlinenoexcept

Get variable value by runtime name.

Template Parameters
T- type of variable
Parameters
svRuntimeName- runtime name of variable
Return values
-optional with variable value if it is present, has valid value and correct type

Definition at line 270 of file layered_configs_manager.inl.

◆ parse()

bool qx::layered_configs_manager::parse ( )
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.

Return values
-true all required variables are present and have valid values

Definition at line 146 of file layered_configs_manager.inl.

◆ set()

template<class T >
bool qx::layered_configs_manager::set ( cstring_view  svRuntimeName,
value 
)
inlinenoexcept

Set variable value by runtime name. Only set if the variable type matches.

Template Parameters
T- type of variable
Parameters
svRuntimeName- runtime name of variable
value- new variable value
Return values
-true if the value was set successfully

Definition at line 288 of file layered_configs_manager.inl.

◆ set_app_description()

void qx::layered_configs_manager::set_app_description ( cstring  sAppDescription)
inlinenoexcept

Set app description. It will be shown in help message.

Parameters
sAppDescription- app description

Definition at line 30 of file layered_configs_manager.inl.

◆ set_args()

void qx::layered_configs_manager::set_args ( int  argc,
char *  argv[] 
)
inlinenoexcept

Set command line arguments.

Should be called once at the beginning of the app before the first parse().

Parameters
argc- number of command line arguments
argv- array of command line arguments

Definition at line 35 of file layered_configs_manager.inl.

◆ show_help()

bool qx::layered_configs_manager::show_help ( ) const
inlinenoexcept

Show help message if "--help" or "-h" argument is present in command line arguments.

Should be called after set_args().

Return values
-true if help message was shown. usually the app should exit after that

Definition at line 40 of file layered_configs_manager.inl.


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