HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VdfTypeDispatchTable< Fn > Class Template Reference

#include <typeDispatchTable.h>

+ Inheritance diagram for VdfTypeDispatchTable< Fn >:

Public Types

using FnSignature = decltype(Fn< int >::Call)
 

Public Member Functions

template<typename Type >
bool RegisterType ()
 
template<typename RetType , typename... Args>
RetType Call (TfType key, Args &&...args) const
 
- 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. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Vdf_TypeDispatchTableBase
VDF_API bool _RegisterType (const std::type_info &ti, void *f)
 
VDF_API void_FindOrFatalError (TfType t) const
 
VDF_API Vdf_TypeDispatchTableBase ()
 
VDF_API ~Vdf_TypeDispatchTableBase ()
 

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 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>();
}

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

template<template< typename > class Fn>
using VdfTypeDispatchTable< Fn >::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

template<template< typename > class Fn>
template<typename RetType , typename... Args>
RetType VdfTypeDispatchTable< Fn >::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.

template<template< typename > class Fn>
template<typename Type >
bool VdfTypeDispatchTable< Fn >::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: