44#ifndef vtkWebGPUHandle_h
45#define vtkWebGPUHandle_h
47#include "vtkABINamespace.h"
55VTK_ABI_NAMESPACE_BEGIN
63template <
typename T,
typename Traits>
103 if (this->Raw !=
nullptr)
105 Traits::AddRef(this->Raw);
110 : Raw(std::exchange(other.Raw,
nullptr))
127 std::swap(this->Raw, other.Raw);
136 if (T raw = std::exchange(this->Raw,
nullptr))
138 Traits::Release(raw);
146 T
Release() {
return std::exchange(this->Raw,
nullptr); }
153 T
Get()
const {
return this->Raw; }
154 operator T() const& {
return this->Raw; }
163 operator T() const&& = delete;
166 explicit operator
bool()
const {
return this->Raw !=
nullptr; }
172template <
typename T,
typename Traits>
175 return handle.
Get() ==
nullptr;
177template <
typename T,
typename Traits>
180 return handle.
Get() !=
nullptr;
182template <
typename T,
typename Traits>
185 return handle.
Get() ==
nullptr;
187template <
typename T,
typename Traits>
190 return handle.
Get() !=
nullptr;
201template <
typename T,
typename ReleaseFn>
213#define vtkWebGPUDeclareHandle(Name) \
214 struct Name##Traits \
216 static void AddRef(WGPU##Name handle) \
218 wgpu##Name##AddRef(handle); \
220 static void Release(WGPU##Name handle) \
222 wgpu##Name##Release(handle); \
225 using Name = Handle<WGPU##Name, Name##Traits>
250#undef vtkWebGPUDeclareHandle
Reference-counted owner of a WebGPU C API handle.
void Reset()
Release the referenced object, if any, and become null.
Handle(const Handle &other)
Handle(Handle &&other) noexcept
T Release()
Relinquish ownership to the caller, who becomes responsible for releasing the returned handle.
static Handle Acquire(T raw)
Adopt raw without adding a reference.
T Get() const
Access the underlying raw handle without transferring ownership.
Handle & operator=(std::nullptr_t)
Release whatever is held and become null.
static Handle Reference(T raw)
Take a new reference to raw, which stays owned by the caller.
Handle & operator=(Handle other) noexcept
Handle(std::nullptr_t)
A null handle.
void ReleaseAndNull(T &raw, ReleaseFn release)
Release raw if it is non-null and set it to null.
bool operator!=(const Handle< T, Traits > &handle, std::nullptr_t)
bool operator==(const Handle< T, Traits > &handle, std::nullptr_t)
#define vtkWebGPUDeclareHandle(Name)