-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparameter.cpp
More file actions
36 lines (26 loc) · 977 Bytes
/
Copy pathparameter.cpp
File metadata and controls
36 lines (26 loc) · 977 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
31
32
33
34
35
36
#include "parameter.h"
std::map<std::string, std::string> parse_argv(char **argv) {
std::map<std::string, std::string> map;
int i = 1; // This is one because we want to ignore the path which is position 1
while (1) {
char *current_argument = argv[i];
if (current_argument == nullptr)
break;
for (const auto &item: available_parameter)
if (current_argument == ("-" + item.name)) {
char *value = argv[++i];
if (value == nullptr) {
printf("You messed up big time. You forgot to provide a value to %s. \n", current_argument);
exit(1);
}
map[item.name] = value;
}
++i;
}
for (const auto &item: available_parameter)
if (item.required && !map.contains(item.name)) {
printf("You failed to provide required data.");
exit(1);
}
return map;
}