| 592 | |
| 593 | template <typename T> |
| 594 | T GetFromEnv(const std::string& name, const T& default_val) { |
| 595 | std::string value_str; |
| 596 | if (GetValueFromEnv(name, &value_str)) { |
| 597 | T value; |
| 598 | FlagType type = FlagTypeTraits<T>::Type; |
| 599 | Flag flag("tmp_" + name, "", "", type, &value, &value); |
| 600 | flag.SetValueFromString(value_str); |
| 601 | if (!ErrorStream().str().empty()) { |
| 602 | ErrorStream().str(""); |
| 603 | std::string error_msg = "value \""; |
| 604 | error_msg += value_str; |
| 605 | error_msg += "\" of environment"; |
| 606 | error_msg += "variable \""; |
| 607 | error_msg += name; |
| 608 | error_msg += "\" is invalid when "; |
| 609 | error_msg += "using GetFromEnv with "; |
| 610 | error_msg += FlagType2String(type); |
| 611 | error_msg += " type."; |
| 612 | LOG_FLAG_FATAL_ERROR(error_msg); |
| 613 | } |
| 614 | return value; |
| 615 | } else { |
| 616 | return default_val; |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | #define INSTANTIATE_GET_FROM_ENV(type) \ |
| 621 | template TEST_API type GetFromEnv(const std::string& name, \ |
nothing calls this directly
no test coverage detected