plugify 1.2.6
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 #if __cpp_impl_three_way_comparison
48 auto operator<=>(const Handle&) const = default;
49#endif // __cpp_impl_three_way_comparison
50
56 Handle& operator=(const Handle&) & = default;
61 Handle& operator=(const Handle&) && = delete;
67 Handle& operator=(Handle&&) & = default;
72 Handle& operator=(Handle&&) && = delete;
73
78 explicit operator bool() const noexcept {
79 return _impl != nullptr;
80 }
81
86 operator uintptr_t() const noexcept {
87 return reinterpret_cast<uintptr_t>(_impl);
88 }
89
94 operator void*() const noexcept {
95 return (void*) _impl;
96 }
97
98 protected:
99 T* _impl;
100 };
101}
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:99
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
Comparison operator (<=>) for comparing two Handle objects.