VTK  9.3.20240716
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
72#ifndef vtkDataArrayIteratorMacro_h
73#define vtkDataArrayIteratorMacro_h
74
75#include "vtkAOSDataArrayTemplate.h" // For classes referred to in the macro
76#include "vtkSetGet.h" // For vtkTemplateMacro
77#include "vtkTypedDataArray.h" // For classes referred to in the macro
78
79// Silence 'unused typedef' warnings on GCC.
80// use of the typedef in question depends on the macro
81// argument _call and thus should not be removed.
82#if defined(__GNUC__)
83#define _vtkDAIMUnused __attribute__((unused))
84#else
85#define _vtkDAIMUnused
86#endif
87
88#define vtkDataArrayIteratorMacro(_array, _call) \
89 vtkTemplateMacro( \
90 vtkAbstractArray* _aa(_array); if (vtkAOSDataArrayTemplate<VTK_TT>* _dat = \
91 vtkAOSDataArrayTemplate<VTK_TT>::FastDownCast(_aa)) { \
92 typedef VTK_TT vtkDAValueType; \
93 typedef vtkAOSDataArrayTemplate<vtkDAValueType> vtkDAContainerType; \
94 typedef vtkDAContainerType::Iterator vtkDAIteratorType; \
95 vtkDAIteratorType vtkDABegin(_dat->Begin()); \
96 vtkDAIteratorType vtkDAEnd(_dat->End()); \
97 (void)vtkDABegin; /* Prevent warnings when unused */ \
98 (void)vtkDAEnd; \
99 _call; \
100 } else if (vtkTypedDataArray<VTK_TT>* _tda = vtkTypedDataArray<VTK_TT>::FastDownCast(_aa)) { \
101 typedef VTK_TT vtkDAValueType; \
102 typedef vtkTypedDataArray<vtkDAValueType> vtkDAContainerType; \
103 typedef vtkDAContainerType::Iterator vtkDAIteratorType; \
104 vtkDAIteratorType vtkDABegin(_tda->Begin()); \
105 vtkDAIteratorType vtkDAEnd(_tda->End()); \
106 (void)vtkDABegin; \
107 (void)vtkDAEnd; \
108 _call; \
109 } else { \
110 /* This is not ideal, as no explicit iterator has been declared. */ \
111 /* Cast the void pointer and hope for the best! */ \
112 typedef VTK_TT vtkDAValueType; \
113 typedef vtkAbstractArray vtkDAContainerType _vtkDAIMUnused; \
114 typedef vtkDAValueType* vtkDAIteratorType; \
115 vtkDAIteratorType vtkDABegin = static_cast<vtkDAIteratorType>(_aa->GetVoidPointer(0)); \
116 vtkDAIteratorType vtkDAEnd = vtkDABegin + _aa->GetMaxId() + 1; \
117 (void)vtkDABegin; \
118 (void)vtkDAEnd; \
119 _call; \
120 })
121
122#endif // vtkDataArrayIteratorMacro_h
123
124// VTK-HeaderTest-Exclude: vtkDataArrayIteratorMacro.h