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#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:
61template <typename ValueType>
63
64namespace vtk
65{
66
67// Typedef for data array indices:
68using ComponentIdType = int;
71
72namespace detail
73{
74
75//------------------------------------------------------------------------------
76// Used by ranges/iterators when tuple size is unknown at compile time
77static constexpr ComponentIdType DynamicTupleSize = 0;
78
79//------------------------------------------------------------------------------
80// Detect data array value types
81template <typename T>
82struct IsVtkDataArray : std::is_base_of<vtkDataArray, T>
83{
84};
85
86template <typename T>
87using EnableIfVtkDataArray = typename std::enable_if<IsVtkDataArray<T>::value>::type;
88
89//------------------------------------------------------------------------------
90// If a value is a valid tuple size
91template <ComponentIdType Size>
92struct IsValidTupleSize : std::integral_constant<bool, (Size > 0 || Size == DynamicTupleSize)>
93{
94};
95
96template <ComponentIdType TupleSize>
97using EnableIfValidTupleSize = typename std::enable_if<IsValidTupleSize<TupleSize>::value>::type;
98
99//------------------------------------------------------------------------------
100// If a value is a non-dynamic tuple size
101template <ComponentIdType Size>
102struct IsStaticTupleSize : std::integral_constant<bool, (Size > 0)>
103{
104};
105
106template <ComponentIdType TupleSize>
107using EnableIfStaticTupleSize = typename std::enable_if<IsStaticTupleSize<TupleSize>::value>::type;
108
109//------------------------------------------------------------------------------
110// If two values are valid non-dynamic tuple sizes:
111template <ComponentIdType S1, ComponentIdType S2>
113 : std::integral_constant<bool, (IsStaticTupleSize<S1>::value && IsStaticTupleSize<S2>::value)>
114{
115};
116
117template <ComponentIdType S1, ComponentIdType S2, typename T = void>
119 typename std::enable_if<AreStaticTupleSizes<S1, S2>::value, T>::type;
120
121//------------------------------------------------------------------------------
122// If either of the tuple sizes is not statically defined
123template <ComponentIdType S1, ComponentIdType S2>
125 : std::integral_constant<bool, (!IsStaticTupleSize<S1>::value || !IsStaticTupleSize<S2>::value)>
126{
127};
128
129template <ComponentIdType S1, ComponentIdType S2, typename T = void>
131 typename std::enable_if<IsEitherTupleSizeDynamic<S1, S2>::value, T>::type;
132
133//------------------------------------------------------------------------------
134// Helper that switches between a storageless integral constant for known
135// sizes, and a runtime variable for variable sizes.
136template <ComponentIdType TupleSize>
137struct GenericTupleSize : public std::integral_constant<ComponentIdType, TupleSize>
138{
139 static_assert(IsValidTupleSize<TupleSize>::value, "Invalid tuple size.");
140
141private:
142 using Superclass = std::integral_constant<ComponentIdType, TupleSize>;
143
144public:
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:
152template <>
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
172template <typename ArrayType>
174{
175 using APIType = typename ArrayType::ValueType;
176};
177template <>
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.
187template <typename ArrayType, typename = detail::EnableIfVtkDataArray<ArrayType>>
189
190//------------------------------------------------------------------------------
191namespace detail
192{
193
194template <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
205template <typename ArrayType>
206using IsAOSDataArray = std::integral_constant<bool, detail::IsAOSDataArrayImpl<ArrayType>::value>;
207
208} // end namespace vtk
209
211
212#endif // vtkDataArrayMeta_h
213
214// VTK-HeaderTest-Exclude: vtkDataArrayMeta.h
Array-Of-Structs implementation of vtkGenericDataArray.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:159
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