/** *Athinwrapperaroundrtl::Referencetoimplementtheacquireanddisposesemanticswewantforreferencestovcl::Windowsubclasses. * *Formoredetailsonthedesignpleaseseevcl/README.lifecycle * *@paramreference_typemustbeasubclassofvcl::Window
*/ template <class reference_type> class VclPtr
{
static_assert(
vcl::detail::isIncompleteOrDerivedFromVclReferenceBase<reference_type>(
nullptr), "template argument type must be derived from VclReferenceBase");
#ifdefined(DBG_UTIL) && !defined(_WIN32)
~VclPtr()
{
assert(m_rInnerRef.get() == nullptr || vclmain::isAlive()); // We can be one of the intermediate counts, but if we are the last // VclPtr keeping this object alive, then something forgot to call dispose().
assert((!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1)
&& "someone forgot to call dispose()");
}
VclPtr(VclPtr const &) = default;
VclPtr(VclPtr &&) = default;
VclPtr & operator =(VclPtr const &) = default;
VclPtr & operator =(VclPtr &&) = default; #endif
/** Probably most common used: handle->someBodyOp().
*/
reference_type * operator->() const
{ return m_rInnerRef.get();
}
/** Get the body. Can be used instead of operator->(). I.e.handle->someBodyOp()andhandle.get()->someBodyOp() arethesame.
*/
reference_type * get() const
{ return m_rInnerRef.get();
}
void disposeAndClear()
{ // hold it alive for the lifetime of this method
::rtl::Reference<reference_type> aTmp(std::move(m_rInnerRef)); // coverity[use_after_move : SUPPRESS] - the move ctor above must take care of it
assert(!m_rInnerRef); if (aTmp.get()) {
aTmp->disposeOnce();
}
}
/** Needed to place VclPtr's into STL collection.
*/ booloperator< (const VclPtr & handle) const
{ return (m_rInnerRef < handle.m_rInnerRef);
}
}; // class VclPtr
template <class reference_type> class ScopedVclPtr : public VclPtr<reference_type>
{ public: /** Constructor...
*/ using VclPtr<reference_type>::VclPtr;
~ScopedVclPtr()
{
VclPtr<reference_type>::disposeAndClear();
assert(VclPtr<reference_type>::get() == nullptr); // make sure there are no lingering references
}
private: // Most likely we don't want this default copy-constructor.
ScopedVclPtr (const ScopedVclPtr<reference_type> &) = delete; // And certainly we don't want a default assignment operator.
ScopedVclPtr<reference_type>& operator = (const ScopedVclPtr<reference_type> &) = delete; // And disallow reset as that doesn't call disposeAndClear on the original reference void reset() = delete; void reset(reference_type *pBody) = delete;
private: // Prevent the above perfect forwarding ctor from hijacking (accidental) // attempts at ScopedVclPtrInstance copy construction (where the hijacking // would typically lead to somewhat obscure error messages); both non-const // and const variants are needed here, as the ScopedVclPtr base class has a // const--variant copy ctor, so the implicitly declared copy ctor for // ScopedVclPtrInstance would also be the const variant, so non-const copy // construction attempts would be hijacked by the perfect forwarding ctor; // but if we only declared a non-const variant here, the const variant would // no longer be implicitly declared (as there would already be an explicitly // declared copy ctor), so const copy construction attempts would then be // hijacked by the perfect forwarding ctor:
ScopedVclPtrInstance(ScopedVclPtrInstance &) = delete;
ScopedVclPtrInstance(ScopedVclPtrInstance const &) = delete;
}; #ifdefined _MSC_VER #pragma warning(pop) #endif
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.