Loading...
Searching...
No Matches
VdfTypeDispatchTable< Fn > Class Template Reference

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.
 

Detailed Description

template<template< typename > class Fn>
class VdfTypeDispatchTable< Fn >

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:

template <typename T>
struct _ExtractExecValue {
static VtValue Call(const VdfVector &v, int offset)
{
const auto accessor = v.GetReadAccessor<T>();
return VtValue(accessor[offset]);
}
};
This class is used to abstract away knowledge of the cache data used for each node.
Definition: vector.h:56
ReadAccessor< TYPE > GetReadAccessor() const
GetReadAccessor() allows low level read-only access to the content of of the VdfVector via the Vdf_Ve...
Definition: vector.h:514
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:152

This call defines a statically initialized type dispatch table that dispatches calls to _ExtractExecValue, keyed off attribute types:

_extractTable)
{
_extractTable->RegisterType<AttributeType0>();
_extractTable->RegisterType<AttributeType1>();
// ...
_extractTable->RegisterType<AttributeTypeN>();
}
Dispatches calls to template instantiations based on a TfType that is determined at runtime.
#define TF_MAKE_STATIC_DATA(Type, Name)
Create a static data object, initializing it with code.
Definition: staticData.h:181

This code calls an instance of _ExtractExecValue, keyed off the type of attribute:

VtValue value = _extractTable->Call<VtValue>()(
attribute.GetTypeName().GetType(), v, offset);

Definition at line 119 of file typeDispatchTable.h.

Member Typedef Documentation

◆ FnSignature

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.

Member Function Documentation

◆ Call()

RetType Call ( TfType  key,
Args &&...  args 
) const
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.

◆ RegisterType()

bool RegisterType ( )
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.


The documentation for this class was generated from the following file: