1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
9 #ifndef anna_core_util_Environment_hpp
10 #define anna_core_util_Environment_hpp
15 #include <anna/core/RuntimeException.hpp>
16 #include <anna/core/Singleton.hpp>
22 Environment variables reader
24 class Environment : public Singleton <Environment> {
33 Parses the environment data (all variables available) when process was started.
34 @param envp Environment array passed on main function as third argument.
35 Cache data is cleared if NULL passed, allowing to get current environment values for variables.
37 void initialize(char **envp = NULL) throw();
40 Return associated value (could be empty). This value could be cached at initialization (envp array from main function), if not, would be
43 @param variableName Environment variable name.
44 @param exceptionIfMissing When enabled, an exception is launched for missing variables. Empty string in other case (default behaviour).
46 @return Environment value.
48 std::string getValue(const char* variableName, bool exceptionIfMissing = false) throw(RuntimeException);
49 std::string getValue(const std::string &variableName, bool exceptionIfMissing = false) throw(RuntimeException);
52 Sets an environment variable. If an empty variable name is provided, or environment set operation fails,
53 an exception will be launched.
55 @param name Variable name.
56 @param value Variable value
57 @param overwrite Overwrite an existing variable name/value or keep old value if exists
59 void setVariable(const std::string &name, const std::string &value, bool overwrite = true) throw(RuntimeException);
62 Unsets an environment variable (different than set empty string). If an empty variable name is provided,
63 or environment set operation fails, an exception will be launched.
65 @param name Variable name. If empty, nothing is done.
67 void unsetVariable(const std::string &name) throw(RuntimeException);
72 std::map < std::string /* variable name */, std::string /* variable value */ > a_vars;
76 friend class Singleton <Environment>;