VTK  9.6.20260201
vtkDataArrayIteratorMacro.h File Reference
#include "vtkAOSDataArrayTemplate.h"
#include "vtkSetGet.h"
Include dependency graph for vtkDataArrayIteratorMacro.h:

Go to the source code of this file.

Macros

#define _vtkDAIMUnused
 
#define vtkDataArrayIteratorMacro(_array, _call)
 (deprecated) A macro for obtaining iterators to vtkDataArray data when the array implementation and type are unknown.
 

Macro Definition Documentation

◆ _vtkDAIMUnused

#define _vtkDAIMUnused

Definition at line 75 of file vtkDataArrayIteratorMacro.h.

◆ vtkDataArrayIteratorMacro

#define vtkDataArrayIteratorMacro ( _array,
_call )
Value:
vtkTemplateMacro( \
typedef VTK_TT vtkDAValueType; \
typedef vtkAOSDataArrayTemplate<vtkDAValueType> vtkDAContainerType; \
typedef vtkDAContainerType::Iterator vtkDAIteratorType; \
vtkDAIteratorType vtkDABegin(_dat->Begin()); \
vtkDAIteratorType vtkDAEnd(_dat->End()); \
(void)vtkDABegin; /* Prevent warnings when unused */ \
(void)vtkDAEnd; \
_call; \
} else { \
/* This is not ideal, as no explicit iterator has been declared. */ \
/* Cast the void pointer and hope for the best! */ \
typedef VTK_TT vtkDAValueType; \
typedef vtkAbstractArray vtkDAContainerType _vtkDAIMUnused; \
typedef vtkDAValueType* vtkDAIteratorType; \
vtkDAIteratorType vtkDABegin = static_cast<vtkDAIteratorType>(_aa->GetVoidPointer(0)); \
vtkDAIteratorType vtkDAEnd = vtkDABegin + _aa->GetMaxId() + 1; \
(void)vtkDABegin; \
(void)vtkDAEnd; \
_call; \
})
Array-Of-Structs implementation of vtkGenericDataArray.
Abstract superclass for all arrays.
static vtkDataArray * FastDownCast(vtkAbstractArray *source)
Perform a fast, safe cast from a vtkAbstractArray to a vtkDataArray.
#define _vtkDAIMUnused

(deprecated) A macro for obtaining iterators to vtkDataArray data when the array implementation and type are unknown.

Deprecated
This macro is deprecated and should not be used any longer. See vtkArrayDispatch.h and vtkDataArrayRange.h for replacements.

See vtkTemplateMacro. This macro is similar, but defines several additional typedefs and variables for safely iterating through data in a vtkAbstractArray container:

  • vtkDAValueType is typedef'd to the array's element value type.
  • vtkDAContainerType is typedef'd to the most derived class of vtkAbstractArray for which a suitable iterator has been found.
  • vtkDAIteratorType is typedef'd to the most suitable iterator type found.
  • vtkDABegin is an object of vtkDAIteratorType that points to the first component of the first tuple in the array.
  • vtkDAEnd is an object of vtkDAIteratorType that points to the element after the last component of the last tuple in the array. The primary advantage to using this macro is that arrays with non-standard memory layouts will be safely handled, and dangerous calls to GetVoidPointer are avoided. For arrays with > 1 component, the iterator will proceed through all components of a tuple before moving on to the next tuple. This matches the memory layout of the standard vtkDataArray subclasses such as vtkFloatArray.

For the standard vtkDataArray implementations (which are subclasses of vtkAOSDataArrayTemplate), the iterators will simply be pointers to the raw memory of the array. This allows very fast iteration when possible, and permits compiler optimizations in the standard template library to occur (such as reducing std::copy to memmove).

For other arrays, there is no reliably safe way to iterate over the array elements. In such cases, this macro performs the legacy behavior of casting vtkAbstractArray::GetVoidPointer(...) to vtkDAValueType* to create the iterators.

To use this macro, create a templated worker function:

template <class Iterator>
void myFunc(Iterator begin, Iterator end, ...) {...}
and then call the vtkDataArrayIteratorMacro inside of a switch statement
using the above objects and typedefs as needed:
vtkAbstractArray *someArray = ...;
switch (someArray->GetDataType())
{
vtkDataArrayIteratorMacro(someArray, myFunc(vtkDABegin, vtkDAEnd, ...));
}
virtual int GetDataType() const
Return the underlying data type.
#define vtkDataArrayIteratorMacro(_array, _call)
(deprecated) A macro for obtaining iterators to vtkDataArray data when the array implementation and t...
See also
vtkArrayDispatch vtkGenericDataArray vtkTemplateMacro

Definition at line 78 of file vtkDataArrayIteratorMacro.h.