MCPcopy Create free account
hub / github.com/Tencent/TAD_Sim / add_complex

Method add_complex

simcore/framework/src/cli/cli.hpp:5382–5421  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5380 /// Add a complex number
5381 template <typename T, typename XC = double>
5382 Option *add_complex(std::string option_name, T &variable, std::string option_description = "", bool defaulted = false,
5383 std::string label = "COMPLEX") {
5384 CLI::callback_t fun = [&variable](const results_t &res) {
5385 XC x, y;
5386 bool worked;
5387 if (res.size() >= 2 && !res[1].empty()) {
5388 auto str1 = res[1];
5389 if (str1.back() == 'i' || str1.back() == 'j') str1.pop_back();
5390 worked = detail::lexical_cast(res[0], x) && detail::lexical_cast(str1, y);
5391 } else {
5392 auto str1 = res.front();
5393 auto nloc = str1.find_last_of('-');
5394 if (nloc != std::string::npos && nloc > 0) {
5395 worked = detail::lexical_cast(str1.substr(0, nloc), x);
5396 str1 = str1.substr(nloc);
5397 if (str1.back() == 'i' || str1.back() == 'j') str1.pop_back();
5398 worked = worked && detail::lexical_cast(str1, y);
5399 } else {
5400 if (str1.back() == 'i' || str1.back() == 'j') {
5401 str1.pop_back();
5402 worked = detail::lexical_cast(str1, y);
5403 x = XC{0};
5404 } else {
5405 worked = detail::lexical_cast(str1, x);
5406 y = XC{0};
5407 }
5408 }
5409 }
5410 if (worked) variable = T{x, y};
5411 return worked;
5412 };
5413
5414 auto default_function = [&variable]() { return CLI::detail::checked_to_string<T, T>(variable); };
5415
5416 CLI::Option *opt =
5417 add_option(option_name, std::move(fun), std::move(option_description), defaulted, default_function);
5418
5419 opt->type_name(label)->type_size(1, 2)->delimiter('+')->run_callback_for_default();
5420 return opt;
5421 }
5422
5423 /// Set a configuration ini file option, or clear it if no name passed
5424 Option *set_config(std::string option_name = "", std::string default_filename = "",

Callers

nothing calls this directly

Calls 10

lexical_castFunction · 0.85
backMethod · 0.80
frontMethod · 0.80
find_last_ofMethod · 0.80
type_sizeMethod · 0.80
sizeMethod · 0.45
emptyMethod · 0.45
delimiterMethod · 0.45
type_nameMethod · 0.45

Tested by

no test coverage detected