From b526c4c9146e68a7f17c205b217c504066fb6971 Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Tue, 25 Aug 2020 13:00:40 -0600 Subject: [PATCH] Make VTKM_ARRAY_HANDLE_NEW_STYLE macro While in the transition between two types of `ArrayHandle` implementations, we need to declare when an `ArrayHandle` is implemented with the new style. To consolidate, create a `VTKM_ARRAY_HANDLE_NEW_STYLE` to override the default `ArrayHandle` implementation with the `ArrayHandleNewStyle` implementation. --- vtkm/cont/ArrayHandle.h | 80 +++++++++++++++++++++++++++++++++ vtkm/cont/ArrayHandleBasic.h | 70 +---------------------------- vtkm/cont/ArrayHandleBitField.h | 70 +---------------------------- vtkm/cont/ArrayHandleSOA.h | 70 +---------------------------- 4 files changed, 83 insertions(+), 207 deletions(-) diff --git a/vtkm/cont/ArrayHandle.h b/vtkm/cont/ArrayHandle.h index fa0bed54f..ae0ba03a6 100644 --- a/vtkm/cont/ArrayHandle.h +++ b/vtkm/cont/ArrayHandle.h @@ -895,6 +895,86 @@ VTKM_CONT_EXPORT VTKM_CONT vtkm::cont::DeviceAdapterId ArrayHandleGetDeviceAdapt } // namespace detail +// This macro is used to declare an ArrayHandle that uses the new style of Storage +// that leverages Buffer objects. This macro will go away once ArrayHandle +// is replaced with ArrayHandleNewStyle. To use this macro, first have a declaration +// of the template and then put the macro like this: +// +// template +// VTKM_ARRAY_HANDLE_NEW_STYLE(T, vtkm::cont::StorageTagFoo); +// +// Don't forget to use VTKM_PASS_COMMAS if one of the macro arguments contains +// a template with multiple parameters. +#define VTKM_ARRAY_HANDLE_NEW_STYLE(ValueType_, StorageType_) \ + class VTKM_ALWAYS_EXPORT ArrayHandle \ + : public ArrayHandleNewStyle \ + { \ + using Superclass = ArrayHandleNewStyle; \ + \ + public: \ + VTKM_CONT \ + ArrayHandle() \ + : Superclass() \ + { \ + } \ + \ + VTKM_CONT \ + ArrayHandle(const ArrayHandle& src) \ + : Superclass(src) \ + { \ + } \ + \ + VTKM_CONT \ + ArrayHandle(ArrayHandle&& src) noexcept \ + : Superclass(std::move(src)) \ + { \ + } \ + \ + VTKM_CONT \ + ArrayHandle(const ArrayHandleNewStyle& src) \ + : Superclass(src) \ + { \ + } \ + \ + VTKM_CONT \ + ArrayHandle(ArrayHandleNewStyle&& src) noexcept \ + : Superclass(std::move(src)) \ + { \ + } \ + \ + VTKM_CONT ArrayHandle( \ + const vtkm::cont::internal::Buffer* buffers, \ + const typename Superclass::StorageType& storage = typename Superclass::StorageType()) \ + : Superclass(buffers, storage) \ + { \ + } \ + \ + VTKM_CONT ArrayHandle( \ + const std::vector& buffers, \ + const typename Superclass::StorageType& storage = typename Superclass::StorageType()) \ + : Superclass(buffers, storage) \ + { \ + } \ + \ + VTKM_CONT \ + ArrayHandle& operator=( \ + const ArrayHandle& src) \ + { \ + this->Superclass::operator=(src); \ + return *this; \ + } \ + \ + VTKM_CONT \ + ArrayHandle& operator=( \ + ArrayHandle&& src) noexcept \ + { \ + this->Superclass::operator=(std::move(src)); \ + return *this; \ + } \ + \ + VTKM_CONT ~ArrayHandle() {} \ + } + /// This new style of ArrayHandle will eventually replace the classic ArrayHandle template class VTKM_ALWAYS_EXPORT ArrayHandleNewStyle : public internal::ArrayHandleBase diff --git a/vtkm/cont/ArrayHandleBasic.h b/vtkm/cont/ArrayHandleBasic.h index 9646f0d06..5e6e207b5 100644 --- a/vtkm/cont/ArrayHandleBasic.h +++ b/vtkm/cont/ArrayHandleBasic.h @@ -69,76 +69,8 @@ public: } // namespace internal -// This can go away once ArrayHandle is replaced with ArrayHandleNewStyle template -class VTKM_ALWAYS_EXPORT ArrayHandle - : public ArrayHandleNewStyle -{ - using Superclass = ArrayHandleNewStyle; - -public: - VTKM_CONT - ArrayHandle() - : Superclass() - { - } - - VTKM_CONT - ArrayHandle(const ArrayHandle& src) - : Superclass(src) - { - } - - VTKM_CONT - ArrayHandle(ArrayHandle&& src) noexcept - : Superclass(std::move(src)) - { - } - - VTKM_CONT - ArrayHandle(const ArrayHandleNewStyle& src) - : Superclass(src) - { - } - - VTKM_CONT - ArrayHandle(ArrayHandleNewStyle&& src) noexcept - : Superclass(std::move(src)) - { - } - - VTKM_CONT ArrayHandle( - const vtkm::cont::internal::Buffer* buffers, - const typename Superclass::StorageType& storage = typename Superclass::StorageType()) - : Superclass(buffers, storage) - { - } - - VTKM_CONT ArrayHandle( - const std::vector& buffers, - const typename Superclass::StorageType& storage = typename Superclass::StorageType()) - : Superclass(buffers, storage) - { - } - - VTKM_CONT - ArrayHandle& operator=( - const ArrayHandle& src) - { - this->Superclass::operator=(src); - return *this; - } - - VTKM_CONT - ArrayHandle& operator=( - ArrayHandle&& src) noexcept - { - this->Superclass::operator=(std::move(src)); - return *this; - } - - VTKM_CONT ~ArrayHandle() {} -}; +VTKM_ARRAY_HANDLE_NEW_STYLE(T, vtkm::cont::StorageTagBasic); template class VTKM_ALWAYS_EXPORT ArrayHandleBasic : public ArrayHandle diff --git a/vtkm/cont/ArrayHandleBitField.h b/vtkm/cont/ArrayHandleBitField.h index 6cc445f3a..1322dcf52 100644 --- a/vtkm/cont/ArrayHandleBitField.h +++ b/vtkm/cont/ArrayHandleBitField.h @@ -137,76 +137,8 @@ public: } // end namespace internal -// This can go away once ArrayHandle is replaced with ArrayHandleNewStyle template -class VTKM_ALWAYS_EXPORT ArrayHandle - : public ArrayHandleNewStyle -{ - using Superclass = ArrayHandleNewStyle; - -public: - VTKM_CONT - ArrayHandle() - : Superclass() - { - } - - VTKM_CONT - ArrayHandle(const ArrayHandle& src) - : Superclass(src) - { - } - - VTKM_CONT - ArrayHandle(ArrayHandle&& src) noexcept - : Superclass(std::move(src)) - { - } - - VTKM_CONT - ArrayHandle(const ArrayHandleNewStyle& src) - : Superclass(src) - { - } - - VTKM_CONT - ArrayHandle(ArrayHandleNewStyle&& src) noexcept - : Superclass(std::move(src)) - { - } - - VTKM_CONT ArrayHandle( - const vtkm::cont::internal::Buffer* buffers, - const typename Superclass::StorageType& storage = typename Superclass::StorageType()) - : Superclass(buffers, storage) - { - } - - VTKM_CONT ArrayHandle( - const std::vector& buffers, - const typename Superclass::StorageType& storage = typename Superclass::StorageType()) - : Superclass(buffers, storage) - { - } - - VTKM_CONT - ArrayHandle& operator=( - const ArrayHandle& src) - { - this->Superclass::operator=(src); - return *this; - } - - VTKM_CONT - ArrayHandle& operator=( - ArrayHandle&& src) noexcept - { - this->Superclass::operator=(std::move(src)); - return *this; - } - - VTKM_CONT ~ArrayHandle() {} -}; +VTKM_ARRAY_HANDLE_NEW_STYLE(T, vtkm::cont::internal::StorageTagBitField); /// The ArrayHandleBitField class is a boolean-valued ArrayHandle that is backed /// by a BitField. diff --git a/vtkm/cont/ArrayHandleSOA.h b/vtkm/cont/ArrayHandleSOA.h index ddeda088e..d5ced911d 100644 --- a/vtkm/cont/ArrayHandleSOA.h +++ b/vtkm/cont/ArrayHandleSOA.h @@ -203,76 +203,8 @@ public: } // namespace internal -// This can go away once ArrayHandle is replaced with ArrayHandleNewStyle template -class VTKM_ALWAYS_EXPORT ArrayHandle - : public ArrayHandleNewStyle -{ - using Superclass = ArrayHandleNewStyle; - -public: - VTKM_CONT - ArrayHandle() - : Superclass() - { - } - - VTKM_CONT - ArrayHandle(const ArrayHandle& src) - : Superclass(src) - { - } - - VTKM_CONT - ArrayHandle(ArrayHandle&& src) noexcept - : Superclass(std::move(src)) - { - } - - VTKM_CONT - ArrayHandle(const ArrayHandleNewStyle& src) - : Superclass(src) - { - } - - VTKM_CONT - ArrayHandle(ArrayHandleNewStyle&& src) noexcept - : Superclass(std::move(src)) - { - } - - VTKM_CONT ArrayHandle( - const vtkm::cont::internal::Buffer* buffers, - const typename Superclass::StorageType& storage = typename Superclass::StorageType()) - : Superclass(buffers, storage) - { - } - - VTKM_CONT ArrayHandle( - const std::vector& buffers, - const typename Superclass::StorageType& storage = typename Superclass::StorageType()) - : Superclass(buffers, storage) - { - } - - VTKM_CONT - ArrayHandle& operator=( - const ArrayHandle& src) - { - this->Superclass::operator=(src); - return *this; - } - - VTKM_CONT - ArrayHandle& operator=( - ArrayHandle&& src) noexcept - { - this->Superclass::operator=(std::move(src)); - return *this; - } - - VTKM_CONT ~ArrayHandle() {} -}; +VTKM_ARRAY_HANDLE_NEW_STYLE(T, vtkm::cont::StorageTagSOA); /// \brief An `ArrayHandle` that for Vecs stores each component in a separate physical array. ///