VTK  9.1.0
vtkDataArrayIteratorMacro.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkDataArrayIteratorMacro.h
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14=========================================================================*/
84#ifndef vtkDataArrayIteratorMacro_h
85#define vtkDataArrayIteratorMacro_h
86
87#include "vtkAOSDataArrayTemplate.h" // For classes referred to in the macro
88#include "vtkSetGet.h" // For vtkTemplateMacro
89#include "vtkTypedDataArray.h" // For classes referred to in the macro
90
91// Silence 'unused typedef' warnings on GCC.
92// use of the typedef in question depends on the macro
93// argument _call and thus should not be removed.
94#if defined(__GNUC__)
95#define _vtkDAIMUnused __attribute__((unused))
96#else
97#define _vtkDAIMUnused
98#endif
99
100#define vtkDataArrayIteratorMacro(_array, _call) \
101 vtkTemplateMacro( \
102 vtkAbstractArray* _aa(_array); if (vtkAOSDataArrayTemplate<VTK_TT>* _dat = \
103 vtkAOSDataArrayTemplate<VTK_TT>::FastDownCast(_aa)) { \
104 typedef VTK_TT vtkDAValueType; \
105 typedef vtkAOSDataArrayTemplate<vtkDAValueType> vtkDAContainerType; \
106 typedef vtkDAContainerType::Iterator vtkDAIteratorType; \
107 vtkDAIteratorType vtkDABegin(_dat->Begin()); \
108 vtkDAIteratorType vtkDAEnd(_dat->End()); \
109 (void)vtkDABegin; /* Prevent warnings when unused */ \
110 (void)vtkDAEnd; \
111 _call; \
112 } else if (vtkTypedDataArray<VTK_TT>* _tda = vtkTypedDataArray<VTK_TT>::FastDownCast(_aa)) { \
113 typedef VTK_TT vtkDAValueType; \
114 typedef vtkTypedDataArray<vtkDAValueType> vtkDAContainerType; \
115 typedef vtkDAContainerType::Iterator vtkDAIteratorType; \
116 vtkDAIteratorType vtkDABegin(_tda->Begin()); \
117 vtkDAIteratorType vtkDAEnd(_tda->End()); \
118 (void)vtkDABegin; \
119 (void)vtkDAEnd; \
120 _call; \
121 } else { \
122 /* This is not ideal, as no explicit iterator has been declared. */ \
123 /* Cast the void pointer and hope for the best! */ \
124 typedef VTK_TT vtkDAValueType; \
125 typedef vtkAbstractArray vtkDAContainerType _vtkDAIMUnused; \
126 typedef vtkDAValueType* vtkDAIteratorType; \
127 vtkDAIteratorType vtkDABegin = static_cast<vtkDAIteratorType>(_aa->GetVoidPointer(0)); \
128 vtkDAIteratorType vtkDAEnd = vtkDABegin + _aa->GetMaxId() + 1; \
129 (void)vtkDABegin; \
130 (void)vtkDAEnd; \
131 _call; \
132 })
133
134#endif // vtkDataArrayIteratorMacro_h
135
136// VTK-HeaderTest-Exclude: vtkDataArrayIteratorMacro.h