31 #include <boost/format.hpp>
52 checkCompatibility(other);
58 checkCompatibility(other);
64 checkCompatibility(other);
73 checkCompatibility(other);
75 m_env = move(other.m_env);
90 m_env.get().
set(m_index, value);
97 m_env.get().
unSet(m_index);
104 m_env.get().
append(m_index, value);
117 m_env.get().
prepend(m_index, value);
143 return m_env.get().get(m_index,
"");
152 return value().empty();
156 return m_env.get().hasKey(m_index);
161 if (m_index != other.
m_index) {
163 error_buffer <<
"The \"" << other.
m_index <<
"\" environment variable"
164 <<
" cannot be copied to the \"" << m_index <<
"\" environment variable."
175 :
m_old_values{}, m_keep_same{keep_same}, m_added_variables{} {
186 setEnv(v.first, v.second);
250 const string new_value =
get(index) + value;
252 set(index, new_value);
259 const string new_value = value +
get(index);
261 set(index, new_value);
267 string value {default_value};
296 map<ShellType, string> set_cmd {{ShellType::sh,
"export %s=%s"},
297 {ShellType::csh,
"setenv %s %s"}};
298 map<ShellType, string> unset_cmd {{ShellType::sh,
"unset %s"},
299 {ShellType::csh,
"unsetenv %s"}};
303 script_text << format(set_cmd[type]) % v.first %
get(v.first) << endl;
305 script_text << format(unset_cmd[type]) % v.first << endl;
310 script_text << format(set_cmd[type]) % v %
get(v) << endl;
313 return script_text.str();
322 error_buffer <<
"The environment doesn't contain the " << index <<
" variable." << endl;
Variable & append(const std::string &)
Environment & set(const std::string &, const std::string &)
std::string get(const std::string &index, const std::string &default_value="") const
std::reference_wrapper< Environment > m_env
a copiable and movable reference
Environment & unSet(const std::string &)
Variable & operator=(const Variable &other)
static bool hasKey(const std::string &)
void checkCompatibility(const Variable &)
Variable & set(const std::string &)
ELEMENTS_API int setEnv(const std::string &name, const std::string &value, bool overwrite=true)
set an environment variables.
const std::string & index() const
proxy class to overload the assignment
Environment & prepend(const std::string &, const std::string &)
std::string m_index
The Name of the variable.
static void checkOutOfRange(const std::string &)
check that the variable is in the environment
ELEMENTS_API bool isEnvSet(const std::string &var)
Check if an environment variable is set or not.
Environment & append(const std::string &, const std::string &)
Variable & operator+=(const std::string &)
Variable operator[](const std::string &)
Environment(bool keep_same=true)
ELEMENTS_API std::string getEnv(const std::string &var)
get a particular environment variable
This file is intended to iron out all the differences between systems (currently Linux and MacOSX) ...
ELEMENTS_API int unSetEnv(const std::string &name)
Simple wrap around unsetenv for strings.
Environment & env() const
std::string generateScript(ShellType) const
std::vector< std::string > m_added_variables
variable added to the environment
std::string value() const
std::map< std::string, std::string > m_old_values
old value for changed variables
Defines a class to handle the Environment.
ELEMENTS_API Environment::Variable operator+(const std::string &, const Environment::Variable &)
Variable & prepend(const std::string &)
ELEMENTS_API std::ostream & operator<<(std::ostream &, const Environment::Variable &)
Variable operator+(const std::string &)