MCPcopy Create free account
hub / github.com/Kitware/VTK / vtkTestingGetArgOrEnvOrDefault

Function vtkTestingGetArgOrEnvOrDefault

Testing/Rendering/vtkTesting.cxx:59–92  ·  view source on GitHub ↗

------------------------------------------------------------------------------ Find in command tail, failing that find in environment, failing that return a default. Up to caller to delete the string returned.

Source from the content-addressed store, hash-verified

57// failing that return a default.
58// Up to caller to delete the string returned.
59static string vtkTestingGetArgOrEnvOrDefault(
60 const string& argName, // argument idnetifier flag. eg "-D"
61 vector<string>& argv, // command tail
62 const string& env, // environment variable name to find
63 const string& def) // default to use if "env" is not found.
64{
65 string argValue;
66
67 // Search command tail.
68 int argc = static_cast<int>(argv.size());
69 for (int i = 0; i < argc; i++)
70 {
71 if ((i < (argc - 1)) && (argName == argv[i]))
72 {
73 argValue = argv[i + 1];
74 }
75 }
76 // If not found search environment.
77 if (argValue.empty() && !(env.empty() || def.empty()))
78 {
79 char* foundenv = getenv(env.c_str());
80 if (foundenv)
81 {
82 argValue = foundenv;
83 }
84 else
85 {
86 // Not found, fall back to default.
87 argValue = def;
88 }
89 }
90
91 return argValue;
92}
93
94//------------------------------------------------------------------------------
95// Description:

Callers 4

GetArgumentMethod · 0.85
GetDataRootMethod · 0.85
GetTempDirectoryMethod · 0.85
GetValidImageFileNameMethod · 0.85

Calls 3

sizeMethod · 0.45
emptyMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected