X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fsupport%2Fenvironment.h;h=78af2e3574dffed7205c63115e88ef5738c77f02;hb=522f3517e1d7f61ed2bbcafe0632f50cb3e8ae2f;hp=d312bffe632afe26d3565c824d738cbe05642fb5;hpb=77b9dbd5570e9da3cf7644f93de821b58d97368b;p=lyx.git diff --git a/src/support/environment.h b/src/support/environment.h index d312bffe63..78af2e3574 100644 --- a/src/support/environment.h +++ b/src/support/environment.h @@ -18,8 +18,11 @@ namespace lyx { namespace support { +/// @returns true if the environment variable @c name exists. +bool hasEnv(std::string const & name); + /// @returns the contents of the environment variable @c name encoded in utf8. -std::string const getEnv(std::string const & envname); +std::string const getEnv(std::string const & name); /** @returns the contents of the environment variable @c name, * split into path elements using the OS-dependent separator token @@ -28,7 +31,7 @@ std::string const getEnv(std::string const & envname); * guarantee that it is in the form of a unix-style path. * If the environment variable is not set, then the function returns * an empty vector. - */ + */ std::vector const getEnvPath(std::string const & name); /** Set the contents of the environment variable @c name to @c value. @@ -54,6 +57,42 @@ void setEnvPath(std::string const & name, std::vector const & env); */ void prependEnvPath(std::string const & name, std::string const & prefix); +/** Remove the variable @c name from the environment. + * @returns true if the variable was unset successfully. + */ +bool unsetEnv(std::string const & name); + + +/** Utility class to change temporarily an environment variable. The + * variable is reset to its original state when the dummy EnvChanger + * variable is deleted. + */ +class EnvChanger { +public: + /// + EnvChanger(std::string const & name, std::string const & value) + : name_(name), set_(hasEnv(name)), value_(getEnv(name)) + { + setEnv(name, value); + } + /// + ~EnvChanger() + { + if (set_) + setEnv(name_, value_); + else + unsetEnv(name_); + } + +private: + /// the name of the variable + std::string name_; + /// was the variable set? + bool set_; + /// + std::string value_; +}; + } // namespace support } // namespace lyx