summaryrefslogtreecommitdiff
path: root/tools/utils.h
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2012-11-22 23:34:11 (GMT)
committerJohn Denker <jsd@av8n.com>2012-11-22 23:34:11 (GMT)
commit174d2e3ae49ed3776449d3dade24cebee304bfb5 (patch)
tree3102d8246737df2e3cd36e423b4ee424fe419a36 /tools/utils.h
parente1d2c30b9d7c08b658464e3db4bf48d5fe52cf5e (diff)
move argParser to utils.h
Diffstat (limited to 'tools/utils.h')
-rw-r--r--tools/utils.h44
1 files changed, 44 insertions, 0 deletions
diff --git a/tools/utils.h b/tools/utils.h
index 2c531b8..4f5418f 100644
--- a/tools/utils.h
+++ b/tools/utils.h
@@ -1,3 +1,6 @@
+#include <string>
+#include <list>
+
std::string basename(const std::string path);
int prefix(const std::string shorter, const std::string longer);
std::string time_out(const int _ttt);
@@ -12,3 +15,44 @@ std::string rtrim(const std::string foo,
std::string trim(const std::string foo,
const std::string strip = " \t\r\n");
+
+typedef const char cc;
+typedef cc* str;
+
+class argParser{
+public:
+ std::list<str> argv;
+ std::string current_arg;
+
+ argParser(const int _argc, const str _argv[])
+ {
+ for (int ii=0; ii < _argc; ii++) {
+ argv.push_back(_argv[ii]);
+ }
+ }
+ std::string shift() {
+ using namespace std;
+ string rslt = argv.front();
+ argv.pop_front();
+ return rslt;
+ }
+ void next(){
+ current_arg = shift();
+ }
+ size_t size() const {
+ return argv.size();
+ }
+ int prefix(const std::string longer, const size_t required = 0){
+ using namespace std;
+ if (argv.size() < required) {
+ if (required==1)
+ cerr << "Option '" << current_arg
+ << "' requires an argument." << endl;
+ else
+ cerr << "Option '" << current_arg
+ << "' requires " << required << " arguments." << endl;
+ throw int(1);
+ }
+ return current_arg == longer.substr(0, current_arg.length());
+ }
+};