VTK  9.3.1
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 #define VTK_ITER_INLINE VTK_ALWAYS_INLINE
36 #define VTK_ITER_ASSUME VTK_ASSUME_NO_ASSERT
37 #define VTK_ITER_OPTIMIZE_START VTK_ALWAYS_OPTIMIZE_START
38 #define VTK_ITER_OPTIMIZE_END VTK_ALWAYS_OPTIMIZE_START
39 #else
40 #define VTK_ITER_INLINE inline
41 #define VTK_ITER_ASSUME VTK_ASSUME
42 #define VTK_ITER_OPTIMIZE_START
43 #define VTK_ITER_OPTIMIZE_END
44 #endif
45 
47 
48 // For IsAOSDataArray:
49 VTK_ABI_NAMESPACE_BEGIN
50 template <typename ValueType>
52 VTK_ABI_NAMESPACE_END
53 
54 namespace vtk
55 {
56 VTK_ABI_NAMESPACE_BEGIN
57 
58 // Typedef for data array indices:
59 using ComponentIdType = int;
62 VTK_ABI_NAMESPACE_END
63 
64 namespace detail
65 {
66 VTK_ABI_NAMESPACE_BEGIN
67 
68 //------------------------------------------------------------------------------
69 // Used by ranges/iterators when tuple size is unknown at compile time
70 static constexpr ComponentIdType DynamicTupleSize = 0;
71 
72 //------------------------------------------------------------------------------
73 // Detect data array value types
74 template <typename T>
75 struct IsVtkDataArray : std::is_base_of<vtkDataArray, T>
76 {
77 };
78 
79 template <typename T>
81 
82 //------------------------------------------------------------------------------
83 // If a value is a valid tuple size
84 template <ComponentIdType Size>
85 struct IsValidTupleSize : std::integral_constant<bool, (Size > 0 || Size == DynamicTupleSize)>
86 {
87 };
88 
89 template <ComponentIdType TupleSize>
91 
92 //------------------------------------------------------------------------------
93 // If a value is a non-dynamic tuple size
94 template <ComponentIdType Size>
95 struct IsStaticTupleSize : std::integral_constant<bool, (Size > 0)>
96 {
97 };
98 
99 template <ComponentIdType TupleSize>
101 
102 //------------------------------------------------------------------------------
103 // If two values are valid non-dynamic tuple sizes:
104 template <ComponentIdType S1, ComponentIdType S2>
106  : std::integral_constant<bool, (IsStaticTupleSize<S1>::value && IsStaticTupleSize<S2>::value)>
107 {
108 };
109 
110 template <ComponentIdType S1, ComponentIdType S2, typename T = void>
113 
114 //------------------------------------------------------------------------------
115 // If either of the tuple sizes is not statically defined
116 template <ComponentIdType S1, ComponentIdType S2>
118  : std::integral_constant<bool, (!IsStaticTupleSize<S1>::value || !IsStaticTupleSize<S2>::value)>
119 {
120 };
121 
122 template <ComponentIdType S1, ComponentIdType S2, typename T = void>
125 
126 //------------------------------------------------------------------------------
127 // Helper that switches between a storageless integral constant for known
128 // sizes, and a runtime variable for variable sizes.
129 template <ComponentIdType TupleSize>
130 struct GenericTupleSize : public std::integral_constant<ComponentIdType, TupleSize>
131 {
132  static_assert(IsValidTupleSize<TupleSize>::value, "Invalid tuple size.");
133 
134 private:
135  using Superclass = std::integral_constant<ComponentIdType, TupleSize>;
136 
137 public:
138  // Need to construct from array for specialization.
139  using Superclass::Superclass;
140  VTK_ITER_INLINE GenericTupleSize() noexcept = default;
142 };
143 
144 // Specialize for dynamic types, mimicking integral_constant API:
145 template <>
146 struct GenericTupleSize<DynamicTupleSize>
147 {
149 
151  : value(0)
152  {
153  }
155  : value(array->GetNumberOfComponents())
156  {
157  }
158 
159  VTK_ITER_INLINE operator value_type() const noexcept { return value; }
160  VTK_ITER_INLINE value_type operator()() const noexcept { return value; }
161 
163 };
164 
165 template <typename ArrayType>
167 {
168  using APIType = typename ArrayType::ValueType;
169 };
170 template <>
172 {
173  using APIType = double;
174 };
175 
176 VTK_ABI_NAMESPACE_END
177 } // end namespace detail
178 
179 VTK_ABI_NAMESPACE_BEGIN
180 
181 //------------------------------------------------------------------------------
182 // Typedef for double if vtkDataArray, or the array's ValueType for subclasses.
183 template <typename ArrayType, typename = detail::EnableIfVtkDataArray<ArrayType>>
185 
186 VTK_ABI_NAMESPACE_END
187 
188 //------------------------------------------------------------------------------
189 namespace detail
190 {
191 VTK_ABI_NAMESPACE_BEGIN
192 
193 template <typename ArrayType>
195 {
197  static constexpr bool value = std::is_base_of<vtkAOSDataArrayTemplate<APIType>, ArrayType>::value;
198 };
199 
200 VTK_ABI_NAMESPACE_END
201 } // end namespace detail
202 
203 VTK_ABI_NAMESPACE_BEGIN
204 //------------------------------------------------------------------------------
205 // True if ArrayType inherits some specialization of vtkAOSDataArrayTemplate
206 template <typename ArrayType>
208 
209 VTK_ABI_NAMESPACE_END
210 } // end namespace vtk
211 
213 
214 #endif // vtkDataArrayMeta_h
215 
216 // VTK-HeaderTest-Exclude: vtkDataArrayMeta.h
vtkIdType TupleIdType
int ComponentIdType
VTK_ITER_INLINE GenericTupleSize() noexcept=default
typename std::enable_if< IsEitherTupleSizeDynamic< S1, S2 >::value, T >::type EnableIfEitherTupleSizeIsDynamic
std::integral_constant< bool, detail::IsAOSDataArrayImpl< ArrayType >::value > IsAOSDataArray
VTK_ITER_INLINE value_type operator()() const noexcept
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
int vtkIdType
Definition: vtkType.h:315
vtkIdType ValueIdType
This file contains a variety of metaprogramming constructs for working with vtk types.
#define VTK_ITER_INLINE
Array-Of-Structs implementation of vtkGenericDataArray.
#define VTK_ITER_OPTIMIZE_END
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
static constexpr ComponentIdType DynamicTupleSize
typename ArrayType::ValueType APIType
GetAPIType< ArrayType > APIType
VTK_ITER_INLINE GenericTupleSize(vtkDataArray *array)
typename detail::GetAPITypeImpl< ArrayType >::APIType GetAPIType
typename std::enable_if< IsVtkDataArray< T >::value >::type EnableIfVtkDataArray
typename std::enable_if< IsStaticTupleSize< TupleSize >::value >::type EnableIfStaticTupleSize
#define VTK_ITER_OPTIMIZE_START
VTK_ITER_INLINE GenericTupleSize(vtkDataArray *) noexcept
typename std::enable_if< IsValidTupleSize< TupleSize >::value >::type EnableIfValidTupleSize
typename std::enable_if< AreStaticTupleSizes< S1, S2 >::value, T >::type EnableIfStaticTupleSizes