Loading...
Searching...
No Matches
staticData.h File Reference
+ 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.

Classes

class  TfStaticData< T, Factory >
 Create or return a previously created object instance of global data. More...
 

Macros

#define TF_MAKE_STATIC_DATA(Type, Name)
 Create a static data object, initializing it with code.
 

Macro Definition Documentation

◆ TF_MAKE_STATIC_DATA

#define TF_MAKE_STATIC_DATA (   Type,
  Name 
)

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) {
someNames->push_back("hello");
someNames->push_back("static");
someNames->push_back("world");
}
TF_MAKE_STATIC_DATA((map<int, int>), intMap) {
(*intMap)[1] = 11;
(*intMap)[2] = 22;
}
#define TF_MAKE_STATIC_DATA(Type, Name)
Create a static data object, initializing it with code.
Definition: staticData.h:198

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("hello");
constNames->push_back("static const");
constNames->push_back("world");
}

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 198 of file staticData.h.