VTK  9.0.1
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 
26 #include <algorithm>
27 #include <cassert>
28 #include <iterator>
29 #include <type_traits>
30 
31 #ifndef __VTK_WRAP__
32 
33 // Disable this specialization when iterator debugging is requested:
34 #ifndef VTK_DEBUG_RANGE_ITERATORS
35 
37 
38 namespace vtk
39 {
40 
41 namespace detail
42 {
43 
44 //------------------------------------------------------------------------------
45 // ValueRange
46 template <typename ValueTypeT, ComponentIdType TupleSize>
47 struct ValueRange<vtkAOSDataArrayTemplate<ValueTypeT>, TupleSize>
48 {
49 private:
50  static_assert(IsValidTupleSize<TupleSize>::value, "Invalid tuple size.");
51 
54 
55 public:
57  using ValueType = ValueTypeT;
58 
60  using ConstIteratorType = ValueType const*;
62  using ConstReferenceType = ValueType const&;
63 
64  // May be DynamicTupleSize, or the actual tuple size.
65  constexpr static ComponentIdType TupleSizeTag = TupleSize;
66 
67  // STL-compat
74 
76  ValueRange() noexcept = default;
77 
79  ValueRange(ArrayType* arr, ValueIdType beginValue, ValueIdType endValue) noexcept
80  : Array(arr)
81  , NumComps(arr)
82  , Begin(arr->GetPointer(beginValue))
83  , End(arr->GetPointer(endValue))
84  {
85  assert(this->Array);
86  assert(beginValue >= 0 && beginValue <= endValue);
87  assert(endValue >= 0 && endValue <= this->Array->GetNumberOfValues());
88  }
89 
91  ValueRange GetSubRange(ValueIdType beginValue = 0, ValueIdType endValue = -1) const noexcept
92  {
93  const ValueIdType realBegin =
94  std::distance(this->Array->GetPointer(0), this->Begin) + beginValue;
95  const ValueIdType realEnd = endValue >= 0
96  ? std::distance(this->Array->GetPointer(0), this->Begin) + endValue
97  : std::distance(this->Array->GetPointer(0), this->End);
98 
99  return ValueRange{ this->Array, realBegin, realEnd };
100  }
101 
103  ArrayType* GetArray() const noexcept { return this->Array; }
104 
106  ComponentIdType GetTupleSize() const noexcept { return this->NumComps.value; }
107 
109  ValueIdType GetBeginValueId() const noexcept
110  {
111  return static_cast<ValueIdType>(this->Begin - this->Array->GetPointer(0));
112  }
113 
115  ValueIdType GetEndValueId() const noexcept
116  {
117  return static_cast<ValueIdType>(this->End - this->Array->GetPointer(0));
118  }
119 
121  size_type size() const noexcept { return static_cast<size_type>(this->End - this->Begin); }
122 
124  iterator begin() noexcept { return this->Begin; }
126  iterator end() noexcept { return this->End; }
127 
129  const_iterator begin() const noexcept { return this->Begin; }
131  const_iterator end() const noexcept { return this->End; }
132 
134  const_iterator cbegin() const noexcept { return this->Begin; }
136  const_iterator cend() const noexcept { return this->End; }
137 
139  reference operator[](size_type i) noexcept { return this->Begin[i]; }
141  const_reference operator[](size_type i) const noexcept { return this->Begin[i]; }
142 
143 private:
144  mutable ArrayType* Array{ nullptr };
145  NumCompsType NumComps{};
146  ValueType* Begin{ nullptr };
147  ValueType* End{ nullptr };
148 };
149 
150 // Unimplemented, only used inside decltype in SelectValueRange:
151 template <typename ArrayType, ComponentIdType TupleSize,
152  // Convenience:
153  typename ValueType = typename ArrayType::ValueType,
154  typename AOSArrayType = vtkAOSDataArrayTemplate<ValueType>,
155  // SFINAE to select AOS arrays:
158 
159 }
160 } // end namespace vtk::detail
161 
163 
164 #endif // VTK_DEBUG_RANGE_ITERATORS
165 #endif // __VTK_WRAP__
166 #endif // vtkDataArrayValueRange_AOS_h
167 
168 // 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