VTK  9.5.20251022
vtkDataArrayValueRange_Generic.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
8#ifndef vtkDataArrayValueRange_Generic_h
9#define vtkDataArrayValueRange_Generic_h
10
12#include "vtkDataArrayMeta.h"
13
14#include <algorithm>
15#include <cassert>
16#include <iterator>
17#include <tuple>
18#include <type_traits>
19
21
22namespace vtk
23{
24namespace detail
25{
26VTK_ABI_NAMESPACE_BEGIN
27
28// Forward decs for friends/args
29template <typename ArrayType, ComponentIdType, typename ForceValueTypeForVtkDataArray>
30struct ValueReference;
31template <typename ArrayType, ComponentIdType, typename ForceValueTypeForVtkDataArray>
32struct ConstValueReference;
33template <typename ArrayType, ComponentIdType, typename ForceValueTypeForVtkDataArray>
34struct ValueIterator;
35template <typename ArrayType, ComponentIdType, typename ForceValueTypeForVtkDataArray>
36struct ConstValueIterator;
37template <typename ArrayType, ComponentIdType, typename ForceValueTypeForVtkDataArray>
38struct ValueRange;
39
40//------------------------------------------------------------------------------
41// Helper that converts ValueId <--> { TupleId, ComponentId }
42// This class stores both representations. Profiling and assembly inspection
43// show that ValueId is much more efficient for comparing Ids, while Tuple/Comp
44// ids are much faster for looking up elements (especially when considering
45// SOA arrays). The overhead of maintaining both is low, and this class is
46// transparent enough that the compiler will produce efficient ASM with
47// simple optimizations enabled.
48template <ComponentIdType TupleSize>
50{
52
54 IdStorage() noexcept
55 : ValueId(0)
56 , TupleId(0)
57 , ComponentId(0)
58 {
59 }
60
62 IdStorage(ValueIdType valueId, NumCompsType numComps) noexcept
63 : ValueId(valueId)
64 , TupleId(static_cast<TupleIdType>(valueId) / static_cast<TupleIdType>(numComps.value))
65 , ComponentId(static_cast<ComponentIdType>(valueId % static_cast<ValueIdType>(numComps.value)))
66 , NumComps(numComps)
67 {
68 }
69
71 IdStorage(TupleIdType tupleId, ComponentIdType comp, NumCompsType numComps) noexcept
72 : ValueId(tupleId * numComps.value + comp)
73 , TupleId(tupleId)
74 , ComponentId(comp)
75 , NumComps(numComps)
76 {
77 }
78
81 ValueIdType valueId, TupleIdType tupleId, ComponentIdType comp, NumCompsType numComps) noexcept
82 : ValueId(valueId)
83 , TupleId(tupleId)
84 , ComponentId(comp)
85 , NumComps(numComps)
86 {
87 }
88
89 template <typename ArrayType>
90 VTK_ITER_INLINE void DebugAsserts(ArrayType* array) const noexcept
91 {
92 (void)array;
93 VTK_ITER_ASSERT(array != nullptr, "Invalid array.");
94 VTK_ITER_ASSERT(this->ValueId == this->TupleId * this->GetTupleSize() + this->ComponentId,
95 "Inconsistent internal state in IdStorage.");
96 VTK_ITER_ASSERT(this->GetTupleSize() > 0, "Invalid number of components.");
98 this->ValueId >= 0 && this->ValueId <= array->GetNumberOfValues(), "Invalid value id.");
99 VTK_ITER_ASSERT(this->GetTupleId() >= 0 && this->GetTupleId() <= array->GetNumberOfTuples(),
100 "Invalid tuple id.");
101 VTK_ITER_ASSERT(this->GetComponentId() >= 0 &&
102 (this->GetComponentId() < this->GetTupleSize() ||
103 (this->GetComponentId() == this->GetTupleSize() &&
104 this->GetTupleId() == array->GetNumberOfTuples())),
105 "Invalid component id.");
106 VTK_ITER_ASSERT(this->GetValueId() >= 0 && this->GetValueId() <= array->GetNumberOfValues(),
107 "Invalid value id.");
108 }
109
111 IdStorage& operator++() noexcept // prefix
112 {
113 ++this->ValueId;
114 ++this->ComponentId;
115 if (this->ComponentId == this->GetTupleSize())
116 {
117 this->ComponentId = 0;
118 ++this->TupleId;
119 }
120 return *this;
121 }
122
124 IdStorage operator++(int) noexcept // postfix
125 {
126 auto v = this->ValueId++;
127 auto t = this->TupleId;
128 auto c = this->ComponentId++;
129 if (this->ComponentId == this->GetTupleSize())
130 {
131 this->ComponentId = 0;
132 ++this->TupleId;
133 }
134 return IdStorage{ v, t, c, this->NumComps };
135 }
136
137 friend VTK_ITER_INLINE IdStorage operator+(const IdStorage& id, ValueIdType offset) noexcept
138 {
139 IdStorage res = id;
140 res.AddOffset(offset);
141 return res;
142 }
143
145 IdStorage& operator--() noexcept // prefix
146 {
147 --this->ValueId;
148 --this->ComponentId;
149 if (this->ComponentId < 0)
150 {
151 this->ComponentId = this->GetTupleSize() - 1;
152 --this->TupleId;
153 }
154 return *this;
155 }
156
158 IdStorage operator--(int) noexcept // postfix
159 {
160 auto v = this->ValueId--;
161 auto t = this->TupleId;
162 auto c = this->ComponentId--;
163 if (this->ComponentId < 0)
164 {
165 this->ComponentId = this->GetTupleSize() - 1;
166 --this->TupleId;
167 }
168 return IdStorage{ v, t, c, this->NumComps };
169 }
170
172 ValueIdType Convert(TupleIdType tuple, ComponentIdType comp) const noexcept
173 {
174 return static_cast<ValueIdType>(tuple) * this->NumComps.value + comp;
175 }
176
178 std::pair<TupleIdType, ComponentIdType> Convert(ValueIdType value) const noexcept
179 {
180 return std::make_pair(static_cast<TupleIdType>(value / this->NumComps.value),
181 static_cast<ComponentIdType>(value % this->NumComps.value));
182 }
183
185 void AddOffset(ValueIdType offset) noexcept
186 {
187 this->ValueId += offset;
188 std::tie(this->TupleId, this->ComponentId) = this->Convert(this->ValueId);
189 }
190
192 ComponentIdType GetTupleSize() const noexcept { return this->NumComps.value; }
193
195 TupleIdType GetTupleId() const noexcept { return this->TupleId; }
196
198 ComponentIdType GetComponentId() const noexcept { return this->ComponentId; }
199
201 ValueIdType GetValueId() const noexcept { return this->ValueId; }
202
203 friend VTK_ITER_INLINE void swap(IdStorage& lhs, IdStorage& rhs) noexcept
204 {
205 using std::swap;
206 swap(lhs.ValueId, rhs.ValueId);
207 swap(lhs.TupleId, rhs.TupleId);
208 swap(lhs.ComponentId, rhs.ComponentId);
209 }
210
211private:
212 vtk::ValueIdType ValueId;
213 vtk::TupleIdType TupleId;
214 vtk::ComponentIdType ComponentId;
215 NumCompsType NumComps;
216};
217
218//------------------------------------------------------------------------------
219// Value reference
220template <typename ArrayType, ComponentIdType TupleSize, typename ForceValueTypeForVtkDataArray>
222{
223private:
224 static_assert(IsValidTupleSize<TupleSize>::value, "Invalid tuple size.");
225 static_assert(IsVtkDataArray<ArrayType>::value, "Invalid array type.");
226
229
230public:
231 using value_type = APIType;
232
235 : Array{ nullptr }
236 , Id{}
237 {
238 }
239
241 ConstValueReference(ArrayType* array, IdStorageType id) noexcept
242 : Array{ array }
243 , Id{ id }
244 {
245 this->Id.DebugAsserts(array);
246 }
247
250 : Array{ o.Array }
251 , Id{ o.Id }
252 {
253 }
254
256 ConstValueReference(const ConstValueReference& o) noexcept = default;
257
260
263 {
264 VTK_ITER_ASSERT(!this->Array, "Const reference already initialized.");
265 // Initialize the reference.
266 this->Array = o.Array;
267 this->Id = o.Id;
268 return *this;
269 }
270
273 {
274 VTK_ITER_ASSERT(!this->Array, "Const reference already initialized.");
275 // Initialize the reference.
276 this->Array = std::move(o.Array);
277 this->Id = std::move(o.Id);
278 return *this;
279 }
280
281 VTK_ITER_INLINE operator APIType() const noexcept
282 {
283 VTK_ITER_ASSUME(this->Id.GetTupleSize() > 0);
284 VTK_ITER_ASSUME(this->Array->GetNumberOfComponents() == this->Id.GetTupleSize());
285 if constexpr (std::is_same_v<ArrayType, vtkDataArray>)
286 {
287 return this->Array->GetComponent(this->Id.GetTupleId(), this->Id.GetComponentId());
288 }
289 else if constexpr (TupleSize == 1)
290 {
291 return this->Array->GetValue(this->Id.GetValueId());
292 }
293 else
294 {
295 return this->Array->GetTypedComponent(this->Id.GetTupleId(), this->Id.GetComponentId());
296 }
297 }
298
299 mutable ArrayType* Array;
301};
302
303//------------------------------------------------------------------------------
304// Value reference
305template <typename ArrayType, ComponentIdType TupleSize, typename ForceValueTypeForVtkDataArray>
307{
308private:
309 static_assert(IsValidTupleSize<TupleSize>::value, "Invalid tuple size.");
310 static_assert(IsVtkDataArray<ArrayType>::value, "Invalid array type.");
311
314
315public:
316 using value_type = APIType;
317
319 ValueReference() noexcept
320 : Array{ nullptr }
321 , Id{}
322 {
323 }
324
326 ValueReference(ArrayType* array, IdStorageType id) noexcept
327 : Array{ array }
328 , Id{ id }
329 {
330 this->Id.DebugAsserts(this->Array);
331 }
332
334 ValueReference(const ValueReference& o) noexcept = default;
336 ValueReference(ValueReference&& o) noexcept = default;
337
340 {
341 if (this->Array)
342 { // Already initialized. Assign the value, not the reference:
343 return *this = static_cast<APIType>(o);
344 }
345 else
346 { // Initialize the reference:
347 this->Array = o.Array;
348 this->Id = o.Id;
349 return *this;
350 }
351 }
352
355 {
356 if (this->Array)
357 { // Already initialized. Assign the value, not the reference:
358 return *this = static_cast<APIType>(o);
359 }
360 else
361 { // Initialize the reference:
362 this->Array = std::move(o.Array);
363 this->Id = std::move(o.Id);
364 return *this;
365 }
366 }
367
368 template <typename OArray, ComponentIdType OSize>
371 { // Always copy the value for different reference types:
372 const APIType tmp = o;
373 return *this = std::move(tmp);
374 }
375
376 VTK_ITER_INLINE operator APIType() const noexcept
377 {
378 VTK_ITER_ASSUME(this->Id.GetTupleSize() > 0);
379 VTK_ITER_ASSUME(this->Array->GetNumberOfComponents() == this->Id.GetTupleSize());
380 if constexpr (std::is_same_v<ArrayType, vtkDataArray>)
381 {
382 return this->Array->GetComponent(this->Id.GetTupleId(), this->Id.GetComponentId());
383 }
384 else if constexpr (TupleSize == 1)
385 {
386 return this->Array->GetValue(this->Id.GetValueId());
387 }
388 else
389 {
390 return this->Array->GetTypedComponent(this->Id.GetTupleId(), this->Id.GetComponentId());
391 }
392 }
393
395 {
396 VTK_ITER_ASSUME(this->Id.GetTupleSize() > 0);
397 VTK_ITER_ASSUME(this->Array->GetNumberOfComponents() == this->Id.GetTupleSize());
398 if constexpr (std::is_same_v<ArrayType, vtkDataArray>)
399 {
400 this->Array->SetComponent(this->Id.GetTupleId(), this->Id.GetComponentId(), val);
401 }
402 else if constexpr (TupleSize == 1)
403 {
404 this->Array->SetValue(this->Id.GetValueId(), val);
405 }
406 else
407 {
408 this->Array->SetTypedComponent(this->Id.GetTupleId(), this->Id.GetComponentId(), val);
409 }
410 return *this;
411 }
412
413 friend VTK_ITER_INLINE void swap(ValueReference lhs, ValueReference rhs) noexcept
414 { // Swap values, not references:
415 APIType tmp = std::move(static_cast<APIType>(lhs));
416 lhs = std::move(static_cast<APIType>(rhs));
417 rhs = std::move(tmp);
418 }
419
420 template <typename OArray, ComponentIdType OSize>
423 { // Swap values, not references:
424 using OAPIType =
426 static_assert(
427 std::is_same<APIType, OAPIType>::value, "Cannot swap components with different types.");
428
429 APIType tmp = std::move(static_cast<APIType>(lhs));
430 lhs = std::move(static_cast<APIType>(rhs));
431 rhs = std::move(tmp);
432 }
433
434 friend VTK_ITER_INLINE void swap(ValueReference lhs, APIType& rhs) noexcept
435 {
436 APIType tmp = std::move(static_cast<APIType>(lhs));
437 lhs = std::move(rhs);
438 rhs = std::move(tmp);
439 }
440
441 friend VTK_ITER_INLINE void swap(APIType& lhs, ValueReference rhs) noexcept
442 {
443 APIType tmp = std::move(lhs);
444 lhs = std::move(static_cast<APIType>(rhs));
445 rhs = std::move(tmp);
446 }
447
449 ValueReference operator++() noexcept // prefix
450 {
451 const APIType newVal = *this + 1;
452 *this = newVal;
453 return *this;
454 }
455
457 APIType operator++(int) noexcept // postfix
458 {
459 const APIType retVal = *this;
460 *this = *this + 1;
461 return retVal;
462 }
463
465 ValueReference operator--() noexcept // prefix
466 {
467 const APIType newVal = *this - 1;
468 *this = newVal;
469 return *this;
470 }
471
473 APIType operator--(int) noexcept // postfix
474 {
475 const APIType retVal = *this;
476 *this = *this - 1;
477 return retVal;
478 }
479
480#define VTK_REF_OP_OVERLOADS(Op, ImplOp) \
481 friend VTK_ITER_INLINE ValueReference operator Op(ValueReference lhs, APIType val) noexcept \
482 { \
483 const APIType newVal = lhs ImplOp val; \
484 lhs = newVal; \
485 return lhs; \
486 } \
487 friend VTK_ITER_INLINE ValueReference operator Op( \
488 ValueReference lhs, ValueReference val) noexcept \
489 { \
490 const APIType newVal = lhs ImplOp val; \
491 lhs = newVal; \
492 return lhs; \
493 } \
494 friend VTK_ITER_INLINE APIType& operator Op(APIType& lhs, ValueReference val) noexcept \
495 { \
496 const APIType newVal = lhs ImplOp val; \
497 lhs = newVal; \
498 return lhs; \
499 }
500
505
506#undef VTK_REF_OP_OVERLOADS
507
508 friend struct ConstValueReference<ArrayType, TupleSize, ForceValueTypeForVtkDataArray>;
509 friend struct ValueIterator<ArrayType, TupleSize, ForceValueTypeForVtkDataArray>;
510
511protected:
512 void CopyReference(const ValueReference& o) noexcept
513 {
514 this->Array = o.Array;
515 this->Id = o.Id;
516 }
517
518 mutable ArrayType* Array;
520};
521
522//------------------------------------------------------------------------------
523// Const value iterator
524template <typename ArrayType, ComponentIdType TupleSize, typename ForceValueTypeForVtkDataArray>
526{
527private:
528 static_assert(IsValidTupleSize<TupleSize>::value, "Invalid tuple size.");
529 static_assert(IsVtkDataArray<ArrayType>::value, "Invalid array type.");
530
533
534public:
535 using iterator_category = std::random_access_iterator_tag;
536 using value_type = APIType;
538 using pointer = void;
540
543 : Array(nullptr)
544 , Id()
545 {
546 }
547
549 ConstValueIterator(ArrayType* array, IdStorageType id) noexcept
550 : Array(array)
551 , Id(id)
552 {
553 this->Id.DebugAsserts(this->Array);
554 }
555
559 : Array{ o.GetArray() }
560 , Id{ o.GetId() }
561 {
562 }
563
565 ConstValueIterator(const ConstValueIterator& o) noexcept = default;
567 ConstValueIterator& operator=(const ConstValueIterator& o) noexcept = default;
568
570 ConstValueIterator& operator++() noexcept // prefix
571 {
572 ++this->Id;
573 this->Id.DebugAsserts(this->Array);
574 return *this;
575 }
576
578 ConstValueIterator operator++(int) noexcept // postfix
579 {
580 auto ret = this->Id++;
581 this->Id.DebugAsserts(this->Array);
582 return ConstValueIterator{ this->Array, ret };
583 }
584
586 ConstValueIterator& operator--() noexcept // prefix
587 {
588 --this->Id;
589 this->Id.DebugAsserts(this->Array);
590 return *this;
591 }
592
594 ConstValueIterator operator--(int) noexcept // postfix
595 {
596 auto ret = this->Id--;
597 this->Id.DebugAsserts(this->Array);
598 return ConstValueIterator{ this->Array, ret };
599 }
600
603 {
604 return reference{ this->Array, this->Id + i };
605 }
606
608 reference operator*() const noexcept { return reference{ this->Array, this->Id }; }
609
610 // Using GetValueType here makes iteration 50% faster by reducing comparisons
611 // and jumps (instead of comparing std::tie(tupleId, compId)).
612#define VTK_TMP_MAKE_OPERATOR(OP) \
613 friend VTK_ITER_INLINE bool operator OP( \
614 const ConstValueIterator& lhs, const ConstValueIterator& rhs) noexcept \
615 { \
616 VTK_ITER_ASSERT(lhs.Array == rhs.Array, "Mismatched arrays in iterator comparison."); \
617 return lhs.Id.GetValueId() OP rhs.Id.GetValueId(); \
618 }
619
626
627#undef VTK_TMP_MAKE_OPERATOR
628
631 {
632 this->Id.AddOffset(offset);
633 this->Id.DebugAsserts(this->Array);
634 return *this;
635 }
636
638 const ConstValueIterator& it, difference_type offset) noexcept
639 {
640 return ConstValueIterator{ it.Array, it.Id + offset };
641 }
642
644 difference_type offset, const ConstValueIterator& it) noexcept
645 {
646 return ConstValueIterator{ it.Array, it.Id + offset };
647 }
648
651 {
652 this->Id.AddOffset(-offset);
653 this->Id.DebugAsserts(this->Array);
654 return *this;
655 }
656
658 const ConstValueIterator& it, difference_type offset) noexcept
659 {
660 return ConstValueIterator{ it.Array, it.Id + (-offset) };
661 }
662
664 const ConstValueIterator& it1, const ConstValueIterator& it2) noexcept
665 {
666 VTK_ITER_ASSERT(it1.Array == it2.Array, "Cannot do math with iterators from different arrays.");
667 return it1.Id.GetValueId() - it2.Id.GetValueId();
668 }
669
671 {
672 // Different arrays may use different iterator implementations.
673 VTK_ITER_ASSERT(lhs.Array == rhs.Array, "Cannot swap iterators from different arrays.");
674
675 using std::swap;
676 swap(lhs.Id, rhs.Id);
677 }
678
679private:
680 mutable ArrayType* Array;
681 IdStorageType Id;
682};
683
684//------------------------------------------------------------------------------
685// Component iterator
686template <typename ArrayType, ComponentIdType TupleSize, typename ForceValueTypeForVtkDataArray>
688{
689private:
690 static_assert(IsValidTupleSize<TupleSize>::value, "Invalid tuple size.");
691 static_assert(IsVtkDataArray<ArrayType>::value, "Invalid array type.");
692
695
696public:
697 using iterator_category = std::random_access_iterator_tag;
702
704 ValueIterator() noexcept = default;
705
707 ValueIterator(ArrayType* array, IdStorageType id) noexcept
708 : Ref{ array, id }
709 {
710 this->DebugIdAsserts();
711 }
712
714 ValueIterator(const ValueIterator& o) noexcept = default;
715
718 {
719 this->Ref.CopyReference(o.Ref);
720 this->DebugIdAsserts();
721 return *this;
722 }
723
725 ValueIterator& operator++() noexcept // prefix
726 {
727 ++this->Ref.Id;
728 this->DebugIdAsserts();
729 return *this;
730 }
731
733 ValueIterator operator++(int) noexcept // postfix
734 {
735 auto ret = this->Ref.Id++;
736 this->DebugIdAsserts();
737 return ValueIterator{ this->Ref.Array, ret };
738 }
739
741 ValueIterator& operator--() noexcept // prefix
742 {
743 --this->Ref.Id;
744 this->DebugIdAsserts();
745 return *this;
746 }
747
749 ValueIterator operator--(int) noexcept // postfix
750 {
751 auto ret = this->Ref.Id--;
752 this->DebugIdAsserts();
753 return ValueIterator{ this->Ref.Array, ret };
754 }
755
758 {
759 return reference{ this->Ref.Array, this->Ref.Id + i };
760 }
761
763 reference operator*() const noexcept { return this->Ref; }
764
766 const pointer& operator->() const noexcept { return this->Ref; }
767
768#define VTK_TMP_MAKE_OPERATOR(OP) \
769 friend VTK_ITER_INLINE bool operator OP( \
770 const ValueIterator& lhs, const ValueIterator& rhs) noexcept \
771 { \
772 VTK_ITER_ASSERT( \
773 lhs.GetArray() == rhs.GetArray(), "Mismatched arrays in iterator comparison."); \
774 return lhs.GetId().GetValueId() OP rhs.GetId().GetValueId(); \
775 }
776
783
784#undef VTK_TMP_MAKE_OPERATOR
785
788 {
789 this->Ref.Id.AddOffset(offset);
790 this->DebugIdAsserts();
791 return *this;
792 }
793
795 const ValueIterator& it, difference_type offset) noexcept
796 {
797 return ValueIterator{ it.GetArray(), it.GetId() + offset };
798 }
799
801 difference_type offset, const ValueIterator& it) noexcept
802 {
803 return ValueIterator{ it.GetArray(), it.GetId() + offset };
804 }
805
808 {
809 this->Ref.Id.AddOffset(-offset);
810 this->Ref.Id.DebugAsserts(this->Ref.Array);
811 return *this;
812 }
813
815 const ValueIterator& it, difference_type offset) noexcept
816 {
817 return ValueIterator{ it.GetArray(), it.GetId() + (-offset) };
818 }
819
821 const ValueIterator& it1, const ValueIterator& it2) noexcept
822 {
824 it1.Ref.Array == it2.Ref.Array, "Cannot do math with iterators from different arrays.");
825 return it1.GetId().GetValueId() - it2.GetId().GetValueId();
826 }
827
828 friend VTK_ITER_INLINE void swap(ValueIterator& lhs, ValueIterator& rhs) noexcept
829 {
830 // Different arrays may use different iterator implementations.
832 lhs.GetArray() == rhs.GetArray(), "Cannot swap iterators from different arrays.");
833
834 using std::swap;
835 swap(lhs.GetId(), rhs.GetId());
836 }
837
838 friend struct ConstValueIterator<ArrayType, TupleSize, ForceValueTypeForVtkDataArray>;
839
840protected:
842 void DebugIdAsserts() const { this->Ref.Id.DebugAsserts(this->Ref.Array); }
843
844 // Needed for access from friend functions. We could just store the array
845 // and ID here instead of the ref, but meh.
846 ArrayType* GetArray() const noexcept { return this->Ref.Array; }
847 IdStorageType& GetId() noexcept { return this->Ref.Id; }
848 const IdStorageType& GetId() const noexcept { return this->Ref.Id; }
849
851};
852
853//------------------------------------------------------------------------------
854// ValueRange
855template <typename ArrayTypeT, ComponentIdType TupleSize, typename ForceValueTypeForVtkDataArray>
857{
858private:
859 static_assert(IsValidTupleSize<TupleSize>::value, "Invalid tuple size.");
860 static_assert(IsVtkDataArray<ArrayTypeT>::value, "Invalid array type.");
861
864
865public:
866 using ArrayType = ArrayTypeT;
868
874
875 // May be DynamicTupleSize, or the actual tuple size.
876 constexpr static ComponentIdType TupleSizeTag = TupleSize;
877
878 // STL-compat
885
887 ValueRange() noexcept = default;
888
890 ValueRange(ArrayType* arr, ValueIdType beginValue, ValueIdType endValue) noexcept
891 : Array(arr)
892 , NumComps(arr)
893 , BeginValue(beginValue, this->NumComps)
894 , EndValue(endValue, this->NumComps)
895 {
896 assert(this->Array);
897 assert(beginValue >= 0 && beginValue <= endValue);
898 assert(endValue >= 0 && endValue <= this->Array->GetNumberOfValues());
899 }
900
902 ValueRange GetSubRange(ValueIdType beginValue = 0, ValueIdType endValue = -1) const noexcept
903 {
904 const ValueIdType realBegin = this->BeginValue.GetValueId() + beginValue;
905 const ValueIdType realEnd =
906 endValue >= 0 ? this->BeginValue.GetValueId() + endValue : this->EndValue.GetValueId();
907
908 return ValueRange{ this->Array, realBegin, realEnd };
909 }
910
912 ArrayType* GetArray() const noexcept { return this->Array; }
914 ComponentIdType GetTupleSize() const noexcept { return this->NumComps.value; }
915
917 ValueIdType GetBeginValueId() const noexcept { return this->BeginValue.GetValueId(); }
918
920 ValueIdType GetEndValueId() const noexcept { return this->EndValue.GetValueId(); }
921
923 size_type size() const noexcept
924 {
925 return this->EndValue.GetValueId() - this->BeginValue.GetValueId();
926 }
927
929 iterator begin() noexcept { return this->NewIterator(this->BeginValue); }
931 iterator end() noexcept { return this->NewIterator(this->EndValue); }
932
934 const_iterator begin() const noexcept { return this->NewConstIterator(this->BeginValue); }
936 const_iterator end() const noexcept { return this->NewConstIterator(this->EndValue); }
937
939 const_iterator cbegin() const noexcept { return this->NewConstIterator(this->BeginValue); }
941 const_iterator cend() const noexcept { return this->NewConstIterator(this->EndValue); }
942
945 {
946 return reference{ this->Array, this->BeginValue + i };
947 }
950 {
951 return const_reference{ this->Array, this->BeginValue + i };
952 }
953
955
962 VTK_DEPRECATED_IN_9_6_0("Use iterators instead.")
963 value_type* data() noexcept
964 {
965 return reinterpret_cast<value_type*>(this->Array->GetVoidPointer(0));
966 }
967 VTK_DEPRECATED_IN_9_6_0("Use iterators instead.")
968 value_type* data() const noexcept
969 {
970 return reinterpret_cast<value_type*>(this->Array->GetVoidPointer(0));
971 }
973
974private:
976 iterator NewIterator(IdStorageType id) const noexcept { return iterator{ this->Array, id }; }
977
979 const_iterator NewConstIterator(IdStorageType id) const noexcept
980 {
981 return const_iterator{ this->Array, id };
982 }
983
984 mutable ArrayType* Array{ nullptr };
985 NumCompsType NumComps{};
986 IdStorageType BeginValue{};
987 IdStorageType EndValue{};
988};
989
990// Unimplemented, only used inside decltype in SelectValueRange:
991template <typename ArrayType, ComponentIdType TupleSize, typename ForceValueTypeForVtkDataArray>
993 vtkDataArray*);
994
995VTK_ABI_NAMESPACE_END
996} // end namespace detail
997} // end namespace vtk
998
1000
1001#endif // vtkDataArrayValueRange_Generic_h
1002
1003// VTK-HeaderTest-Exclude: vtkDataArrayValueRange_Generic.h
abstract superclass for arrays of numeric data
ValueRange< AOSArrayType, TupleSize, ForceValueTypeForVtkDataArray > DeclareValueRangeSpecialization(ArrayType *)
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
vtkIdType ValueIdType
typename detail::GetAPITypeImpl< ArrayType, ForceValueTypeForVtkDataArray >::APIType GetAPIType
vtkIdType TupleIdType
int ComponentIdType
friend VTK_ITER_INLINE void swap(ConstValueIterator &lhs, ConstValueIterator &rhs) noexcept
VTK_ITER_INLINE reference operator*() const noexcept
VTK_ITER_INLINE ConstValueIterator(const ValueIterator< ArrayType, TupleSize, ForceValueTypeForVtkDataArray > &o) noexcept
VTK_ITER_INLINE ConstValueIterator operator++(int) noexcept
friend VTK_ITER_INLINE ConstValueIterator operator-(const ConstValueIterator &it, difference_type offset) noexcept
std::random_access_iterator_tag iterator_category
VTK_ITER_INLINE reference operator[](difference_type i) const noexcept
friend VTK_ITER_INLINE difference_type operator-(const ConstValueIterator &it1, const ConstValueIterator &it2) noexcept
VTK_ITER_INLINE ConstValueIterator operator--(int) noexcept
VTK_ITER_INLINE ConstValueIterator & operator-=(difference_type offset) noexcept
friend VTK_ITER_INLINE ConstValueIterator operator+(const ConstValueIterator &it, difference_type offset) noexcept
VTK_ITER_INLINE ConstValueIterator & operator--() noexcept
VTK_ITER_INLINE ConstValueIterator & operator++() noexcept
VTK_ITER_INLINE ConstValueIterator(const ConstValueIterator &o) noexcept=default
VTK_ITER_INLINE ConstValueIterator & operator=(const ConstValueIterator &o) noexcept=default
VTK_ITER_INLINE ConstValueIterator(ArrayType *array, IdStorageType id) noexcept
VTK_ITER_INLINE ConstValueIterator & operator+=(difference_type offset) noexcept
friend VTK_ITER_INLINE ConstValueIterator operator+(difference_type offset, const ConstValueIterator &it) noexcept
VTK_ITER_INLINE ConstValueReference(const ConstValueReference &o) noexcept=default
VTK_ITER_INLINE ConstValueReference(const ValueReference< ArrayType, TupleSize, ForceValueTypeForVtkDataArray > &o)
VTK_ITER_INLINE ConstValueReference(ArrayType *array, IdStorageType id) noexcept
VTK_ITER_INLINE ConstValueReference(ConstValueReference &&o) noexcept=default
VTK_ITER_INLINE ConstValueReference operator=(const ConstValueReference &o) noexcept
VTK_ITER_INLINE ConstValueReference operator=(ConstValueReference &&o) noexcept
GenericTupleSize< TupleSize > NumCompsType
VTK_ITER_INLINE ComponentIdType GetComponentId() const noexcept
VTK_ITER_INLINE IdStorage operator--(int) noexcept
VTK_ITER_INLINE IdStorage(ValueIdType valueId, NumCompsType numComps) noexcept
VTK_ITER_INLINE IdStorage & operator++() noexcept
VTK_ITER_INLINE std::pair< TupleIdType, ComponentIdType > Convert(ValueIdType value) const noexcept
VTK_ITER_INLINE void DebugAsserts(ArrayType *array) const noexcept
VTK_ITER_INLINE void AddOffset(ValueIdType offset) noexcept
VTK_ITER_INLINE IdStorage operator++(int) noexcept
VTK_ITER_INLINE IdStorage & operator--() noexcept
VTK_ITER_INLINE IdStorage() noexcept
VTK_ITER_INLINE ComponentIdType GetTupleSize() const noexcept
friend VTK_ITER_INLINE void swap(IdStorage &lhs, IdStorage &rhs) noexcept
friend VTK_ITER_INLINE IdStorage operator+(const IdStorage &id, ValueIdType offset) noexcept
VTK_ITER_INLINE ValueIdType GetValueId() const noexcept
VTK_ITER_INLINE IdStorage(TupleIdType tupleId, ComponentIdType comp, NumCompsType numComps) noexcept
VTK_ITER_INLINE ValueIdType Convert(TupleIdType tuple, ComponentIdType comp) const noexcept
VTK_ITER_INLINE TupleIdType GetTupleId() const noexcept
VTK_ITER_INLINE IdStorage(ValueIdType valueId, TupleIdType tupleId, ComponentIdType comp, NumCompsType numComps) noexcept
friend VTK_ITER_INLINE ValueIterator operator+(const ValueIterator &it, difference_type offset) noexcept
VTK_ITER_INLINE ValueIterator & operator++() noexcept
VTK_ITER_INLINE reference operator*() const noexcept
std::random_access_iterator_tag iterator_category
VTK_ITER_INLINE ValueIterator & operator-=(difference_type offset) noexcept
VTK_ITER_INLINE ValueIterator operator--(int) noexcept
VTK_ITER_INLINE ValueIterator & operator=(const ValueIterator &o) noexcept
VTK_ITER_INLINE void DebugIdAsserts() const
ValueReference< ArrayType, TupleSize, ForceValueTypeForVtkDataArray > Ref
VTK_ITER_INLINE ValueIterator & operator--() noexcept
friend VTK_ITER_INLINE ValueIterator operator+(difference_type offset, const ValueIterator &it) noexcept
GetAPIType< ArrayType, ForceValueTypeForVtkDataArray > value_type
VTK_ITER_INLINE ValueIterator() noexcept=default
friend VTK_ITER_INLINE ValueIterator operator-(const ValueIterator &it, difference_type offset) noexcept
VTK_ITER_INLINE ValueIterator operator++(int) noexcept
VTK_ITER_INLINE ValueIterator & operator+=(difference_type offset) noexcept
ArrayType * GetArray() const noexcept
friend VTK_ITER_INLINE void swap(ValueIterator &lhs, ValueIterator &rhs) noexcept
VTK_ITER_INLINE const pointer & operator->() const noexcept
VTK_ITER_INLINE reference operator[](difference_type i) const noexcept
const IdStorageType & GetId() const noexcept
friend VTK_ITER_INLINE difference_type operator-(const ValueIterator &it1, const ValueIterator &it2) noexcept
VTK_ITER_INLINE ValueIterator(const ValueIterator &o) noexcept=default
VTK_ITER_INLINE ArrayType * GetArray() const noexcept
VTK_ITER_INLINE const_iterator begin() const noexcept
static constexpr ComponentIdType TupleSizeTag
GetAPIType< ArrayType, ForceValueTypeForVtkDataArray > ValueType
VTK_ITER_INLINE const_iterator cend() const noexcept
VTK_ITER_INLINE ValueRange GetSubRange(ValueIdType beginValue=0, ValueIdType endValue=-1) const noexcept
VTK_ITER_INLINE iterator begin() noexcept
ConstValueReference< ArrayType, TupleSize, ForceValueTypeForVtkDataArray > ConstReferenceType
VTK_ITER_INLINE const_iterator end() const noexcept
VTK_ITER_INLINE ValueIdType GetBeginValueId() const noexcept
VTK_ITER_INLINE ValueRange() noexcept=default
VTK_ITER_INLINE size_type size() const noexcept
VTK_ITER_INLINE reference operator[](size_type i) noexcept
VTK_ITER_INLINE const_reference operator[](size_type i) const noexcept
ValueReference< ArrayType, TupleSize, ForceValueTypeForVtkDataArray > ReferenceType
VTK_ITER_INLINE iterator end() noexcept
VTK_ITER_INLINE ComponentIdType GetTupleSize() const noexcept
ConstValueIterator< ArrayType, TupleSize, ForceValueTypeForVtkDataArray > ConstIteratorType
ValueIterator< ArrayType, TupleSize, ForceValueTypeForVtkDataArray > IteratorType
VTK_ITER_INLINE const_iterator cbegin() const noexcept
VTK_ITER_INLINE ValueIdType GetEndValueId() const noexcept
VTK_ITER_INLINE ValueReference operator++() noexcept
VTK_ITER_INLINE ValueReference operator=(APIType val) noexcept
VTK_ITER_INLINE ValueReference operator=(ValueReference &&o) noexcept
VTK_ITER_INLINE ValueReference operator--() noexcept
VTK_ITER_INLINE ValueReference operator=(const ValueReference< OArray, OSize, ForceValueTypeForVtkDataArray > &o) noexcept
void CopyReference(const ValueReference &o) noexcept
VTK_ITER_INLINE ValueReference operator=(const ValueReference &o) noexcept
VTK_ITER_INLINE ValueReference(const ValueReference &o) noexcept=default
friend VTK_ITER_INLINE void swap(ValueReference lhs, APIType &rhs) noexcept
friend VTK_ITER_INLINE void swap(ValueReference lhs, ValueReference< OArray, OSize, ForceValueTypeForVtkDataArray > rhs) noexcept
friend VTK_ITER_INLINE void swap(APIType &lhs, ValueReference rhs) noexcept
VTK_ITER_INLINE APIType operator++(int) noexcept
VTK_ITER_INLINE ValueReference(ValueReference &&o) noexcept=default
VTK_ITER_INLINE ValueReference(ArrayType *array, IdStorageType id) noexcept
friend VTK_ITER_INLINE void swap(ValueReference lhs, ValueReference rhs) 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
#define VTK_ITER_ASSERT(x, msg)
#define VTK_ITER_ASSUME
#define VTK_TMP_MAKE_OPERATOR(OP)
#define VTK_REF_OP_OVERLOADS(Op, ImplOp)
#define VTK_DEPRECATED_IN_9_6_0(reason)