X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=include%2Fanna%2Fcore%2Futil%2FEnvironment.hpp;h=4fc3e6de074e81b81f1f058220a8d59d7a6d6f61;hb=0c646b4aa99a84ef6976a51b6d4554aea11ded35;hp=fa7fb094acda1ab5cc5b2acfd973cda02349efe3;hpb=bebea4009ed5a273fbf9ed3644a2140a8f477f99;p=anna.git diff --git a/include/anna/core/util/Environment.hpp b/include/anna/core/util/Environment.hpp index fa7fb09..4fc3e6d 100644 --- a/include/anna/core/util/Environment.hpp +++ b/include/anna/core/util/Environment.hpp @@ -1,8 +1,8 @@ -// ANNA - Anna is Not 'N' Anymore +// ANNA - Anna is Not Nothingness Anymore // // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo // -// https://bitbucket.org/testillano/anna +// http://redmine.teslayout.com/projects/anna-suite // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions @@ -14,7 +14,7 @@ // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. -// * Neither the name of Google Inc. nor the names of its +// * Neither the name of the copyright holder nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // @@ -34,8 +34,8 @@ // cisco.tierra@gmail.com -#ifndef anna_core_Environment_hpp -#define anna_core_Environment_hpp +#ifndef anna_core_util_Environment_hpp +#define anna_core_util_Environment_hpp #include #include @@ -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 a_managedVars; + std::map < std::string /* variable name */, std::string /* variable value */ > a_vars; - Environment() { initialize();} + Environment() {;} friend class Singleton ; };