![]() |
|
Dispatches calls to template instantiations based on a TfType that is determined at runtime. More...
#include <typeDispatchTable.h>
Inheritance diagram for VdfTypeDispatchTable< Fn >:Public Types | |
| using | FnSignature = decltype(Fn< int >::Call) |
| The signature of the functions dispatched by the table. | |
Public Member Functions | |
| template<typename Type > | |
| bool | RegisterType () |
| Register an additional type with the type dispatch table. | |
| template<typename RetType , typename... Args> | |
| RetType | Call (TfType key, Args &&... args) const |
Invoke the function registered for key type. | |
Public Member Functions inherited from Vdf_TypeDispatchTableBase | |
| VDF_API bool | IsTypeRegistered (TfType t) const |
Returns true if a function has been registered for type t. | |
Additional Inherited Members | |
Protected Member Functions inherited from Vdf_TypeDispatchTableBase | |
| VDF_API bool | _RegisterType (const std::type_info &ti, void *f) |
Register function pointer f as the implementation to dispatch to for type ti. | |
| VDF_API void * | _FindOrFatalError (TfType t) const |
Find a registered function pointer for type t. | |
Dispatches calls to template instantiations based on a TfType that is determined at runtime.
Parameters:
Fn is a class template where Fn<T>::Call(...) is a static function to be dispatched on type T. Note that the function signature cannot depend on the template argument and Fn<int>::Call(...) must be a valid instantiation even if int is never registered as a type.
The given function is instantiated once for each of the types registered using RegisterType. The resulting function pointers are called using the Call() member function.
Example:
Given this class template to be instantiated for each attribute type that may be computed:
This call defines a statically initialized type dispatch table that dispatches calls to _ExtractExecValue, keyed off attribute types:
This code calls an instance of _ExtractExecValue, keyed off the type of attribute:
Definition at line 119 of file typeDispatchTable.h.
| using FnSignature = decltype(Fn<int>::Call) |
The signature of the functions dispatched by the table.
Fn<int> is special only because it was the default instantiation used by the previous VdfTypeDispatchTable implementation to determine the function type for all Fn<T>.
Definition at line 129 of file typeDispatchTable.h.
|
inline |
Invoke the function registered for key type.
Calling this with an unregistered type is a fatal error.
Definition at line 150 of file typeDispatchTable.h.
|
inline |
Register an additional type with the type dispatch table.
This will return true, if Type has been successfully added to the dispatch table and false if it was registered already.
Definition at line 136 of file typeDispatchTable.h.