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:
parent
db64002610
commit
6fa7b21435
1 changed files with 26 additions and 3 deletions
|
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue