VTK  9.1.0
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=========================================================================*/
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#ifndef __VTK_WRAP__
33
34// Disable this specialization when iterator debugging is requested:
35#ifndef VTK_DEBUG_RANGE_ITERATORS
36
38
39namespace vtk
40{
41
42namespace detail
43{
44
45//------------------------------------------------------------------------------
46// ValueRange
47template <typename ValueTypeT, ComponentIdType TupleSize>
48struct ValueRange<vtkAOSDataArrayTemplate<ValueTypeT>, TupleSize>
49{
50private:
51 static_assert(IsValidTupleSize<TupleSize>::value, "Invalid tuple size.");
52
55
56public:
58 using ValueType = ValueTypeT;
59
64
65 // May be DynamicTupleSize, or the actual tuple size.
66 constexpr static ComponentIdType TupleSizeTag = TupleSize;
67
68 // STL-compat
75
77 ValueRange() noexcept = default;
78
80 ValueRange(ArrayType* arr, ValueIdType beginValue, ValueIdType endValue) noexcept
81 : Array(arr)
82 , NumComps(arr)
83 , Begin(arr->GetPointer(beginValue))
84 , End(arr->GetPointer(endValue))
85 {
86 assert(this->Array);
87 assert(beginValue >= 0 && beginValue <= endValue);
88 assert(endValue >= 0 && endValue <= this->Array->GetNumberOfValues());
89 }
90
92 ValueRange GetSubRange(ValueIdType beginValue = 0, ValueIdType endValue = -1) const noexcept
93 {
94 const ValueIdType realBegin =
95 std::distance(this->Array->GetPointer(0), this->Begin) + beginValue;
96 const ValueIdType realEnd = endValue >= 0
97 ? std::distance(this->Array->GetPointer(0), this->Begin) + endValue
98 : std::distance(this->Array->GetPointer(0), this->End);
99
100 return ValueRange{ this->Array, realBegin, realEnd };
101 }
102
104 ArrayType* GetArray() const noexcept { return this->Array; }
105
107 ComponentIdType GetTupleSize() const noexcept { return this->NumComps.value; }
108
111 {
112 return static_cast<ValueIdType>(this->Begin - this->Array->GetPointer(0));
113 }
114
116 ValueIdType GetEndValueId() const noexcept
117 {
118 return static_cast<ValueIdType>(this->End - this->Array->GetPointer(0));
119 }
120
122 size_type size() const noexcept { return static_cast<size_type>(this->End - this->Begin); }
123
125 iterator begin() noexcept { return this->Begin; }
127 iterator end() noexcept { return this->End; }
128
130 const_iterator begin() const noexcept { return this->Begin; }
132 const_iterator end() const noexcept { return this->End; }
133
135 const_iterator cbegin() const noexcept { return this->Begin; }
137 const_iterator cend() const noexcept { return this->End; }
138
140 reference operator[](size_type i) noexcept { return this->Begin[i]; }
142 const_reference operator[](size_type i) const noexcept { return this->Begin[i]; }
143
144private:
145 mutable ArrayType* Array{ nullptr };
146 NumCompsType NumComps{};
147 ValueType* Begin{ nullptr };
148 ValueType* End{ nullptr };
149};
150
151// Unimplemented, only used inside decltype in SelectValueRange:
152template <typename ArrayType, ComponentIdType TupleSize,
153 // Convenience:
154 typename ValueType = typename ArrayType::ValueType,
155 typename AOSArrayType = vtkAOSDataArrayTemplate<ValueType>,
156 // SFINAE to select AOS arrays:
159
160}
161} // end namespace vtk::detail
162
164
165#endif // VTK_DEBUG_RANGE_ITERATORS
166#endif // __VTK_WRAP__
167#endif // vtkDataArrayValueRange_AOS_h
168
169// VTK-HeaderTest-Exclude: vtkDataArrayValueRange_AOS.h
Array-Of-Structs implementation of vtkGenericDataArray.
@ value
Definition: vtkX3D.h:226
@ type
Definition: vtkX3D.h:522
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