var = assignment.substr(0, equalPos - 1);
val = assignment.substr(equalPos, assignment.size() - 1);
a_vars[var] = val;
}
var = assignment.substr(0, equalPos - 1);
val = assignment.substr(equalPos, assignment.size() - 1);
a_vars[var] = val;
}
throw RuntimeException("Invalid NULL variable name!", ANNA_FILE_LOCATION);
std::string var = variableName;
throw RuntimeException("Invalid NULL variable name!", ANNA_FILE_LOCATION);
std::string var = variableName;
return getValue(var, exceptionIfMissing);
}
std::string Environment::getValue(const std::string &variableName, bool exceptionIfMissing) throw(RuntimeException) {
std::string result = "";
return getValue(var, exceptionIfMissing);
}
std::string Environment::getValue(const std::string &variableName, bool exceptionIfMissing) throw(RuntimeException) {
std::string result = "";
std::string msg = "The variable '";
msg += variableName;
msg += "' is not defined in the environment.";
LOGDEBUG(Logger::debug(msg, ANNA_FILE_LOCATION));
if(exceptionIfMissing) throw RuntimeException(msg, ANNA_FILE_LOCATION);
std::string msg = "The variable '";
msg += variableName;
msg += "' is not defined in the environment.";
LOGDEBUG(Logger::debug(msg, ANNA_FILE_LOCATION));
if(exceptionIfMissing) throw RuntimeException(msg, ANNA_FILE_LOCATION);
void Environment::setVariable(const std::string &name, const std::string &value, bool overwrite) throw(RuntimeException) {
void Environment::setVariable(const std::string &name, const std::string &value, bool overwrite) throw(RuntimeException) {
- if (name == "") throw RuntimeException("Must provide non-empty variable name", ANNA_FILE_LOCATION);
-
- if(setenv(name.c_str(), value.c_str(), overwrite ? 1:0) != 0) {
+ if(setenv(name.c_str(), value.c_str(), overwrite ? 1 : 0) != 0) {
std::string msg = "Cannot set the environment variable '";
msg += name;
msg += "=\"";
msg += value;
msg += "\"'. The errno is ";
msg += anna::functions::asString(errno);
std::string msg = "Cannot set the environment variable '";
msg += name;
msg += "=\"";
msg += value;
msg += "\"'. The errno is ";
msg += anna::functions::asString(errno);
if(unsetenv(name.c_str()) != 0) {
std::string msg = "Cannot unset the environment variable named '";
msg += name;
msg += "'. The errno is ";
msg += anna::functions::asString(errno);
if(unsetenv(name.c_str()) != 0) {
std::string msg = "Cannot unset the environment variable named '";
msg += name;
msg += "'. The errno is ";
msg += anna::functions::asString(errno);
throw RuntimeException(msg, ANNA_FILE_LOCATION);
}
std::map<std::string, std::string>::iterator it = a_vars.find(name);
throw RuntimeException(msg, ANNA_FILE_LOCATION);
}
std::map<std::string, std::string>::iterator it = a_vars.find(name);