44#ifndef vtkWebGPUHandle_h
45#define vtkWebGPUHandle_h
47#include "vtkABINamespace.h"
55VTK_ABI_NAMESPACE_BEGIN
64template <
typename T,
void (*AddRefFn)(T),
void (*ReleaseFn)(T)>
104 if (this->Raw !=
nullptr)
111 : Raw(std::exchange(other.Raw,
nullptr))
128 std::swap(this->Raw, other.Raw);
137 if (T raw = std::exchange(this->Raw,
nullptr))
147 T
Release() {
return std::exchange(this->Raw,
nullptr); }
154 T
Get()
const {
return this->Raw; }
155 operator T() const& {
return this->Raw; }
164 operator T() const&& = delete;
167 explicit operator
bool()
const {
return this->Raw !=
nullptr; }
173template <
typename T,
void (*A)(T),
void (*R)(T)>
176 return handle.
Get() ==
nullptr;
178template <
typename T,
void (*A)(T),
void (*R)(T)>
181 return handle.
Get() !=
nullptr;
183template <
typename T,
void (*A)(T),
void (*R)(T)>
186 return handle.
Get() ==
nullptr;
188template <
typename T,
void (*A)(T),
void (*R)(T)>
191 return handle.
Get() !=
nullptr;
202template <
typename T,
typename ReleaseFn>
212#define vtkWebGPUDeclareHandle(Name) \
213 using Name = Handle<WGPU##Name, &wgpu##Name##AddRef, &wgpu##Name##Release>
238#undef vtkWebGPUDeclareHandle
Reference-counted owner of a WebGPU C API handle.
Handle(std::nullptr_t)
A null handle.
void Reset()
Release the referenced object, if any, and become null.
T Get() const
Access the underlying raw handle without transferring ownership.
Handle(Handle &&other) noexcept
T Release()
Relinquish ownership to the caller, who becomes responsible for releasing the returned handle.
Handle & operator=(std::nullptr_t)
Release whatever is held and become null.
Handle & operator=(Handle other) noexcept
Handle(const Handle &other)
static Handle Acquire(T raw)
Adopt raw without adding a reference.
static Handle Reference(T raw)
Take a new reference to raw, which stays owned by the caller.
bool operator==(const Handle< T, A, R > &handle, std::nullptr_t)
void ReleaseAndNull(T &raw, ReleaseFn release)
Release raw if it is non-null and set it to null.
bool operator!=(const Handle< T, A, R > &handle, std::nullptr_t)
#define vtkWebGPUDeclareHandle(Name)