aboutsummaryrefslogtreecommitdiffstats
path: root/checks/getopt.h
diff options
context:
space:
mode:
authorlloyd <[email protected]>2006-08-09 08:27:03 +0000
committerlloyd <[email protected]>2006-08-09 08:27:03 +0000
commit53414fe78b29b1957ab8b29fde05a90e179092d7 (patch)
treed057b1c41ea435489ea2268b8e856a55c8a6ff5f /checks/getopt.h
parentd9fda681dd79dca09b9955960eaf27fda200f928 (diff)
Add a simple option parser to the check utility; it makes for much saner
code in check.cpp, and now the order of options on the command line should not change what heppens. The options taken have changed slightly. All options that take values are now --arg=value instead of "--arg value", and the various --bench-(blah) options have been turned into a new option --bench-type that takes an argument specifying the type of algorithm to benchmark.
Diffstat (limited to 'checks/getopt.h')
-rw-r--r--checks/getopt.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/checks/getopt.h b/checks/getopt.h
new file mode 100644
index 000000000..5796f7ae7
--- /dev/null
+++ b/checks/getopt.h
@@ -0,0 +1,38 @@
+
+#include <string>
+#include <vector>
+#include <map>
+
+class OptionParser
+ {
+ public:
+ std::vector<std::string> leftovers() const { return leftover; }
+ bool is_set(const std::string&) const;
+ std::string value(const std::string&) const;
+
+ void parse(char*[]);
+ OptionParser(const std::string&);
+ private:
+ class OptionFlag
+ {
+ public:
+ std::string name() const { return opt_name; }
+ bool takes_arg() const { return opt_takes_arg; }
+
+ OptionFlag(const std::string& opt_string)
+ {
+ std::string::size_type mark = opt_string.find('=');
+ opt_name = opt_string.substr(0, mark);
+ opt_takes_arg = (mark != std::string::npos);
+ }
+ private:
+ std::string opt_name;
+ bool opt_takes_arg;
+ };
+
+ OptionFlag find_option(const std::string&) const;
+
+ std::vector<OptionFlag> flags;
+ std::map<std::string, std::string> options;
+ std::vector<std::string> leftover;
+ };