-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcmdparser.cpp
More file actions
30 lines (26 loc) · 759 Bytes
/
cmdparser.cpp
File metadata and controls
30 lines (26 loc) · 759 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "cmdparser.h"
CommandParser::CommandParser(int argc, char* argv[]) {
for(int i = 0; i < argc; i++) {
cmdline.push_back(string(argv[i]));
}
}
string CommandParser::getParameter(string keyword, string keyword_s) {
for(unsigned int i = 0; i < cmdline.size(); i++) {
if(cmdline[i].compare("--" + keyword) == 0 || cmdline[i].compare("-" + keyword_s) == 0) {
if(i + 1 < cmdline.size()) {
return cmdline[i + 1];
} else {
return "";
}
}
}
return "";
}
bool CommandParser::hasFlag(string flag, string flag_s) {
for(unsigned int i = 0; i < cmdline.size(); i++) {
if(cmdline[i].compare("--" + flag) == 0 || cmdline[i].compare("-" + flag_s) == 0) {
return true;
}
}
return false;
}