- /* close */
- pclose(fp);
-
- // Parsing:
- po::variables_map vm;
- try {
- po::store(po::parse_environment(desc, [](const std::string& variable) { return variable; }), vm); // can throw
-
- std::map<std::string, std::string>::const_iterator it;
- std::string var, val;
- for (it = a_managedVars.begin(); it != a_managedVars.end(); it++) {
- var = (*it).first;
- if (vm.count(var.c_str())) { // protection
- val = vm[var.c_str()].as<std::string>();
- a_managedVars[var] = val;
- }
+std::string Environment::getValue(const char* variableName, bool exceptionIfMissing) throw(RuntimeException) {
+ if(!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 = "";
+ std::map<std::string, std::string>::const_iterator it = a_vars.find(variableName);
+
+ if(it == a_vars.end()) {
+ char *current = getenv(variableName.c_str());
+
+ if(!current) {
+ 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);
+ } else {
+ // assignment
+ a_vars[variableName] = current;
+ result = current;