//============================================================================ // Copyright (c) Kitware, Inc. // All rights reserved. // See LICENSE.txt 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. //============================================================================ #ifndef vtk_m_cont_VirtualObjectHandle_hxx #define vtk_m_cont_VirtualObjectHandle_hxx #include #include #include #include #include #include namespace vtkm { namespace cont { template VirtualObjectHandle::VirtualObjectHandle() : Internals(std::make_shared()) { } template template VirtualObjectHandle::VirtualObjectHandle(VirtualDerivedType* derived, bool acquireOwnership, DeviceAdapterList devices) : Internals(std::make_shared()) { this->Reset(derived, acquireOwnership, devices); } template bool VirtualObjectHandle::GetValid() const { return this->Internals->HostPtr() != nullptr; } template bool VirtualObjectHandle::OwnsObject() const { return this->Internals->WillReleaseHostPointer(); } template VirtualBaseType* VirtualObjectHandle::Get() { return static_cast(this->Internals->HostPtr()); } /// Reset the underlying derived type object template template void VirtualObjectHandle::Reset(VirtualDerivedType* derived, bool acquireOwnership, DeviceAdapterList devices) { VTKM_STATIC_ASSERT_MSG((std::is_base_of::value), "Tried to bind a type that is not a subclass of the base class."); if (acquireOwnership) { // auto deleter = [](void* p) { delete static_cast(p); }; this->Internals->UpdateHost(derived, nullptr); } else { this->Internals->UpdateHost(derived, nullptr); } if (derived) { vtkm::cont::internal::ForEachValidDevice( devices, internal::CreateTransferInterface(), this->Internals.get(), derived); } } template const VirtualBaseType* VirtualObjectHandle::PrepareForExecution( vtkm::cont::DeviceAdapterId deviceId) const { const bool validId = this->Internals->DeviceIdIsValid(deviceId); if (!validId) { //can't be reached since DeviceIdIsValid will through an exception //if deviceId is not valid return nullptr; } return static_cast(this->Internals->PrepareForExecution(deviceId)); } } } // vtkm::cont #endif // vtk_m_cont_VirtualObjectHandle_h