VTK  9.2.6
vtkDataArrayValueRange_AOS.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkDataArrayValueRange_AOS.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=========================================================================*/
18
19#ifndef vtkDataArrayValueRange_AOS_h
20#define vtkDataArrayValueRange_AOS_h
21
23#include "vtkDataArrayMeta.h"
25#include "vtkDebugRangeIterators.h"
26
27#include <algorithm>
28#include <cassert>
29#include <iterator>
30#include <type_traits>
31
32// Disable this specialization when iterator debugging is requested:
33#ifndef VTK_DEBUG_RANGE_ITERATORS
34
36
37namespace vtk
38{
39
40namespace detail
41{
42
43//------------------------------------------------------------------------------
44// ValueRange
45template <typename ValueTypeT, ComponentIdType TupleSize>
46struct ValueRange<vtkAOSDataArrayTemplate<ValueTypeT>, TupleSize>
47{
48private:
49 static_assert(IsValidTupleSize<TupleSize>::value, "Invalid tuple size.");
50
51 using IdStorageType = IdStorage<TupleSize>;
52 using NumCompsType = GenericTupleSize<TupleSize>;
53
54public:
56 using ValueType = ValueTypeT;
57
62
63 // May be DynamicTupleSize, or the actual tuple size.
64 constexpr static ComponentIdType TupleSizeTag = TupleSize;
65
66 // STL-compat
73
75 ValueRange() noexcept = default;
76
78 ValueRange(ArrayType* arr, ValueIdType beginValue, ValueIdType endValue) noexcept
79 : Array(arr)
80 , NumComps(arr)
81 , Begin(arr->GetPointer(beginValue))
82 , End(arr->GetPointer(endValue))
83 {
84 assert(this->Array);
85 assert(beginValue >= 0 && beginValue <= endValue);
86 assert(endValue >= 0 && endValue <= this->Array->GetNumberOfValues());
87 }
88
90 ValueRange GetSubRange(ValueIdType beginValue = 0, ValueIdType endValue = -1) const noexcept
91 {
92 const ValueIdType realBegin =
93 std::distance(this->Array->GetPointer(0), this->Begin) + beginValue;
94 const ValueIdType realEnd = endValue >= 0
95 ? std::distance(this->Array->GetPointer(0), this->Begin) + endValue
96 : std::distance(this->Array->GetPointer(0), this->End);
97
98 return ValueRange{ this->Array, realBegin, realEnd };
99 }
100
102 ArrayType* GetArray() const noexcept { return this->Array; }
103
105 ComponentIdType GetTupleSize() const noexcept { return this->NumComps.value; }
106
109 {
110 return static_cast<ValueIdType>(this->Begin - this->Array->GetPointer(0));
111 }
112
114 ValueIdType GetEndValueId() const noexcept
115 {
116 return static_cast<ValueIdType>(this->End - this->Array->GetPointer(0));
117 }
118
120 size_type size() const noexcept { return static_cast<size_type>(this->End - this->Begin); }
121
123 iterator begin() noexcept { return this->Begin; }
125 iterator end() noexcept { return this->End; }
126
128 const_iterator begin() const noexcept { return this->Begin; }
130 const_iterator end() const noexcept { return this->End; }
131
133 const_iterator cbegin() const noexcept { return this->Begin; }
135 const_iterator cend() const noexcept { return this->End; }
136
138 reference operator[](size_type i) noexcept { return this->Begin[i]; }
140 const_reference operator[](size_type i) const noexcept { return this->Begin[i]; }
141
142private:
143 mutable ArrayType* Array{ nullptr };
144 NumCompsType NumComps{};
145 ValueType* Begin{ nullptr };
146 ValueType* End{ nullptr };
147};
148
149// Unimplemented, only used inside decltype in SelectValueRange:
150template <typename ArrayType, ComponentIdType TupleSize,
151 // Convenience:
152 typename ValueType = typename ArrayType::ValueType,
153 typename AOSArrayType = vtkAOSDataArrayTemplate<ValueType>,
154 // SFINAE to select AOS arrays:
155 typename = typename std::enable_if<IsAOSDataArray<ArrayType>::value>::type>
157
158}
159} // end namespace vtk::detail
160
162
163#endif // VTK_DEBUG_RANGE_ITERATORS
164#endif // vtkDataArrayValueRange_AOS_h
165
166// 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.
int ComponentIdType
vtkIdType ValueIdType
VTK_ITER_INLINE ValueRange GetSubRange(ValueIdType beginValue=0, ValueIdType endValue=-1) const noexcept
VTK_ITER_INLINE const_reference operator[](size_type i) 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