From 4118b266f9d844a22aa27e4b9d0b6ebc7574dbe9 Mon Sep 17 00:00:00 2001 From: JOAN VINYALS YLLA CATALA Date: Mon, 8 Jul 2024 17:06:11 +0200 Subject: [PATCH] Revert "Merge branch 'make-env-a-bit-more-complex' into 'master'" This reverts merge request !30 --- src/backends/detection/detection.hpp | 7 +----- .../dlb/dlb_talp_tree/dlb_talp_tree.hpp | 23 +++++++++---------- src/backends/extrae/extrae_type_stack.hpp | 7 +++--- src/delegator.cpp | 13 +++++++---- src/utils/environment_variable.hpp | 12 +++------- 5 files changed, 26 insertions(+), 36 deletions(-) diff --git a/src/backends/detection/detection.hpp b/src/backends/detection/detection.hpp index b07b0b5..e1d8758 100644 --- a/src/backends/detection/detection.hpp +++ b/src/backends/detection/detection.hpp @@ -42,12 +42,7 @@ class DetectionStrategy : public ProperlyNestedAnnotationStrategy { "DETECTION_VERBOSE", "Enables the verbose mode in the detection backend", true); - std::mutex starts_mutex_; - std::mutex ends_mutex_; - EnvironmentVariable verbose_mode_ = - EnvironmentVariable( - "DETECTION_VERBOSE", - "Enables the verbose mode in the detection backend"); + bool has_errors_ = false; public: DetectionStrategy(); diff --git a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp index 56f124b..f013186 100644 --- a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp @@ -33,22 +33,21 @@ class DLBTalpTreeStrategy : public ProperlyNestedAnnotationStrategy { // Configuration variables inline static const std::string def_json_file_name_ = "nesmik_talp_tree.json"; - EnvironmentVariable env_json_file_name_ = - EnvironmentVariable( - "JSON_FILE", - "Set the name of the output JSON file. (default: " - "nesmik_talp_tree.json)"); + EnvironmentVariable env_json_file_name_ = EnvironmentVariable< + std::string>( + "JSON_FILE", + "Set the name of the output JSON file. (default: nesmik_talp_tree.json)", + false); inline static const bool def_enable_json_ = true; - EnvironmentVariable env_enable_json_ = - EnvironmentVariable("JSON_OUTPUT", - "Enables output to a JSON file."); + EnvironmentVariable env_enable_json_ = EnvironmentVariable( + "JSON_OUTPUT", "Enables output to a JSON file.", false); inline static const bool def_enable_ascii_ = false; - EnvironmentVariable env_enable_ascii_ = - EnvironmentVariable( - "ASCII_OUTPUT", - "Enables human readable output to standard output. (default: off)"); + EnvironmentVariable env_enable_ascii_ = EnvironmentVariable( + "ASCII_OUTPUT", + "Enables human readable output to standard output. (default: off)", + false); public: DLBTalpTreeStrategy(); diff --git a/src/backends/extrae/extrae_type_stack.hpp b/src/backends/extrae/extrae_type_stack.hpp index 30ffb3c..207894a 100644 --- a/src/backends/extrae/extrae_type_stack.hpp +++ b/src/backends/extrae/extrae_type_stack.hpp @@ -25,10 +25,9 @@ class ExtraeTypeStackStrategy : public ProperlyNestedAnnotationStrategy { static const std::string paraverConfigOverviewWindow; static const std::string paraverConfigLevelWindow; - EnvironmentVariable write_config_file_ = - EnvironmentVariable( - "EXTRAE_WRITE_CONFIG_FILE", - "Write corresponding Paraver .cfg file if set to True"); + EnvironmentVariable write_config_file_ = EnvironmentVariable( + "EXTRAE_WRITE_CONFIG_FILE", + "Write corresponding Paraver .cfg file if set to True", false); inline static bool didInitialize{false}; diff --git a/src/delegator.cpp b/src/delegator.cpp index 259e7f0..ea73f97 100644 --- a/src/delegator.cpp +++ b/src/delegator.cpp @@ -92,11 +92,14 @@ void Delegator::Init(std::string_view nesting_mode, std::string_view backend) { if (stringsAreCaseInsensitiveEqual("ENV", std::string(backend))) { // We instantiate the variable here, because its only required if the // backend is set to "env". - EnvironmentVariable env_backend( - "BACKEND", - "Set the backend to use, when init with \"env\" backend name."); - - backend = env_backend.getValue(); + EnvironmentVariable env_backend = + EnvironmentVariable( + "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 diff --git a/src/utils/environment_variable.hpp b/src/utils/environment_variable.hpp index ea04550..edf98f3 100644 --- a/src/utils/environment_variable.hpp +++ b/src/utils/environment_variable.hpp @@ -16,7 +16,7 @@ std::optional fromEnvString(const std::string &env_string); template <> std::optional fromEnvString(const std::string &env_string); -template +template class EnvironmentVariable { inline static std::string PREFIX = "NESMIK_"; @@ -25,7 +25,7 @@ class EnvironmentVariable { Upon construction it will do the getenv */ EnvironmentVariable(const std::string &variable_name, - const std::string &description) + const std::string &description, bool required = false) : variable_name_(variable_name), description_(description) { const std::string variable_to_query = EnvironmentVariable::PREFIX + variable_name_; @@ -49,13 +49,7 @@ class EnvironmentVariable { std::optional value_; public: - auto getValue() const { - if constexpr (required) { - return value_.value(); - } else { - return value_; - } - } + std::optional getValue() const { return value_; } bool isSet() const { return value_.has_value(); } }; -- GitLab