Skip to content

Commit b16e328

Browse files
committed
Rename some identifiers
1 parent e364745 commit b16e328

File tree

2 files changed

+48
-49
lines changed

2 files changed

+48
-49
lines changed

argument_parser.cpp

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@ namespace partdiff {
1313
return static_cast<U>(v);
1414
}
1515

16-
static constexpr bounds<uint64_t> num_bounds{1, 1024};
17-
static constexpr bounds<calculation_method> method_bounds{calculation_method::gauss_seidel,
18-
calculation_method::jacobi};
19-
static constexpr bounds<uint64_t> lines_bounds{0, 10240};
20-
static constexpr bounds<perturbation_function> func_bounds{perturbation_function::f0, perturbation_function::fpisin};
21-
static constexpr bounds<termination_condition> term_bounds{termination_condition::accuracy,
22-
termination_condition::iterations};
23-
static constexpr bounds<uint64_t> iteration_bounds{1, 200000};
24-
static constexpr bounds<double> accuracy_bounds{1e-20, 1e-4};
16+
static constexpr bounds_t<uint64_t> num_bounds{1, 1024};
17+
static constexpr bounds_t<calculation_method> method_bounds{calculation_method::gauss_seidel,
18+
calculation_method::jacobi};
19+
static constexpr bounds_t<uint64_t> lines_bounds{0, 10240};
20+
static constexpr bounds_t<perturbation_function> func_bounds{perturbation_function::f0,
21+
perturbation_function::fpisin};
22+
static constexpr bounds_t<termination_condition> term_bounds{termination_condition::accuracy,
23+
termination_condition::iterations};
24+
static constexpr bounds_t<uint64_t> iteration_bounds{1, 200000};
25+
static constexpr bounds_t<double> accuracy_bounds{1e-20, 1e-4};
2526

