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