VTK  9.7.20260716
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
151private:
152 mutable ArrayType* Array{ nullptr };
153 NumCompsType NumComps{};
154 ValueIdType BeginValue{ 0 };
155 ValueIdType EndValue{ 0 };
156};
157
158// Unimplemented, only used inside decltype in SelectValueRange:
159template <typename ArrayType, ComponentIdType TupleSize, typename ForceValueTypeForVtkDataArray,
160 // Convenience:
161 typename ValueType = typename ArrayType::ValueType,
162 typename AOSArrayType = vtkAOSDataArrayTemplate<ValueType>,
163 // SFINAE to select AOS arrays:
164 typename = typename std::enable_if<IsAOSDataArray<ArrayType>::value>::type>
166 ArrayType*);
167
168VTK_ABI_NAMESPACE_END
169}
170} // end namespace vtk::detail
171
173
174#endif // VTK_DEBUG_RANGE_ITERATORS
175#endif // vtkDataArrayValueRange_AOS_h
176
177// 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