|
Environment setting variable. More...
Go to the source code of this file.
Macros | |
#define | TF_DEFINE_ENV_SETTING(envVar, defValue, description) |
Define an env setting named envVar with default value defValue and a descriptive string description . | |
Functions | |
template<class T > | |
T const & | TfGetEnvSetting (TfEnvSetting< T > &setting) |
Returns the value of the specified env setting, registered using TF_DEFINE_ENV_SETTING . | |
Environment setting variable.
A TfEnvSetting<T>
is used to access an environment variable that controls program execution according to the value set in the environment. Currently, the legal types for T are bool, int, and string.
The TfEnvSetting facility is used to enable new features in the code that are still in "experimental" mode, and warn the user and/or QA that they are pushing the edge of the envelope by setting a non-standard value for these variables. Accordingly, the TfEnvSetting
construct should be used as sparingly as possible in code.
In contrast, a variable that allows the user to customize program execution but is not an in-development code path should simply use TfGetenv() to access the variable. An example would be supplying a variable to override a default font or fontsize, for users who don't like the default program choice (and when there is no other way to set the preference).
Here is how to use the TfEnvSetting facility.
The first argument is the name of your variable; it is also the name for the variable you can set in your shell to set the value at runtime. The second argument is the default value. To create a bool variable, pass either true or false. To create a string variable, pass an explicit string(), i.e.
You can also access a variable's value from Python:
Tf.GetEnvSetting()
returns the value for the TfEnvSetting variable, or None if no such variable is defined in the currently loaded C++ code.
If a user's environment has a value for a TfEnvSetting variable that differs from the default, when the program starts or the module defining the TfEnvSetting variable is loaded, a warning messages is printed.
Additionally, at program startup time (or when lib/tf is first loaded), the environment variable PIXAR_TF_ENV_SETTING_FILE is examined. If this variable indicates a file that can be read, then the file is parsed, and should contain lines of the form key=value. For each line read, the environment variable key is set to value. For example:
Blank lines in the file and lines where the first character is '#' are ignored. If the file itself cannot be read, no error is printed; however, if the file is malformed, errors are printed to stderr.
Definition in file envSetting.h.
#define TF_DEFINE_ENV_SETTING | ( | envVar, | |
defValue, | |||
description | |||
) |
Define an env setting named envVar
with default value defValue
and a descriptive string description
.
Definition at line 162 of file envSetting.h.
|
inline |
Returns the value of the specified env setting, registered using TF_DEFINE_ENV_SETTING
.
Definition at line 141 of file envSetting.h.