Skip to content

Commit 77eef5c

Browse files
Doxygen-friendly comments
And some formatting.
1 parent 72783b6 commit 77eef5c

File tree

4 files changed

+141
-122
lines changed

4 files changed

+141
-122
lines changed

args.hpp

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,19 @@ namespace pgm
2121
{
2222

2323
////////////////////////////////////////////////////////////////////////////////
24-
// parsed values for an option or positional parameter
24+
/*! @struct argval
25+
* @brief parsed values for an option or positional parameter
26+
*/
2527
struct argval
2628
{
2729
auto count() const { return data_.size(); }
2830
auto empty() const { return data_.empty(); }
2931

3032
explicit operator bool() const { return !empty(); }
3133

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); }
3537

3638
auto value_or(std::string_view def) const { return empty() ? std::string{def} : value(); }
3739

@@ -43,58 +45,66 @@ struct argval
4345
};
4446

4547
////////////////////////////////////////////////////////////////////////////////
46-
// option or param spec
48+
/*! @enum spec
49+
* @brief option or param spec
50+
*/
4751
enum spec
4852
{
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
5357
};
5458

5559
constexpr auto operator|(spec lhs, spec rhs);
5660

5761
////////////////////////////////////////////////////////////////////////////////
58-
// program option
62+
/*! @struct option
63+
* @brief program option
64+
*/
5965
struct option
6066
{
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
6571

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
6975

70-
argval values_; // parsed value(s)
76+
argval values_; //!< parsed value(s)
7177
};
7278

7379
////////////////////////////////////////////////////////////////////////////////
74-
// positional parameter
80+
/*! @struct param
81+
* @brief positional parameter
82+
*/
7583
struct param
7684
{
77-
std::string name_; // param name
78-
std::string description_; // description
85+
std::string name_; //!< param name
86+
std::string description_; //!< description
7987

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
8290

83-
argval values_; // parsed value(s)
91+
argval values_; //!< parsed value(s)
8492
};
8593

8694
////////////////////////////////////////////////////////////////////////////////
87-
// program argument (either option or param)
95+
/*! @struct arg
96+
* @brief program argument (either option or param)
97+
*/
8898
struct arg
8999
{
90100
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)}
92102
{ }
93103
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)}
95105
{ }
96106
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)}
98108
{ }
99109

100110
arg(std::string name1, spec, std::string description);
@@ -112,13 +122,15 @@ struct arg
112122
};
113123

114124
////////////////////////////////////////////////////////////////////////////////
115-
// program arguments
125+
/*! @struct args
126+
* @brief program arguments
127+
*/
116128
struct args
117129
{
118130
args() = default;
119131
explicit args(std::initializer_list<arg> il)
120132
{
121-
for(auto& el : il) add(std::move(el));
133+
for (auto&& el : il) add(std::move(el));
122134
}
123135

124136
void add(arg);
@@ -129,7 +141,9 @@ struct args
129141
argval const& operator[](std::string_view) const;
130142

131143
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;
133147

134148
private:
135149
std::vector<option> options_;
@@ -143,7 +157,7 @@ struct args
143157
struct argument_exception : std::invalid_argument
144158
{
145159
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} + "."}
147161
{ }
148162
};
149163

0 commit comments

Comments
 (0)