From 9a83cf6c08fe1c314cb6777d4869e70bf06e0c4a Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Mon, 23 Oct 2023 21:09:56 -0700 Subject: [PATCH] Add option to set config values. --- CMakeLists.txt | 2 +- include/scsl/SimpleConfig.h | 13 +++++++++++++ src/sl/SimpleConfig.cc | 14 ++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cfac812..2c5ef49 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.22) project(scsl LANGUAGES CXX - VERSION 1.0.2 + VERSION 1.0.3 DESCRIPTION "Shimmering Clarity Standard Library") set(CMAKE_CXX_STANDARD 14) diff --git a/include/scsl/SimpleConfig.h b/include/scsl/SimpleConfig.h index 550bf0d..f0d7f78 100644 --- a/include/scsl/SimpleConfig.h +++ b/include/scsl/SimpleConfig.h @@ -121,6 +121,10 @@ public: /// \return The value stored under the key, or the default /// value. static std::string GetGlobal(std::string &key, const std::string &defaultValue); + + /// \brief Set a configuration value. This will override any + /// value set. + static void PutGlobal(std::string &key, const std::string &value); #endif /// \brief The constructor doesn't need any initialisation. @@ -173,6 +177,15 @@ public: /// value. std::string Get(std::string &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); + private: std::string envPrefix; std::map vars; diff --git a/src/sl/SimpleConfig.cc b/src/sl/SimpleConfig.cc index 78fcd13..4dae11c 100644 --- a/src/sl/SimpleConfig.cc +++ b/src/sl/SimpleConfig.cc @@ -90,6 +90,13 @@ SimpleConfig::GetGlobal(std::string &key, const std::string &defaultValue) } +void +SimpleConfig::PutGlobal(std::string &key, const std::string &value) +{ + return globalConfig.Put(key, value); +} + + SimpleConfig::SimpleConfig() { } @@ -173,6 +180,13 @@ SimpleConfig::Get(std::string &key, std::string defaultValue) } +void +SimpleConfig::Put(std::string &key, const std::string value) +{ + this->vars[key] = std::move(key); +} + + std::vector SimpleConfig::KeyList() {