VTK  9.6.20260501
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
6
7#ifndef vtkDataArrayValueRange_AOS_h
8#define vtkDataArrayValueRange_AOS_h
9
11#include "vtkDataArrayMeta.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
24
25namespace vtk
26{
27namespace detail
28{
29VTK_ABI_NAMESPACE_BEGIN
30
31//------------------------------------------------------------------------------
32// ValueRange
33// For vtkAOSDataArrayTemplate, the `ForceValueTypeForVtkDataArray` template parameter is not used
34// at all.
35template <typename ValueTypeT, ComponentIdType TupleSize, typename ForceValueTypeForVtkDataArray>
36struct ValueRange<vtkAOSDataArrayTemplate<ValueTypeT>, TupleSize, ForceValueTypeForVtkDataArray>
37{
38private:
39 static_assert(IsValidTupleSize<TupleSize>::value, "Invalid tuple size.");
40
41 using IdStorageType = IdStorage<TupleSize>;
42 using NumCompsType = GenericTupleSize<TupleSize>;
43
44public:
46 using ValueType = ValueTypeT;
47
52
53 // May be DynamicTupleSize, or the actual tuple size.
54 constexpr static ComponentIdType TupleSizeTag = TupleSize;
55
56 // STL-compat
63
65 ValueRange() noexcept = default;
66
68 ValueRange(ArrayType* arr, ValueIdType beginValue, ValueIdType endValue) noexcept
69 : Array(arr)
70 , NumComps(arr)
71 , BeginValue(beginValue)
72 , EndValue(endValue)
73 {
74 assert(this->Array);
75 assert(beginValue >= 0 && beginValue <= endValue);
76 assert(endValue >= 0 && endValue <= this->Array->GetNumberOfValues());
78 {
79 assert(arr->GetNumberOfComponents() == TupleSize);
80 }
81 }
82
84 ValueRange GetSubRange(ValueIdType beginValue = 0, ValueIdType endValue = -1) const noexcept
85 {
86 const ValueIdType realBegin =
87 std::distance(this->Array->GetPointer(0), this->Array->GetPointer(this->BeginValue)) +
88 beginValue;
89 const ValueIdType realEnd = endValue >= 0
90 ? std::distance(this->Array->GetPointer(0), this->Array->GetPointer(this->BeginValue)) +
91 endValue
92 : std::distance(this->Array->GetPointer(0), this->Array->GetPointer(this->EndValue));
93
95 realEnd };
96 }
97
99 ArrayType* GetArray() const noexcept { return this->Array; }
100
102 ComponentIdType GetTupleSize() const noexcept { return this->NumComps.value; }
103
106 {
107 return static_cast<ValueIdType>(
108 this->Array->GetPointer(this->BeginValue) - this->Array->GetPointer(0));
109 }
110
112 ValueIdType GetEndValueId() const noexcept
113 {
114 return static_cast<ValueIdType>(
115 this->Array->GetPointer(this->EndValue) - this->Array->GetPointer(0));
116 }
117
119 size_type size() const noexcept
120 {
121 return static_cast<size_type>(
122 this->Array->GetPointer(this->EndValue) - this->Array->GetPointer(this->BeginValue));
123 }
124
126 iterator begin() noexcept { return this->Array->GetPointer(this->BeginValue); }
128 iterator end() noexcept { return this->Array->GetPointer(this->EndValue); }
129
131 const_iterator begin() const noexcept { return this->Array->GetPointer(this->BeginValue); }
133 const_iterator end() const noexcept { return this->Array->GetPointer(this->EndValue); }
134
136 const_iterator cbegin() const noexcept { return this->Array->GetPointer(this->BeginValue); }
138 const_iterator cend() const noexcept { return this->Array->GetPointer(this->EndValue); }
139
142 {
143 return this->Array->Buffer->GetBuffer()[this->BeginValue + i];
144 }
147 {
148 return this->Array->Buffer->GetBuffer()[this->BeginValue + i];
149 }
150
151 // Danger! pointer is non-const!
152 VTK_DEPRECATED_IN_9_6_0("Use iterators instead.")
153 value_type* data() noexcept { return this->Array->Buffer->GetBuffer(); }
154
155 VTK_DEPRECATED_IN_9_6_0("Use iterators instead.")
156 value_type* data() const noexcept { return this->Array->Buffer->GetBuffer(); }
157
158private:
159 mutable ArrayType* Array{ nullptr };
160 NumCompsType NumComps{};
161 ValueIdType BeginValue{ 0 };
162 ValueIdType EndValue{ 0 };
163};
164
165// Unimplemented, only used inside decltype in SelectValueRange:
166template <typename ArrayType, ComponentIdType TupleSize, typename ForceValueTypeForVtkDataArray,
167 // Convenience:
168 typename ValueType = typename ArrayType::ValueType,
169 typename AOSArrayType = vtkAOSDataArrayTemplate<ValueType>,
170 // SFINAE to select AOS arrays:
171 typename = typename std::enable_if<IsAOSDataArray<ArrayType>::value>::type>
173 ArrayType*);
174
175VTK_ABI_NAMESPACE_END
176}
177} // end namespace vtk::detail
178
180
181#endif // VTK_DEBUG_RANGE_ITERATORS
182#endif // vtkDataArrayValueRange_AOS_h
183
184// VTK-HeaderTest-Exclude: vtkDataArrayValueRange_AOS.h
Array-Of-Structs implementation of vtkGenericDataArray.
ValueRange< AOSArrayType, TupleSize, ForceValueTypeForVtkDataArray > DeclareValueRangeSpecialization(ArrayType *)
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
int ComponentIdType
vtkIdType ValueIdType
VTK_ITER_INLINE ValueRange GetSubRange(ValueIdType beginValue=0, ValueIdType endValue=-1) const noexcept
This file contains a variety of metaprogramming constructs for working with vtkDataArrays.
#define VTK_ITER_OPTIMIZE_START
#define VTK_ITER_INLINE
#define VTK_ITER_OPTIMIZE_END
#define VTK_DEPRECATED_IN_9_6_0(reason)