Loading...
Searching...
No Matches
registryManager.h File Reference
+ 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
 Manage initialization of registries. More...
 

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 a function that is called on demand by TfRegistryManager.
 
#define TF_REGISTRY_FUNCTION_WITH_TAG(KEY_TYPE, TAG)
 Define a function that is called on demand by TfRegistryManager.
 

Macro Definition Documentation

◆ TF_REGISTRY_DEFINE

#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*)

Definition at line 178 of file registryManager.h.

◆ TF_REGISTRY_DEFINE_WITH_TYPE

#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*)

Definition at line 163 of file registryManager.h.

◆ TF_REGISTRY_FUNCTION

#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);
}
An enum class that records both enum type and enum value.
Definition: enum.h:137
#define TF_ADD_ENUM_NAME(VAL,...)
Macro used to associate a name with an enumerated value.
Definition: enum.h:470
#define TF_REGISTRY_FUNCTION(KEY_TYPE)
Define a function that is called on demand by TfRegistryManager.

Definition at line 219 of file registryManager.h.

◆ TF_REGISTRY_FUNCTION_WITH_TAG

#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:
...
}
#define TF_REGISTRY_FUNCTION_WITH_TAG(KEY_TYPE, TAG)
Define a function that is called on demand by TfRegistryManager.

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.

◆ TF_REGISTRY_PRIORITY

#define TF_REGISTRY_PRIORITY   100

Definition at line 155 of file registryManager.h.