diff --git a/vtkm/cont/Storage.h b/vtkm/cont/Storage.h index 43fae45e3..4fd5f28d7 100644 --- a/vtkm/cont/Storage.h +++ b/vtkm/cont/Storage.h @@ -122,6 +122,11 @@ public: /// using PortalConstType = ::vtkm::cont::internal::ArrayPortalFromIterators; + VTKM_CONT Storage(const Storage& src); + VTKM_CONT Storage(Storage&& src) noexcept; + VTKM_CONT Storage& operator=(const Storage& src); + VTKM_CONT Storage& operator=(Storage&& src); + /// Returns a portal to the array. /// VTKM_CONT diff --git a/vtkm/cont/StorageBasic.cxx b/vtkm/cont/StorageBasic.cxx index 6ce467e3d..73f4b3197 100644 --- a/vtkm/cont/StorageBasic.cxx +++ b/vtkm/cont/StorageBasic.cxx @@ -118,11 +118,11 @@ StorageBasicBase::~StorageBasicBase() this->ReleaseResources(); } -StorageBasicBase::StorageBasicBase(StorageBasicBase&& src) - : Array(src.Array) - , AllocatedByteSize(src.AllocatedByteSize) - , NumberOfValues(src.NumberOfValues) - , DeleteFunction(src.DeleteFunction) +StorageBasicBase::StorageBasicBase(StorageBasicBase&& src) noexcept + : Array(src.Array), + AllocatedByteSize(src.AllocatedByteSize), + NumberOfValues(src.NumberOfValues), + DeleteFunction(src.DeleteFunction) { src.Array = nullptr; @@ -146,7 +146,7 @@ StorageBasicBase::StorageBasicBase(const StorageBasicBase& src) } } -StorageBasicBase StorageBasicBase::operator=(StorageBasicBase&& src) +StorageBasicBase& StorageBasicBase::operator=(StorageBasicBase&& src) noexcept { this->ReleaseResources(); this->Array = src.Array; @@ -161,7 +161,7 @@ StorageBasicBase StorageBasicBase::operator=(StorageBasicBase&& src) return *this; } -StorageBasicBase StorageBasicBase::operator=(const StorageBasicBase& src) +StorageBasicBase& StorageBasicBase::operator=(const StorageBasicBase& src) { if (src.DeleteFunction) { diff --git a/vtkm/cont/StorageBasic.h b/vtkm/cont/StorageBasic.h index 63162798a..f8157b1a7 100644 --- a/vtkm/cont/StorageBasic.h +++ b/vtkm/cont/StorageBasic.h @@ -83,10 +83,10 @@ public: VTKM_CONT ~StorageBasicBase(); - VTKM_CONT StorageBasicBase(StorageBasicBase&& src); + VTKM_CONT StorageBasicBase(StorageBasicBase&& src) noexcept; VTKM_CONT StorageBasicBase(const StorageBasicBase& src); - VTKM_CONT StorageBasicBase operator=(StorageBasicBase&& src); - VTKM_CONT StorageBasicBase operator=(const StorageBasicBase& src); + VTKM_CONT StorageBasicBase& operator=(StorageBasicBase&& src) noexcept; + VTKM_CONT StorageBasicBase& operator=(const StorageBasicBase& src); /// \brief Return the number of bytes allocated for this storage object(Capacity). /// @@ -178,6 +178,8 @@ public: public: /// \brief construct storage that VTK-m is responsible for VTKM_CONT Storage(); + VTKM_CONT Storage(const Storage& src); + VTKM_CONT Storage(Storage&& src) noexcept; /// \brief construct storage that VTK-m is not responsible for VTKM_CONT Storage(const ValueType* array, vtkm::Id numberOfValues); @@ -186,6 +188,9 @@ public: /// responsible for VTKM_CONT Storage(const ValueType* array, vtkm::Id numberOfValues, void (*deleteFunction)(void*)); + VTKM_CONT Storage& operator=(const Storage& src); + VTKM_CONT Storage& operator=(Storage&& src); + VTKM_CONT void Allocate(vtkm::Id numberOfValues); VTKM_CONT PortalType GetPortal(); diff --git a/vtkm/cont/StorageBasic.hxx b/vtkm/cont/StorageBasic.hxx index 36c0816d7..e30430a42 100644 --- a/vtkm/cont/StorageBasic.hxx +++ b/vtkm/cont/StorageBasic.hxx @@ -29,12 +29,25 @@ namespace cont namespace internal { + template Storage::Storage() : StorageBasicBase() { } +template +Storage::Storage(const Storage& src) + : StorageBasicBase(src) +{ +} + +template +Storage::Storage( + Storage&& src) noexcept : StorageBasicBase(std::move(src)) +{ +} + template Storage::Storage(const T* array, vtkm::Id numberOfValues) : StorageBasicBase(const_cast(array), numberOfValues, sizeof(T)) @@ -49,6 +62,22 @@ Storage::Storage(const T* array, { } +template +Storage& Storage::Storage:: +operator=(const Storage& src) +{ + return static_cast&>(StorageBasicBase::operator=(src)); +} + +template +Storage& Storage::Storage:: +operator=(Storage&& src) +{ + return static_cast&>( + StorageBasicBase::operator=(std::move(src))); +} + + template void Storage::Allocate(vtkm::Id numberOfValues) { diff --git a/vtkm/cont/StorageImplicit.h b/vtkm/cont/StorageImplicit.h index 5113800da..a9749adf5 100644 --- a/vtkm/cont/StorageImplicit.h +++ b/vtkm/cont/StorageImplicit.h @@ -55,6 +55,9 @@ namespace internal template class Storage> { + using ClassType = + Storage>; + public: using ValueType = typename ArrayPortalType::ValueType; using PortalConstType = ArrayPortalType; @@ -74,6 +77,11 @@ public: { } + VTKM_CONT Storage(const ClassType& src) = default; + VTKM_CONT Storage(ClassType&& src) = default; + VTKM_CONT ClassType& operator=(const ClassType& src) = default; + VTKM_CONT ClassType& operator=(ClassType&& src) = default; + // All these methods do nothing but raise errors. VTKM_CONT PortalType GetPortal() { throw vtkm::cont::ErrorBadValue("Implicit arrays are read-only."); }