VTK  9.2.20220630
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 // Disable this specialization when iterator debugging is requested:
33 #ifndef VTK_DEBUG_RANGE_ITERATORS
34 
36 
37 namespace vtk
38 {
39 
40 namespace detail
41 {
42 
43 //------------------------------------------------------------------------------
44 // ValueRange
45 template <typename ValueTypeT, ComponentIdType TupleSize>
46 struct ValueRange<vtkAOSDataArrayTemplate<ValueTypeT>, TupleSize>
47 {
48 private:
49  static_assert(IsValidTupleSize<TupleSize>::value, "Invalid tuple size.");
50 
53 
54 public:
56  using ValueType = ValueTypeT;
57 
59  using ConstIteratorType = ValueType const*;
61  using ConstReferenceType = ValueType const&;
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 
108  ValueIdType GetBeginValueId() const noexcept
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 
142 private:
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:
150 template <typename ArrayType, ComponentIdType TupleSize,
151  // Convenience:
152  typename ValueType = typename ArrayType::ValueType,
153  typename AOSArrayType = vtkAOSDataArrayTemplate<ValueType>,
154  // SFINAE to select AOS arrays:
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.
@ 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
constexpr static ComponentIdType TupleSizeTag
ValueReference< ArrayType, TupleSize > ReferenceType
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