VTK
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:
157 ValueRange<AOSArrayType, TupleSize> DeclareValueRangeSpecialization(ArrayType*);
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
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::GetArray
VTK_ITER_INLINE ArrayType * GetArray() const noexcept
Definition: vtkDataArrayValueRange_AOS.h:103
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::GetSubRange
VTK_ITER_INLINE ValueRange GetSubRange(ValueIdType beginValue=0, ValueIdType endValue=-1) const noexcept
Definition: vtkDataArrayValueRange_AOS.h:91
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::cbegin
VTK_ITER_INLINE const_iterator cbegin() const noexcept
Definition: vtkDataArrayValueRange_AOS.h:134
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::size
VTK_ITER_INLINE size_type size() const noexcept
Definition: vtkDataArrayValueRange_AOS.h:121
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::const_iterator
ConstIteratorType const_iterator
Definition: vtkDataArrayValueRange_AOS.h:71
vtkDataArrayValueRange_Generic.h
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::ConstIteratorType
ValueType const * ConstIteratorType
Definition: vtkDataArrayValueRange_AOS.h:60
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::ConstReferenceType
ValueType const & ConstReferenceType
Definition: vtkDataArrayValueRange_AOS.h:62
vtkX3D::value
Definition: vtkX3D.h:226
vtkX3D::type
Definition: vtkX3D.h:522
VTK_ITER_OPTIMIZE_START
#define VTK_ITER_OPTIMIZE_START
Definition: vtkDataArrayMeta.h:54
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::end
VTK_ITER_INLINE iterator end() noexcept
Definition: vtkDataArrayValueRange_AOS.h:126
vtk::detail::ValueRange::ArrayType
ArrayTypeT ArrayType
Definition: vtkDataArrayValueRange_Generic.h:856
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::size_type
ValueIdType size_type
Definition: vtkDataArrayValueRange_AOS.h:69
vtk::ValueIdType
vtkIdType ValueIdType
Definition: vtkDataArrayMeta.h:70
vtkAOSDataArrayTemplate.h
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::const_reference
ConstReferenceType const_reference
Definition: vtkDataArrayValueRange_AOS.h:73
detail
Definition: vtkGenericDataArrayLookupHelper.h:31
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::GetTupleSize
VTK_ITER_INLINE ComponentIdType GetTupleSize() const noexcept
Definition: vtkDataArrayValueRange_AOS.h:106
vtk::ComponentIdType
int ComponentIdType
Definition: vtkDataArrayMeta.h:68
vtk::detail::ValueRange::IteratorType
ValueIterator< ArrayType, TupleSize > IteratorType
Definition: vtkDataArrayValueRange_Generic.h:859
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::begin
VTK_ITER_INLINE iterator begin() noexcept
Definition: vtkDataArrayValueRange_AOS.h:124
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::ReferenceType
ValueType & ReferenceType
Definition: vtkDataArrayValueRange_AOS.h:61
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::begin
VTK_ITER_INLINE const_iterator begin() const noexcept
Definition: vtkDataArrayValueRange_AOS.h:129
vtk::detail::ValueRange
Definition: vtkDataArrayValueRange_Generic.h:52
vtk::detail::IdStorage
Definition: vtkDataArrayValueRange_Generic.h:63
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::operator[]
VTK_ITER_INLINE reference operator[](size_type i) noexcept
Definition: vtkDataArrayValueRange_AOS.h:139
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::GetEndValueId
VTK_ITER_INLINE ValueIdType GetEndValueId() const noexcept
Definition: vtkDataArrayValueRange_AOS.h:115
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::operator[]
VTK_ITER_INLINE const_reference operator[](size_type i) const noexcept
Definition: vtkDataArrayValueRange_AOS.h:141
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::ValueType
ValueTypeT ValueType
Definition: vtkDataArrayValueRange_AOS.h:57
vtk::detail::ValueRange::TupleSizeTag
constexpr static ComponentIdType TupleSizeTag
Definition: vtkDataArrayValueRange_Generic.h:865
VTK_ITER_OPTIMIZE_END
#define VTK_ITER_OPTIMIZE_END
Definition: vtkDataArrayMeta.h:55
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::iterator
IteratorType iterator
Definition: vtkDataArrayValueRange_AOS.h:70
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::end
VTK_ITER_INLINE const_iterator end() const noexcept
Definition: vtkDataArrayValueRange_AOS.h:131
vtk::detail::ValueRange::ConstReferenceType
ConstValueReference< ArrayType, TupleSize > ConstReferenceType
Definition: vtkDataArrayValueRange_Generic.h:862
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::GetBeginValueId
VTK_ITER_INLINE ValueIdType GetBeginValueId() const noexcept
Definition: vtkDataArrayValueRange_AOS.h:109
vtk::detail::ValueRange::ConstIteratorType
ConstValueIterator< ArrayType, TupleSize > ConstIteratorType
Definition: vtkDataArrayValueRange_Generic.h:860
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::cend
VTK_ITER_INLINE const_iterator cend() const noexcept
Definition: vtkDataArrayValueRange_AOS.h:136
vtk
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
Definition: vtkAtomicTypeConcepts.h:21
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::value_type
ValueType value_type
Definition: vtkDataArrayValueRange_AOS.h:68
vtk::detail::IsValidTupleSize
Definition: vtkDataArrayMeta.h:92
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::reference
ReferenceType reference
Definition: vtkDataArrayValueRange_AOS.h:72
vtk::detail::ValueRange::ValueType
GetAPIType< ArrayTypeT > ValueType
Definition: vtkDataArrayValueRange_Generic.h:857
vtk::detail::ValueRange::ReferenceType
ValueReference< ArrayType, TupleSize > ReferenceType
Definition: vtkDataArrayValueRange_Generic.h:861
vtk::detail::ValueRange::ValueRange
VTK_ITER_INLINE ValueRange() noexcept=default
vtkAOSDataArrayTemplate
Array-Of-Structs implementation of vtkGenericDataArray.
Definition: vtkAOSDataArrayTemplate.h:41
vtkDataArrayMeta.h
VTK_ITER_INLINE
#define VTK_ITER_INLINE
Definition: vtkDataArrayMeta.h:52
vtk::detail::ValueRange< vtkAOSDataArrayTemplate< ValueTypeT >, TupleSize >::IteratorType
ValueType * IteratorType
Definition: vtkDataArrayValueRange_AOS.h:59
vtk::detail::GenericTupleSize
Definition: vtkDataArrayMeta.h:137
vtk::detail::DeclareValueRangeSpecialization
ValueRange< AOSArrayType, TupleSize > DeclareValueRangeSpecialization(ArrayType *)