All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
staticData.h File Reference
#include "pxr/pxr.h"
#include "pxr/base/arch/hints.h"
#include "pxr/base/tf/preprocessorUtils.h"
#include "pxr/base/tf/preprocessorUtilsLite.h"
#include <atomic>
#include <type_traits>
+ Include dependency graph for staticData.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.


struct  Tf_StaticDataDefaultFactory< T >
class  TfStaticData< T, Factory >


#define TF_MAKE_STATIC_DATA(Type, Name)

Macro Definition Documentation

#define TF_MAKE_STATIC_DATA (   Type,

Create a static data object, initializing it with code.

The macro takes two arguments. The first is the type of static data, the second is the name of the variable. The block of code following the macro will be invoked to initialize the static data when it is first used. See example usage:

TF_MAKE_STATIC_DATA(string, myString) { *myString = "hello!"; }
TF_MAKE_STATIC_DATA(vector<string>, someNames) {
TF_MAKE_STATIC_DATA((map<int, int>), intMap) {
(*intMap)[1] = 11;
(*intMap)[2] = 22;

If the type uses commas to separate template arguments you need to enclose the type in parentheses as shown in the last example.

If the data does not need to be mutated after initialization, you may specify a const type. The underlying data is non-const but the TfStaticData accessors only provide const access.

TF_MAKE_STATIC_DATA(const vector<string>, constNames) {
constNames->push_back("static const");

Note that this macro may only be used at namespace scope (not function scope).

Also note that in multithreaded code, it is possible for the provided code to be invoked more than once (with different target objects) for the same static data instance. This is fine as long as the initialization code does not have side-effects, but you should be aware of it.

Definition at line 199 of file staticData.h.