@@ -21,17 +21,19 @@ namespace pgm
21
21
{
22
22
23
23
// //////////////////////////////////////////////////////////////////////////////
24
- // parsed values for an option or positional parameter
24
+ /* ! @struct argval
25
+ * @brief parsed values for an option or positional parameter
26
+ */
25
27
struct argval
26
28
{
27
29
auto count () const { return data_.size (); }
28
30
auto empty () const { return data_.empty (); }
29
31
30
32
explicit operator bool () const { return !empty (); }
31
33
32
- auto const & values () const { return data_; }
33
- auto const & value () const { return data_.at (0 ); }
34
- auto const & value (std::size_t n) const { return data_.at (n); }
34
+ auto & values () const { return data_; }
35
+ auto & value () const { return data_.at (0 ); }
36
+ auto & value (std::size_t n) const { return data_.at (n); }
35
37
36
38
auto value_or (std::string_view def) const { return empty () ? std::string{def} : value (); }
37
39
@@ -43,58 +45,66 @@ struct argval
43
45
};
44
46
45
47
// //////////////////////////////////////////////////////////////////////////////
46
- // option or param spec
48
+ /* ! @enum spec
49
+ * @brief option or param spec
50
+ */
47
51
enum spec
48
52
{
49
- req = 1 , // mandatory option
50
- mul = 2 , // option/param can be specified multiple times
51
- optval = 4 , // option value is optional
52
- opt = 8 , // optional param
53
+ req = 1 , // !< mandatory option
54
+ mul = 2 , // !< option/param can be specified multiple times
55
+ optval = 4 , // !< option value is optional
56
+ opt = 8 , // !< optional param
53
57
};
54
58
55
59
constexpr auto operator |(spec lhs, spec rhs);
56
60
57
61
// //////////////////////////////////////////////////////////////////////////////
58
- // program option
62
+ /* ! @struct option
63
+ * @brief program option
64
+ */
59
65
struct option
60
66
{
61
- std::string short_; // short option name
62
- std::string long_; // long option name
63
- std::string valname_; // name of the option value; eg, --opt-name=<value>
64
- std::string description_; // description
67
+ std::string short_; // !< short option name
68
+ std::string long_; // !< long option name
69
+ std::string valname_; // !< name of the option value; eg, --opt-name=<value>
70
+ std::string description_; // !< description
65
71
66
- bool req_ = false ; // mandatory (required) option
67
- bool mul_ = false ; // can be specified multiple times
68
- bool optval_ = false ; // option value is optional
72
+ bool req_ = false ; // !< mandatory (required) option
73
+ bool mul_ = false ; // !< can be specified multiple times
74
+ bool optval_ = false ; // !< option value is optional
69
75
70
- argval values_; // parsed value(s)
76
+ argval values_; // !< parsed value(s)
71
77
};
72
78
73
79
// //////////////////////////////////////////////////////////////////////////////
74
- // positional parameter
80
+ /* ! @struct param
81
+ * @brief positional parameter
82
+ */
75
83
struct param
76
84
{
77
- std::string name_; // param name
78
- std::string description_; // description
85
+ std::string name_; // !< param name
86
+ std::string description_; // !< description
79
87
80
- bool opt_ = false ; // optional param
81
- bool mul_ = false ; // can be specified multiple times
88
+ bool opt_ = false ; // !< optional param
89
+ bool mul_ = false ; // !< can be specified multiple times
82
90
83
- argval values_; // parsed value(s)
91
+ argval values_; // !< parsed value(s)
84
92
};
85
93
86
94
// //////////////////////////////////////////////////////////////////////////////
87
- // program argument (either option or param)
95
+ /* ! @struct arg
96
+ * @brief program argument (either option or param)
97
+ */
88
98
struct arg
89
99
{
90
100
arg (std::string name1, std::string description) :
91
- arg{std::move (name1), spec{ }, std::move (description)}
101
+ arg{std::move (name1), spec{}, std::move (description)}
92
102
{ }
93
103
arg (std::string name1, std::string name2, std::string description) :
94
- arg{std::move (name1), std::move (name2), spec{ }, std::move (description)}
104
+ arg{std::move (name1), std::move (name2), spec{}, std::move (description)}
95
105
{ }
96
106
arg (std::string name1, std::string name2, std::string name3, std::string description) :
97
- arg{std::move (name1), std::move (name2), std::move (name3), spec{ }, std::move (description)}
107
+ arg{std::move (name1), std::move (name2), std::move (name3), spec{}, std::move (description)}
98
108
{ }
99
109
100
110
arg (std::string name1, spec, std::string description);
@@ -112,13 +122,15 @@ struct arg
112
122
};
113
123
114
124
// //////////////////////////////////////////////////////////////////////////////
115
- // program arguments
125
+ /* ! @struct args
126
+ * @brief program arguments
127
+ */
116
128
struct args
117
129
{
118
130
args () = default ;
119
131
explicit args (std::initializer_list<arg> il)
120
132
{
121
- for (auto & el : il) add (std::move (el));
133
+ for (auto & & el : il) add (std::move (el));
122
134
}
123
135
124
136
void add (arg);
@@ -129,7 +141,9 @@ struct args
129
141
argval const & operator [](std::string_view) const ;
130
142
131
143
void parse (int argc, char * argv[]);
132
- std::string usage (std::string_view program, std::string_view preamble = { }, std::string_view prologue = { }, std::string_view epilogue = { }) const ;
144
+ std::string usage (std::string_view program,
145
+ std::string_view preamble = {}, std::string_view prologue = {}, std::string_view epilogue = {}
146
+ ) const ;
133
147
134
148
private:
135
149
std::vector<option> options_;
@@ -143,7 +157,7 @@ struct args
143
157
struct argument_exception : std::invalid_argument
144
158
{
145
159
argument_exception (std::string_view what, std::string_view why) :
146
- std::invalid_argument{std::string{what}+ " : " + std::string{why}+ " ." }
160
+ std::invalid_argument{std::string{what} + " : " + std::string{why} + " ." }
147
161
{ }
148
162
};
149
163
0 commit comments