SimpleConfig: Add const char * key variants.
This commit is contained in:
parent
9a83cf6c08
commit
1bc8a9ad82
|
@ -1,6 +1,6 @@
|
|||
cmake_minimum_required(VERSION 3.22)
|
||||
project(scsl LANGUAGES CXX
|
||||
VERSION 1.0.3
|
||||
VERSION 1.1.0
|
||||
DESCRIPTION "Shimmering Clarity Standard Library")
|
||||
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
|
|
|
@ -110,6 +110,27 @@ public:
|
|||
/// \return The value stored under the key, or an empty string.
|
||||
static std::string GetGlobal(std::string &key);
|
||||
|
||||
/// \brief Get the value stored for the key from the config.
|
||||
///
|
||||
/// \note This operates on the global config.
|
||||
///
|
||||
/// \param key The key to look up. See the class documentation
|
||||
/// for information on how this is used.
|
||||
/// \return The value stored under the key, or an empty string.
|
||||
static std::string GetGlobal(const char *key);
|
||||
|
||||
/// \brief Get the value stored for the key from the config.
|
||||
///
|
||||
/// \note This operates on the global config.
|
||||
///
|
||||
/// \param key The key to look up. See the class documentation
|
||||
/// for information on how this is used.
|
||||
/// \param defaultValue A default value to cache and use if no
|
||||
/// value is stored under the key.
|
||||
/// \return The value stored under the key, or the default
|
||||
/// value.
|
||||
static std::string GetGlobal(const char *key, const std::string &defaultValue);
|
||||
|
||||
/// \brief Get the value stored for the key from the config.
|
||||
///
|
||||
/// \note This operates on the global config.
|
||||
|
@ -125,6 +146,10 @@ public:
|
|||
/// \brief Set a configuration value. This will override any
|
||||
/// value set.
|
||||
static void PutGlobal(std::string &key, const std::string &value);
|
||||
|
||||
/// \brief Set a configuration value. This will override any
|
||||
/// value set.
|
||||
static void PutGlobal(const char *key, const std::string &value);
|
||||
#endif
|
||||
|
||||
/// \brief The constructor doesn't need any initialisation.
|
||||
|
@ -167,6 +192,13 @@ public:
|
|||
/// \return The value stored under the key, or an empty string.
|
||||
std::string Get(std::string &key);
|
||||
|
||||
/// \brief Get the value stored for the key from the config.
|
||||
///
|
||||
/// \param key The key to look up. See the class documentation
|
||||
/// for information on how this is used.
|
||||
/// \return The value stored under the key, or an empty string.
|
||||
std::string Get(const char *key);
|
||||
|
||||
/// \brief Get the value stored for the key from the config.
|
||||
///
|
||||
/// \param key The key to look up. See the class documentation
|
||||
|
@ -177,15 +209,31 @@ public:
|
|||
/// value.
|
||||
std::string Get(std::string &key, std::string defaultValue);
|
||||
|
||||
/// \brief Get the value stored for the key from the config.
|
||||
///
|
||||
/// \param key The key to look up. See the class documentation
|
||||
/// for information on how this is used.
|
||||
/// \param defaultValue A default value to cache and use if no
|
||||
/// value is stored under the key.
|
||||
/// \return The value stored under the key, or the default
|
||||
/// value.
|
||||
std::string Get(const char *key, std::string defaultValue);
|
||||
|
||||
/// \brief Set a configuration value. This will override any
|
||||
/// value set.
|
||||
///
|
||||
/// \param key The key to look up. See the class documentation
|
||||
/// for information on how this is used.
|
||||
/// \param value The value to set.
|
||||
/// \return
|
||||
void Put(std::string &key, const std::string value);
|
||||
|
||||
/// \brief Set a configuration value. This will override any
|
||||
/// value set.
|
||||
///
|
||||
/// \param key The key to look up. See the class documentation
|
||||
/// for information on how this is used.
|
||||
/// \param value The value to set.
|
||||
void Put(const char *key, const std::string value);
|
||||
private:
|
||||
std::string envPrefix;
|
||||
std::map<std::string, std::string> vars;
|
||||
|
|
|
@ -83,6 +83,13 @@ SimpleConfig::GetGlobal(std::string &key)
|
|||
}
|
||||
|
||||
|
||||
std::string
|
||||
SimpleConfig::GetGlobal(const char *key)
|
||||
{
|
||||
return globalConfig.Get(key);
|
||||
}
|
||||
|
||||
|
||||
std::string
|
||||
SimpleConfig::GetGlobal(std::string &key, const std::string &defaultValue)
|
||||
{
|
||||
|
@ -90,6 +97,13 @@ SimpleConfig::GetGlobal(std::string &key, const std::string &defaultValue)
|
|||
}
|
||||
|
||||
|
||||
std::string
|
||||
SimpleConfig::GetGlobal(const char *key, const std::string &defaultValue)
|
||||
{
|
||||
return globalConfig.Get(key, defaultValue);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SimpleConfig::PutGlobal(std::string &key, const std::string &value)
|
||||
{
|
||||
|
@ -160,6 +174,14 @@ SimpleConfig::Get(std::string &key)
|
|||
}
|
||||
|
||||
|
||||
std::string
|
||||
SimpleConfig::Get(const char *key)
|
||||
{
|
||||
auto keyStr = std::string(key);
|
||||
return this->Get(keyStr, "");
|
||||
}
|
||||
|
||||
|
||||
std::string
|
||||
SimpleConfig::Get(std::string &key, std::string defaultValue)
|
||||
{
|
||||
|
@ -180,6 +202,14 @@ SimpleConfig::Get(std::string &key, std::string defaultValue)
|
|||
}
|
||||
|
||||
|
||||
std::string
|
||||
SimpleConfig::Get(const char *key, std::string defaultValue)
|
||||
{
|
||||
auto keyStr = std::string(key);
|
||||
return this->Get(keyStr, std::move(defaultValue));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SimpleConfig::Put(std::string &key, const std::string value)
|
||||
{
|
||||
|
@ -187,6 +217,14 @@ SimpleConfig::Put(std::string &key, const std::string value)
|
|||
}
|
||||
|
||||
|
||||
void
|
||||
SimpleConfig::Put(const char *key, const std::string value)
|
||||
{
|
||||
auto keyStr = std::string(key);
|
||||
this->vars[std::move(keyStr)] = std::move(key);
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::string>
|
||||
SimpleConfig::KeyList()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue