16 std::expected<T, layered_configs_manager::get_error> value =
17 layered_configs_manager::get_instance().get<T>(m_svRuntimeName);
18 return value ? *value : m_DefaultValue;
24 return layered_configs_manager::get_instance().set(m_svRuntimeName, std::move(value));
29 string_view svRuntimeName,
30 T defaultValue) noexcept
31 : m_svRuntimeName(svRuntimeName)
32 , m_DefaultValue(std::move(defaultValue))
34 m_Data.pStringToT = [](string_view svData) -> std::optional<std::any>
36 if constexpr (std::is_same_v<T, string_view>)
43 string sData = svData;
45 std::optional<T> optResult = sData.
to<T>();
49 return std::move(*optResult);
52 m_Data.pTToString = [](
const std::any& data) ->
string
54 return convert_to_string<typename details::layered_config_variable_type<T>::type, char_type>(
55 std::any_cast<const typename details::layered_config_variable_type<T>::type&>(data));
57 m_Data.svTypeName = []() -> string_view
59 if constexpr (std::is_same_v<T, string_view>)
73 m_Data.svEnvName = svEnvName;
79 string_view svFullName,
80 string_view svShortName)
82 m_Data.svFullCommandLineName = svFullName;
83 if (!m_Data.svFullCommandLineName.starts_with(QXT(
"--")))
84 throw QXT(
"Full command line name must start with --");
86 m_Data.svShortCommandLineName = svShortName;
87 if (!m_Data.svShortCommandLineName.empty() && !m_Data.svShortCommandLineName.starts_with(QXT(
"-")))
88 throw QXT(
"Short command line name must start with -");
96 m_Data.svGroupName = svGroupName;
102 string_view svDescription) noexcept
104 m_Data.svDescription = svDescription;
111 m_Data.bRequired =
true;
119 layeredConfigVariable.m_DefaultValue = m_DefaultValue;
120 layeredConfigVariable.m_svRuntimeName = m_svRuntimeName;
122 layered_configs_manager::get_instance().add_variable(m_svRuntimeName, std::move(m_Data), std::move(m_DefaultValue));
124 return layeredConfigVariable;
std::optional< to_t > to(const_pointer pszFormat=nullptr) const noexcept
Convert string to specified type.
A builder for creating layered_config_variable instances.
consteval layered_config_variable_builder(string_view svRuntimeName, T defaultValue={}) noexcept
layered_config_variable_builder object constructor
consteval layered_config_variable_builder env(string_view svEnvName) noexcept
Add environment variable layer with specified name.
consteval layered_config_variable_builder command_line(string_view svFullName, string_view svShortName={})
Add command line argument layer with specified full and short names. Full name should start with "--"...
layered_config_variable< T > build() noexcept
Finalize building layered_config_variable instance and add it to layered_configs_manager.
consteval layered_config_variable_builder group(string_view svGroupName) noexcept
Set the group name for the variable.
consteval layered_config_variable_builder required() noexcept
Mark variable as required. If a required variable is not set in any layer or has invalid value,...
consteval layered_config_variable_builder description(string_view svDescription) noexcept
Set the description for the variable.
A configuration variable that can be set from different layers (default value, environment variable,...
constexpr std::expected< void, layered_configs_manager::set_error > set(T value) noexcept
Set variable value at runtime. It will override value from all other layers.
constexpr T get() const noexcept
Get variable value. If the variable is not set in any layer or has invalid value, the default value w...
static constexpr string_view_type get_signature()
Get type signature (full name with template parameters)