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

Function to_flag_value

simcore/framework/src/cli/cli.hpp:1406–1446  ·  view source on GitHub ↗

Convert a flag into an integer value typically binary flags

Source from the content-addressed store, hash-verified

1404
1405/// Convert a flag into an integer value typically binary flags
1406inline std::int64_t to_flag_value(std::string val) {
1407 static const std::string trueString("true");
1408 static const std::string falseString("false");
1409 if (val == trueString) {
1410 return 1;
1411 }
1412 if (val == falseString) {
1413 return -1;
1414 }
1415 val = detail::to_lower(val);
1416 std::int64_t ret;
1417 if (val.size() == 1) {
1418 if (val[0] >= '1' && val[0] <= '9') {
1419 return (static_cast<std::int64_t>(val[0]) - '0');
1420 }
1421 switch (val[0]) {
1422 case '0':
1423 case 'f':
1424 case 'n':
1425 case '-':
1426 ret = -1;
1427 break;
1428 case 't':
1429 case 'y':
1430 case '+':
1431 ret = 1;
1432 break;
1433 default:
1434 throw std::invalid_argument("unrecognized character");
1435 }
1436 return ret;
1437 }
1438 if (val == trueString || val == "on" || val == "yes" || val == "enable") {
1439 ret = 1;
1440 } else if (val == falseString || val == "off" || val == "no" || val == "disable") {
1441 ret = -1;
1442 } else {
1443 ret = std::stoll(val);
1444 }
1445 return ret;
1446}
1447
1448/// Signed integers
1449template <typename T,

Callers 3

lexical_castFunction · 0.85
sum_flag_vectorFunction · 0.85
get_flag_valueMethod · 0.85

Calls 2

to_lowerFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected