16 std::optional<T> optValue = layered_configs_manager::get_instance().get<T>(m_svRuntimeName);
17 return optValue ? *optValue : m_DefaultValue;
23 layered_configs_manager::get_instance().set(m_svRuntimeName, std::move(value));
28 cstring_view svRuntimeName,
29 T defaultValue) noexcept
31 m_svRuntimeName = svRuntimeName;
32 m_DefaultValue = std::move(defaultValue);
33 m_Data.pStringToT = [](cstring_view svData) -> std::optional<std::any>
35 if constexpr (std::is_same_v<T, cstring_view>)
44 std::optional<T> optResult = sData.
to<T>();
48 return std::move(*optResult);
51 m_Data.pTToString = [](
const std::any& data) ->
cstring
53 return convert_to_string<T, char>(std::any_cast<T>(data));
55 m_Data.svTypeName = []() -> cstring_view
57 if constexpr (std::is_same_v<T, cstring_view>)
71 m_Data.svEnvName = svEnvName;
77 cstring_view svFullName,
78 cstring_view svShortName) noexcept
80 m_Data.svFullCommandLineName = svFullName;
81 if (!m_Data.svFullCommandLineName.starts_with(
"--"))
82 throw "Full command line name must start with --";
84 m_Data.svShortCommandLineName = svShortName;
85 if (!m_Data.svShortCommandLineName.empty() && !m_Data.svShortCommandLineName.starts_with(
"-"))
86 throw "Short command line name must start with -";
93 cstring_view svGroupName) noexcept
95 m_Data.svGroupName = svGroupName;
101 cstring_view svDescription) noexcept
103 m_Data.svDescription = svDescription;
110 m_Data.bRequired =
true;
121 layered_configs_manager::get_instance().add_variable(m_svRuntimeName, std::move(m_Data), std::move(m_DefaultValue));
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 env(cstring_view svEnvName) noexcept
Add environment variable layer with specified name.
consteval layered_config_variable_builder group(cstring_view svGroupName) noexcept
Set the group name for the variable.
layered_config_variable< T > build() noexcept
Finalize building layered_config_variable instance and add it to layered_configs_manager.
consteval layered_config_variable_builder description(cstring_view svDescription) noexcept
Set the description 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(cstring_view svRuntimeName, T defaultValue={}) noexcept
layered_config_variable_builder object constructor
consteval layered_config_variable_builder command_line(cstring_view svFullName, cstring_view svShortName={}) noexcept
Add command line argument layer with specified full and short names. Full name should start with "--"...
A configuration variable that can be set from different layers (default value, environment variable,...
constexpr void 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)