20 #include <unordered_map>
30 string_view svEnvName;
31 string_view svFullCommandLineName;
32 string_view svShortCommandLineName;
34 string_view svGroupName;
35 string_view svDescription;
36 bool bRequired =
false;
38 std::optional<std::any> (*pStringToT)(string_view svData) =
nullptr;
39 string (*pTToString)(
const std::any& data) =
nullptr;
40 string_view svTypeName;
51 string_view svDescription;
52 string_view svTypeName;
53 string_view svGroupName;
104 void set_args(
int argc,
char* argv[]) noexcept;
119 bool parse() noexcept;
128 std::expected<T,
get_error>
get(string_view svRuntimeName) const noexcept;
138 std::expected<
void,
set_error>
set(string_view svRuntimeName, T value) noexcept;
147 std::expected<std::reference_wrapper<const std::any>,
get_error>
get(string_view svRuntimeName) const noexcept;
155 std::expected<
void,
set_error>
set(string_view svRuntimeName, std::any value) noexcept;
173 std::expected<
void,
set_error>
set_string(string_view svRuntimeName, string_view svValue) noexcept;
184 void reset() noexcept;
196 string_view svRuntimeName,
197 const details::layered_config_variable_data& data,
198 T defaultValue) noexcept;
201 string m_sAppDescription;
202 std::vector<
string> m_Args;
204 std::unordered_map<string_view, details::layered_config_variable_data> m_VariableData;
205 std::unordered_map<string_view, std::any> m_DefaultVariables;
206 std::unordered_map<string_view, std::any> m_Variables;
211 #include <qx/layered_config/layered_configs_manager.inl>
A builder for creating layered_config_variable instances.
A singleton that manages layered configuration variables.
std::expected< void, set_error > set_string(string_view svRuntimeName, string_view svValue) noexcept
Set a variable from text using its existing registered parser.
void set_app_description(string sAppDescription) noexcept
Set app description. It will be shown in help message.
get_error
Errors returned when reading a registered variable.
std::vector< layered_config_variable_info > get_variables() const noexcept
Enumerate registered variables without exposing converters or stored values.
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.
void reset() noexcept
Clear all variables and command line arguments. You should call parse() after that to set variables a...
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.
set_error
Errors returned when writing a variable; failed writes preserve the current value.
std::expected< T, get_error > get(string_view svRuntimeName) const noexcept
Get variable value by runtime name.
bool parse() noexcept
Parse command line arguments, environment variables, and default values.
bool show_help() const noexcept
Show help message if "--help" or "-h" argument is present in command line arguments.
void set_args(int argc, char *argv[]) noexcept
Copy command line arguments, converting narrow input with to_string().
Inherit the necessary singleton class from this.
Public variable metadata for enumeration and help; views refer to registered static names.