VTK: Common/Core/vtkDataArrayValueRange_AOS.h Source File

| VTK 9.3.1

vtkDataArrayValueRange_AOS.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
7 #ifndef vtkDataArrayValueRange_AOS_h
8 #define vtkDataArrayValueRange_AOS_h
9
10 #include "vtkAOSDataArrayTemplate.h"
11 #include "vtkDataArrayMeta.h"
12 #include "vtkDataArrayValueRange_Generic.h"
13 #include "vtkDebugRangeIterators.h"
14
15 #include <algorithm>
16 #include <cassert>
17 #include <iterator>
18 #include <type_traits>
19
20 // Disable this specialization when iterator debugging is requested:
21 #ifndef VTK_DEBUG_RANGE_ITERATORS
22
23 VTK_ITER_OPTIMIZE_START
24
25 namespace vtk
26 {
27 namespace detail
28 {
29 VTK_ABI_NAMESPACE_BEGIN
30
31 //------------------------------------------------------------------------------
32 // ValueRange
33 template <typename ValueTypeT, ComponentIdType TupleSize>
34 struct ValueRange<vtkAOSDataArrayTemplate<ValueTypeT>, TupleSize>
35 {
36 private:
37 static_assert(IsValidTupleSize<TupleSize>::value, "Invalid tuple size.");
38
39 using IdStorageType = IdStorage<TupleSize>;
40 using NumCompsType = GenericTupleSize<TupleSize>;
41
42 public:
43 using ArrayType = vtkAOSDataArrayTemplate<ValueTypeT>;
44 using ValueType = ValueTypeT;
45
46 using IteratorType = ValueType*;
47 using ConstIteratorType = ValueType const*;
48 using ReferenceType = ValueType&;
49 using ConstReferenceType = ValueType const&;
50
51 // May be DynamicTupleSize, or the actual tuple size.
52 constexpr static ComponentIdType TupleSizeTag = TupleSize;
53
54 // STL-compat
55 using value_type = ValueType;
56 using size_type = ValueIdType;
57 using iterator = IteratorType;
58 using const_iterator = ConstIteratorType;
59 using reference = ReferenceType;
60 using const_reference = ConstReferenceType;
61
62 VTK_ITER_INLINE
63 ValueRange() noexcept = default;
64
65 VTK_ITER_INLINE
66 ValueRange(ArrayType* arr, ValueIdType beginValue, ValueIdType endValue) noexcept
67 : Array(arr)
68 , NumComps(arr)
69 , Begin(arr->GetPointer(beginValue))
70 , End(arr->GetPointer(endValue))
71 {
72 assert(this->Array);
73 assert(beginValue >= 0 && beginValue <= endValue);
74 assert(endValue >= 0 && endValue <= this->Array->GetNumberOfValues());
75 }
76
77 VTK_ITER_INLINE
78 ValueRange GetSubRange(ValueIdType beginValue = 0, ValueIdType endValue = -1) const noexcept
79 {
80 const ValueIdType realBegin =
81 std::distance(this->Array->GetPointer(0), this->Begin) + beginValue;
82 const ValueIdType realEnd = endValue >= 0
83 ? std::distance(this->Array->GetPointer(0), this->Begin) + endValue
84 : std::distance(this->Array->GetPointer(0), this->End);
85
86 return ValueRange{ this->Array, realBegin, realEnd };
87 }
88
89 VTK_ITER_INLINE
90 ArrayType* GetArray() const noexcept { return this->Array; }
91
92 VTK_ITER_INLINE
93 ComponentIdType GetTupleSize() const noexcept { return this->NumComps.value; }
94
95 VTK_ITER_INLINE
96 ValueIdType GetBeginValueId() const noexcept
97 {
98 return static_cast<ValueIdType>(this->Begin - this->Array->GetPointer(0));
99 }
100
101 VTK_ITER_INLINE
102 ValueIdType GetEndValueId() const noexcept
103 {
104 return static_cast<ValueIdType>(this->End - this->Array->GetPointer(0));
105 }
106
107 VTK_ITER_INLINE
108 size_type size() const noexcept { return static_cast<size_type>(this->End - this->Begin); }
109
110 VTK_ITER_INLINE
111 iterator begin() noexcept { return this->Begin; }
112 VTK_ITER_INLINE
113 iterator end() noexcept { return this->End; }
114
115 VTK_ITER_INLINE
116 const_iterator begin() const noexcept { return this->Begin; }
117 VTK_ITER_INLINE
118 const_iterator end() const noexcept { return this->End; }
119
120 VTK_ITER_INLINE
121 const_iterator cbegin() const noexcept { return this->Begin; }
122 VTK_ITER_INLINE
123 const_iterator cend() const noexcept { return this->End; }
124
125 VTK_ITER_INLINE
126 reference operator[](size_type i) noexcept { return this->Begin[i]; }
127 VTK_ITER_INLINE
128 const_reference operator[](size_type i) const noexcept { return this->Begin[i]; }
129
130 private:
131 mutable ArrayType* Array{ nullptr };
132 NumCompsType NumComps{};
133 ValueType* Begin{ nullptr };
134 ValueType* End{ nullptr };
135 };
136
137 // Unimplemented, only used inside decltype in SelectValueRange:
138 template <typename ArrayType, ComponentIdType TupleSize,
139 // Convenience:
140 typename ValueType = typename ArrayType::ValueType,
141 typename AOSArrayType = vtkAOSDataArrayTemplate<ValueType>,
142 // SFINAE to select AOS arrays:
143 typename = typename std::enable_if<IsAOSDataArray<ArrayType>::value>::type>
144 ValueRange<AOSArrayType, TupleSize> DeclareValueRangeSpecialization(ArrayType*);
145
146 VTK_ABI_NAMESPACE_END
147 }
148 } // end namespace vtk::detail
149
150 VTK_ITER_OPTIMIZE_END
151
152 #endif // VTK_DEBUG_RANGE_ITERATORS
153 #endif // vtkDataArrayValueRange_AOS_h
154
155 // VTK-HeaderTest-Exclude: vtkDataArrayValueRange_AOS.h
vtkAOSDataArrayTemplate
Array-Of-Structs implementation of vtkGenericDataArray.
Definition: vtkAOSDataArrayTemplate.h:37
detail
Definition: vtkCellTreeLocator.h:59
vtkX3D::value
@ value
Definition: vtkX3D.h:220
vtkX3D::type
@ type
Definition: vtkX3D.h:516
vtk::detail::DeclareValueRangeSpecialization
ValueRange< AOSArrayType, TupleSize > DeclareValueRangeSpecialization(ArrayType *)
vtk
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
Definition: vtkSMPThreadLocalAPI.h:30
vtk::ValueIdType
vtkIdType ValueIdType
Definition: vtkDataArrayMeta.h:61
vtk::ComponentIdType
int ComponentIdType
Definition: vtkDataArrayMeta.h:59
vtk::detail::GenericTupleSize
Definition: vtkDataArrayMeta.h:131
vtk::detail::IdStorage
Definition: vtkDataArrayValueRange_Generic.h:50
vtk::detail::IsValidTupleSize
Definition: vtkDataArrayMeta.h:86
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::const_reference
ConstReferenceType const_reference
Definition: vtkDataArrayValueRange_AOS.h:60
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::GetBeginValueId
VTK_ITER_INLINE ValueIdType GetBeginValueId() const noexcept
Definition: vtkDataArrayValueRange_AOS.h:96
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::ValueType
ValueTypeT ValueType
Definition: vtkDataArrayValueRange_AOS.h:44
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::end
VTK_ITER_INLINE const_iterator end() const noexcept
Definition: vtkDataArrayValueRange_AOS.h:118
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::GetSubRange
VTK_ITER_INLINE ValueRange GetSubRange(ValueIdType beginValue=0, ValueIdType endValue=-1) const noexcept
Definition: vtkDataArrayValueRange_AOS.h:78
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::begin
VTK_ITER_INLINE iterator begin() noexcept
Definition: vtkDataArrayValueRange_AOS.h:111
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::size_type
ValueIdType size_type
Definition: vtkDataArrayValueRange_AOS.h:56
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::reference
ReferenceType reference
Definition: vtkDataArrayValueRange_AOS.h:59
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::ConstReferenceType
ValueType const & ConstReferenceType
Definition: vtkDataArrayValueRange_AOS.h:49
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::operator[]
VTK_ITER_INLINE reference operator[](size_type i) noexcept
Definition: vtkDataArrayValueRange_AOS.h:126
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::cend
VTK_ITER_INLINE const_iterator cend() const noexcept
Definition: vtkDataArrayValueRange_AOS.h:123
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::ConstIteratorType
ValueType const * ConstIteratorType
Definition: vtkDataArrayValueRange_AOS.h:47
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::GetArray
VTK_ITER_INLINE ArrayType * GetArray() const noexcept
Definition: vtkDataArrayValueRange_AOS.h:90
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::IteratorType
ValueType * IteratorType
Definition: vtkDataArrayValueRange_AOS.h:46
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::iterator
IteratorType iterator
Definition: vtkDataArrayValueRange_AOS.h:57
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::size
VTK_ITER_INLINE size_type size() const noexcept
Definition: vtkDataArrayValueRange_AOS.h:108
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::ReferenceType
ValueType & ReferenceType
Definition: vtkDataArrayValueRange_AOS.h:48
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::const_iterator
ConstIteratorType const_iterator
Definition: vtkDataArrayValueRange_AOS.h:58
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::begin
VTK_ITER_INLINE const_iterator begin() const noexcept
Definition: vtkDataArrayValueRange_AOS.h:116
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::GetEndValueId
VTK_ITER_INLINE ValueIdType GetEndValueId() const noexcept
Definition: vtkDataArrayValueRange_AOS.h:102
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::value_type
ValueType value_type
Definition: vtkDataArrayValueRange_AOS.h:55
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::ValueRange
VTK_ITER_INLINE ValueRange() noexcept=default
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::end
VTK_ITER_INLINE iterator end() noexcept
Definition: vtkDataArrayValueRange_AOS.h:113
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::GetTupleSize
VTK_ITER_INLINE ComponentIdType GetTupleSize() const noexcept
Definition: vtkDataArrayValueRange_AOS.h:93
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::cbegin
VTK_ITER_INLINE const_iterator cbegin() const noexcept
Definition: vtkDataArrayValueRange_AOS.h:121
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::operator[]
VTK_ITER_INLINE const_reference operator[](size_type i) const noexcept
Definition: vtkDataArrayValueRange_AOS.h:128
vtk::detail::ValueRange
Definition: vtkDataArrayValueRange_Generic.h:827
vtk::detail::ValueRange::ValueType
GetAPIType< ArrayTypeT > ValueType
Definition: vtkDataArrayValueRange_Generic.h:837
vtk::detail::ValueRange::ConstReferenceType
ConstValueReference< ArrayType, TupleSize > ConstReferenceType
Definition: vtkDataArrayValueRange_Generic.h:842
vtk::detail::ValueRange::IteratorType
ValueIterator< ArrayType, TupleSize > IteratorType
Definition: vtkDataArrayValueRange_Generic.h:839
vtk::detail::ValueRange::TupleSizeTag
constexpr static ComponentIdType TupleSizeTag
Definition: vtkDataArrayValueRange_Generic.h:845
vtk::detail::ValueRange::ArrayType
ArrayTypeT ArrayType
Definition: vtkDataArrayValueRange_Generic.h:836
vtk::detail::ValueRange::ReferenceType
ValueReference< ArrayType, TupleSize > ReferenceType
Definition: vtkDataArrayValueRange_Generic.h:841
vtk::detail::ValueRange::ConstIteratorType
ConstValueIterator< ArrayType, TupleSize > ConstIteratorType
Definition: vtkDataArrayValueRange_Generic.h:840
vtkAOSDataArrayTemplate.h
vtkDataArrayMeta.h
This file contains a variety of metaprogramming constructs for working with vtkDataArrays.
VTK_ITER_OPTIMIZE_START
#define VTK_ITER_OPTIMIZE_START
Definition: vtkDataArrayMeta.h:42
VTK_ITER_INLINE
#define VTK_ITER_INLINE
Definition: vtkDataArrayMeta.h:40
VTK_ITER_OPTIMIZE_END
#define VTK_ITER_OPTIMIZE_END
Definition: vtkDataArrayMeta.h:43
vtkDataArrayValueRange_Generic.h