All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
staticData.h File Reference
+ Include dependency graph for staticData.h:

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. More...
 

Macro Definition Documentation

#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;
* }
*

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

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