Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathOptionParser.hpp
More file actions
Latest commit
153 lines (128 loc) · 5.46 KB
/
Copy pathOptionParser.hpp
File metadata and controls
153 lines (128 loc) · 5.46 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/* Part of SMITHLAB software
*
* Copyright (C) 2018 Cold Spring Harbor Laboratory,
* University of Southern California and
* Andrew D. Smith
* Authors: Andrew D. Smith
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*/
#ifndef OPTION_PARSER_HPP
#defineOPTION_PARSER_HPP
#include<cstddef>
#include<limits>
#include<string>
#include<vector>
classOption {
public:
Option(const std::string l_name, constchar s_name, const std::string descr,
constbool reqd, int &val);
Option(const std::string l_name, constchar s_name, const std::string descr,
constbool reqd, unsigned &val);
Option(const std::string l_name, constchar s_name, const std::string descr,
constbool reqd, long &val);
Option(const std::string l_name, constchar s_name, const std::string descr,
constbool reqd, unsignedlong &val);
Option(const std::string l_name, constchar s_name, const std::string descr,
constbool reqd, float &val);
Option(const std::string l_name, constchar s_name, const std::string descr,
constbool reqd, double &val);
Option(const std::string l_name, constchar s_name, const std::string descr,
constbool reqd, std::string &val);
Option(const std::string l_name, constchar s_name, const std::string descr,
constbool reqd, bool &val);
Option(const std::string l_name, constchar s_name, const std::string descr,
constbool reqd, char &val);
boolparse(std::vector<std::string> &command_line);
voidparse_config_file(std::vector<std::string> &options);
std::string format_option_name() const;
std::string format_option_description(constsize_t offset,
constbool show_default = false) const;
std::string format_default_value() const;
private:
unsigned arg_type;
std::string long_name;
char short_name;
std::string description;
bool required;
bool specified;
// the values of the options: ugly but clean
int *int_value;
unsignedint *uint_value;
long *long_value;
unsignedlong *ulong_value;
float *float_value;
double *double_value;
std::string *string_value;
bool *bool_value;
char *char_value;
voidformat_option(const std::string &argument);
staticvoidset_max_length(size_t num);
staticsize_tget_max_length();
booloption_match(const std::string &other);
};
classOptionParser {
public:
OptionParser(const std::string nm, const std::string descr,
std::string noflag_msg = "",
constsize_t n_left = std::numeric_limits<size_t>::max());
voidset_show_defaults() { show_defaults = true; }
voidadd_opt(const std::string l_name, constchar s_name,
const std::string descr, constbool reqd, int &val);
voidadd_opt(const std::string l_name, constchar s_name,
const std::string descr, constbool reqd, unsigned &val);
voidadd_opt(const std::string l_name, constchar s_name,
const std::string descr, constbool reqd, long &val);
voidadd_opt(const std::string l_name, constchar s_name,
const std::string descr, constbool reqd, unsignedlong &val);
voidadd_opt(const std::string l_name, constchar s_name,
const std::string descr, constbool reqd, float &val);
voidadd_opt(const std::string l_name, constchar s_name,
const std::string descr, constbool reqd, double &val);
voidadd_opt(const std::string l_name, constchar s_name,
const std::string descr, constbool reqd, std::string &val);
voidadd_opt(const std::string l_name, constchar s_name,
const std::string descr, constbool reqd, bool &val);
voidadd_opt(const std::string l_name, constchar s_name,
const std::string descr, constbool reqd, char &val);
voidparse(constint argc, char *argv[], std::vector<std::string> &arguments);
std::vector<std::string> parse(constint argc, char *argv[]);
voidparse(constint argc, char *argv[], std::vector<std::string> &arguments,
std::string config_filename);
boolhelp_requested() const { return help_request; }
std::string help_message() const;
boolabout_requested() const { return about_request; }
std::string about_message() const;
std::string about_message_raw() const;
std::string invalid_leftover() const;
booloption_missing() const { return !first_missing_option_name.empty(); }
boolwrong_number_leftover() const {
return n_leftover != std::numeric_limits<size_t>::max() &&
leftover_args.size() != n_leftover;
}
std::string option_missing_message() const;
voidset_prog_descr_raw() { prog_descr_is_raw = true; }
staticconstboolOPTIONAL = false;
staticconstboolREQUIRED = true;
private:
std::string prog_name;
std::string prog_descr;
bool prog_descr_is_raw{};
std::string noflag_message;
std::vector<Option> options;
bool help_request;
bool about_request;
bool show_defaults;
std::string first_missing_option_name;
std::vector<std::string> leftover_args;
size_t n_leftover;
};
#endif