1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-09 23:34:20 +00:00

VSTComSmartPtr: Enable automatic upcasting

This commit is contained in:
reuk 2025-08-20 15:33:57 +01:00
parent db64002610
commit 6fa7b21435
No known key found for this signature in database

View file

@ -166,8 +166,19 @@ class VSTComSmartPtr
{ {
public: public:
VSTComSmartPtr() = default; VSTComSmartPtr() = default;
VSTComSmartPtr (const VSTComSmartPtr& other) noexcept : source (other.source) { if (source != nullptr) source->addRef(); }
~VSTComSmartPtr() { if (source != nullptr) source->release(); } ~VSTComSmartPtr()
{
if (source != nullptr)
source->release();
}
VSTComSmartPtr (const VSTComSmartPtr& other) noexcept
: VSTComSmartPtr (other.get(), true) {}
template <typename Other, std::enable_if_t<! std::is_same_v<Other, ObjectType>, int> = 0>
VSTComSmartPtr (const VSTComSmartPtr<Other>& other) noexcept
: VSTComSmartPtr (other.get(), true) {}
explicit operator bool() const noexcept { return operator!= (nullptr); } explicit operator bool() const noexcept { return operator!= (nullptr); }
ObjectType* get() const noexcept { return source; } ObjectType* get() const noexcept { return source; }
@ -181,6 +192,12 @@ public:
return *this; return *this;
} }
template <typename Other, std::enable_if_t<! std::is_same_v<Other, ObjectType>, int> = 0>
VSTComSmartPtr& operator= (const VSTComSmartPtr<Other>& other)
{
return operator= (VSTComSmartPtr { other });
}
VSTComSmartPtr& operator= (std::nullptr_t) VSTComSmartPtr& operator= (std::nullptr_t)
{ {
return operator= (VSTComSmartPtr{}); return operator= (VSTComSmartPtr{});
@ -215,7 +232,13 @@ public:
} }
private: private:
explicit VSTComSmartPtr (ObjectType* object, bool autoAddRef) noexcept : source (object) { if (source != nullptr && autoAddRef) source->addRef(); } VSTComSmartPtr (ObjectType* object, bool autoAddRef) noexcept
: source (object)
{
if (source != nullptr && autoAddRef)
source->addRef();
}
ObjectType* source = nullptr; ObjectType* source = nullptr;
}; };