nux-1.14.0
|
A weak smart pointer class. Implemented as an intrusive smart pointer. More...
#include <NuxCore/ObjectPtr.h>
Public Member Functions | |
ObjectWeakPtr () | |
Constructor. | |
ObjectWeakPtr (T *ptr) | |
Construction with a base pointer of type T. | |
template<typename O > | |
ObjectWeakPtr (O *ptr, bool WarnMissuse=false) | |
Construction with a base pointer of type O that inherits from type T. | |
ObjectWeakPtr (ObjectWeakPtr< T > const &other) | |
Copy constructor. | |
template<typename O > | |
ObjectWeakPtr (const ObjectWeakPtr< O > &other) | |
Copy constructor. | |
template<typename O > | |
ObjectWeakPtr (const ObjectPtr< O > &other) | |
Construction from a smart pointer of type O that inherits from type T. | |
ObjectWeakPtr & | operator= (ObjectWeakPtr< T > const &other) |
Assignment of a weak smart pointer of type T. | |
template<typename O > | |
ObjectWeakPtr & | operator= (const ObjectWeakPtr< O > &other) |
Assignment of a weak smart pointer of Type O that inherits from type T. | |
template<typename O > | |
ObjectWeakPtr & | operator= (const ObjectPtr< O > &other) |
Assignment of a smart pointer of Type O that inherits from type T. | |
ObjectWeakPtr & | operator= (T *ptr) |
Construction with a base pointer of type T. | |
template<typename O > | |
ObjectWeakPtr & | operator= (O *ptr) |
T & | operator* () const |
T * | operator-> () const |
bool | operator< (T *ptr) const |
bool | operator> (T *ptr) const |
bool | operator< (ObjectWeakPtr< T > other) const |
bool | operator> (ObjectWeakPtr< T > other) const |
template<typename U > | |
bool | operator!= (U other) const |
bool | operator== (T *ptr) const |
template<typename U > | |
bool | operator== (U *ptr) const |
template<typename U > | |
bool | operator== (const ObjectWeakPtr< U > &other) const |
template<typename U > | |
bool | operator== (const ObjectPtr< U > &other) const |
bool | operator() () const |
Return true is the hosted pointer is not null or has not been destroyed. | |
bool | IsValid () const |
Return true is the hosted pointer is not null or has not been destroyed. | |
bool | IsNull () const |
Return true is the hosted pointer is null or has been destroyed. | |
bool | Release () |
Release the hosted pointer from this object. | |
const T * | GetPointer () const |
Return the stored pointer. | |
T * | GetPointer () |
Return the stored pointer. | |
Friends | |
class | ObjectWeakPtr |
template<typename U > | |
bool | operator== (U *, const ObjectWeakPtr< U > &a) |
template<typename U > | |
bool | operator!= (U *, const ObjectWeakPtr< U > &a) |
template<typename U , typename F > | |
ObjectWeakPtr< U > | staticCast (const ObjectWeakPtr< F > &from) |
template<typename U , typename F > | |
ObjectWeakPtr< U > | constCast (const ObjectWeakPtr< F > &from) |
template<typename U , typename F > | |
ObjectWeakPtr< U > | dynamicCast (const ObjectWeakPtr< F > &from) |
template<typename U , typename F > | |
ObjectWeakPtr< U > | checkedCast (const ObjectWeakPtr< F > &from) |
template<typename U , typename F > | |
ObjectWeakPtr< U > | queryCast (const ObjectWeakPtr< F > &from) |
A weak smart pointer class. Implemented as an intrusive smart pointer.
A weak smart pointer is built from a smart pointer or another weak smart pointer. It increments and decrements the total reference count of an pointer. Even is the original pointer is destroyed, weak smart pointers still point to the RefCounts pointers of the original pointer and can use it to check if the pointer is still valid or not.
Definition at line 365 of file ObjectPtr.h.
nux::ObjectWeakPtr< T >::ObjectWeakPtr | ( | T * | ptr | ) | [inline, explicit] |
Construction with a base pointer of type T.
ptr | Start maintaining a reference count of the passed pointer. |
WarnMissuse | If True, then ObjectPtr test is ptr is owned or not. If ptr is not owned and WarnMissuse is True, then Print a warning message. This is a debug feature to detect cases such as "ObjectPtr(ObjectA) myobject(ptr);", because the calling code will no longer have a reference on ptr. |
Definition at line 383 of file ObjectPtr.h.
: ptr_(ptr) { ConnectListener(); }
nux::ObjectWeakPtr< T >::ObjectWeakPtr | ( | O * | ptr, |
bool | WarnMissuse = false |
||
) | [inline, explicit] |
Construction with a base pointer of type O that inherits from type T.
ptr | Start maintaining a reference count of the passed pointer. |
WarnMissuse | If True, then ObjectPtr test is ptr is owned or not. If ptr is not owned and WarnMissuse is True, then Print a warning message. This is a debug feature to detect cases such as "ObjectPtr(ObjectA) myobject(ptr);", because the calling code will no longer have a reference on ptr. |
Definition at line 399 of file ObjectPtr.h.
: ptr_(nullptr) { if (ptr && (ptr->Type().IsDerivedFromType(T::StaticObjectType))) { ptr_ = static_cast<T*>(ptr); ConnectListener(); } }
nux::ObjectWeakPtr< T >::ObjectWeakPtr | ( | ObjectWeakPtr< T > const & | other | ) | [inline] |
Copy constructor.
other | Parameter with type T. |
Definition at line 414 of file ObjectPtr.h.
: ptr_(other.ptr_) { ConnectListener(); }
nux::ObjectWeakPtr< T >::ObjectWeakPtr | ( | const ObjectWeakPtr< O > & | other | ) | [inline] |
Copy constructor.
other | Parameter with a type derived from T. |
Definition at line 425 of file ObjectPtr.h.
: ptr_(nullptr) { if (other.ptr_ && (other.ptr_->Type().IsDerivedFromType(T::StaticObjectType))) { ptr_ = static_cast<T*>(other.ptr_); ConnectListener(); } }
nux::ObjectWeakPtr< T >::ObjectWeakPtr | ( | const ObjectPtr< O > & | other | ) | [inline] |
Construction from a smart pointer of type O that inherits from type T.
other | Maintains a weak smart pointer reference to this parameter. |
Definition at line 441 of file ObjectPtr.h.
: ptr_(nullptr) { if (other.ptr_ && (other.ptr_->Type().IsDerivedFromType(T::StaticObjectType))) { ptr_ = static_cast<T*>(other.ptr_); ConnectListener(); } }
const T* nux::ObjectWeakPtr< T >::GetPointer | ( | ) | const [inline] |
Return the stored pointer.
Caller of this function should Reference the pointer if they intend to keep it.
Return | the stored pointer. |
Definition at line 659 of file ObjectPtr.h.
Referenced by nux::WindowCompositor::GetProcessingTopView().
{
return ptr_;
}
T* nux::ObjectWeakPtr< T >::GetPointer | ( | ) | [inline] |
Return the stored pointer.
Caller of this function should Reference the pointer if they intend to keep it.
Return | the stored pointer. |
Definition at line 669 of file ObjectPtr.h.
{
return ptr_;
}
bool nux::ObjectWeakPtr< T >::IsNull | ( | ) | const [inline] |
Return true is the hosted pointer is null or has been destroyed.
Definition at line 632 of file ObjectPtr.h.
{ return !IsValid(); }
bool nux::ObjectWeakPtr< T >::IsValid | ( | ) | const [inline] |
Return true is the hosted pointer is not null or has not been destroyed.
Definition at line 623 of file ObjectPtr.h.
Referenced by nux::ObjectWeakPtr< BaseWindow >::IsNull(), and nux::WindowCompositor::ValidateMouseInsideTooltipArea().
{
return bool(ptr_);
}
bool nux::ObjectWeakPtr< T >::operator() | ( | ) | const [inline] |
Return true is the hosted pointer is not null or has not been destroyed.
Definition at line 614 of file ObjectPtr.h.
{
return bool(ptr_);
}
ObjectWeakPtr& nux::ObjectWeakPtr< T >::operator= | ( | const ObjectWeakPtr< O > & | other | ) | [inline] |
Assignment of a weak smart pointer of Type O that inherits from type T.
other | Weak smart pointer of type O. |
Definition at line 471 of file ObjectPtr.h.
{ Disconnect(); if (other.ptr_ && other.ptr_->Type().IsDerivedFromType(T::StaticObjectType)) { ptr_ = static_cast<T*>(other.ptr_); ConnectListener(); } return *this; }
ObjectWeakPtr& nux::ObjectWeakPtr< T >::operator= | ( | T * | ptr | ) | [inline] |
Construction with a base pointer of type T.
ptr | Start maintaining a reference count of the passed pointer. |
WarnMissuse | If True, then ObjectPtr test is ptr is owned or not. If ptr is not owned and WarnMissuse is True, then Print a warning message. This is a debug feature to detect cases such as "ObjectPtr(ObjectA) myobject(ptr);", because the calling code will no longer have a reference on ptr. |
Definition at line 507 of file ObjectPtr.h.
{ Disconnect(); ptr_ = ptr; ConnectListener(); return *this; }
ObjectWeakPtr& nux::ObjectWeakPtr< T >::operator= | ( | const ObjectPtr< O > & | other | ) | [inline] |
Assignment of a smart pointer of Type O that inherits from type T.
other | Maintains a weak smart pointer reference to this parameter. |
Definition at line 488 of file ObjectPtr.h.
{ Disconnect(); if (other.ptr_ && other.ptr_->Type().IsDerivedFromType(T::StaticObjectType)) { ptr_ = static_cast<T*>(other.ptr_); ConnectListener(); } return *this; }
ObjectWeakPtr& nux::ObjectWeakPtr< T >::operator= | ( | ObjectWeakPtr< T > const & | other | ) | [inline] |
Assignment of a weak smart pointer of type T.
other | Weak smart pointer of type T. |
Definition at line 456 of file ObjectPtr.h.
{ Disconnect(); ptr_ = other.ptr_; ConnectListener(); return *this; }
bool nux::ObjectWeakPtr< T >::operator== | ( | const ObjectWeakPtr< U > & | other | ) | const [inline] |
A weak pointer
Definition at line 589 of file ObjectPtr.h.
{ if (other.ptr_ && (!other.ptr_->Type().IsDerivedFromType (T::StaticObjectType) ) ) return false; return ptr_ == static_cast<T*>(other.ptr_); }
bool nux::ObjectWeakPtr< T >::operator== | ( | const ObjectPtr< U > & | other | ) | const [inline] |
An object pointer
Definition at line 602 of file ObjectPtr.h.
{ if (other.ptr_ && (!other.ptr_->Type().IsDerivedFromType (T::StaticObjectType) ) ) return false; return ptr_ == static_cast<T*>(other.ptr_); }
bool nux::ObjectWeakPtr< T >::Release | ( | ) | [inline] |
Release the hosted pointer from this object.
Release the hosted pointer from this object. After this call, the following members are null: _reference_count _weak_reference_count ptr_ This call decreases the count of weak reference before setting _weak_reference_count to null.
Definition at line 647 of file ObjectPtr.h.
{ Disconnect(); ptr_ = nullptr; return false; }