VTK  9.3.0
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
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
33template <typename ValueTypeT, ComponentIdType TupleSize>
34struct ValueRange<vtkAOSDataArrayTemplate<ValueTypeT>, TupleSize>
35{
36private:
37 static_assert(IsValidTupleSize<TupleSize>::value, "Invalid tuple size.");
38
41
42public:
44 using ValueType = ValueTypeT;
45
50
51 // May be DynamicTupleSize, or the actual tuple size.
52 constexpr static ComponentIdType TupleSizeTag = TupleSize;
53
54 // STL-compat
61
63 ValueRange() noexcept = default;
64
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
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
90 ArrayType* GetArray() const noexcept { return this->Array; }
91
93 ComponentIdType GetTupleSize() const noexcept { return this->NumComps.value; }
94
97 {
98 return static_cast<ValueIdType>(this->Begin - this->Array->GetPointer(0));
99 }
100
102 ValueIdType GetEndValueId() const noexcept
103 {
104 return static_cast<ValueIdType>(this->End - this->Array->GetPointer(0));
105 }
106
108 size_type size() const noexcept { return static_cast<size_type>(this->End - this->Begin); }
109
111 iterator begin() noexcept { return this->Begin; }
113 iterator end() noexcept { return this->End; }
114
116 const_iterator begin() const noexcept { return this->Begin; }
118 const_iterator end() const noexcept { return this->End; }
119
121 const_iterator cbegin() const noexcept { return this->Begin; }
123 const_iterator cend() const noexcept { return this->End; }
124
126 reference operator[](size_type i) noexcept { return this->Begin[i]; }
128 const_reference operator[](size_type i) const noexcept { return this->Begin[i]; }
129
130private:
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:
138template <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>
145
146VTK_ABI_NAMESPACE_END
147}
148} // end namespace vtk::detail
149
151
152#endif // VTK_DEBUG_RANGE_ITERATORS
153#endif // vtkDataArrayValueRange_AOS_h
154
155// VTK-HeaderTest-Exclude: vtkDataArrayValueRange_AOS.h
Array-Of-Structs implementation of vtkGenericDataArray.
ValueRange< AOSArrayType, TupleSize > DeclareValueRangeSpecialization(ArrayType *)
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
vtkIdType ValueIdType
int ComponentIdType
VTK_ITER_INLINE ValueRange GetSubRange(ValueIdType beginValue=0, ValueIdType endValue=-1) const noexcept
VTK_ITER_INLINE const_reference operator[](size_type i) const noexcept
ConstValueReference< ArrayType, TupleSize > ConstReferenceType
ValueIterator< ArrayType, TupleSize > IteratorType
ValueReference< ArrayType, TupleSize > ReferenceType
static constexpr ComponentIdType TupleSizeTag
ConstValueIterator< ArrayType, TupleSize > ConstIteratorType
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