diff --git a/.circleci/config.yml b/.circleci/config.yml index 72607c8..dc6bb7f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,7 +3,7 @@ version: 2.1 jobs: ctest: docker: - - image: git.wntrmute.dev/sc/dev:main + - image: git.wntrmute.dev/sc/dev:alpine steps: - checkout - run: @@ -12,19 +12,8 @@ jobs: - run: name: Valgrind checks. command: cmake-run-valgrind.sh - NOT_REQUIRED_static_analysis: - docker: - - image: git.wntrmute.dev/sc/dev:main - steps: - - checkout - - run: - name: Trunk check - command: ./trunk check --upstream=HEAD^ workflows: ctest: jobs: - ctest - static_analysis: - jobs: - - NOT_REQUIRED_static_analysis diff --git a/CMakeLists.txt b/CMakeLists.txt index bda30d7..084f752 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.22) project(scsl LANGUAGES CXX - VERSION 0.2.5 + VERSION 1.0.0 DESCRIPTION "Shimmering Clarity Standard Library") set(CMAKE_CXX_STANDARD 14) diff --git a/include/scsl/SimpleConfig.h b/include/scsl/SimpleConfig.h index 2367329..550bf0d 100644 --- a/include/scsl/SimpleConfig.h +++ b/include/scsl/SimpleConfig.h @@ -89,7 +89,7 @@ public: /// /// \param prefix The prefix to prepend to the key when looking /// up values from the environment. - static void SetPrefixGlobal(const std::string prefix); + static void SetPrefixGlobal(const std::string &prefix); /// \brief Return the keys cached in the config. /// @@ -108,7 +108,7 @@ public: /// \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(std::string key); + static std::string GetGlobal(std::string &key); /// \brief Get the value stored for the key from the config. /// @@ -120,7 +120,7 @@ public: /// value is stored under the key. /// \return The value stored under the key, or the default /// value. - static std::string GetGlobal(std::string key, std::string defaultValue); + static std::string GetGlobal(std::string &key, const std::string &defaultValue); #endif /// \brief The constructor doesn't need any initialisation. @@ -128,7 +128,7 @@ public: /// \brief The constructor can explicitly set the environment /// prefix. - SimpleConfig(std::string prefix); + explicit SimpleConfig(std::string &prefix); /// \brief Load key-value pairs from a file. /// @@ -146,7 +146,7 @@ public: /// /// \param prefix The prefix to prepend to the key when looking /// up values from the environment. - void SetPrefix(const std::string prefix); + void SetPrefix(const std::string &prefix); /// \brief Return the keys cached in the config. /// @@ -161,7 +161,7 @@ public: /// \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(std::string key); + std::string Get(std::string &key); /// \brief Get the value stored for the key from the config. /// @@ -171,7 +171,7 @@ public: /// value is stored under the key. /// \return The value stored under the key, or the default /// value. - std::string Get(std::string key, std::string defaultValue); + std::string Get(std::string &key, std::string defaultValue); private: std::string envPrefix; diff --git a/src/sl/SimpleConfig.cc b/src/sl/SimpleConfig.cc index 7e52327..78fcd13 100644 --- a/src/sl/SimpleConfig.cc +++ b/src/sl/SimpleConfig.cc @@ -63,7 +63,7 @@ SimpleConfig::LoadGlobal(std::string &path) void -SimpleConfig::SetPrefixGlobal(const std::string prefix) +SimpleConfig::SetPrefixGlobal(const std::string &prefix) { globalConfig.SetPrefix(prefix); } @@ -77,14 +77,14 @@ SimpleConfig::KeyListGlobal() std::string -SimpleConfig::GetGlobal(std::string key) +SimpleConfig::GetGlobal(std::string &key) { return globalConfig.Get(key); } std::string -SimpleConfig::GetGlobal(std::string key, std::string defaultValue) +SimpleConfig::GetGlobal(std::string &key, const std::string &defaultValue) { return globalConfig.Get(key, defaultValue); } @@ -95,7 +95,7 @@ SimpleConfig::SimpleConfig() } -SimpleConfig::SimpleConfig(std::string prefix) +SimpleConfig::SimpleConfig(std::string &prefix) : envPrefix(prefix) { } @@ -140,21 +140,21 @@ SimpleConfig::Load(std::string &path) void -SimpleConfig::SetPrefix(const std::string prefix) +SimpleConfig::SetPrefix(const std::string &prefix) { this->envPrefix = std::move(prefix); } std::string -SimpleConfig::Get(std::string key) +SimpleConfig::Get(std::string &key) { return this->Get(key, ""); } std::string -SimpleConfig::Get(std::string key, std::string defaultValue) +SimpleConfig::Get(std::string &key, std::string defaultValue) { if (this->vars.count(key)) { return this->vars[key]; @@ -168,7 +168,7 @@ SimpleConfig::Get(std::string key, std::string defaultValue) return this->Get(key); } - this->vars[key] = defaultValue; + this->vars[key] = std::move(defaultValue); return this->Get(key); } @@ -178,10 +178,8 @@ SimpleConfig::KeyList() { std::vector keyList; - for (auto &entry : this->vars) { - keyList.push_back(entry.first); - } - + std::transform(this->vars.begin(), this->vars.end(), std::back_inserter(keyList), + [](std::pair pair){return pair.first;}); return keyList; }