mirror of
https://github.com/hyprwm/hyprutils.git
synced 2026-05-09 08:48:03 +02:00
memory: Add force reinterpret constructor to shared pointer
This commit is contained in:
parent
61a5382f4b
commit
c3ddf46b2a
1 changed files with 14 additions and 2 deletions
|
|
@ -16,6 +16,12 @@
|
|||
namespace Hyprutils {
|
||||
namespace Memory {
|
||||
|
||||
struct SForceReinterpret {
|
||||
explicit SForceReinterpret() = default;
|
||||
};
|
||||
|
||||
constexpr SForceReinterpret FORCE_REINTERPRET = SForceReinterpret();
|
||||
|
||||
template <typename T>
|
||||
class CSharedPointer {
|
||||
public:
|
||||
|
|
@ -38,6 +44,12 @@ namespace Hyprutils {
|
|||
increment();
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
CSharedPointer(const CSharedPointer<U>& ref, SForceReinterpret) noexcept {
|
||||
impl_ = ref.impl_;
|
||||
increment();
|
||||
}
|
||||
|
||||
CSharedPointer(const CSharedPointer& ref) noexcept {
|
||||
impl_ = ref.impl_;
|
||||
increment();
|
||||
|
|
@ -144,7 +156,7 @@ namespace Hyprutils {
|
|||
Impl_::impl_base* impl_ = nullptr;
|
||||
|
||||
private:
|
||||
/*
|
||||
/*
|
||||
no-op if there is no impl_
|
||||
may delete the stored object if ref == 0
|
||||
may delete and reset impl_ if ref == 0 and weak == 0
|
||||
|
|
@ -167,7 +179,7 @@ namespace Hyprutils {
|
|||
impl_->inc();
|
||||
}
|
||||
|
||||
/* destroy the pointed-to object
|
||||
/* destroy the pointed-to object
|
||||
if able, will also destroy impl */
|
||||
void destroyImpl() {
|
||||
// destroy the impl contents
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue