HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
registryManager.h File Reference
#include "pxr/pxr.h"
#include "pxr/base/arch/attributes.h"
#include "pxr/base/tf/preprocessorUtilsLite.h"
#include "pxr/base/tf/api.h"
#include <functional>
#include <typeinfo>
+ Include dependency graph for registryManager.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  TfRegistryManager
 
class  Tf_RegistryInit
 

Macros

#define TF_REGISTRY_PRIORITY   100
 
#define TF_REGISTRY_DEFINE_WITH_TYPE(KEY_TYPE, TAG)
 
#define TF_REGISTRY_DEFINE(KEY_TYPE, NAME)
 
#define TF_REGISTRY_FUNCTION(KEY_TYPE)
 
#define TF_REGISTRY_FUNCTION_WITH_TAG(KEY_TYPE, TAG)
 

Functions

TF_API void Tf_RegistryInitCtor (char const *name)
 
TF_API void Tf_RegistryInitDtor (char const *name)
 

Macro Definition Documentation

#define TF_REGISTRY_DEFINE (   KEY_TYPE,
  NAME 
)
Value:
static void TF_PP_CAT(_Tf_RegistryFunction, NAME)(KEY_TYPE*, void*); \
ARCH_CONSTRUCTOR(TF_PP_CAT(_Tf_RegistryAdd, NAME), \
TF_REGISTRY_PRIORITY, KEY_TYPE*) \
{ \
Tf_RegistryInit::Add(TF_PP_STRINGIZE(MFB_ALT_PACKAGE_NAME), \
(void(*)(KEY_TYPE*, void*)) \
TF_PP_CAT(_Tf_RegistryFunction, NAME), \
TF_PP_STRINGIZE(KEY_TYPE)); \
} \
_ARCH_ENSURE_PER_LIB_INIT(Tf_RegistryStaticInit, _tfRegistryInit); \
static void TF_PP_CAT(_Tf_RegistryFunction, NAME)(KEY_TYPE*, void*)
#define TF_PP_STRINGIZE(x)
Expand and convert the argument to a string, using a most minimal macro.
#define TF_PP_CAT(x, y)
static TF_API void Add(const char *libName, TfRegistryManager::RegistrationFunctionType func, const char *typeName)
#define _ARCH_ENSURE_PER_LIB_INIT(T, prefix)
Definition: attributes.h:228
#define TF_REGISTRY_PRIORITY

Definition at line 178 of file registryManager.h.

#define TF_REGISTRY_DEFINE_WITH_TYPE (   KEY_TYPE,
  TAG 
)
Value:
static void _Tf_RegistryFunction(KEY_TYPE*, TAG*); \
ARCH_CONSTRUCTOR(TF_PP_CAT(_Tf_RegistryAdd, __LINE__), \
TF_REGISTRY_PRIORITY, KEY_TYPE*, TAG*) \
{ \
Tf_RegistryInit::Add(TF_PP_STRINGIZE(MFB_ALT_PACKAGE_NAME), \
(void(*)(KEY_TYPE*, TAG*))_Tf_RegistryFunction, \
TF_PP_STRINGIZE(KEY_TYPE)); \
} \
_ARCH_ENSURE_PER_LIB_INIT(Tf_RegistryStaticInit, _tfRegistryInit); \
static void _Tf_RegistryFunction(KEY_TYPE*, TAG*)
#define TF_PP_STRINGIZE(x)
Expand and convert the argument to a string, using a most minimal macro.
#define TF_PP_CAT(x, y)
static TF_API void Add(const char *libName, TfRegistryManager::RegistrationFunctionType func, const char *typeName)
#define _ARCH_ENSURE_PER_LIB_INIT(T, prefix)
Definition: attributes.h:228
#define TF_REGISTRY_PRIORITY

Definition at line 163 of file registryManager.h.

#define TF_REGISTRY_FUNCTION (   KEY_TYPE)

Define a function that is called on demand by TfRegistryManager.

This is a simpler form of TF_REGISTRY_FUNCTION_WITH_TAG() that provides a tag for you, based on the MFB package, file name, and line number being compiled. For most cases (private registry functions inside .cpp files) this should do.

A very common use is to symbolically define enum names (see TfEnum):

{
// Bit-depth types.
TF_ADD_ENUM_NAME(ELEM_BITDEPTH_8);
TF_ADD_ENUM_NAME(ELEM_BITDEPTH_10);
TF_ADD_ENUM_NAME(ELEM_BITDEPTH_32);
// Destination types.
TF_ADD_ENUM_NAME(ELEM_DESTINATION_DISKFARM);
TF_ADD_ENUM_NAME(ELEM_DESTINATION_JOBDIR);
// Renderer types.
TF_ADD_ENUM_NAME(ELEM_RENDERER_GRAIL);
TF_ADD_ENUM_NAME(ELEM_RENDERER_PRMAN);
}

Definition at line 219 of file registryManager.h.

#define TF_REGISTRY_FUNCTION_WITH_TAG (   KEY_TYPE,
  TAG 
)

Define a function that is called on demand by TfRegistryManager.

Here is an example of using this macro:

TF_REGISTRY_FUNCTION_WITH_TAG(XyzRegistry, MyTag)
{
// calls to, presumably, XyzRegistry:
...
}

Given the above, a call to TfRegistryManager::SubscribeTo<XyzRegistry>() will cause the above function to be immediately run. (If the above function has not yet been loaded, but is loaded in the future, it will be run then.) The second type, MyType, is unimportant, but cannot be repeated with the first type (i.e. there can be at most one call to TF_REGISTRY_FUNCTION() for a given pair of types).

In contrast to the typical static-constructor design, the code within a TF_REGISTRY_FUNCTION() function is (usually) not run before main(); specifically, it is not run unless and until a call to SubscribeTo<T>() occurs. This is important: if there are no subscribers, the code may never be run.

Note two restrictions: the type-names KEY_TYPE and TAG passed to this macro must be untemplated, and not qualified with a namespace. (Translation: the name as given must consist solely of letters and numbers: no "\<", "\>" or ":" characters are allowed.) KEY_TYPE may be inside a namespace but must not be explicitly qualified; you must use 'using namespace <foo>::KEY_TYPE' before calling this macro. Every use of TF_REGISTRY_FUNCTION() must use a different pair for KEY_TYPE and TAG or a multiply defined symbol will result at link time. Note that this means the same KEY_TYPE in two or more namespaces may not be registered in more than one namespace.

Definition at line 260 of file registryManager.h.

#define TF_REGISTRY_PRIORITY   100

Definition at line 155 of file registryManager.h.

Function Documentation

TF_API void Tf_RegistryInitCtor ( char const *  name)
TF_API void Tf_RegistryInitDtor ( char const *  name)