| 451 | |
| 452 | template <typename T> |
| 453 | T TreeNode::parseString(const std::string& str) const |
| 454 | { |
| 455 | if constexpr(std::is_enum_v<T> && !std::is_same_v<T, NodeStatus>) |
| 456 | { |
| 457 | // Check the ScriptingEnumsRegistry first, if available. |
| 458 | if(config().enums) |
| 459 | { |
| 460 | auto it = config().enums->find(str); |
| 461 | if(it != config().enums->end()) |
| 462 | { |
| 463 | return static_cast<T>(it->second); |
| 464 | } |
| 465 | } |
| 466 | // Try numeric conversion (e.g. "2" for an enum value). |
| 467 | int tmp = 0; |
| 468 | auto [ptr, ec] = std::from_chars(str.data(), str.data() + str.size(), tmp); |
| 469 | if(ec == std::errc() && ptr == str.data() + str.size()) |
| 470 | { |
| 471 | return static_cast<T>(tmp); |
| 472 | } |
| 473 | // Fall back to convertFromString<T>, which uses a user-provided |
| 474 | // specialization if one exists. Issue #948. |
| 475 | return convertFromString<T>(str); |
| 476 | } |
| 477 | return convertFromString<T>(str); |
| 478 | } |
| 479 | |
| 480 | template <typename T> |
| 481 | inline Expected<Timestamp> TreeNode::getInputStamped(const std::string& key, |