VTK
|
vtkDataArray code generator/dispatcher. More...
#include <vtkArrayDispatch.h>
Public Types | |
typedef vtkTypeList::Unique< vtkTypeList_Create_12(char, int, long, long long, short, signed char, unsigned char, unsigned int, unsigned long, unsigned long long, unsigned short, vtkIdType) >::Result | Integrals |
A Typelist containing all integral ValueTypes. More... | |
typedef vtkTypeList::Append< Reals, Integrals >::Result | AllTypes |
A Typelist containing all standard VTK array ValueTypes. More... | |
vtkDataArray code generator/dispatcher.
vtkArrayDispatch implements a mechanism for generating optimized code for multiple subclasses of vtkDataArray at once. Using a TypeList based approach (see vtkTypeList), a templated worker implementation is generated for a restricted or unrestricted set of vtkDataArray subclasses.
A more detailed description of this class and related tools can be found here.
The primary goals of this class are to simplify multi-array dispatch implementations, and provide tools to lower compilation time and binary size (i.e. avoiding 'template explosions').
vtkArrayDispatch is also intended to replace code that currently relies on the encapsulation-breaking vtkDataArray::GetVoidPointer method. Not all subclasses of vtkDataArray use the memory layout assumed by GetVoidPointer; calling this method on, e.g. a vtkSOADataArrayTemplate will trigger a deep copy of the array data into an AOS buffer. This is very inefficient and should be avoided.
The vtkDataArrayAccessor wrapper is worth mentioning here, as it allows vtkArrayDispatch workers to operate on selected concrete subclasses for 'fast paths', yet fallback to using the slower vtkDataArray API for uncommon array types. This helps mitigate the "template explosion" issues that can result from instantiating a large worker functions for many array types.
These dispatchers extend the basic functionality of vtkTemplateMacro with the following features:
The basic Dispatch implementation will generate code paths for all arrays in the application-wide array list, and operates on a single array.
Dispatchers that start with Dispatch2 operate on 2 arrays simultaneously, while those that begin with Dispatch3 operate on 3 arrays.
To reduce compile time and binary size, the following dispatchers can be used to restrict the set of arrays that will be used. There are versions of these that operate on 1, 2, or 3 arrays:
Execution: There are three components to a dispatch: The dispatcher, the worker, and the array(s). They are combined like so:
The dispatcher can also be instantiated into an object, e.g.:
Return value: The Execute method of the dispatcher will return true if a code path matching the array arguments is found, or false if the arrays are not supported. If false is returned, the arrays will not be modified, and the worker will not be executed.
Workers: The dispatch requires a Worker functor that performs the work. For single array, the functor must be callable with the array object as an argument. For 2-array dispatch, the arguments must be (array1, array2). For 3-array dispatch, the arguments must be (array1, array2, array3). Workers are passed by reference, so stateful functors are permitted if additional input/output data is needed.
A simple worker implementation for triple dispatch:
Note that optimized implementations (e.g. for AoS arrays vs SoA arrays) can be supported by providing overloads of operator() that have more restrictive template parameters.
Examples: See TestArrayDispatchers.cxx for examples of each dispatch type.
typedef vtkTypeList::Unique< vtkTypeList_Create_12(char, int, long, long long, short, signed char, unsigned char, unsigned int, unsigned long, unsigned long long, unsigned short, vtkIdType) >::Result vtkArrayDispatch::Integrals |
A Typelist containing all integral ValueTypes.
Definition at line 181 of file vtkArrayDispatch.h.
typedef vtkTypeList::Append<Reals, Integrals>::Result vtkArrayDispatch::AllTypes |
A Typelist containing all standard VTK array ValueTypes.
Definition at line 186 of file vtkArrayDispatch.h.