plugify 1.0.0.0
Loading...
Searching...
No Matches
handle.hpp
1#pragma once
2
3#include <type_traits>
4#include <utility>
5
6namespace plugify {
17 template<typename T>
18 class Handle {
19 public:
23 Handle() noexcept : _impl{nullptr} {}
24
29 Handle(T& impl) noexcept : _impl{&impl} {}
30
35 Handle(const Handle&) = default;
40 Handle(Handle&&) = default;
41
47 auto operator<=>(const Handle&) const = default;
48
54 Handle& operator=(const Handle&) & = default;
59 Handle& operator=(const Handle&) && = delete;
65 Handle& operator=(Handle&&) & = default;
70 Handle& operator=(Handle&&) && = delete;
71
76 explicit operator bool() const noexcept {
77 return _impl != nullptr;
78 }
79
84 operator uintptr_t() const noexcept {
85 return reinterpret_cast<uintptr_t>(_impl);
86 }
87
92 operator void*() const noexcept {
93 return (void*) _impl;
94 }
95
96 protected:
97 T* _impl;
98 };
99}
A generic handle class that manages a pointer to an object of type T.
Definition handle.hpp:18
Handle(T &impl) noexcept
Constructs a Handle object from an instance of type T.
Definition handle.hpp:29
Handle() noexcept
Default constructor. Initializes the handle with a null pointer.
Definition handle.hpp:23
Handle(const Handle &)=default
Copy constructor. Creates a new Handle object from another Handle object.
Handle & operator=(const Handle &) &&=delete
Copy assignment operator for rvalue references is deleted.
Handle & operator=(Handle &&) &&=delete
Move assignment operator for rvalue references is deleted.
T * _impl
A pointer to the referenced implementation of type T.
Definition handle.hpp:97
auto operator<=>(const Handle &) const =default
Comparison operator (<=>) for comparing two Handle objects.
Handle(Handle &&)=default
Move constructor. Transfers ownership from another Handle object.
Handle & operator=(Handle &&) &=default
Move assignment operator. Transfers ownership from another Handle object.
Handle & operator=(const Handle &) &=default
Copy assignment operator. Copies the handle from another Handle object.