VTK  9.3.20240327
vtkDataArrayMeta.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
3 
4 #ifndef vtkDataArrayMeta_h
5 #define vtkDataArrayMeta_h
6 
7 #include "vtkAssume.h"
8 #include "vtkDataArray.h"
9 #include "vtkDebugRangeIterators.h"
10 #include "vtkMeta.h"
11 #include "vtkSetGet.h"
12 #include "vtkType.h"
13 
14 #include <type_traits>
15 #include <utility>
16 
23 // When enabled, extra debugging checks are enabled for the iterators.
24 // Specifically:
25 // - Specializations are disabled (All code uses the generic implementation).
26 // - Additional assertions are inserted to ensure correct runtime usage.
27 // - Performance-related annotations (e.g. force inlining) are disabled.
28 #if defined(VTK_DEBUG_RANGE_ITERATORS)
29 #define VTK_ITER_ASSERT(x, msg) assert((x) && msg)
30 #else
31 #define VTK_ITER_ASSERT(x, msg)
32 #endif
33 
34 #if (defined(VTK_ALWAYS_OPTIMIZE_ARRAY_ITERATORS) || !defined(VTK_DEBUG_RANGE_ITERATORS)) && \
35  !defined(VTK_COMPILER_MSVC)
36 #define VTK_ITER_INLINE VTK_ALWAYS_INLINE
37 #define VTK_ITER_ASSUME VTK_ASSUME_NO_ASSERT
38 #define VTK_ITER_OPTIMIZE_START VTK_ALWAYS_OPTIMIZE_START
39 #define VTK_ITER_OPTIMIZE_END VTK_ALWAYS_OPTIMIZE_END
40 #else
41 #define VTK_ITER_INLINE inline
42 #define VTK_ITER_ASSUME VTK_ASSUME
43 #define VTK_ITER_OPTIMIZE_START
44 #define VTK_ITER_OPTIMIZE_END
45 #endif
46 
48 
49 // For IsAOSDataArray:
50 VTK_ABI_NAMESPACE_BEGIN
51 template <typename ValueType>
53 VTK_ABI_NAMESPACE_END
54 
55 namespace vtk
56 {
57 VTK_ABI_NAMESPACE_BEGIN
58 
59 // Typedef for data array indices:
60 using ComponentIdType = int;
63 VTK_ABI_NAMESPACE_END
64 
65 namespace detail
66 {
67 VTK_ABI_NAMESPACE_BEGIN
68 
69 //------------------------------------------------------------------------------
70 // Used by ranges/iterators when tuple size is unknown at compile time
71 static constexpr ComponentIdType DynamicTupleSize = 0;
72 
73 //------------------------------------------------------------------------------
74 // Detect data array value types
75 template <typename T>
76 struct IsVtkDataArray : std::is_base_of<vtkDataArray, T>
77 {
78 };
79 
80 template <typename T>
82 
83 //------------------------------------------------------------------------------
84 // If a value is a valid tuple size
85 template <ComponentIdType Size>
86 struct IsValidTupleSize : std::integral_constant<bool, (Size > 0 || Size == DynamicTupleSize)>
87 {
88 };
89 
90 template <ComponentIdType TupleSize>
92 
93 //------------------------------------------------------------------------------
94 // If a value is a non-dynamic tuple size
95 template <ComponentIdType Size>
96 struct IsStaticTupleSize : std::integral_constant<bool, (Size > 0)>
97 {
98 };
99 
100 template <ComponentIdType TupleSize>
102 
103 //------------------------------------------------------------------------------
104 // If two values are valid non-dynamic tuple sizes:
105 template <ComponentIdType S1, ComponentIdType S2>
107  : std::integral_constant<bool, (IsStaticTupleSize<S1>::value && IsStaticTupleSize<S2>::value)>
108 {
109 };
110 
111 template <ComponentIdType S1, ComponentIdType S2, typename T = void>
114 
115 //------------------------------------------------------------------------------
116 // If either of the tuple sizes is not statically defined
117 template <ComponentIdType S1, ComponentIdType S2>
119  : std::integral_constant<bool, (!IsStaticTupleSize<S1>::value || !IsStaticTupleSize<S2>::value)>
120 {
121 };
122 
123 template <ComponentIdType S1, ComponentIdType S2, typename T = void>
126 
127 //------------------------------------------------------------------------------
128 // Helper that switches between a storageless integral constant for known
129 // sizes, and a runtime variable for variable sizes.
130 template <ComponentIdType TupleSize>
131 struct GenericTupleSize : public std::integral_constant<ComponentIdType, TupleSize>
132 {
133  static_assert(IsValidTupleSize<TupleSize>::value, "Invalid tuple size.");
134 
135 private:
136  using Superclass = std::integral_constant<ComponentIdType, TupleSize>;
137 
138 public:
139  // Need to construct from array for specialization.
140  using Superclass::Superclass;
141  VTK_ITER_INLINE GenericTupleSize() noexcept = default;
143 };
144 
145 // Specialize for dynamic types, mimicking integral_constant API:
146 template <>
148 {
150 
152  : value(0)
153  {
154  }
156  : value(array->GetNumberOfComponents())
157  {
158  }
159 
160  VTK_ITER_INLINE operator value_type() const noexcept { return value; }
161  VTK_ITER_INLINE value_type operator()() const noexcept { return value; }
162 
164 };
165 
166 template <typename ArrayType, typename ForceValueTypeForVtkDataArray = double>
168 {
169  using APIType = typename ArrayType::ValueType;
170 };
171 template <typename ForceValueTypeForVtkDataArray>
172 struct GetAPITypeImpl<vtkDataArray, ForceValueTypeForVtkDataArray>
173 {
174  using APIType = ForceValueTypeForVtkDataArray;
175 };
176 
177 VTK_ABI_NAMESPACE_END
178 } // end namespace detail
179 
180 VTK_ABI_NAMESPACE_BEGIN
181 
182 //------------------------------------------------------------------------------
183 // Typedef for double if vtkDataArray, or the array's ValueType for subclasses.
184 template <typename ArrayType, typename ForceValueTypeForVtkDataArray = double,
186 using GetAPIType =
188 
189 VTK_ABI_NAMESPACE_END
190 
191 //------------------------------------------------------------------------------
192 namespace detail
193 {
194 VTK_ABI_NAMESPACE_BEGIN
195 
196 template <typename ArrayType>
198 {
200  static constexpr bool value = std::is_base_of<vtkAOSDataArrayTemplate<APIType>, ArrayType>::value;
201 };
202 
203 VTK_ABI_NAMESPACE_END
204 } // end namespace detail
205 
206 VTK_ABI_NAMESPACE_BEGIN
207 //------------------------------------------------------------------------------
208 // True if ArrayType inherits some specialization of vtkAOSDataArrayTemplate
209 template <typename ArrayType>
211 
212 VTK_ABI_NAMESPACE_END
213 } // end namespace vtk
214 
216 
217 #endif // vtkDataArrayMeta_h
218 
219 // VTK-HeaderTest-Exclude: vtkDataArrayMeta.h
Array-Of-Structs implementation of vtkGenericDataArray.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:154
@ value
Definition: vtkX3D.h:220
@ type
Definition: vtkX3D.h:516
typename std::enable_if< IsValidTupleSize< TupleSize >::value >::type EnableIfValidTupleSize
typename std::enable_if< IsStaticTupleSize< TupleSize >::value >::type EnableIfStaticTupleSize
typename std::enable_if< IsVtkDataArray< T >::value >::type EnableIfVtkDataArray
typename std::enable_if< AreStaticTupleSizes< S1, S2 >::value, T >::type EnableIfStaticTupleSizes
static constexpr ComponentIdType DynamicTupleSize
typename std::enable_if< IsEitherTupleSizeDynamic< S1, S2 >::value, T >::type EnableIfEitherTupleSizeIsDynamic
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
vtkIdType ValueIdType
typename detail::GetAPITypeImpl< ArrayType, ForceValueTypeForVtkDataArray >::APIType GetAPIType
vtkIdType TupleIdType
std::integral_constant< bool, detail::IsAOSDataArrayImpl< ArrayType >::value > IsAOSDataArray
int ComponentIdType
VTK_ITER_INLINE value_type operator()() const noexcept
VTK_ITER_INLINE GenericTupleSize(vtkDataArray *array)
VTK_ITER_INLINE GenericTupleSize() noexcept=default
typename ArrayType::ValueType APIType
GetAPIType< ArrayType > APIType
#define VTK_ITER_OPTIMIZE_START
#define VTK_ITER_INLINE
#define VTK_ITER_OPTIMIZE_END
This file contains a variety of metaprogramming constructs for working with vtk types.
int vtkIdType
Definition: vtkType.h:315