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 =========================================================================*/
78 #ifndef vtkDataArrayIteratorMacro_h
79 #define vtkDataArrayIteratorMacro_h
80 
81 #include "vtkDataArrayTemplate.h" // For all classes referred to in the macro
82 #include "vtkSetGet.h" // For vtkTemplateMacro
83 
84 // Silence 'unused typedef' warnings on GCC.
85 // use of the typedef in question depends on the macro
86 // argument _call and thus should not be removed.
87 #if defined(__GNUC__)
88 #define _vtkDAIMUnused __attribute__ ((unused))
89 #else
90 #define _vtkDAIMUnused
91 #endif
92 
93 #define vtkDataArrayIteratorMacro(_array, _call) \
94  vtkTemplateMacro( \
95  vtkAbstractArray *_aa(_array); \
96  if (vtkDataArrayTemplate<VTK_TT> *_dat = \
97  vtkDataArrayTemplate<VTK_TT>::FastDownCast(_aa)) \
98  { \
99  typedef VTK_TT vtkDAValueType; \
100  typedef vtkDataArrayTemplate<vtkDAValueType> vtkDAContainerType; \
101  typedef vtkDAContainerType::Iterator vtkDAIteratorType; \
102  vtkDAIteratorType vtkDABegin(_dat->Begin()); \
103  vtkDAIteratorType vtkDAEnd(_dat->End()); \
104  (void)vtkDABegin; /* Prevent warnings when unused */ \
105  (void)vtkDAEnd; \
106  _call; \
107  } \
108  else if (vtkTypedDataArray<VTK_TT> *_tda = \
109  vtkTypedDataArray<VTK_TT>::FastDownCast(_aa)) \
110  { \
111  typedef VTK_TT vtkDAValueType; \
112  typedef vtkTypedDataArray<vtkDAValueType> vtkDAContainerType; \
113  typedef vtkDAContainerType::Iterator vtkDAIteratorType; \
114  vtkDAIteratorType vtkDABegin(_tda->Begin()); \
115  vtkDAIteratorType vtkDAEnd(_tda->End()); \
116  (void)vtkDABegin; \
117  (void)vtkDAEnd; \
118  _call; \
119  } \
120  else \
121  { \
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 = \
128  static_cast<vtkDAIteratorType>(_aa->GetVoidPointer(0)); \
129  vtkDAIteratorType vtkDAEnd = vtkDABegin + _aa->GetMaxId() + 1; \
130  (void)vtkDABegin; \
131  (void)vtkDAEnd; \
132  _call; \
133  } \
134  )
135 
136 #endif //vtkDataArrayIteratorMacro_h
137 
138 // VTK-HeaderTest-Exclude: vtkDataArrayIteratorMacro.h