VTK  9.6.20260302
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// VTK_DEPRECATED_IN_9_7_0
79#if defined(__GNUC__) || defined(__clang__)
80#define VTK_MACRO_DEPRECATION_WARNING \
81 _Pragma("GCC warning \"vtkDataArrayIteratorMacro is deprecated in 9.7.0\"")
82#elif defined(_MSC_VER)
83#define VTK_MACRO_DEPRECATION_WARNING \
84 __pragma(message("warning: vtkDataArrayIteratorMacro is deprecated in 9.7.0"))
85#else
86#define VTK_MACRO_DEPRECATION_WARNING
87#endif
88
89#define vtkDataArrayIteratorMacro(_array, _call) \
90 VTK_MACRO_DEPRECATION_WARNING \
91 vtkTemplateMacro( \
92 vtkAbstractArray* _aa(_array); if (vtkAOSDataArrayTemplate<VTK_TT>* _dat = \
93 vtkAOSDataArrayTemplate<VTK_TT>::FastDownCast(_aa)) { \
94 typedef VTK_TT vtkDAValueType; \
95 typedef vtkAOSDataArrayTemplate<vtkDAValueType> vtkDAContainerType; \
96 typedef vtkDAContainerType::Iterator vtkDAIteratorType; \
97 vtkDAIteratorType vtkDABegin(_dat->Begin()); \
98 vtkDAIteratorType vtkDAEnd(_dat->End()); \
99 (void)vtkDABegin; /* Prevent warnings when unused */ \
100 (void)vtkDAEnd; \
101 _call; \
102 } else { \
103 /* This is not ideal, as no explicit iterator has been declared. */ \
104 /* Cast the void pointer and hope for the best! */ \
105 typedef VTK_TT vtkDAValueType; \
106 typedef vtkAbstractArray vtkDAContainerType _vtkDAIMUnused; \
107 typedef vtkDAValueType* vtkDAIteratorType; /* NOLINTNEXTLINE(bugprone-unsafe-functions) */ \
108 vtkDAIteratorType vtkDABegin = static_cast<vtkDAIteratorType>(_aa->GetVoidPointer(0)); \
109 vtkDAIteratorType vtkDAEnd = vtkDABegin + _aa->GetMaxId() + 1; \
110 (void)vtkDABegin; \
111 (void)vtkDAEnd; \
112 _call; \
113 })
114
115#endif // vtkDataArrayIteratorMacro_h
116
117// VTK-HeaderTest-Exclude: vtkDataArrayIteratorMacro.h