-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathargs.h
115 lines (86 loc) · 2.51 KB
/
args.h
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#ifndef args_h
#define args_h
#include <stdio.h>
#include <iostream>
#include <vector>
struct arg {
std::string full_name;
std::string abbreviation = "";
std::string description = "";
bool required = false;
bool has_param = false;
std::string help_text();
};
struct bool_arg : public arg {
bool_arg(std::string fn, std::string desc = "", std::string abbr = "", bool req = false, bool val = false) {
full_name = fn;
description = desc;
abbreviation = abbr;
required = req;
value = val;
};
bool value = false;
};
struct string_arg : public arg {
string_arg(std::string fn, std::string desc = "", std::string abbr = "", bool req = false, std::string val = "") {
full_name = fn;
description = desc;
abbreviation = abbr;
required = req;
value = val;
};
bool has_param = true;
std::string value;
int parse(int argc, const char ** argv);
};
struct int_arg : public arg {
int_arg(std::string fn, std::string desc = "", std::string abbr = "", bool req = false, int * val = nullptr) {
full_name = fn;
description = desc;
abbreviation = abbr;
required = req;
value = val;
};
int * value;
int parse(int argc, const char ** argv);
};
struct float_arg : public arg {
float_arg(std::string fn, std::string desc = "", std::string abbr = "", bool req = false, float * val = nullptr) {
full_name = fn;
description = desc;
abbreviation = abbr;
required = req;
value = val;
};
bool has_param = true;
float * value;
int parse(int argc, const char ** argv);
};
struct arg_list {
std::vector<float_arg> fargs;
std::vector<int_arg> iargs;
std::vector<bool_arg> bargs;
std::vector<string_arg> sargs;
bool for_help = false;
void add_argument(float_arg arg) {
fargs.push_back(arg);
}
void add_argument(int_arg arg) {
iargs.push_back(arg);
}
void add_argument(bool_arg arg) {
bargs.push_back(arg);
}
void add_argument(string_arg arg) {
sargs.push_back(arg);
}
void help();
void validate();
void parse(int argc, const char ** argv);
int find_and_parse(std::string name, int argc, const char ** argv);
std::string get_string_param(std::string full_name);
int * get_int_param(std::string full_name);
float * get_float_param(std::string full_name);
bool get_bool_param(std::string full_name);
};
#endif