VTK  9.0.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 #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>
63 
64 namespace vtk
65 {
66 
67 // Typedef for data array indices:
68 using ComponentIdType = int;
71 
72 namespace detail
73 {
74 
75 //------------------------------------------------------------------------------
76 // Used by ranges/iterators when tuple size is unknown at compile time
77 static constexpr ComponentIdType DynamicTupleSize = 0;
78 
79 //------------------------------------------------------------------------------
80 // Detect data array value types
81 template <typename T>
82 struct IsVtkDataArray : std::is_base_of<vtkDataArray, T>
83 {
84 };
85 
86 template <typename T>
88 
89 //------------------------------------------------------------------------------
90 // If a value is a valid tuple size
91 template <ComponentIdType Size>
92 struct IsValidTupleSize : std::integral_constant<bool, (Size > 0 || Size == DynamicTupleSize)>
93 {
94 };
95 
96 template <ComponentIdType TupleSize>
98 
99 //------------------------------------------------------------------------------
100 // If a value is a non-dynamic tuple size
101 template <ComponentIdType Size>
102 struct IsStaticTupleSize : std::integral_constant<bool, (Size > 0)>
103 {
104 };
105 
106 template <ComponentIdType TupleSize>
108 
109 //------------------------------------------------------------------------------
110 // If two values are valid non-dynamic tuple sizes:
111 template <ComponentIdType S1, ComponentIdType S2>
113  : std::integral_constant<bool, (IsStaticTupleSize<S1>::value && IsStaticTupleSize<S2>::value)>
114 {
115 };
116 
117 template <ComponentIdType S1, ComponentIdType S2, typename T = void>
120 
121 //------------------------------------------------------------------------------
122 // If either of the tuple sizes is not statically defined
123 template <ComponentIdType S1, ComponentIdType S2>
125  : std::integral_constant<bool, (!IsStaticTupleSize<S1>::value || !IsStaticTupleSize<S2>::value)>
126 {
127 };
128 
129 template <ComponentIdType S1, ComponentIdType S2, typename T = void>
132 
133 //------------------------------------------------------------------------------
134 // Helper that switches between a storageless integral constant for known
135 // sizes, and a runtime variable for variable sizes.
136 template <ComponentIdType TupleSize>
137 struct GenericTupleSize : public std::integral_constant<ComponentIdType, TupleSize>
138 {
139  static_assert(IsValidTupleSize<TupleSize>::value, "Invalid tuple size.");
140 
141 private:
142  using Superclass = std::integral_constant<ComponentIdType, TupleSize>;
143 
144 public:
145  // Need to construct from array for specialization.
146  using Superclass::Superclass;
147  VTK_ITER_INLINE GenericTupleSize() noexcept = default;
149 };
150 
151 // Specialize for dynamic types, mimicking integral_constant API:
152 template <>
154 {
156 
158  : value(0)
159  {
160  }
162  : value(array->GetNumberOfComponents())
163  {
164  }
165 
166  VTK_ITER_INLINE operator value_type() const noexcept { return value; }
167  VTK_ITER_INLINE value_type operator()() const noexcept { return value; }
168 
170 };
171 
172 template <typename ArrayType>
174 {
175  using APIType = typename ArrayType::ValueType;
176 };
177 template <>
179 {
180  using APIType = double;
181 };
182 
183 } // end namespace detail
184 
185 //------------------------------------------------------------------------------
186 // Typedef for double if vtkDataArray, or the array's ValueType for subclasses.
187 template <typename ArrayType, typename = detail::EnableIfVtkDataArray<ArrayType>>
189 
190 //------------------------------------------------------------------------------
191 namespace detail
192 {
193 
194 template <typename ArrayType>
196 {
198  static constexpr bool value = std::is_base_of<vtkAOSDataArrayTemplate<APIType>, ArrayType>::value;
199 };
200 
201 } // end namespace detail
202 
203 //------------------------------------------------------------------------------
204 // True if ArrayType inherits some specialization of vtkAOSDataArrayTemplate
205 template <typename ArrayType>
207 
208 } // end namespace vtk
209 
211 
212 #endif // vtkDataArrayMeta_h
213 
214 // VTK-HeaderTest-Exclude: vtkDataArrayMeta.h
vtk::detail::EnableIfStaticTupleSizes
typename std::enable_if< AreStaticTupleSizes< S1, S2 >::value, T >::type EnableIfStaticTupleSizes
Definition: vtkDataArrayMeta.h:119
vtk::detail::EnableIfValidTupleSize
typename std::enable_if< IsValidTupleSize< TupleSize >::value >::type EnableIfValidTupleSize
Definition: vtkDataArrayMeta.h:97
vtk::detail::IsStaticTupleSize
Definition: vtkDataArrayMeta.h:102
vtk::detail::IsAOSDataArrayImpl::APIType
GetAPIType< ArrayType > APIType
Definition: vtkDataArrayMeta.h:197
vtk::detail::IsVtkDataArray
Definition: vtkDataArrayMeta.h:82
vtkX3D::value
Definition: vtkX3D.h:226
vtk::detail::IsAOSDataArrayImpl::value
static constexpr bool value
Definition: vtkDataArrayMeta.h:198
vtkX3D::type
Definition: vtkX3D.h:522
vtkIdType
int vtkIdType
Definition: vtkType.h:330
vtk::IsAOSDataArray
std::integral_constant< bool, detail::IsAOSDataArrayImpl< ArrayType >::value > IsAOSDataArray
Definition: vtkDataArrayMeta.h:206
VTK_ITER_OPTIMIZE_START
#define VTK_ITER_OPTIMIZE_START
Definition: vtkDataArrayMeta.h:54
vtk::detail::GenericTupleSize< DynamicTupleSize >::value_type
ComponentIdType value_type
Definition: vtkDataArrayMeta.h:155
vtk::ValueIdType
vtkIdType ValueIdType
Definition: vtkDataArrayMeta.h:70
vtkMeta.h
vtk::detail::EnableIfEitherTupleSizeIsDynamic
typename std::enable_if< IsEitherTupleSizeDynamic< S1, S2 >::value, T >::type EnableIfEitherTupleSizeIsDynamic
Definition: vtkDataArrayMeta.h:131
vtk::detail::IsEitherTupleSizeDynamic
Definition: vtkDataArrayMeta.h:124
vtk::detail::GetAPITypeImpl< vtkDataArray >::APIType
double APIType
Definition: vtkDataArrayMeta.h:180
detail
Definition: vtkGenericDataArrayLookupHelper.h:31
vtk::detail::GenericTupleSize< DynamicTupleSize >::GenericTupleSize
VTK_ITER_INLINE GenericTupleSize() noexcept
Definition: vtkDataArrayMeta.h:157
vtk::ComponentIdType
int ComponentIdType
Definition: vtkDataArrayMeta.h:68
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:49
vtk::GetAPIType
typename detail::GetAPITypeImpl< ArrayType >::APIType GetAPIType
Definition: vtkDataArrayMeta.h:188
vtk::detail::DynamicTupleSize
static constexpr ComponentIdType DynamicTupleSize
Definition: vtkDataArrayMeta.h:77
vtkType.h
vtk::detail::GenericTupleSize::GenericTupleSize
VTK_ITER_INLINE GenericTupleSize() noexcept=default
vtk::detail::GenericTupleSize< DynamicTupleSize >::GenericTupleSize
VTK_ITER_INLINE GenericTupleSize(vtkDataArray *array)
Definition: vtkDataArrayMeta.h:161
vtkAssume.h
VTK_ITER_OPTIMIZE_END
#define VTK_ITER_OPTIMIZE_END
Definition: vtkDataArrayMeta.h:55
vtk::detail::GetAPITypeImpl::APIType
typename ArrayType::ValueType APIType
Definition: vtkDataArrayMeta.h:175
vtk::detail::AreStaticTupleSizes
Definition: vtkDataArrayMeta.h:112
vtk::detail::IsAOSDataArrayImpl
Definition: vtkDataArrayMeta.h:195
vtk::detail::GetAPITypeImpl
Definition: vtkDataArrayMeta.h:173
vtk::detail::EnableIfStaticTupleSize
typename std::enable_if< IsStaticTupleSize< TupleSize >::value >::type EnableIfStaticTupleSize
Definition: vtkDataArrayMeta.h:107
vtk::TupleIdType
vtkIdType TupleIdType
Definition: vtkDataArrayMeta.h:69
vtkDataArray.h
vtk::detail::GenericTupleSize< DynamicTupleSize >::value
ComponentIdType value
Definition: vtkDataArrayMeta.h:169
vtk
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
Definition: vtkCollectionRange.h:28
vtk::detail::IsValidTupleSize
Definition: vtkDataArrayMeta.h:92
vtk::detail::GenericTupleSize::GenericTupleSize
VTK_ITER_INLINE GenericTupleSize(vtkDataArray *) noexcept
Definition: vtkDataArrayMeta.h:148
vtkAOSDataArrayTemplate
Array-Of-Structs implementation of vtkGenericDataArray.
Definition: vtkAOSDataArrayTemplate.h:43
VTK_ITER_INLINE
#define VTK_ITER_INLINE
Definition: vtkDataArrayMeta.h:52
vtk::detail::GenericTupleSize
Definition: vtkDataArrayMeta.h:137
vtk::detail::GenericTupleSize< DynamicTupleSize >::operator()
VTK_ITER_INLINE value_type operator()() const noexcept
Definition: vtkDataArrayMeta.h:167
vtk::detail::EnableIfVtkDataArray
typename std::enable_if< IsVtkDataArray< T >::value >::type EnableIfVtkDataArray
Definition: vtkDataArrayMeta.h:87