OpenEnroth b6fd866
|
#include <Environment.h>
Public Member Functions | |
virtual | ~Environment ()=default |
virtual std::string | queryRegistry (const std::string &path) const =0 |
virtual std::string | path (EnvironmentPath path) const =0 |
virtual std::string | getenv (const std::string &key) const =0 |
virtual void | setenv (const std::string &key, const std::string &value) const =0 |
Static Public Member Functions | |
static std::unique_ptr< Environment > | createStandardEnvironment () |
Base class akin to Platform
that provides an abstraction for the process's environment.
All strings accepted by and returned from methods of this class are UTF8-encoded.
Why is this class not a part of Platform
? Mainly for the following reasons:
Platform
handles an unrelated domain (UI and window management). Using a NullPlatform
while still relying on Environment
working as usual looks like a perfectly valid use case.Environment
implementations don't depend on SDL, but if Environment
was a part of Platform
then we'd still drag SDL with it (and into our unit tests).Environment
doesn't depend on Logger
.
|
virtualdefault |
|
static |
Environment
instance.
|
pure virtual |
Same as std::getenv
, but takes & returns UTF8-encoded keys and values on all platforms.
Note that on Windows std::getenv
doesn't switch to UTF8 even if UnicodeCrt
is used (aka std::setlocale(LC_ALL, ".UTF-8")
).
Returns an empty string for non-existent environment variables, and thus doesn't distinguish between empty and non-existent values (and you shouldn't, either).
key | UTF8-encoded name of the environment variable to query. |
Implemented in AndroidEnvironment, PosixEnvironment, and WinEnvironment.
|
pure virtual |
Accessor for various system paths.
path | Path to get. |
Implemented in AndroidEnvironment, PosixEnvironment, and WinEnvironment.
|
pure virtual |
Windows-only function for querying the registry. Always returns an empty string on non-Windows systems.
path | UTF8-encoded registry path to query. |
Implemented in AndroidEnvironment, PosixEnvironment, and WinEnvironment.
|
pure virtual |
Same as POSIX setenv(key, value, 1)
. Takes UTF8-encoded keys and values on all platforms.
key | UTF8-encoded name of the environment variable to set. |
value | UTF8-encoded value of the environment variable. |
Implemented in AndroidEnvironment, PosixEnvironment, and WinEnvironment.