VTK  9.3.0
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:
49VTK_ABI_NAMESPACE_BEGIN
50template <typename ValueType>
52VTK_ABI_NAMESPACE_END
53
54namespace vtk
55{
56VTK_ABI_NAMESPACE_BEGIN
57
58// Typedef for data array indices:
59using ComponentIdType = int;
62VTK_ABI_NAMESPACE_END
63
64namespace detail
65{
66VTK_ABI_NAMESPACE_BEGIN
67
68//------------------------------------------------------------------------------
69// Used by ranges/iterators when tuple size is unknown at compile time
70static constexpr ComponentIdType DynamicTupleSize = 0;
71
72//------------------------------------------------------------------------------
73// Detect data array value types
74template <typename T>
75struct IsVtkDataArray : std::is_base_of<vtkDataArray, T>
76{
77};
78
79template <typename T>
80using EnableIfVtkDataArray = typename std::enable_if<IsVtkDataArray<T>::value>::type;
81
82//------------------------------------------------------------------------------
83// If a value is a valid tuple size
84template <ComponentIdType Size>
85struct IsValidTupleSize : std::integral_constant<bool, (Size > 0 || Size == DynamicTupleSize)>
86{
87};
88
89template <ComponentIdType TupleSize>
90using EnableIfValidTupleSize = typename std::enable_if<IsValidTupleSize<TupleSize>::value>::type;
91
92//------------------------------------------------------------------------------
93// If a value is a non-dynamic tuple size
94template <ComponentIdType Size>
95struct IsStaticTupleSize : std::integral_constant<bool, (Size > 0)>
96{
97};
98
99template <ComponentIdType TupleSize>
100using EnableIfStaticTupleSize = typename std::enable_if<IsStaticTupleSize<TupleSize>::value>::type;
101
102//------------------------------------------------------------------------------
103// If two values are valid non-dynamic tuple sizes:
104template <ComponentIdType S1, ComponentIdType S2>
106 : std::integral_constant<bool, (IsStaticTupleSize<S1>::value && IsStaticTupleSize<S2>::value)>
107{
108};
109
110template <ComponentIdType S1, ComponentIdType S2, typename T = void>
112 typename std::enable_if<AreStaticTupleSizes<S1, S2>::value, T>::type;
113
114//------------------------------------------------------------------------------
115// If either of the tuple sizes is not statically defined
116template <ComponentIdType S1, ComponentIdType S2>
118 : std::integral_constant<bool, (!IsStaticTupleSize<S1>::value || !IsStaticTupleSize<S2>::value)>
119{
120};
121
122template <ComponentIdType S1, ComponentIdType S2, typename T = void>
124 typename std::enable_if<IsEitherTupleSizeDynamic<S1, S2>::value, T>::type;
125
126//------------------------------------------------------------------------------
127// Helper that switches between a storageless integral constant for known
128// sizes, and a runtime variable for variable sizes.
129template <ComponentIdType TupleSize>
130struct GenericTupleSize : public std::integral_constant<ComponentIdType, TupleSize>
131{
132 static_assert(IsValidTupleSize<TupleSize>::value, "Invalid tuple size.");
133
134private:
135 using Superclass = std::integral_constant<ComponentIdType, TupleSize>;
136
137public:
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:
145template <>
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
165template <typename ArrayType>
167{
168 using APIType = typename ArrayType::ValueType;
169};
170template <>
172{
173 using APIType = double;
174};
175
176VTK_ABI_NAMESPACE_END
177} // end namespace detail
178
179VTK_ABI_NAMESPACE_BEGIN
180
181//------------------------------------------------------------------------------
182// Typedef for double if vtkDataArray, or the array's ValueType for subclasses.
183template <typename ArrayType, typename = detail::EnableIfVtkDataArray<ArrayType>>
185
186VTK_ABI_NAMESPACE_END
187
188//------------------------------------------------------------------------------
189namespace detail
190{
191VTK_ABI_NAMESPACE_BEGIN
192
193template <typename ArrayType>
195{
197 static constexpr bool value = std::is_base_of<vtkAOSDataArrayTemplate<APIType>, ArrayType>::value;
198};
199
200VTK_ABI_NAMESPACE_END
201} // end namespace detail
202
203VTK_ABI_NAMESPACE_BEGIN
204//------------------------------------------------------------------------------
205// True if ArrayType inherits some specialization of vtkAOSDataArrayTemplate
206template <typename ArrayType>
207using IsAOSDataArray = std::integral_constant<bool, detail::IsAOSDataArrayImpl<ArrayType>::value>;
208
209VTK_ABI_NAMESPACE_END
210} // end namespace vtk
211
213
214#endif // vtkDataArrayMeta_h
215
216// VTK-HeaderTest-Exclude: vtkDataArrayMeta.h
Array-Of-Structs implementation of vtkGenericDataArray.
abstract superclass for arrays of numeric data
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.
typename detail::GetAPITypeImpl< ArrayType >::APIType GetAPIType
vtkIdType ValueIdType
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