From 5bfd8dab2577aee71f9d8a4f082dda3de079f042 Mon Sep 17 00:00:00 2001 From: Andrew MacIntyre Date: Thu, 3 Feb 2022 12:32:54 -0400 Subject: [PATCH 1/3] Add is_set function to OptionParser. Simple syntax for checking if Switch flags are set. --- include/popl.hpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/include/popl.hpp b/include/popl.hpp index 8fd668b..c7bc1d4 100644 --- a/include/popl.hpp +++ b/include/popl.hpp @@ -380,6 +380,16 @@ class OptionParser template std::shared_ptr get_option(char short_name) const; + /// Check if an option is set by it's long name + /// @param the Option's long name + /// @return true if set at least once + bool is_set(const std::string& long_name) const; + + /// Check if an option is set by it's short name + /// @param the Option's long name + /// @return true if set at least once + bool is_set(char short_name) const; + protected: std::vector options_; std::string description_; @@ -940,6 +950,26 @@ inline std::shared_ptr OptionParser::get_option(char short_name) const return result; } +bool OptionParser::is_set(const std::string& long_name) const +{ + Option_ptr option = find_option(long_name); + if (option && option->is_set()) + { + return true; + } + return false; +} + +bool OptionParser::is_set(char short_name) const +{ + Option_ptr option = find_option(short_name); + if (option && option->is_set()) + { + return true; + } + return false; +} + inline void OptionParser::parse(const std::string& ini_filename) { std::ifstream file(ini_filename.c_str()); From 92a2726fa32e9543be936ddf5b03a7b89ae36b56 Mon Sep 17 00:00:00 2001 From: Andrew MacIntyre Date: Sun, 13 Feb 2022 10:23:30 -0400 Subject: [PATCH 2/3] PR Feedback Co-authored-by: Pavel I. Kryukov --- include/popl.hpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/include/popl.hpp b/include/popl.hpp index c7bc1d4..5f3ef7e 100644 --- a/include/popl.hpp +++ b/include/popl.hpp @@ -953,11 +953,7 @@ inline std::shared_ptr OptionParser::get_option(char short_name) const bool OptionParser::is_set(const std::string& long_name) const { Option_ptr option = find_option(long_name); - if (option && option->is_set()) - { - return true; - } - return false; + return option && option->is_set(); } bool OptionParser::is_set(char short_name) const From 6a0441b3f3d078840855bb2bb02fa48a9984f33d Mon Sep 17 00:00:00 2001 From: Andrew MacIntyre Date: Sun, 13 Feb 2022 10:23:34 -0400 Subject: [PATCH 3/3] Update include/popl.hpp Co-authored-by: Pavel I. Kryukov --- include/popl.hpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/include/popl.hpp b/include/popl.hpp index 5f3ef7e..8912438 100644 --- a/include/popl.hpp +++ b/include/popl.hpp @@ -959,11 +959,7 @@ bool OptionParser::is_set(const std::string& long_name) const bool OptionParser::is_set(char short_name) const { Option_ptr option = find_option(short_name); - if (option && option->is_set()) - { - return true; - } - return false; + return option && option->is_set(); } inline void OptionParser::parse(const std::string& ini_filename)