1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkDataArrayTupleRange_AOS.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/**
* Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
*/
#ifndef vtkDataArrayTupleRange_AOS_h
#define vtkDataArrayTupleRange_AOS_h
#include "vtkAOSDataArrayTemplate.h"
#include "vtkDataArrayMeta.h"
#include "vtkDataArrayTupleRange_Generic.h"
#include "vtkDebugRangeIterators.h"
#include <algorithm>
#include <cassert>
#include <iterator>
#include <type_traits>
// Disable this specialization when iterator debugging is requested:
#ifndef VTK_DEBUG_RANGE_ITERATORS
VTK_ITER_OPTIMIZE_START
namespace vtk
{
namespace detail
{
VTK_ABI_NAMESPACE_BEGIN
// Forward decs for friends/args
template <typename ArrayType, ComponentIdType>
struct ConstTupleReference;
template <typename ArrayType, ComponentIdType>
struct TupleReference;
template <typename ArrayType, ComponentIdType>
struct ConstTupleIterator;
template <typename ArrayType, ComponentIdType>
struct TupleIterator;
template <typename ArrayType, ComponentIdType>
struct TupleRange;
//------------------------------------------------------------------------------
// Const tuple reference
template <typename ValueType, ComponentIdType TupleSize>
struct ConstTupleReference<vtkAOSDataArrayTemplate<ValueType>, TupleSize>
{
private:
using ArrayType = vtkAOSDataArrayTemplate<ValueType>;
using NumCompsType = GenericTupleSize<TupleSize>;
using APIType = ValueType;
public:
using size_type = ComponentIdType;
using value_type = APIType;
using const_reference = const ValueType&;
using iterator = const ValueType*;
using const_iterator = const ValueType*;
VTK_ITER_INLINE
ConstTupleReference() noexcept
: Tuple{ nullptr }
{
}
VTK_ITER_INLINE
ConstTupleReference(const ValueType* tuple, NumCompsType numComps) noexcept
: Tuple(tuple)
, NumComps(numComps)
{
}
VTK_ITER_INLINE
ConstTupleReference(const TupleReference<ArrayType, TupleSize>& o) noexcept
: Tuple{ o.Tuple }
, NumComps{ o.NumComps }
{
}
VTK_ITER_INLINE
ConstTupleReference(const ConstTupleReference&) noexcept = default;
VTK_ITER_INLINE
ConstTupleReference(ConstTupleReference&&) noexcept = default;
// Allow this type to masquerade as a pointer, so that tupleIiter->foo works.
VTK_ITER_INLINE
ConstTupleReference* operator->() noexcept { return this; }
VTK_ITER_INLINE
const ConstTupleReference* operator->() const noexcept { return this; }
// Caller must ensure that there are size() elements in array.
VTK_ITER_INLINE void GetTuple(volatile APIType* tuple) const noexcept
{
// Yes, the tuple argument is marked volatile. No, it's not a mistake.
//
// `volatile`'s intended usage per the standard is to disable optimizations
// when accessing a variable. Without it, GCC 8 will optimize the following
// loop to memcpy, but we're usually copying small tuples here, and the
// call to memcpy is more expensive than just doing an inline copy. By
// disabling the memcpy optimization, benchmarks are 60% faster when
// iterating with the Get/SetTuple methods, and are comparable to other
// methods of array access.
VTK_ITER_ASSUME(this->NumComps.value > 0);
for (ComponentIdType i = 0; i < this->NumComps.value; ++i)
{
tuple[i] = this->Tuple[i];
}
}
// skips some runtime checks when both sizes are fixed:
template <typename OArrayType, ComponentIdType OSize>
VTK_ITER_INLINE EnableIfStaticTupleSizes<TupleSize, OSize, bool> operator==(
const TupleReference<OArrayType, OSize>& other) const noexcept
{
// Check that types are convertible:
using OAPIType = GetAPIType<OArrayType>;
static_assert(
(std::is_convertible<OAPIType, APIType>{}), "Incompatible types when assigning tuples.");
// SFINAE guarantees that the tuple sizes are not dynamic in this overload:
static_assert(TupleSize == OSize, "Cannot assign tuples with different sizes.");
return std::equal(this->cbegin(), this->cend(), other.cbegin());
}
// Needs a runtime check:
template <typename OArrayType, ComponentIdType OSize>
VTK_ITER_INLINE EnableIfEitherTupleSizeIsDynamic<TupleSize, OSize, bool> operator==(
const TupleReference<OArrayType, OSize>& other) const noexcept
{
// Check that types are convertible:
using OAPIType = GetAPIType<OArrayType>;
static_assert(
(std::is_convertible<OAPIType, APIType>{}), "Incompatible types when assigning tuples.");
// Need to check the size at runtime :-(
if (other.size() != this->NumComps.value)
{
return false;
}
return std::equal(this->cbegin(), this->cend(), other.cbegin());
}
// skips some runtime checks when both sizes are fixed:
template <typename OArrayType, ComponentIdType OSize>
VTK_ITER_INLINE EnableIfStaticTupleSizes<TupleSize, OSize, bool> operator==(
const ConstTupleReference<OArrayType, OSize>& other) const noexcept
{
// Check that types are convertible:
using OAPIType = GetAPIType<OArrayType>;
static_assert(
(std::is_convertible<OAPIType, APIType>{}), "Incompatible types when assigning tuples.");
// SFINAE guarantees that the tuple sizes are not dynamic in this overload:
static_assert(TupleSize == OSize, "Cannot assign tuples with different sizes.");
return std::equal(this->cbegin(), this->cend(), other.cbegin());
}
// Needs a runtime check:
template <typename OArrayType, ComponentIdType OSize>
VTK_ITER_INLINE EnableIfEitherTupleSizeIsDynamic<TupleSize, OSize, bool> operator==(
const ConstTupleReference<OArrayType, OSize>& other) const noexcept
{
// Check that types are convertible:
using OAPIType = GetAPIType<OArrayType>;
static_assert(
(std::is_convertible<OAPIType, APIType>{}), "Incompatible types when assigning tuples.");
// Need to check the size at runtime :-(
if (other.size() != this->NumComps.value)
{
return false;
}
return std::equal(this->cbegin(), this->cend(), other.cbegin());
}
template <typename OArrayType, ComponentIdType OSize>
VTK_ITER_INLINE bool operator!=(const TupleReference<OArrayType, OSize>& o) const noexcept
{
return !(*this == o);
}
template <typename OArray, ComponentIdType OSize>
VTK_ITER_INLINE bool operator!=(const ConstTupleReference<OArray, OSize>& o) const noexcept
{
return !(*this == o);
}
VTK_ITER_INLINE
const_reference operator[](size_type i) const noexcept { return this->Tuple[i]; }
VTK_ITER_INLINE
size_type size() const noexcept { return this->NumComps.value; }
VTK_ITER_INLINE
const_iterator begin() const noexcept { return const_iterator{ this->Tuple }; }
VTK_ITER_INLINE
const_iterator end() const noexcept
{
return const_iterator{ this->Tuple + this->NumComps.value };
}
VTK_ITER_INLINE
const_iterator cbegin() const noexcept { return const_iterator{ this->Tuple }; }
VTK_ITER_INLINE
const_iterator cend() const noexcept
{
return const_iterator{ this->Tuple + this->NumComps.value };
}
friend struct ConstTupleIterator<ArrayType, TupleSize>;
protected:
// Intentionally hidden:
VTK_ITER_INLINE
ConstTupleReference& operator=(const ConstTupleReference&) noexcept = default;
const ValueType* Tuple;
NumCompsType NumComps;
};
//------------------------------------------------------------------------------
// Tuple reference
template <typename ValueType, ComponentIdType TupleSize>
struct TupleReference<vtkAOSDataArrayTemplate<ValueType>, TupleSize>
{
private:
using ArrayType = vtkAOSDataArrayTemplate<ValueType>;
using NumCompsType = GenericTupleSize<TupleSize>;
using APIType = ValueType;
public:
using size_type = ComponentIdType;
using value_type = APIType;
using iterator = ValueType*;
using const_iterator = const ValueType*;
using reference = ValueType&;
using const_reference = ValueType const&;
VTK_ITER_INLINE
TupleReference() noexcept
: Tuple{ nullptr }
{
}
VTK_ITER_INLINE
TupleReference(ValueType* tuple, NumCompsType numComps) noexcept
: Tuple(tuple)
, NumComps(numComps)
{
}
VTK_ITER_INLINE
TupleReference(const TupleReference&) noexcept = default;
VTK_ITER_INLINE
TupleReference(TupleReference&&) noexcept = default;
// Allow this type to masquerade as a pointer, so that tupleIiter->foo works.
VTK_ITER_INLINE
TupleReference* operator->() noexcept { return this; }
VTK_ITER_INLINE
const TupleReference* operator->() const noexcept { return this; }
// Caller must ensure that there are size() elements in array.
VTK_ITER_INLINE
void GetTuple(volatile APIType* tuple) const noexcept
{
// Yes, the tuple argument is marked volatile. No, it's not a mistake.
//
// `volatile`'s intended usage per the standard is to disable optimizations
// when accessing a variable. Without it, GCC 8 will optimize the following
// loop to memcpy, but we're usually copying small tuples here, and the
// call to memcpy is more expensive than just doing an inline copy. By
// disabling the memcpy optimization, benchmarks are 60% faster when
// iterating with the Get/SetTuple methods, and are comparable to other
// methods of array access.
VTK_ITER_ASSUME(this->NumComps.value > 0);
for (ComponentIdType i = 0; i < this->NumComps.value; ++i)
{
tuple[i] = this->Tuple[i];
}
}
// Caller must ensure that there are size() elements in array.
VTK_ITER_INLINE
void SetTuple(const APIType* tuple) noexcept
{
volatile APIType* out = this->Tuple;
// Yes, this variable argument is marked volatile. See the explanation in
// GetTuple.
VTK_ITER_ASSUME(this->NumComps.value > 0);
for (ComponentIdType i = 0; i < this->NumComps.value; ++i)
{
out[i] = tuple[i];
}
}
VTK_ITER_INLINE
TupleReference& operator=(const TupleReference& other) noexcept
{
std::copy_n(other.cbegin(), this->NumComps.value, this->begin());
return *this;
}
template <typename OArrayType, ComponentIdType OSize>
VTK_ITER_INLINE EnableIfStaticTupleSizes<TupleSize, OSize, TupleReference&> operator=(
const TupleReference<OArrayType, OSize>& other) noexcept
{
// Check that types are convertible:
using OAPIType = GetAPIType<OArrayType>;
static_assert(
(std::is_convertible<OAPIType, APIType>{}), "Incompatible types when assigning tuples.");
// SFINAE guarantees that the tuple sizes are not dynamic in this overload:
static_assert(TupleSize == OSize, "Cannot assign tuples with different sizes.");
std::copy_n(other.cbegin(), OSize, this->begin());
return *this;
}
template <typename OArrayType, ComponentIdType OSize>
VTK_ITER_INLINE EnableIfEitherTupleSizeIsDynamic<TupleSize, OSize, TupleReference&> operator=(
const TupleReference<OArrayType, OSize>& other) noexcept
{
// Check that types are convertible:
using OAPIType = GetAPIType<OArrayType>;
static_assert(
(std::is_convertible<OAPIType, APIType>{}), "Incompatible types when assigning tuples.");
// Note that the sizes are not checked here. Enable
// VTK_DEBUG_RANGE_ITERATORS to enable check.
std::copy_n(other.cbegin(), this->NumComps.value, this->begin());
return *this;
}
template <typename OArrayType, ComponentIdType OSize>
VTK_ITER_INLINE EnableIfStaticTupleSizes<TupleSize, OSize, TupleReference&> operator=(
const ConstTupleReference<OArrayType, OSize>& other) noexcept
{
// Check that types are convertible:
using OAPIType = GetAPIType<OArrayType>;
static_assert(
(std::is_convertible<OAPIType, APIType>{}), "Incompatible types when assigning tuples.");
// SFINAE guarantees that the tuple sizes are not dynamic in this overload:
static_assert(TupleSize == OSize, "Cannot assign tuples with different sizes.");
std::copy_n(other.cbegin(), OSize, this->begin());
return *this;
}
template <typename OArrayType, ComponentIdType OSize>
VTK_ITER_INLINE EnableIfEitherTupleSizeIsDynamic<TupleSize, OSize, TupleReference&> operator=(
const ConstTupleReference<OArrayType, OSize>& other) noexcept
{
// Check that types are convertible:
using OAPIType = GetAPIType<OArrayType>;
static_assert(
(std::is_convertible<OAPIType, APIType>{}), "Incompatible types when assigning tuples.");
// Note that the sizes are not checked here. Enable
// VTK_DEBUG_RANGE_ITERATORS to enable check.
std::copy_n(other.cbegin(), this->NumComps.value, this->begin());
return *this;
}
// skips some runtime checks when both sizes are fixed:
template <typename OArrayType, ComponentIdType OSize>
VTK_ITER_INLINE EnableIfStaticTupleSizes<TupleSize, OSize, bool> operator==(
const TupleReference<OArrayType, OSize>& other) const noexcept
{
// Check that types are convertible:
using OAPIType = GetAPIType<OArrayType>;
static_assert(
(std::is_convertible<OAPIType, APIType>{}), "Incompatible types when assigning tuples.");
// SFINAE guarantees that the tuple sizes are not dynamic in this overload:
static_assert(TupleSize == OSize, "Cannot assign tuples with different sizes.");
return std::equal(this->cbegin(), this->cend(), other.cbegin());
}
// Needs a runtime check:
template <typename OArrayType, ComponentIdType OSize>
VTK_ITER_INLINE EnableIfEitherTupleSizeIsDynamic<TupleSize, OSize, bool> operator==(
const TupleReference<OArrayType, OSize>& other) const noexcept
{
// Check that types are convertible:
using OAPIType = GetAPIType<OArrayType>;
static_assert(
(std::is_convertible<OAPIType, APIType>{}), "Incompatible types when assigning tuples.");
// Note that the sizes are not checked here. Enable
// VTK_DEBUG_RANGE_ITERATORS to enable check.
return std::equal(this->cbegin(), this->cend(), other.cbegin());
}
// skips some runtime checks when both sizes are fixed:
template <typename OArrayType, ComponentIdType OSize>
VTK_ITER_INLINE EnableIfStaticTupleSizes<TupleSize, OSize, bool> operator==(
const ConstTupleReference<OArrayType, OSize>& other) const noexcept
{
// Check that types are convertible:
using OAPIType = GetAPIType<OArrayType>;
static_assert(
(std::is_convertible<OAPIType, APIType>{}), "Incompatible types when assigning tuples.");
// SFINAE guarantees that the tuple sizes are not dynamic in this overload:
static_assert(TupleSize == OSize, "Cannot assign tuples with different sizes.");
return std::equal(this->cbegin(), this->cend(), other.cbegin());
}
// Needs a runtime check:
template <typename OArrayType, ComponentIdType OSize>
VTK_ITER_INLINE EnableIfEitherTupleSizeIsDynamic<TupleSize, OSize, bool> operator==(
const ConstTupleReference<OArrayType, OSize>& other) const noexcept
{
// Check that types are convertible:
using OAPIType = GetAPIType<OArrayType>;
static_assert(
(std::is_convertible<OAPIType, APIType>{}), "Incompatible types when assigning tuples.");
// Note that the sizes are not checked here. Enable
// VTK_DEBUG_RANGE_ITERATORS to enable check.
return std::equal(this->cbegin(), this->cend(), other.cbegin());
}
template <typename OArrayType, ComponentIdType OSize>
VTK_ITER_INLINE bool operator!=(const TupleReference<OArrayType, OSize>& o) const noexcept
{
return !(*this == o);
}
template <typename OArray, ComponentIdType OSize>
VTK_ITER_INLINE bool operator!=(const ConstTupleReference<OArray, OSize>& o) const noexcept
{
return !(*this == o);
}
// skips some runtime checks:
template <typename OArrayType, ComponentIdType OSize>
VTK_ITER_INLINE EnableIfStaticTupleSizes<TupleSize, OSize, void> swap(
TupleReference<OArrayType, OSize> other) noexcept
{
// Check that types are convertible:
using OAPIType = GetAPIType<OArrayType>;
static_assert((std::is_same<OAPIType, APIType>{}), "Incompatible types when swapping tuples.");
// SFINAE guarantees that the tuple sizes are not dynamic in this overload:
static_assert(TupleSize == OSize, "Cannot swap tuples with different sizes.");
std::swap_ranges(this->begin(), this->end(), other.begin());
}
// Needs a runtime check:
template <typename OArrayType, ComponentIdType OSize>
VTK_ITER_INLINE EnableIfEitherTupleSizeIsDynamic<TupleSize, OSize, void> swap(
TupleReference<OArrayType, OSize> other) noexcept
{
// Check that types are convertible:
using OAPIType = GetAPIType<OArrayType>;
static_assert((std::is_same<OAPIType, APIType>{}), "Incompatible types when swapping tuples.");
// Note that the sizes are not checked here. Enable
// VTK_DEBUG_RANGE_ITERATORS to enable check.
std::swap_ranges(this->begin(), this->end(), other.begin());
}
friend VTK_ITER_INLINE void swap(TupleReference a, TupleReference b) noexcept { a.swap(b); }
template <typename OArray, ComponentIdType OSize>
friend VTK_ITER_INLINE void swap(TupleReference a, TupleReference<OArray, OSize> b) noexcept
{
a.swap(b);
}
VTK_ITER_INLINE
reference operator[](size_type i) noexcept { return this->Tuple[i]; }
VTK_ITER_INLINE
const_reference operator[](size_type i) const noexcept { return this->Tuple[i]; }
VTK_ITER_INLINE
void fill(const value_type& v) noexcept { std::fill(this->begin(), this->end(), v); }
VTK_ITER_INLINE
size_type size() const noexcept { return this->NumComps.value; }
VTK_ITER_INLINE
iterator begin() noexcept { return iterator{ this->Tuple }; }
VTK_ITER_INLINE
iterator end() noexcept { return iterator{ this->Tuple + this->NumComps.value }; }
VTK_ITER_INLINE
const_iterator begin() const noexcept { return const_iterator{ this->Tuple }; }
VTK_ITER_INLINE
const_iterator end() const noexcept
{
return const_iterator{ this->Tuple + this->NumComps.value };
}
VTK_ITER_INLINE
const_iterator cbegin() const noexcept { return const_iterator{ this->Tuple }; }
VTK_ITER_INLINE
const_iterator cend() const noexcept
{
return const_iterator{ this->Tuple + this->NumComps.value };
}
friend struct ConstTupleReference<ArrayType, TupleSize>;
friend struct TupleIterator<ArrayType, TupleSize>;
protected:
VTK_ITER_INLINE
void CopyReference(const TupleReference& o) noexcept
{
this->Tuple = o.Tuple;
this->NumComps = o.NumComps;
}
ValueType* Tuple;
NumCompsType NumComps;
};
//------------------------------------------------------------------------------
// Const tuple iterator
template <typename ValueType, ComponentIdType TupleSize>
struct ConstTupleIterator<vtkAOSDataArrayTemplate<ValueType>, TupleSize>
{
private:
using ArrayType = vtkAOSDataArrayTemplate<ValueType>;
using NumCompsType = GenericTupleSize<TupleSize>;
public:
using iterator_category = std::random_access_iterator_tag;
using value_type = ConstTupleReference<ArrayType, TupleSize>;
using difference_type = TupleIdType;
using pointer = ConstTupleReference<ArrayType, TupleSize>;
using reference = ConstTupleReference<ArrayType, TupleSize>;
VTK_ITER_INLINE
ConstTupleIterator() noexcept = default;
VTK_ITER_INLINE
ConstTupleIterator(const ValueType* tuple, NumCompsType numComps) noexcept
: Ref(tuple, numComps)
{
}
VTK_ITER_INLINE
ConstTupleIterator(const TupleIterator<ArrayType, TupleSize>& o) noexcept
: Ref{ o.Ref }
{
}
VTK_ITER_INLINE
ConstTupleIterator(const ConstTupleIterator& o) noexcept = default;
VTK_ITER_INLINE
ConstTupleIterator& operator=(const ConstTupleIterator& o) noexcept = default;
VTK_ITER_INLINE
ConstTupleIterator& operator++() noexcept // prefix
{
this->Ref.Tuple += this->Ref.NumComps.value;
return *this;
}
VTK_ITER_INLINE
ConstTupleIterator operator++(int) noexcept // postfix
{
auto tuple = this->Ref.Tuple;
this->Ref.Tuple += this->Ref.NumComps.value;
return ConstTupleIterator{ tuple, this->Ref.NumComps };
}
VTK_ITER_INLINE
ConstTupleIterator& operator--() noexcept // prefix
{
this->Ref.Tuple -= this->Ref.NumComps.value;
return *this;
}
VTK_ITER_INLINE
ConstTupleIterator operator--(int) noexcept // postfix
{
auto tuple = this->Ref.Tuple;
this->Ref.Tuple -= this->Ref.NumComps.value;
return ConstTupleIterator{ tuple, this->Ref.NumComps };
}
VTK_ITER_INLINE
reference operator[](difference_type i) noexcept
{
return reference{ this->Ref.Tuple + i * this->Ref.NumComps, this->Ref.NumComps };
}
VTK_ITER_INLINE
reference operator*() noexcept { return this->Ref; }
VTK_ITER_INLINE
pointer& operator->() noexcept { return this->Ref; }
#define VTK_TMP_MAKE_OPERATOR(OP) \
friend VTK_ITER_INLINE bool operator OP( \
const ConstTupleIterator& lhs, const ConstTupleIterator& rhs) noexcept \
{ \
return lhs.GetTuple() OP rhs.GetTuple(); \
}
VTK_TMP_MAKE_OPERATOR(==)
VTK_TMP_MAKE_OPERATOR(!=)
VTK_TMP_MAKE_OPERATOR(<)
VTK_TMP_MAKE_OPERATOR(>)
VTK_TMP_MAKE_OPERATOR(<=)
VTK_TMP_MAKE_OPERATOR(>=)
#undef VTK_TMP_MAKE_OPERATOR
VTK_ITER_INLINE
ConstTupleIterator& operator+=(difference_type offset) noexcept
{
this->Ref.Tuple += offset * this->Ref.NumComps.value;
return *this;
}
friend VTK_ITER_INLINE ConstTupleIterator operator+(
const ConstTupleIterator& it, difference_type offset) noexcept
{
return ConstTupleIterator{ it.GetTuple() + offset * it.GetNumComps().value, it.GetNumComps() };
}
friend VTK_ITER_INLINE ConstTupleIterator operator+(
difference_type offset, const ConstTupleIterator& it) noexcept
{
return ConstTupleIterator{ it.GetTuple() + offset * it.GetNumComps().value, it.GetNumComps() };
}
VTK_ITER_INLINE
ConstTupleIterator& operator-=(difference_type offset) noexcept
{
this->Ref.Tuple -= offset * this->Ref.NumComps.value;
return *this;
}
friend VTK_ITER_INLINE ConstTupleIterator operator-(
const ConstTupleIterator& it, difference_type offset) noexcept
{
return ConstTupleIterator{ it.GetTuple() - offset * it.GetNumComps().value, it.GetNumComps() };
}
friend VTK_ITER_INLINE difference_type operator-(
const ConstTupleIterator& it1, const ConstTupleIterator& it2) noexcept
{
return static_cast<difference_type>(
(it1.GetTuple() - it2.GetTuple()) / it1.GetNumComps().value);
}
friend VTK_ITER_INLINE void swap(ConstTupleIterator& lhs, ConstTupleIterator& rhs) noexcept
{
using std::swap;
swap(lhs.GetTuple(), rhs.GetTuple());
swap(lhs.GetNumComps(), rhs.GetNumComps());
}
private:
VTK_ITER_INLINE
const ValueType*& GetTuple() noexcept { return this->Ref.Tuple; }
VTK_ITER_INLINE
const ValueType* GetTuple() const noexcept { return this->Ref.Tuple; }
VTK_ITER_INLINE
NumCompsType& GetNumComps() noexcept { return this->Ref.NumComps; }
VTK_ITER_INLINE
NumCompsType GetNumComps() const noexcept { return this->Ref.NumComps; }
ConstTupleReference<ArrayType, TupleSize> Ref;
};
//------------------------------------------------------------------------------
// Tuple iterator
template <typename ValueType, ComponentIdType TupleSize>
struct TupleIterator<vtkAOSDataArrayTemplate<ValueType>, TupleSize>
{
private:
using ArrayType = vtkAOSDataArrayTemplate<ValueType>;
using NumCompsType = GenericTupleSize<TupleSize>;
public:
using iterator_category = std::random_access_iterator_tag;
using value_type = TupleReference<ArrayType, TupleSize>;
using difference_type = TupleIdType;
using pointer = TupleReference<ArrayType, TupleSize>;
using reference = TupleReference<ArrayType, TupleSize>;
VTK_ITER_INLINE
TupleIterator() noexcept = default;
VTK_ITER_INLINE
TupleIterator(ValueType* tuple, NumCompsType numComps) noexcept
: Ref(tuple, numComps)
{
}
VTK_ITER_INLINE
TupleIterator(const TupleIterator& o) noexcept = default;
VTK_ITER_INLINE
TupleIterator& operator=(const TupleIterator& o) noexcept
{
this->Ref.CopyReference(o.Ref);
return *this;
}
VTK_ITER_INLINE
TupleIterator& operator++() noexcept // prefix
{
this->Ref.Tuple += this->Ref.NumComps.value;
return *this;
}
VTK_ITER_INLINE
TupleIterator operator++(int) noexcept // postfix
{
auto tuple = this->Ref.Tuple;
this->Ref.Tuple += this->Ref.NumComps.value;
return TupleIterator{ tuple, this->Ref.NumComps };
}
VTK_ITER_INLINE
TupleIterator& operator--() noexcept // prefix
{
this->Ref.Tuple -= this->Ref.NumComps.value;
return *this;
}
VTK_ITER_INLINE
TupleIterator operator--(int) noexcept // postfix
{
auto tuple = this->Ref.Tuple;
this->Ref.Tuple -= this->Ref.NumComps.value;
return TupleIterator{ tuple, this->Ref.NumComps };
}
VTK_ITER_INLINE
reference operator[](difference_type i) noexcept
{
return reference{ this->Ref.Tuple + i * this->Ref.NumComps.value, this->Ref.NumComps };
}
reference operator*() noexcept { return this->Ref; }
pointer& operator->() noexcept { return this->Ref; }
#define VTK_TMP_MAKE_OPERATOR(OP) \
friend VTK_ITER_INLINE bool operator OP( \
const TupleIterator& lhs, const TupleIterator& rhs) noexcept \
{ \
return lhs.GetTuple() OP rhs.GetTuple(); \
}
VTK_TMP_MAKE_OPERATOR(==)
VTK_TMP_MAKE_OPERATOR(!=)
VTK_TMP_MAKE_OPERATOR(<)
VTK_TMP_MAKE_OPERATOR(>)
VTK_TMP_MAKE_OPERATOR(<=)
VTK_TMP_MAKE_OPERATOR(>=)
#undef VTK_TMP_MAKE_OPERATOR
VTK_ITER_INLINE
TupleIterator& operator+=(difference_type offset) noexcept
{
this->Ref.Tuple += offset * this->Ref.NumComps.value;
return *this;
}
friend VTK_ITER_INLINE TupleIterator operator+(
const TupleIterator& it, difference_type offset) noexcept
{
return TupleIterator{ it.GetTuple() + offset * it.GetNumComps().value, it.GetNumComps() };
}
friend VTK_ITER_INLINE TupleIterator operator+(
difference_type offset, const TupleIterator& it) noexcept
{
return TupleIterator{ it.GetTuple() + offset * it.GetNumComps().value, it.GetNumComps() };
}
VTK_ITER_INLINE
TupleIterator& operator-=(difference_type offset) noexcept
{
this->Ref.Tuple -= offset * this->Ref.NumComps.value;
return *this;
}
friend VTK_ITER_INLINE TupleIterator operator-(
const TupleIterator& it, difference_type offset) noexcept
{
return TupleIterator{ it.GetTuple() - offset * it.GetNumComps().value, it.GetNumComps() };
}
friend VTK_ITER_INLINE difference_type operator-(
const TupleIterator& it1, const TupleIterator& it2) noexcept
{
return static_cast<difference_type>(
(it1.GetTuple() - it2.GetTuple()) / it1.GetNumComps().value);
}
friend VTK_ITER_INLINE void swap(TupleIterator& lhs, TupleIterator& rhs) noexcept
{
using std::swap;
swap(lhs.GetTuple(), rhs.GetTuple());
swap(lhs.GetNumComps(), rhs.GetNumComps());
}
friend struct ConstTupleIterator<ArrayType, TupleSize>;
protected:
VTK_ITER_INLINE
ValueType* GetTuple() const noexcept { return this->Ref.Tuple; }
VTK_ITER_INLINE
ValueType*& GetTuple() noexcept { return this->Ref.Tuple; }
VTK_ITER_INLINE
NumCompsType GetNumComps() const noexcept { return this->Ref.NumComps; }
VTK_ITER_INLINE
NumCompsType& GetNumComps() noexcept { return this->Ref.NumComps; }
TupleReference<ArrayType, TupleSize> Ref;
};
//------------------------------------------------------------------------------
// Tuple range
template <typename ValueType, ComponentIdType TupleSize>
struct TupleRange<vtkAOSDataArrayTemplate<ValueType>, TupleSize>
{
using ArrayType = vtkAOSDataArrayTemplate<ValueType>;
using APIType = GetAPIType<ArrayType>;
private:
static_assert(IsValidTupleSize<TupleSize>::value, "Invalid tuple size.");
static_assert(IsVtkDataArray<ArrayType>::value, "Invalid array type.");
using NumCompsType = GenericTupleSize<TupleSize>;
public:
using TupleIteratorType = TupleIterator<ArrayType, TupleSize>;
using ConstTupleIteratorType = ConstTupleIterator<ArrayType, TupleSize>;
using TupleReferenceType = TupleReference<ArrayType, TupleSize>;
using ConstTupleReferenceType = ConstTupleReference<ArrayType, TupleSize>;
using ComponentIteratorType = APIType*;
using ConstComponentIteratorType = APIType const*;
using ComponentReferenceType = APIType&;
using ConstComponentReferenceType = const APIType&;
using ComponentType = APIType;
using size_type = TupleIdType;
using iterator = TupleIteratorType;
using const_iterator = ConstTupleIteratorType;
using reference = TupleReferenceType;
using const_reference = ConstTupleReferenceType;
// May be DynamicTupleSize, or the actual tuple size.
constexpr static ComponentIdType TupleSizeTag = TupleSize;
VTK_ITER_INLINE
TupleRange() noexcept = default;
VTK_ITER_INLINE
TupleRange(ArrayType* arr, TupleIdType beginTuple, TupleIdType endTuple) noexcept
: Array(arr)
, NumComps(arr)
, BeginTuple(TupleRange::GetTuplePointer(arr, beginTuple))
, EndTuple(TupleRange::GetTuplePointer(arr, endTuple))
{
assert(this->Array);
assert(beginTuple >= 0 && beginTuple <= endTuple);
assert(endTuple >= 0 && endTuple <= this->Array->GetNumberOfTuples());
}
VTK_ITER_INLINE
TupleRange GetSubRange(TupleIdType beginTuple = 0, TupleIdType endTuple = -1) const noexcept
{
const TupleIdType curBegin = this->GetTupleId(this->BeginTuple);
const TupleIdType realBegin = curBegin + beginTuple;
const TupleIdType realEnd =
endTuple >= 0 ? curBegin + endTuple : this->GetTupleId(this->EndTuple);
return TupleRange{ this->Array, realBegin, realEnd };
}
VTK_ITER_INLINE
ArrayType* GetArray() const noexcept { return this->Array; }
VTK_ITER_INLINE
ComponentIdType GetTupleSize() const noexcept { return this->NumComps.value; }
VTK_ITER_INLINE
TupleIdType GetBeginTupleId() const noexcept { return this->GetTupleId(this->BeginTuple); }
VTK_ITER_INLINE
TupleIdType GetEndTupleId() const noexcept { return this->GetTupleId(this->EndTuple); }
VTK_ITER_INLINE
size_type size() const noexcept
{
return static_cast<size_type>(this->EndTuple - this->BeginTuple) /
static_cast<size_type>(this->NumComps.value);
}
VTK_ITER_INLINE
iterator begin() noexcept { return iterator(this->BeginTuple, this->NumComps); }
VTK_ITER_INLINE
iterator end() noexcept { return iterator(this->EndTuple, this->NumComps); }
VTK_ITER_INLINE
const_iterator begin() const noexcept { return const_iterator(this->BeginTuple, this->NumComps); }
VTK_ITER_INLINE
const_iterator end() const noexcept { return const_iterator(this->EndTuple, this->NumComps); }
VTK_ITER_INLINE
const_iterator cbegin() const noexcept
{
return const_iterator(this->BeginTuple, this->NumComps);
}
VTK_ITER_INLINE
const_iterator cend() const noexcept { return const_iterator(this->EndTuple, this->NumComps); }
VTK_ITER_INLINE
reference operator[](size_type i) noexcept
{
return reference{ this->BeginTuple + i * this->NumComps.value, this->NumComps };
}
VTK_ITER_INLINE
const_reference operator[](size_type i) const noexcept
{
return const_reference{ this->BeginTuple + i * this->NumComps.value, this->NumComps };
}
private:
VTK_ITER_INLINE
ValueType* GetTuplePointer(ArrayType* array, vtkIdType tuple) const noexcept
{
return array->GetPointer(tuple * this->NumComps.value);
}
VTK_ITER_INLINE
TupleIdType GetTupleId(const ValueType* ptr) const noexcept
{
return static_cast<TupleIdType>((ptr - this->Array->GetPointer(0)) / this->NumComps.value);
}
mutable ArrayType* Array{ nullptr };
NumCompsType NumComps{};
ValueType* BeginTuple{ nullptr };
ValueType* EndTuple{ nullptr };
};
// Unimplemented, only used inside decltype in SelectTupleRange:
template <typename ArrayType, ComponentIdType TupleSize,
// Convenience:
typename ValueType = typename ArrayType::ValueType,
typename AOSArrayType = vtkAOSDataArrayTemplate<ValueType>,
// SFINAE to select AOS arrays:
typename = typename std::enable_if<IsAOSDataArray<ArrayType>::value>::type>
TupleRange<AOSArrayType, TupleSize> DeclareTupleRangeSpecialization(ArrayType*);
VTK_ABI_NAMESPACE_END
} // end namespace detail
} // end namespace vtk
VTK_ITER_OPTIMIZE_END
#endif // VTK_DEBUG_RANGE_ITERATORS
#endif // vtkDataArrayTupleRange_AOS_h
// VTK-HeaderTest-Exclude: vtkDataArrayTupleRange_AOS.h
|