VTK  9.1.0
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 "vtkDataArray.h"
21 #include "vtkDebugRangeIterators.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 // - Performance-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  !defined(VTK_COMPILER_MSVC) && !defined(__PPC64__)
48 #define VTK_ITER_INLINE VTK_ALWAYS_INLINE
49 #define VTK_ITER_ASSUME VTK_ASSUME_NO_ASSERT
50 #define VTK_ITER_OPTIMIZE_START VTK_ALWAYS_OPTIMIZE_START
51 #define VTK_ITER_OPTIMIZE_END VTK_ALWAYS_OPTIMIZE_START
52 #else
53 #define VTK_ITER_INLINE inline
54 #define VTK_ITER_ASSUME VTK_ASSUME
55 #define VTK_ITER_OPTIMIZE_START
56 #define VTK_ITER_OPTIMIZE_END
57 #endif
58 
60 
61 // For IsAOSDataArray:
62 template <typename ValueType>
64 
65 namespace vtk
66 {
67 
68 // Typedef for data array indices:
69 using ComponentIdType = int;
72 
73 namespace detail
74 {
75 
76 //------------------------------------------------------------------------------
77 // Used by ranges/iterators when tuple size is unknown at compile time
78 static constexpr ComponentIdType DynamicTupleSize = 0;
79 
80 //------------------------------------------------------------------------------
81 // Detect data array value types
82 template <typename T>
83 struct IsVtkDataArray : std::is_base_of<vtkDataArray, T>
84 {
85 };
86 
87 template <typename T>
89 
90 //------------------------------------------------------------------------------
91 // If a value is a valid tuple size
92 template <ComponentIdType Size>
93 struct IsValidTupleSize : std::integral_constant<bool, (Size > 0 || Size == DynamicTupleSize)>
94 {
95 };
96 
97 template <ComponentIdType TupleSize>
99 
100 //------------------------------------------------------------------------------
101 // If a value is a non-dynamic tuple size
102 template <ComponentIdType Size>
103 struct IsStaticTupleSize : std::integral_constant<bool, (Size > 0)>
104 {
105 };
106 
107 template <ComponentIdType TupleSize>
109 
110 //------------------------------------------------------------------------------
111 // If two values are valid non-dynamic tuple sizes:
112 template <ComponentIdType S1, ComponentIdType S2>
114  : std::integral_constant<bool, (IsStaticTupleSize<S1>::value && IsStaticTupleSize<S2>::value)>
115 {
116 };
117 
118 template <ComponentIdType S1, ComponentIdType S2, typename T = void>
121 
122 //------------------------------------------------------------------------------
123 // If either of the tuple sizes is not statically defined
124 template <ComponentIdType S1, ComponentIdType S2>
126  : std::integral_constant<bool, (!IsStaticTupleSize<S1>::value || !IsStaticTupleSize<S2>::value)>
127 {
128 };
129 
130 template <ComponentIdType S1, ComponentIdType S2, typename T = void>
133 
134 //------------------------------------------------------------------------------
135 // Helper that switches between a storageless integral constant for known
136 // sizes, and a runtime variable for variable sizes.
137 template <ComponentIdType TupleSize>
138 struct GenericTupleSize : public std::integral_constant<ComponentIdType, TupleSize>
139 {
140  static_assert(IsValidTupleSize<TupleSize>::value, "Invalid tuple size.");
141 
142 private:
143  using Superclass = std::integral_constant<ComponentIdType, TupleSize>;
144 
145 public:
146  // Need to construct from array for specialization.
147  using Superclass::Superclass;
148  VTK_ITER_INLINE GenericTupleSize() noexcept = default;
150 };
151 
152 // Specialize for dynamic types, mimicking integral_constant API:
153 template <>
155 {
157 
159  : value(0)
160  {
161  }
163  : value(array->GetNumberOfComponents())
164  {
165  }
166 
167  VTK_ITER_INLINE operator value_type() const noexcept { return value; }
168  VTK_ITER_INLINE value_type operator()() const noexcept { return value; }
169 
171 };
172 
173 template <typename ArrayType>
175 {
176  using APIType = typename ArrayType::ValueType;
177 };
178 template <>
180 {
181  using APIType = double;
182 };
183 
184 } // end namespace detail
185 
186 //------------------------------------------------------------------------------
187 // Typedef for double if vtkDataArray, or the array's ValueType for subclasses.
188 template <typename ArrayType, typename = detail::EnableIfVtkDataArray<ArrayType>>
190 
191 //------------------------------------------------------------------------------
192 namespace detail
193 {
194 
195 template <typename ArrayType>
197 {
199  static constexpr bool value = std::is_base_of<vtkAOSDataArrayTemplate<APIType>, ArrayType>::value;
200 };
201 
202 } // end namespace detail
203 
204 //------------------------------------------------------------------------------
205 // True if ArrayType inherits some specialization of vtkAOSDataArrayTemplate
206 template <typename ArrayType>
208 
209 } // end namespace vtk
210 
212 
213 #endif // vtkDataArrayMeta_h
214 
215 // VTK-HeaderTest-Exclude: vtkDataArrayMeta.h
Array-Of-Structs implementation of vtkGenericDataArray.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:50
@ value
Definition: vtkX3D.h:226
@ type
Definition: vtkX3D.h:522
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:332