diff --git a/src/backends/detection/detection.hpp b/src/backends/detection/detection.hpp index b07b0b526d7b034bb4d0e3f36d66a772b93c0e17..e1d87582e2d2f52046fa0e987b060145784abef8 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 56f124b7267d5f5de53f778edbd99556c253b94d..f013186f93d88e5f4143c4e3ac1ea0bc1ad5f4f0 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 30ffb3c46a0cb88e8a40d4aa4b5e58b38baf0275..207894a5342c1bc5fef0f34069f0e918be718a19 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 259e7f0bca4fb989e152be45fd11a783d54a455c..ea73f973363c0211b307824be7c3f6a5259f298c 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 ea04550126b30bdfa03ca8bb8d62ab35dc400d2a..edf98f3ddf319d3a50882842e7cf107a80251fd1 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(); } };