X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fsupport%2Fenvironment.h;h=78af2e3574dffed7205c63115e88ef5738c77f02;hb=8d640dc77608bedddb5b00982c23665584f52d21;hp=296ebc15fbd09d7dfb3416a7755296d4bc9ab51f;hpb=aeeac1512881a53fa8b29a1a52d7a47adb3065be;p=lyx.git diff --git a/src/support/environment.h b/src/support/environment.h index 296ebc15fb..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 @@ -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