VTK
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
vtkDoubleDispatcher< BaseLhs, BaseRhs, ReturnType, CastingPolicy > Class Template Reference

Dispatch to functor based on two pointer types. More...

#include <vtkDoubleDispatcher.h>

Public Member Functions

template<class SomeLhs , class SomeRhs , class Functor >
void Add (Functor fun)
 Add in a functor that is mapped to the combination of the two template parameters passed in. More...
 
template<class SomeLhs , class SomeRhs >
bool Remove ()
 Remove a functor that is bound to the given parameter types. More...
 
ReturnType Go (BaseLhs *lhs, BaseRhs *rhs)
 Given two pointers of objects that derive from the BaseLhs and BaseRhs we find the matching functor that was added, and call it passing along the given parameters. More...
 

Protected Types

typedef vtkDispatcherCommon::TypeInfo TypeInfo
 
typedef vtkDoubleDispatcherPrivate::Functor< ReturnType, BaseLhs, BaseRhs > MappedType
 
typedef std::pair< TypeInfo, TypeInfoKeyType
 
typedef std::map< KeyType, MappedTypeMapType
 

Protected Member Functions

void DoAddFunctor (TypeInfo lhs, TypeInfo rhs, MappedType fun)
 
bool DoRemove (TypeInfo lhs, TypeInfo rhs)
 

Protected Attributes

MapType FunctorMap
 

Detailed Description

template<class BaseLhs, class BaseRhs = BaseLhs, typename ReturnType = void, template< class, class > class CastingPolicy = vtkDispatcherCommon::vtkCaster>
class vtkDoubleDispatcher< BaseLhs, BaseRhs, ReturnType, CastingPolicy >

Dispatch to functor based on two pointer types.

vtkDoubleDispatcher is a class that allows calling a functor based on the derived types of two pointers. This form of dynamic dispatching allows the conversion of runtime polymorphism to a compile time polymorphism. For example it can be used as a replacement for the vtkTemplateMacro when you want to know multiple parameter types, or need to call a specialized implementation for a subset

Note: By default the return type is void.

The functors that are passed around can contain state, and are allowed to be const or non const. If you are using a functor that does have state, make sure your copy constructor is correct.

struct functor{
template<typename T,typename U>
void operator()(T& t,U& u) const
{
}
};
Here is an example of using the double dispatcher.
\code
dispatcher.Add<vtkPoints,vtkDoubleArray>(makePointsWrapperFunctor());
dispatcher.Add<vtkPoints,vtkPoints>(straightCopyFunctor());
dispatcher.Go(ptr1,ptr2); //this will return a vtkPoints pointer
See also
vtkDispatcher

Definition at line 82 of file vtkDoubleDispatcher.h.

Member Typedef Documentation

◆ TypeInfo

template<class BaseLhs , class BaseRhs = BaseLhs, typename ReturnType = void, template< class, class > class CastingPolicy = vtkDispatcherCommon::vtkCaster>
typedef vtkDispatcherCommon::TypeInfo vtkDoubleDispatcher< BaseLhs, BaseRhs, ReturnType, CastingPolicy >::TypeInfo
protected

Definition at line 136 of file vtkDoubleDispatcher.h.

◆ MappedType

template<class BaseLhs , class BaseRhs = BaseLhs, typename ReturnType = void, template< class, class > class CastingPolicy = vtkDispatcherCommon::vtkCaster>
typedef vtkDoubleDispatcherPrivate::Functor<ReturnType, BaseLhs, BaseRhs> vtkDoubleDispatcher< BaseLhs, BaseRhs, ReturnType, CastingPolicy >::MappedType
protected

Definition at line 137 of file vtkDoubleDispatcher.h.

◆ KeyType

template<class BaseLhs , class BaseRhs = BaseLhs, typename ReturnType = void, template< class, class > class CastingPolicy = vtkDispatcherCommon::vtkCaster>
typedef std::pair<TypeInfo, TypeInfo> vtkDoubleDispatcher< BaseLhs, BaseRhs, ReturnType, CastingPolicy >::KeyType
protected

Definition at line 142 of file vtkDoubleDispatcher.h.

◆ MapType

template<class BaseLhs , class BaseRhs = BaseLhs, typename ReturnType = void, template< class, class > class CastingPolicy = vtkDispatcherCommon::vtkCaster>
typedef std::map<KeyType, MappedType> vtkDoubleDispatcher< BaseLhs, BaseRhs, ReturnType, CastingPolicy >::MapType
protected

Definition at line 143 of file vtkDoubleDispatcher.h.

Member Function Documentation

◆ Add()