2627
argument_parser::argument_parser(const int argc, char const *argv[])
2728
: app_name(argv[0]),
@@ -52,7 +53,7 @@ namespace partdiff {
5253
std::println("");
5354
std::println("");
5455
for (std::size_t i = 0; i <= to_underlying(argument_index::term_dummy); i++) {
55-
const std::string description = this->get_description(i).description_for_usage.value_or("<invalid>");
56+
const std::string description = this->get_description(i).description.value_or("<invalid>");
5657
std::println("{}{}", get_name(this->get_description(i).name), description);
5758
}
5859
std::println("Example: {} 1 2 100 1 2 100", app_name);
@@ -91,10 +92,10 @@ namespace partdiff {
9192
constexpr int indent_width = 17;
9293
const std::string indent = std::format("{:{}s}", "", indent_width);
9394

94-
auto display_enum = [indent]<typename T>(bounds<T> enum_bounds) -> std::string {
95+
auto display_enum = [indent]<typename T>(bounds_t<T> bounds) -> std::string {
9596
std::string result = "";
96-
auto lower = to_underlying(enum_bounds.lower);
97-
auto upper = to_underlying(enum_bounds.upper);
97+
auto lower = to_underlying(bounds.lower);
98+
auto upper = to_underlying(bounds.upper);
9899
for (auto i = lower; i <= upper; i++) {
99100
if (i != lower) {
100101
result += "\n";
@@ -105,57 +106,56 @@ namespace partdiff {
105106
};
106107

107108
auto number = &(this->options.number);
108-
this->add_argument_description("num", number, std::format("number of threads ({:d})", num_bounds), num_bounds);
109+
this->add_argument("num", number, std::format("number of threads ({:d})", num_bounds), num_bounds);
109110

110111
auto method = &(this->options.method);
111-
this->add_argument_description(
112-
"method", method, std::format("calculation method ({:d})\n{}", method_bounds, display_enum(method_bounds)),
113-
method_bounds);
112+
this->add_argument("method", method,
113+
std::format("calculation method ({:d})\n{}", method_bounds, display_enum(method_bounds)),
114+
method_bounds);
114115

115116
auto interlines = &(this->options.interlines);
116-
this->add_argument_description("lines", interlines,
117-
std::format("number of interlines ({1:d})\n"
118-
"{0}matrixsize = (interlines * 8) + 9",
119-
indent, lines_bounds),
120-
lines_bounds);
117+
this->add_argument("lines", interlines,
118+
std::format("number of interlines ({1:d})\n"
119+
"{0}matrixsize = (interlines * 8) + 9",
120+
indent, lines_bounds),
121+
lines_bounds);
121122

122123
auto pert_func = &(this->options.pert_func);
123-
this->add_argument_description(
124-
"func", pert_func, std::format("perturbation function ({:d})\n{}", func_bounds, display_enum(func_bounds)),
125-
func_bounds);
124+
this->add_argument("func", pert_func,
125+
std::format("perturbation function ({:d})\n{}", func_bounds, display_enum(func_bounds)),
126+
func_bounds);
126127

127128
auto termination = &(this->options.termination);
128-
this->add_argument_description(
129-
"term", termination, std::format("termination condition ({:d})\n{}", term_bounds, display_enum(term_bounds)),
130-
term_bounds);
129+
this->add_argument("term", termination,
130+
std::format("termination condition ({:d})\n{}", term_bounds, display_enum(term_bounds)),
131+
term_bounds);
131132

132-
this->add_argument_description("acc/iter", std::format("depending on term:\n"
133-
"{0}accuracy: {1:.0e}\n"
134-
"{0}iterations: {2:d}\n",
135-
indent, accuracy_bounds, iteration_bounds));
133+
this->add_argument("acc/iter", std::format("depending on term:\n"
134+
"{0}accuracy: {1:.0e}\n"
135+
"{0}iterations: {2:d}\n",
136+
indent, accuracy_bounds, iteration_bounds));
136137

137138
auto term_accuracy = &(this->options.term_accuracy);
138-
this->add_argument_description("acc", term_accuracy, std::nullopt, accuracy_bounds);
139+
this->add_argument("acc", term_accuracy, std::nullopt, accuracy_bounds);
139140

140141
auto term_iteration = &(this->options.term_iteration);
141-
this->add_argument_description("iter", term_iteration, std::nullopt, iteration_bounds);
142+
this->add_argument("iter", term_iteration, std::nullopt, iteration_bounds);
142143
}
143144

144-
void argument_parser::add_argument_description(std::string name, std::optional<std::string> description_for_usage) {
145+
void argument_parser::add_argument(std::string name, std::optional<std::string> description) {
145146
argument_description arg_desc;
146147
arg_desc.name = name;
147-
arg_desc.description_for_usage = description_for_usage;
148+
arg_desc.description = description;
148149
this->argument_descriptions.push_back(arg_desc);
149150
}
150151

151152
template <class T>
152-
void argument_parser::add_argument_description(std::string name, T *target,
153-
std::optional<std::string> description_for_usage,
154-
bounds<T> target_bounds) {
153+
void argument_parser::add_argument(std::string name, T *target, std::optional<std::string> description,
154+
bounds_t<T> bounds) {
155155
argument_description arg_desc;
156156
arg_desc.name = name;
157157
arg_desc.target = target;
158-
arg_desc.read_from_string = [target = arg_desc.target, target_bounds](const std::string &input) {
158+
arg_desc.read_from_string = [target = arg_desc.target, bounds](const std::string &input) {
159159
T *casted_ptr = std::any_cast<T *>(target);
160160
bool valid_input = false;
161161
std::istringstream iss(input);
@@ -166,10 +166,10 @@ namespace partdiff {
166166
} else {
167167
valid_input = static_cast<bool>(iss >> *casted_ptr);
168168
}
169-
valid_input &= target_bounds.contains(*casted_ptr);
169+
valid_input &= bounds.contains(*casted_ptr);
170170
return valid_input;
171171
};
172-
arg_desc.description_for_usage = description_for_usage;
172+
arg_desc.description = description;
173173
this->argument_descriptions.push_back(arg_desc);
174174
}
175175

argument_parser.hpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <vector>
77

88
template <typename T>
9-
struct bounds {
9+
struct bounds_t {
1010
T lower;
1111
T upper;
1212
bool contains(T x) const {
@@ -18,15 +18,15 @@ namespace std {
1818

1919
template <typename T, typename Char>
2020
requires std::formattable<T, Char>
21-
struct formatter<bounds<T>, Char> {
21+
struct formatter<bounds_t<T>, Char> {
2222
std::formatter<T, Char> underlying_;
2323

2424
constexpr auto parse(std::basic_format_parse_context<Char> &ctx) {
2525
return underlying_.parse(ctx);
2626
}
2727

2828
template <typename FormatContext>
29-
auto format(const bounds<T> &b, FormatContext &ctx) const {
29+
auto format(const bounds_t<T> &b, FormatContext &ctx) const {
3030
auto out = ctx.out();
3131
out = underlying_.format(b.lower, ctx);
3232
for (const char &c : std::string(" .. ")) {
@@ -50,7 +50,7 @@ namespace partdiff {
5050
struct argument_description {
5151
std::any target;
5252
std::string name;
53-
std::optional<std::string> description_for_usage;
53+
std::optional<std::string> description;
5454
std::function<bool(const std::string &input)> read_from_string = [](auto) { return false; };
5555
};
5656

@@ -79,9 +79,8 @@ namespace partdiff {
7979
void ask_param(argument_index index);
8080
void fill_argument_descriptions();
8181
template <class T>
82-
void add_argument_description(std::string name, T *target, std::optional<std::string> description_for_usage,
83-
bounds<T> target_bounds);
84-
void add_argument_description(std::string name, std::optional<std::string> description_for_usage);
82+
void add_argument(std::string name, T *target, std::optional<std::string> description, bounds_t<T> bounds);
83+
void add_argument(std::string name, std::optional<std::string> description);
8584
};
8685

8786
} // namespace partdiff

0 commit comments

Comments
 (0)