6 #include "Tpetra_Details_Environment.hpp" 8 using Tpetra::Details::Environment;
10 void Environment::cacheVariable(
const std::string& variableName,
11 const char* variableValue) {
13 environCache_[variableName] = variableValue;
16 bool Environment::variableExists(
const std::string& variableName) {
18 if (environCache_.find(variableName) != environCache_.end()) {
20 return environCache_[variableName] != NULL;
23 const char* variableValue = std::getenv(variableName.c_str());
24 cacheVariable(variableName, variableValue);
25 return variableValue != NULL;
29 bool Environment::variableIsCached(
const std::string& variableName) {
31 if (environCache_.find(variableName) != environCache_.end()) {
39 bool Environment::getBooleanValue(
const std::string& variableName,
40 const std::string& defaultValue) {
42 std::string variableValue(getValue(variableName, defaultValue));
43 std::transform(variableValue.begin(), variableValue.end(),
44 variableValue.begin(), ::toupper);
46 if (variableValue.empty() ||
47 variableValue ==
"0" ||
48 variableValue ==
"NO" ||
49 variableValue ==
"FALSE") {
56 std::string Environment::getValue(
const std::string& variableName,
57 const std::string& defaultValue) {
60 if (variableExists(variableName)) {
61 tmpValue = environCache_[variableName];
65 tmpValue = std::getenv(variableName.c_str());
66 cacheVariable(variableName, tmpValue);
69 std::string variableValue;
70 if (tmpValue != NULL) {
71 variableValue = std::string(tmpValue);
74 variableValue = defaultValue;
91 void Environment::clearCache() {
92 environCache_.clear();