template<class BaseLhs , class BaseRhs = BaseLhs, typename ReturnType = void, template< class, class > class CastingPolicy = vtkDispatcherCommon::vtkCaster>
template<class SomeLhs , class SomeRhs , class Functor >
void vtkDoubleDispatcher< BaseLhs, BaseRhs, ReturnType, CastingPolicy >::Add ( Functor  fun)
inline

Add in a functor that is mapped to the combination of the two template parameters passed in.

When instances of the two parameters are passed in on the Go method we will call the functor and pass along the given parameters. Note: This copies the functor so pass stateful functors by pointer.

dispatcher.Add<vtkImageData,vtkVoxel>(exampleFunctor());
dispatcher.Add<vtkImageData,vtkVoxel>(&exampleFunctorWithState);

Definition at line 99 of file vtkDoubleDispatcher.h.

◆ Remove()

template<class BaseLhs, class BaseRhs = BaseLhs, typename ReturnType = void, template< class, class > class CastingPolicy = vtkDispatcherCommon::vtkCaster>
template<class SomeLhs , class SomeRhs >
bool vtkDoubleDispatcher< BaseLhs, BaseRhs, ReturnType, CastingPolicy >::Remove ( )
inline

Remove a functor that is bound to the given parameter types.

Will return true if we did remove a functor.

Definition at line 110 of file vtkDoubleDispatcher.h.

◆ Go()

template<class BaseLhs , class BaseRhs , typename ReturnType , template< class, class > class CastingPolicy>
ReturnType vtkDoubleDispatcher< BaseLhs, BaseRhs, ReturnType, CastingPolicy >::Go ( BaseLhs *  lhs,
BaseRhs *  rhs 
)

Given two pointers of objects that derive from the BaseLhs and BaseRhs we find the matching functor that was added, and call it passing along the given parameters.

It should be noted that the functor will be called with the parameters being the derived type that Functor was registered with.

Note: This will only find exact matches. So if you add functor to find vtkDataArray,vtkDataArray, it will not be called if passed with vtkDoubleArray,vtkDoubleArray.

dispatcher.Add(vtkFloatArray,vtkFloatArray>(floatFunctor())
dispatcher.Add(vtkFloatArray,vtkDoubleArray>(mixedTypeFunctor())
dispatcher.Go( dataArray1, dataArray2);

Definition at line 205 of file vtkDoubleDispatcher.h.

◆ DoAddFunctor()

template<class BaseLhs , class BaseRhs , typename ReturnType , template< class, class > class CastingPolicy>
void vtkDoubleDispatcher< BaseLhs, BaseRhs, ReturnType, CastingPolicy >::DoAddFunctor ( TypeInfo  lhs,
TypeInfo  rhs,
MappedType  fun 
)
protected

Definition at line 187 of file vtkDoubleDispatcher.h.

◆ DoRemove()

template<class BaseLhs , class BaseRhs , typename ReturnType , template< class, class > class CastingPolicy>
bool vtkDoubleDispatcher< BaseLhs, BaseRhs, ReturnType, CastingPolicy >::DoRemove ( TypeInfo  lhs,
TypeInfo  rhs 
)
protected

Definition at line 196 of file vtkDoubleDispatcher.h.

Member Data Documentation

◆ FunctorMap

template<class BaseLhs, class BaseRhs = BaseLhs, typename ReturnType = void, template< class, class > class CastingPolicy = vtkDispatcherCommon::vtkCaster>
MapType vtkDoubleDispatcher< BaseLhs, BaseRhs, ReturnType, CastingPolicy >::FunctorMap
protected

Definition at line 144 of file vtkDoubleDispatcher.h.


The documentation for this class was generated from the following file:
vtkPoints
represent and manipulate 3D points
Definition: vtkPoints.h:33
vtkDoubleDispatcher::Add
void Add(Functor fun)
Add in a functor that is mapped to the combination of the two template parameters passed in.
Definition: vtkDoubleDispatcher.h:99
vtkFloatArray
dynamic, self-adjusting array of float
Definition: vtkFloatArray.h:35
vtkDoubleDispatcher::Go
ReturnType Go(BaseLhs *lhs, BaseRhs *rhs)
Given two pointers of objects that derive from the BaseLhs and BaseRhs we find the matching functor t...
Definition: vtkDoubleDispatcher.h:205
vtkImageData
topologically and geometrically regular array of data
Definition: vtkImageData.h:41
vtkDispatcher::Add
void Add(Functor fun)
Add in a functor that is mapped to the template SomeLhs parameter.
Definition: vtkDispatcher.h:104
vtkDoubleDispatcher
Dispatch to functor based on two pointer types.
Definition: vtkDoubleDispatcher.h:82
vtkDoubleArray
dynamic, self-adjusting array of double
Definition: vtkDoubleArray.h:35
vtkVoxel
a cell that represents a 3D orthogonal parallelepiped
Definition: vtkVoxel.h:38