VTK
vtkDataArrayMeta.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkDataArrayMeta.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 =========================================================================*/
15 
16 #ifndef vtkDataArrayMeta_h
17 #define vtkDataArrayMeta_h
18 
19 #include "vtkAssume.h"
20 #include "vtkConfigure.h"
21 #include "vtkDataArrayAccessor.h"
22 #include "vtkMeta.h"
23 #include "vtkSetGet.h"
24 #include "vtkType.h"
25 
26 #include <type_traits>
27 #include <utility>
28 
35 // When enabled, extra debugging checks are enabled for the iterators.
36 // Specifically:
37 // - Specializations are disabled (All code uses the generic implementation).
38 // - Additional assertions are inserted to ensure correct runtime usage.
39 // - Perfomance-related annotations (e.g. force inlining) are disabled.
40 #if defined(VTK_DEBUG_RANGE_ITERATORS)
41 #define VTK_ITER_ASSERT(x, msg) assert((x) && msg)
42 #else
43 #define VTK_ITER_ASSERT(x, msg)
44 #endif
45 
46 #if defined(VTK_ALWAYS_OPTIMIZE_ARRAY_ITERATORS) && !defined(VTK_DEBUG_RANGE_ITERATORS)
47 #define VTK_ITER_INLINE VTK_ALWAYS_INLINE
48 #define VTK_ITER_ASSUME VTK_ASSUME_NO_ASSERT
49 #define VTK_ITER_OPTIMIZE_START VTK_ALWAYS_OPTIMIZE_START
50 #define VTK_ITER_OPTIMIZE_END VTK_ALWAYS_OPTIMIZE_START
51 #else
52 #define VTK_ITER_INLINE inline
53 #define VTK_ITER_ASSUME VTK_ASSUME
54 #define VTK_ITER_OPTIMIZE_START
55 #define VTK_ITER_OPTIMIZE_END
56 #endif
57 
59 
60 // For IsAOSDataArray:
61 template <typename ValueType> class vtkAOSDataArrayTemplate;
62 
63 namespace vtk
64 {
65 
66 // Typedef for data array indices:
70 
71 namespace detail
72 {
73 
74 //------------------------------------------------------------------------------
75 // Used by ranges/iterators when tuple size is unknown at compile time
76 static constexpr ComponentIdType DynamicTupleSize = 0;
77 
78 //------------------------------------------------------------------------------
79 // Detect data array value types
80 template <typename T>
81 struct IsVtkDataArray : std::is_base_of<vtkDataArray, T> {};
82 
83 template <typename T>
86 
87 //------------------------------------------------------------------------------
88 // If a value is a valid tuple size
89 template <ComponentIdType Size>
91  std::integral_constant<bool, (Size > 0 || Size == DynamicTupleSize)> {};
92 
93 template <ComponentIdType TupleSize>
96 
97 //------------------------------------------------------------------------------
98 // If a value is a non-dynamic tuple size
99 template <ComponentIdType Size>
100 struct IsStaticTupleSize : std::integral_constant<bool, (Size > 0)> {};
101 
102 template <ComponentIdType TupleSize>
105 
106 //------------------------------------------------------------------------------
107 // If two values are valid non-dynamic tuple sizes:
108 template <ComponentIdType S1, ComponentIdType S2>
110  std::integral_constant<bool, (IsStaticTupleSize<S1>::value &&
111  IsStaticTupleSize<S2>::value)> {};
112 
113 template <ComponentIdType S1, ComponentIdType S2, typename T = void>
116 
117 //------------------------------------------------------------------------------
118 // If either of the tuple sizes is not statically defined
119 template <ComponentIdType S1, ComponentIdType S2>
121  std::integral_constant<bool, (!IsStaticTupleSize<S1>::value ||
122  !IsStaticTupleSize<S2>::value)> {};
123 
124 template <ComponentIdType S1, ComponentIdType S2, typename T = void>
127 
128 //------------------------------------------------------------------------------
129 // Helper that switches between a storageless integral constant for known
130 // sizes, and a runtime variable for variable sizes.
131 template <ComponentIdType TupleSize>
133  public std::integral_constant<ComponentIdType, TupleSize>
134 {
135  static_assert(IsValidTupleSize<TupleSize>::value, "Invalid tuple size.");
136 
137 private:
138  using Superclass = std::integral_constant<ComponentIdType, TupleSize>;
139 public:
140  // Need to construct from array for specialization.
141  using Superclass::Superclass;
142  VTK_ITER_INLINE GenericTupleSize() = default;
144 };
145 
146 // Specialize for dynamic types, mimicking integral_constant API:
147 template <>
148 struct GenericTupleSize<DynamicTupleSize>
149 {
151 
154  : value(array->GetNumberOfComponents())
155  {
156  }
157 
158  VTK_ITER_INLINE operator value_type() const noexcept { return value; }
159  VTK_ITER_INLINE value_type operator()() const noexcept { return value; }
160 
162 };
163 
164 } // end namespace detail
165 
166 //------------------------------------------------------------------------------
167 // Typedef for double if vtkDataArray, or the array's ValueType for subclasses.
168 template <typename ArrayType,
171 
172 //------------------------------------------------------------------------------
173 namespace detail
174 {
175 
176 template <typename ArrayType>
178 {
180  static constexpr bool value =
181  std::is_base_of<vtkAOSDataArrayTemplate<APIType>, ArrayType>::value;
182 
183 };
184 
185 } // end namespace detail
186 
187 //------------------------------------------------------------------------------
188 // True if ArrayType inherits some specialization of vtkAOSDataArrayTemplate
189 template <typename ArrayType>
190 using IsAOSDataArray =
192 
193 } // end namespace vtk
194 
196 
197 #endif // vtkDataArrayMeta_h
198 
199 // VTK-HeaderTest-Exclude: vtkDataArrayMeta.h
vtkIdType TupleIdType
int ComponentIdType
typename std::enable_if< IsEitherTupleSizeDynamic< S1, S2 >::value, T >::type EnableIfEitherTupleSizeIsDynamic
std::integral_constant< bool, detail::IsAOSDataArrayImpl< ArrayType >::value > IsAOSDataArray
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
int vtkIdType
Definition: vtkType.h:349
vtkIdType ValueIdType
#define VTK_ITER_INLINE
Array-Of-Structs implementation of vtkGenericDataArray.
VTK_ITER_INLINE value_type operator()() const noexcept
#define VTK_ITER_OPTIMIZE_END
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:55
static constexpr ComponentIdType DynamicTupleSize
ArrayType::ValueType APIType
GetAPIType< ArrayType > APIType
VTK_ITER_INLINE GenericTupleSize(vtkDataArray *array)
typename std::enable_if< IsVtkDataArray< T >::value >::type EnableIfVtkDataArray
typename std::enable_if< IsStaticTupleSize< TupleSize >::value >::type EnableIfStaticTupleSize
#define VTK_ITER_OPTIMIZE_START
typename vtkDataArrayAccessor< ArrayType >::APIType GetAPIType
typename std::enable_if< IsValidTupleSize< TupleSize >::value >::type EnableIfValidTupleSize
VTK_ITER_INLINE GenericTupleSize(vtkDataArray *)
typename std::enable_if< AreStaticTupleSizes< S1, S2 >::value, T >::type EnableIfStaticTupleSizes