VTK  9.6.20260202
vtkDataArrayIteratorMacro.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
62
63#ifndef vtkDataArrayIteratorMacro_h
64#define vtkDataArrayIteratorMacro_h
65
66#include "vtkAOSDataArrayTemplate.h" // For classes referred to in the macro
67#include "vtkSetGet.h" // For vtkTemplateMacro
68
69// Silence 'unused typedef' warnings on GCC.
70// use of the typedef in question depends on the macro
71// argument _call and thus should not be removed.
72#if defined(__GNUC__)
73#define _vtkDAIMUnused __attribute__((unused))
74#else
75#define _vtkDAIMUnused
76#endif
77
78#define vtkDataArrayIteratorMacro(_array, _call) \
79 vtkTemplateMacro( \
80 vtkAbstractArray* _aa(_array); if (vtkAOSDataArrayTemplate<VTK_TT>* _dat = \
81 vtkAOSDataArrayTemplate<VTK_TT>::FastDownCast(_aa)) { \
82 typedef VTK_TT vtkDAValueType; \
83 typedef vtkAOSDataArrayTemplate<vtkDAValueType> vtkDAContainerType; \
84 typedef vtkDAContainerType::Iterator vtkDAIteratorType; \
85 vtkDAIteratorType vtkDABegin(_dat->Begin()); \
86 vtkDAIteratorType vtkDAEnd(_dat->End()); \
87 (void)vtkDABegin; /* Prevent warnings when unused */ \
88 (void)vtkDAEnd; \
89 _call; \
90 } else { \
91 /* This is not ideal, as no explicit iterator has been declared. */ \
92 /* Cast the void pointer and hope for the best! */ \
93 typedef VTK_TT vtkDAValueType; \
94 typedef vtkAbstractArray vtkDAContainerType _vtkDAIMUnused; \
95 typedef vtkDAValueType* vtkDAIteratorType; \
96 vtkDAIteratorType vtkDABegin = static_cast<vtkDAIteratorType>(_aa->GetVoidPointer(0)); \
97 vtkDAIteratorType vtkDAEnd = vtkDABegin + _aa->GetMaxId() + 1; \
98 (void)vtkDABegin; \
99 (void)vtkDAEnd; \
100 _call; \
101 })
102
103#endif // vtkDataArrayIteratorMacro_h
104
105// VTK-HeaderTest-Exclude: vtkDataArrayIteratorMacro.h