@@ -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
0 commit comments