10 #ifndef vtk_m_internal_ArrayPortalValueReference_h
11 #define vtk_m_internal_ArrayPortalValueReference_h
27 template <typename Vec, typename = typename std::enable_if<vtkm::HasVecTraits<Vec>::value>::type>
38 template <typename Vec, typename = typename std::enable_if<vtkm::HasVecTraits<Vec>::value>::type>
46 template <typename T, typename = typename std::enable_if<!vtkm::HasVecTraits<T>::value>::type>
70 template <
typename ArrayPortalType>
71 struct ArrayPortalValueReference
73 using ValueType =
typename ArrayPortalType::ValueType;
77 ArrayPortalValueReference(
const ArrayPortalType& portal,
vtkm::Id index)
85 ArrayPortalValueReference(
const ArrayPortalValueReference& ref)
93 ValueType
Get()
const {
return this->Portal.Get(this->
Index); }
97 operator ValueType(
void)
const {
return this->
Get(); }
107 void Set(ValueType&& value)
const { this->Portal.Set(this->
Index, std::move(value)); }
111 void Set(
const ValueType& value)
const { this->Portal.Set(this->
Index, value); }
114 void Swap(
const ArrayPortalValueReference<ArrayPortalType>& rhs)
const noexcept
119 const ValueType aValue = *
this;
132 const ArrayPortalValueReference<ArrayPortalType>& operator=(ValueType&& value)
const
134 this->Set(std::move(value));
140 const ArrayPortalValueReference<ArrayPortalType>& operator=(
const ValueType& value)
const
151 VTKM_EXEC_CONT ArrayPortalValueReference<ArrayPortalType>& operator=(
152 const ArrayPortalValueReference<ArrayPortalType>& rhs)
154 this->Set(
static_cast<ValueType
>(rhs.Portal.Get(rhs.Index)));
159 template <
typename T>
162 ValueType lhs = this->
Get();
168 template <
typename T>
169 VTKM_EXEC_CONT ValueType operator+=(
const ArrayPortalValueReference<T>& rhs)
const
171 ValueType lhs = this->
Get();
178 template <
typename T>
181 ValueType lhs = this->
Get();
187 template <
typename T>
188 VTKM_EXEC_CONT ValueType operator-=(
const ArrayPortalValueReference<T>& rhs)
const
190 ValueType lhs = this->
Get();
197 template <
typename T>
200 ValueType lhs = this->
Get();
206 template <
typename T>
207 VTKM_EXEC_CONT ValueType operator*=(
const ArrayPortalValueReference<T>& rhs)
const
209 ValueType lhs = this->
Get();
216 template <
typename T>
219 ValueType lhs = this->
Get();
225 template <
typename T>
226 VTKM_EXEC_CONT ValueType operator/=(
const ArrayPortalValueReference<T>& rhs)
const
228 ValueType lhs = this->
Get();
235 template <
typename T>
238 ValueType lhs = this->
Get();
244 template <
typename T>
245 VTKM_EXEC_CONT ValueType operator%=(
const ArrayPortalValueReference<T>& rhs)
const
247 ValueType lhs = this->
Get();
254 template <
typename T>
257 ValueType lhs = this->
Get();
263 template <
typename T>
264 VTKM_EXEC_CONT ValueType operator&=(
const ArrayPortalValueReference<T>& rhs)
const
266 ValueType lhs = this->
Get();
273 template <
typename T>
276 ValueType lhs = this->
Get();
282 template <
typename T>
283 VTKM_EXEC_CONT ValueType operator|=(
const ArrayPortalValueReference<T>& rhs)
const
285 ValueType lhs = this->
Get();
292 template <
typename T>
295 ValueType lhs = this->
Get();
301 template <
typename T>
302 VTKM_EXEC_CONT ValueType operator^=(
const ArrayPortalValueReference<T>& rhs)
const
304 ValueType lhs = this->
Get();
311 template <
typename T>
314 ValueType lhs = this->
Get();
320 template <
typename T>
321 VTKM_EXEC_CONT ValueType operator>>=(
const ArrayPortalValueReference<T>& rhs)
const
323 ValueType lhs = this->
Get();
330 template <
typename T>
333 ValueType lhs = this->
Get();
339 template <
typename T>
340 VTKM_EXEC_CONT ValueType operator<<=(
const ArrayPortalValueReference<T>& rhs)
const
342 ValueType lhs = this->
Get();
353 return detail::SafeGetNumberOfComponents(
static_cast<ValueType
>(*
this));
356 -> decltype(detail::SafeGetComponent(std::declval<ValueType>(), index))
358 return detail::SafeGetComponent(
static_cast<ValueType
>(*
this), index);
362 const ArrayPortalType& Portal;
368 template <
typename T>
369 void swap(
const vtkm::internal::ArrayPortalValueReference<T>& a,
370 const vtkm::internal::ArrayPortalValueReference<T>& b)
375 template <
typename T>
376 void swap(
const vtkm::internal::ArrayPortalValueReference<T>& a,
377 typename vtkm::internal::ArrayPortalValueReference<T>::ValueType& b)
379 using ValueType =
typename vtkm::internal::ArrayPortalValueReference<T>::ValueType;
380 const ValueType tmp = a;
385 template <
typename T>
386 void swap(
typename vtkm::internal::ArrayPortalValueReference<T>::ValueType& a,
387 const vtkm::internal::ArrayPortalValueReference<T>& b)
389 using ValueType =
typename vtkm::internal::ArrayPortalValueReference<T>::ValueType;
390 const ValueType tmp = b;
401 template <
typename LhsPortalType>
403 const typename LhsPortalType::ValueType& rhs)
404 -> decltype(lhs.Get() == rhs)
406 return lhs.Get() == rhs;
409 template <
typename LhsPortalType,
typename RhsPortalType>
411 const ArrayPortalValueReference<RhsPortalType>& rhs)
412 -> decltype(lhs.Get() == rhs.Get())
414 return lhs.Get() == rhs.Get();
417 template <
typename RhsPortalType>
419 const ArrayPortalValueReference<RhsPortalType>& rhs)
420 -> decltype(lhs == rhs.Get())
422 return lhs == rhs.Get();
426 template <
typename LhsPortalType>
428 const typename LhsPortalType::ValueType& rhs)
429 -> decltype(lhs.Get() != rhs)
431 return lhs.Get() != rhs;
434 template <
typename LhsPortalType,
typename RhsPortalType>
436 const ArrayPortalValueReference<RhsPortalType>& rhs)
437 -> decltype(lhs.Get() != rhs.Get())
439 return lhs.Get() != rhs.Get();
442 template <
typename RhsPortalType>
444 const ArrayPortalValueReference<RhsPortalType>& rhs)
445 -> decltype(lhs != rhs.Get())
447 return lhs != rhs.Get();
451 template <
typename LhsPortalType>
452 VTKM_EXEC_CONT auto operator<(
const ArrayPortalValueReference<LhsPortalType>& lhs,
453 const typename LhsPortalType::ValueType& rhs)
454 -> decltype(lhs.Get() < rhs)
456 return lhs.Get() < rhs;
459 template <
typename LhsPortalType,
typename RhsPortalType>
460 VTKM_EXEC_CONT auto operator<(
const ArrayPortalValueReference<LhsPortalType>& lhs,
461 const ArrayPortalValueReference<RhsPortalType>& rhs)
462 -> decltype(lhs.Get() < rhs.Get())
464 return lhs.Get() < rhs.Get();
467 template <
typename RhsPortalType>
468 VTKM_EXEC_CONT auto operator<(
const typename RhsPortalType::ValueType& lhs,
469 const ArrayPortalValueReference<RhsPortalType>& rhs)
470 -> decltype(lhs < rhs.Get())
472 return lhs < rhs.Get();
476 template <
typename LhsPortalType>
477 VTKM_EXEC_CONT auto operator>(
const ArrayPortalValueReference<LhsPortalType>& lhs,
478 const typename LhsPortalType::ValueType& rhs)
479 -> decltype(lhs.Get() > rhs)
481 return lhs.Get() > rhs;
484 template <
typename LhsPortalType,
typename RhsPortalType>
485 VTKM_EXEC_CONT auto operator>(
const ArrayPortalValueReference<LhsPortalType>& lhs,
486 const ArrayPortalValueReference<RhsPortalType>& rhs)
487 -> decltype(lhs.Get() > rhs.Get())
489 return lhs.Get() > rhs.Get();
492 template <
typename RhsPortalType>
493 VTKM_EXEC_CONT auto operator>(
const typename RhsPortalType::ValueType& lhs,
494 const ArrayPortalValueReference<RhsPortalType>& rhs)
495 -> decltype(lhs > rhs.Get())
497 return lhs > rhs.Get();
501 template <
typename LhsPortalType>
502 VTKM_EXEC_CONT auto operator<=(
const ArrayPortalValueReference<LhsPortalType>& lhs,
503 const typename LhsPortalType::ValueType& rhs)
504 -> decltype(lhs.Get() <= rhs)
506 return lhs.Get() <= rhs;
509 template <
typename LhsPortalType,
typename RhsPortalType>
510 VTKM_EXEC_CONT auto operator<=(
const ArrayPortalValueReference<LhsPortalType>& lhs,
511 const ArrayPortalValueReference<RhsPortalType>& rhs)
512 -> decltype(lhs.Get() <= rhs.Get())
514 return lhs.Get() <= rhs.Get();
517 template <
typename RhsPortalType>
518 VTKM_EXEC_CONT auto operator<=(
const typename RhsPortalType::ValueType& lhs,
519 const ArrayPortalValueReference<RhsPortalType>& rhs)
520 -> decltype(lhs <= rhs.Get())
522 return lhs <= rhs.Get();
526 template <
typename LhsPortalType>
527 VTKM_EXEC_CONT auto operator>=(
const ArrayPortalValueReference<LhsPortalType>& lhs,
528 const typename LhsPortalType::ValueType& rhs)
529 -> decltype(lhs.Get() >= rhs)
531 return lhs.Get() >= rhs;
534 template <
typename LhsPortalType,
typename RhsPortalType>
535 VTKM_EXEC_CONT auto operator>=(
const ArrayPortalValueReference<LhsPortalType>& lhs,
536 const ArrayPortalValueReference<RhsPortalType>& rhs)
537 -> decltype(lhs.Get() >= rhs.Get())
539 return lhs.Get() >= rhs.Get();
542 template <
typename RhsPortalType>
543 VTKM_EXEC_CONT auto operator>=(
const typename RhsPortalType::ValueType& lhs,
544 const ArrayPortalValueReference<RhsPortalType>& rhs)
545 -> decltype(lhs >= rhs.Get())
547 return lhs >= rhs.Get();
551 template <
typename LhsPortalType>
553 const typename LhsPortalType::ValueType& rhs)
554 -> decltype(lhs.Get() + rhs)
556 return lhs.Get() + rhs;
559 template <
typename LhsPortalType,
typename RhsPortalType>
561 const ArrayPortalValueReference<RhsPortalType>& rhs)
562 -> decltype(lhs.Get() + rhs.Get())
564 return lhs.Get() + rhs.Get();
567 template <
typename RhsPortalType>
569 const ArrayPortalValueReference<RhsPortalType>& rhs)
570 -> decltype(lhs + rhs.Get())
572 return lhs + rhs.Get();
576 template <
typename LhsPortalType>
578 const typename LhsPortalType::ValueType& rhs)
579 -> decltype(lhs.Get() - rhs)
581 return lhs.Get() - rhs;
584 template <
typename LhsPortalType,
typename RhsPortalType>
586 const ArrayPortalValueReference<RhsPortalType>& rhs)
587 -> decltype(lhs.Get() - rhs.Get())
589 return lhs.Get() - rhs.Get();
592 template <
typename RhsPortalType>
594 const ArrayPortalValueReference<RhsPortalType>& rhs)
595 -> decltype(lhs - rhs.Get())
597 return lhs - rhs.Get();
601 template <
typename LhsPortalType>
603 const typename LhsPortalType::ValueType& rhs)
604 -> decltype(lhs.Get() * rhs)
606 return lhs.Get() * rhs;
609 template <
typename LhsPortalType,
typename RhsPortalType>
611 const ArrayPortalValueReference<RhsPortalType>& rhs)
612 -> decltype(lhs.Get() * rhs.Get())
614 return lhs.Get() * rhs.Get();
617 template <
typename RhsPortalType>
619 const ArrayPortalValueReference<RhsPortalType>& rhs)
620 -> decltype(lhs * rhs.Get())
622 return lhs * rhs.Get();
626 template <
typename LhsPortalType>
628 const typename LhsPortalType::ValueType& rhs)
629 -> decltype(lhs.Get() / rhs)
631 return lhs.Get() / rhs;
634 template <
typename LhsPortalType,
typename RhsPortalType>
636 const ArrayPortalValueReference<RhsPortalType>& rhs)
637 -> decltype(lhs.Get() / rhs.Get())
639 return lhs.Get() / rhs.Get();
642 template <
typename RhsPortalType>
644 const ArrayPortalValueReference<RhsPortalType>& rhs)
645 -> decltype(lhs / rhs.Get())
647 return lhs / rhs.Get();
651 template <
typename LhsPortalType>
652 VTKM_EXEC_CONT auto operator%(
const ArrayPortalValueReference<LhsPortalType>& lhs,
653 const typename LhsPortalType::ValueType& rhs)
654 -> decltype(lhs.Get() % rhs)
656 return lhs.Get() % rhs;
659 template <
typename LhsPortalType,
typename RhsPortalType>
660 VTKM_EXEC_CONT auto operator%(
const ArrayPortalValueReference<LhsPortalType>& lhs,
661 const ArrayPortalValueReference<RhsPortalType>& rhs)
662 -> decltype(lhs.Get() % rhs.Get())
664 return lhs.Get() % rhs.Get();
667 template <
typename RhsPortalType>
668 VTKM_EXEC_CONT auto operator%(
const typename RhsPortalType::ValueType& lhs,
669 const ArrayPortalValueReference<RhsPortalType>& rhs)
670 -> decltype(lhs % rhs.Get())
672 return lhs % rhs.Get();
676 template <
typename LhsPortalType>
677 VTKM_EXEC_CONT auto operator^(
const ArrayPortalValueReference<LhsPortalType>& lhs,
678 const typename LhsPortalType::ValueType& rhs)
679 -> decltype(lhs.Get() ^ rhs)
681 return lhs.Get() ^ rhs;
684 template <
typename LhsPortalType,
typename RhsPortalType>
685 VTKM_EXEC_CONT auto operator^(
const ArrayPortalValueReference<LhsPortalType>& lhs,
686 const ArrayPortalValueReference<RhsPortalType>& rhs)
687 -> decltype(lhs.Get() ^ rhs.Get())
689 return lhs.Get() ^ rhs.Get();
692 template <
typename RhsPortalType>
693 VTKM_EXEC_CONT auto operator^(
const typename RhsPortalType::ValueType& lhs,
694 const ArrayPortalValueReference<RhsPortalType>& rhs)
695 -> decltype(lhs ^ rhs.Get())
697 return lhs ^ rhs.Get();
701 template <
typename LhsPortalType>
703 const typename LhsPortalType::ValueType& rhs)
704 -> decltype(lhs.Get() | rhs)
706 return lhs.Get() | rhs;
709 template <
typename LhsPortalType,
typename RhsPortalType>
711 const ArrayPortalValueReference<RhsPortalType>& rhs)
712 -> decltype(lhs.Get() | rhs.Get())
714 return lhs.Get() | rhs.Get();
717 template <
typename RhsPortalType>
719 const ArrayPortalValueReference<RhsPortalType>& rhs)
720 -> decltype(lhs | rhs.Get())
722 return lhs | rhs.Get();
726 template <
typename LhsPortalType>
728 const typename LhsPortalType::ValueType& rhs)
729 -> decltype(lhs.Get() & rhs)
731 return lhs.Get() & rhs;
734 template <
typename LhsPortalType,
typename RhsPortalType>
736 const ArrayPortalValueReference<RhsPortalType>& rhs)
737 -> decltype(lhs.Get() & rhs.Get())
739 return lhs.Get() & rhs.Get();
742 template <
typename RhsPortalType>
744 const ArrayPortalValueReference<RhsPortalType>& rhs)
745 -> decltype(lhs & rhs.Get())
747 return lhs & rhs.Get();
751 template <
typename LhsPortalType>
753 const typename LhsPortalType::ValueType& rhs)
754 -> decltype(lhs.Get() << rhs)
756 return lhs.Get() << rhs;
759 template <
typename LhsPortalType,
typename RhsPortalType>
761 const ArrayPortalValueReference<RhsPortalType>& rhs)
762 -> decltype(lhs.Get() << rhs.Get())
764 return lhs.Get() << rhs.Get();
767 template <
typename RhsPortalType>
769 const ArrayPortalValueReference<RhsPortalType>& rhs)
770 -> decltype(lhs << rhs.Get())
772 return lhs << rhs.Get();
776 template <
typename LhsPortalType>
778 const typename LhsPortalType::ValueType& rhs)
779 -> decltype(lhs.Get() >> rhs)
781 return lhs.Get() >> rhs;
784 template <
typename LhsPortalType,
typename RhsPortalType>
786 const ArrayPortalValueReference<RhsPortalType>& rhs)
787 -> decltype(lhs.Get() >> rhs.Get())
789 return lhs.Get() >> rhs.Get();
792 template <
typename RhsPortalType>
794 const ArrayPortalValueReference<RhsPortalType>& rhs)
795 -> decltype(lhs >> rhs.Get())
797 return lhs >> rhs.Get();
801 template <
typename PortalType>
802 VTKM_EXEC_CONT auto operator~(
const ArrayPortalValueReference<PortalType>& ref)
803 -> decltype(~ref.Get())
809 template <
typename PortalType>
810 VTKM_EXEC_CONT auto operator!(
const ArrayPortalValueReference<PortalType>& ref)
811 -> decltype(!ref.Get())
817 template <
typename LhsPortalType>
818 VTKM_EXEC_CONT auto operator&&(
const ArrayPortalValueReference<LhsPortalType>& lhs,
819 const typename LhsPortalType::ValueType& rhs)
820 -> decltype(lhs.Get() && rhs)
822 return lhs.Get() && rhs;
825 template <
typename LhsPortalType,
typename RhsPortalType>
826 VTKM_EXEC_CONT auto operator&&(
const ArrayPortalValueReference<LhsPortalType>& lhs,
827 const ArrayPortalValueReference<RhsPortalType>& rhs)
828 -> decltype(lhs.Get() && rhs.Get())
830 return lhs.Get() && rhs.Get();
833 template <
typename RhsPortalType>
834 VTKM_EXEC_CONT auto operator&&(
const typename RhsPortalType::ValueType& lhs,
835 const ArrayPortalValueReference<RhsPortalType>& rhs)
836 -> decltype(lhs && rhs.Get())
838 return lhs && rhs.Get();
842 template <
typename LhsPortalType>
843 VTKM_EXEC_CONT auto operator||(
const ArrayPortalValueReference<LhsPortalType>& lhs,
844 const typename LhsPortalType::ValueType& rhs)
845 -> decltype(lhs.Get() || rhs)
847 return lhs.Get() || rhs;
850 template <
typename LhsPortalType,
typename RhsPortalType>
851 VTKM_EXEC_CONT auto operator||(
const ArrayPortalValueReference<LhsPortalType>& lhs,
852 const ArrayPortalValueReference<RhsPortalType>& rhs)
853 -> decltype(lhs.Get() || rhs.Get())
855 return lhs.Get() || rhs.Get();
858 template <
typename RhsPortalType>
859 VTKM_EXEC_CONT auto operator||(
const typename RhsPortalType::ValueType& lhs,
860 const ArrayPortalValueReference<RhsPortalType>& rhs)
861 -> decltype(lhs || rhs.Get())
863 return lhs || rhs.Get();
874 template <
typename PortalType>
875 struct TypeTraits<
vtkm::internal::ArrayPortalValueReference<PortalType>>
876 :
vtkm::TypeTraits<typename vtkm::internal::ArrayPortalValueReference<PortalType>::ValueType>
880 template <
typename PortalType>
881 struct VecTraits<
vtkm::internal::ArrayPortalValueReference<PortalType>>
882 :
vtkm::VecTraits<typename vtkm::internal::ArrayPortalValueReference<PortalType>::ValueType>
888 #endif //vtk_m_internal_ArrayPortalValueReference_h