From 989534a10b4fd6eba210a22467c2bb314b174f51 Mon Sep 17 00:00:00 2001 From: lloyd Date: Sat, 9 Dec 2006 08:59:25 +0000 Subject: Add a value_if_set member function to the getopt implementation (returns the option argument, or an empty string if no argument set) --- checks/getopt.cpp | 8 +++++++- checks/getopt.h | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'checks') diff --git a/checks/getopt.cpp b/checks/getopt.cpp index a30134ff9..c0145ca75 100644 --- a/checks/getopt.cpp +++ b/checks/getopt.cpp @@ -12,7 +12,8 @@ OptionParser::OptionParser(const std::string& opt_string) flags.push_back(OptionFlag(opts[j])); } -OptionParser::OptionFlag OptionParser::find_option(const std::string& name) const +OptionParser::OptionFlag +OptionParser::find_option(const std::string& name) const { for(size_t j = 0; j != flags.size(); j++) if(flags[j].name() == name) @@ -33,6 +34,11 @@ std::string OptionParser::value(const std::string& key) const return i->second; } +std::string OptionParser::value_if_set(const std::string& key) const + { + return is_set(key) ? value(key) : ""; + } + void OptionParser::parse(char* argv[]) { std::vector args; diff --git a/checks/getopt.h b/checks/getopt.h index 132bf5482..6d6cfe89f 100644 --- a/checks/getopt.h +++ b/checks/getopt.h @@ -11,7 +11,9 @@ class OptionParser public: std::vector leftovers() const { return leftover; } bool is_set(const std::string&) const; + std::string value(const std::string&) const; + std::string value_if_set(const std::string&) const; void parse(char*[]); OptionParser(const std::string&); -- cgit v1.2.3