-
Notifications
You must be signed in to change notification settings - Fork 0
/
takina.h
68 lines (50 loc) · 2.02 KB
/
takina.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
#ifndef _TAKINA_TAKINA_H_
#define _TAKINA_TAKINA_H_
#include <string>
#include <vector>
#include <functional> // function
// I don't want to introduce std::max()
#define TAKINA_MAX(x, y) (((x) < (y)) ? (y) : (x))
namespace takina {
typedef std::function<bool(char const *arg)> OptionFunction;
// Use aggregation initialization to create a OptionDescription object
struct OptionDescption {
// FIXME use char const *
std::string sopt; // short option
std::string lopt; // long option
std::string desc; // description of option
std::string param_name{}; // name of parameters
};
using OptDesc = OptionDescption;
/** Add usage of process */
void AddUsage(std::string const &desc);
/** Add description of process */
void AddDescription(std::string const &desc);
/** Add section of options(or options group) */
void AddSection(std::string &§ion);
/** Add Options */
void AddOption(OptDesc &&desc, bool *param);
void AddOption(OptDesc &&desc, std::string *param);
void AddOption(OptDesc &&desc, int *param);
void AddOption(OptDesc &&desc, double *param);
void AddOption(OptDesc &&desc, std::vector<std::string> *param);
void AddOption(OptDesc &&desc, std::vector<int> *param);
void AddOption(OptDesc &&desc, std::vector<double> *param);
void AddOption(OptDesc &&desc, std::string *param, unsigned int n);
void AddOption(OptDesc &&desc, int *param, unsigned int n);
void AddOption(OptDesc &&desc, double *param, unsigned int n);
void AddOption(OptDesc &&desc, OptionFunction fn, unsigned int n = 1);
#define MAX_OPTION_ARGS_NUM ((unsigned int)-1)
/** parse the command line arguments */
bool Parse(char **argv_begin, char **argv_end, std::string *errmsg);
inline bool Parse(int argc, char **argv, std::string *errmsg)
{
return Parse(argv + 1, argv + argc, errmsg);
}
/** Free the resources used for parsing options */
void Teardown();
void DebugPrint();
void EnableIndependentNonOptionArgument(bool opt) noexcept;
std::vector<char const *> &GetNonOptionArguments();
} // namespace takina
#endif // _TAKINA_TAKINA_H_