X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=include%2Fanna%2Fcore%2Futil%2FEnvironment.hpp;h=7db6aa13164b4f219b84fa48df937160bb0fc94f;hb=42c9ed133c166de9c99b4837f834aa5cf465e9a2;hp=02c6aba9fdfeec35204163e22fc8a8dc697eabc3;hpb=2357b29571f7b46859a6841d82a4b88b366c037f;p=anna.git diff --git a/include/anna/core/util/Environment.hpp b/include/anna/core/util/Environment.hpp index 02c6aba..7db6aa1 100644 --- a/include/anna/core/util/Environment.hpp +++ b/include/anna/core/util/Environment.hpp @@ -58,25 +58,48 @@ public: ~Environment() {;} /** - Parses the current environment data (all variables available) + Parses the environment data (all variables available) when process was started. + @param envp Environment array passed on main function as third argument. + Cache data is cleared if NULL passed, allowing to get current environment values for variables. */ - void initialize() throw(); + void initialize(char **envp = NULL) throw(); /** - Return associated value (could be empty). + Return associated value (could be empty). This value could be cached at initialization (envp array from main function), if not, would be + cached here. @param variableName Environment variable name. @param exceptionIfMissing When enabled, an exception is launched for missing variables. Empty string in other case (default behaviour). @return Environment value. */ - std::string getValue(const char* variableName, bool exceptionIfMissing = false) const throw(RuntimeException); + std::string getValue(const char* variableName, bool exceptionIfMissing = false) throw(RuntimeException); + std::string getValue(const std::string &variableName, bool exceptionIfMissing = false) throw(RuntimeException); + + /** + Sets an environment variable. If an empty variable name is provided, or environment set operation fails, + an exception will be launched. + + @param name Variable name. + @param value Variable value + @param overwrite Overwrite an existing variable name/value or keep old value if exists + */ + void setVariable(const std::string &name, const std::string &value, bool overwrite = true) throw(RuntimeException); + + /** + Unsets an environment variable (different than set empty string). If an empty variable name is provided, + or environment set operation fails, an exception will be launched. + + @param name Variable name. If empty, nothing is done. + */ + void unsetVariable(const std::string &name) throw(RuntimeException); + private: - std::map < std::string /* variable name */, std::string /* variable value */ > a_managedVars; + std::map < std::string /* variable name */, std::string /* variable value */ > a_vars; - Environment() { initialize();} + Environment() {;} friend class Singleton ; };