MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / GetFromEnv

Function GetFromEnv

paddle/common/flags_native.cc:594–618  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

592
593template <typename T>
594T 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, \

Callers

nothing calls this directly

Calls 5

GetValueFromEnvFunction · 0.85
FlagType2StringFunction · 0.85
SetValueFromStringMethod · 0.80
emptyMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected