diff --git a/src/delegator.cpp b/src/delegator.cpp index 142fea775c46ff5f3afb7ca29b3a631e9fbb4675..72958f7843336c57b7d27e2b6d0e9aad7dc32d6e 100644 --- a/src/delegator.cpp +++ b/src/delegator.cpp @@ -10,6 +10,7 @@ #include #include +#include #ifdef ENABLE_DLB #include "backends/dlb/dlb/dlb.hpp" #include "backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp" @@ -91,6 +92,19 @@ void Delegator::Init(std::string_view nesting_mode, std::string_view backend) { break; } + if (stringsAreCaseInsensitiveEqual("ENV",std::string(backend))) { + // We instanciate the variable here, because its only required if the + // backend is set to "env". + EnvironmentVariable env_backend = EnvironmentVariable< + std::string>( + "BACKEND", + "Set the backend to use, when init with \"env\" backend name.", + true); + + // Unwraping the std::optional is safe because the variable is required. + backend = env_backend.getValue().value(); + } + // next choose backend switch (nesting_mode_) { case NestingMode::Detection: diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt index 369cedfeed5a75d18805932e80298436db34b79b..ea714acbd422f8e87dc05a2c6cbaa6238e657d1e 100644 --- a/src/utils/CMakeLists.txt +++ b/src/utils/CMakeLists.txt @@ -1 +1 @@ -target_sources(nesmik PRIVATE environment_variable.cpp parallelism_helper.cpp) \ No newline at end of file +target_sources(nesmik PRIVATE environment_variable.cpp parallelism_helper.cpp string_helpers.cpp) \ No newline at end of file diff --git a/src/utils/environment_variable.cpp b/src/utils/environment_variable.cpp index 589d53d6351d03cd69c30ecdef18b45464864194..9b1df9d62207d8ac85d63aa9a9960367daa6c945 100644 --- a/src/utils/environment_variable.cpp +++ b/src/utils/environment_variable.cpp @@ -4,26 +4,18 @@ #include #include -#include "environment_variable.hpp" - -// some helper function to compare case insenstive strings -bool charToLowerEquals(char a, char b) { - return std::tolower(static_cast(a)) == - std::tolower(static_cast(b)); -} +#include -bool compareCaseInsenstive(const std::string &a, const std::string &b) { - return std::equal(a.begin(), a.end(), b.begin(), b.end(), charToLowerEquals); -} +#include "environment_variable.hpp" template <> std::optional fromEnvString(const std::string &env_string) { - if (compareCaseInsenstive(env_string, "0") || - compareCaseInsenstive(env_string, "false") || - compareCaseInsenstive(env_string, "off")) { + if (stringsAreCaseInsensitiveEqual(env_string, "0") || + stringsAreCaseInsensitiveEqual(env_string, "false") || + stringsAreCaseInsensitiveEqual(env_string, "off")) { return std::optional{false}; - } else if (compareCaseInsenstive(env_string, "1") || - compareCaseInsenstive(env_string, "true") || - compareCaseInsenstive(env_string, "on")) { + } else if (stringsAreCaseInsensitiveEqual(env_string, "1") || + stringsAreCaseInsensitiveEqual(env_string, "true") || + stringsAreCaseInsensitiveEqual(env_string, "on")) { return std::optional{true}; } else { return std::nullopt; diff --git a/src/utils/environment_variable.hpp b/src/utils/environment_variable.hpp index d4543b0339aae48591c4bee7b50edfefa947536b..97834f0b6193434e4c1bc2352e79a43ee25075ce 100644 --- a/src/utils/environment_variable.hpp +++ b/src/utils/environment_variable.hpp @@ -7,11 +7,6 @@ #include #include -// some helper function to compare case insenstive strings -bool charToLowerEquals(char a, char b); - -bool compareCaseInsenstive(const std::string &a, const std::string &b); - // dont allow the compiler to guess, but force user to implement conversion template std::optional fromEnvString(const std::string &env_string) = delete; diff --git a/src/utils/string_helpers.cpp b/src/utils/string_helpers.cpp new file mode 100644 index 0000000000000000000000000000000000000000..15de8fc4500de4cc0bbf4d4ca8fdb781c4a8dc4d --- /dev/null +++ b/src/utils/string_helpers.cpp @@ -0,0 +1,14 @@ +#include +#include + +#include "string_helpers.hpp" + +// some helper function to compare case insenstive strings +bool charToLowerEquals(char a, char b) { + return std::tolower(static_cast(a)) == + std::tolower(static_cast(b)); +} + +bool stringsAreCaseInsensitiveEqual(const std::string &a, const std::string &b) { + return std::equal(a.begin(), a.end(), b.begin(), b.end(), charToLowerEquals); +} diff --git a/src/utils/string_helpers.hpp b/src/utils/string_helpers.hpp new file mode 100644 index 0000000000000000000000000000000000000000..043600d470ba6e3d04e08c0cbeb91b479dc15e1d --- /dev/null +++ b/src/utils/string_helpers.hpp @@ -0,0 +1,8 @@ +#ifndef NESMIK_STRING_HELPERS_HPP +#define NESMIK_STRING_HELPERS_HPP + +#include + +bool stringsAreCaseInsensitiveEqual(const std::string &a, const std::string &b); + +#endif // NESMIK_STRING_HELPERS_HPP