nux-1.14.0
nux::ObjectWeakPtr< T > Class Template Reference

A weak smart pointer class. Implemented as an intrusive smart pointer. More...

#include <NuxCore/ObjectPtr.h>

List of all members.

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.
ObjectWeakPtroperator= (ObjectWeakPtr< T > const &other)
 Assignment of a weak smart pointer of type T.
template<typename O >
ObjectWeakPtroperator= (const ObjectWeakPtr< O > &other)
 Assignment of a weak smart pointer of Type O that inherits from type T.
template<typename O >
ObjectWeakPtroperator= (const ObjectPtr< O > &other)
 Assignment of a smart pointer of Type O that inherits from type T.
ObjectWeakPtroperator= (T *ptr)
 Construction with a base pointer of type T.
template<typename O >
ObjectWeakPtroperator= (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)

Detailed Description

template<typename T>
class nux::ObjectWeakPtr< T >

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.


Constructor & Destructor Documentation

template<typename T>
nux::ObjectWeakPtr< T >::ObjectWeakPtr ( T *  ptr) [inline, explicit]

Construction with a base pointer of type T.

Parameters:
ptrStart maintaining a reference count of the passed pointer.
WarnMissuseIf 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();
    }
template<typename T>
template<typename O >
nux::ObjectWeakPtr< T >::ObjectWeakPtr ( O *  ptr,
bool  WarnMissuse = false 
) [inline, explicit]

Construction with a base pointer of type O that inherits from type T.

Parameters:
ptrStart maintaining a reference count of the passed pointer.
WarnMissuseIf 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();
      }
    }
template<typename T>
nux::ObjectWeakPtr< T >::ObjectWeakPtr ( ObjectWeakPtr< T > const &  other) [inline]

Copy constructor.

Parameters:
otherParameter with type T.

Definition at line 414 of file ObjectPtr.h.

      : ptr_(other.ptr_)
    {
      ConnectListener();
    }
template<typename T>
template<typename O >
nux::ObjectWeakPtr< T >::ObjectWeakPtr ( const ObjectWeakPtr< O > &  other) [inline]

Copy constructor.

Parameters:
otherParameter 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();
      }
    }
template<typename T>
template<typename O >
nux::ObjectWeakPtr< T >::ObjectWeakPtr ( const ObjectPtr< O > &  other) [inline]

Construction from a smart pointer of type O that inherits from type T.

Parameters:
otherMaintains 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();
      }
    }

Member Function Documentation

template<typename T>
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.

Parameters:
Returnthe stored pointer.

Definition at line 659 of file ObjectPtr.h.

Referenced by nux::WindowCompositor::GetProcessingTopView().

    {
      return ptr_;
    }
template<typename T>
T* nux::ObjectWeakPtr< T >::GetPointer ( ) [inline]

Return the stored pointer.

Caller of this function should Reference the pointer if they intend to keep it.

Parameters:
Returnthe stored pointer.

Definition at line 669 of file ObjectPtr.h.

    {
      return ptr_;
    }
template<typename T>
bool nux::ObjectWeakPtr< T >::IsNull ( ) const [inline]

Return true is the hosted pointer is null or has been destroyed.

Returns:
True if the internal pointer is null or has been destroyed.

Definition at line 632 of file ObjectPtr.h.

    {
      return !IsValid();
    }
template<typename T>
bool nux::ObjectWeakPtr< T >::IsValid ( ) const [inline]

Return true is the hosted pointer is not null or has not been destroyed.

Returns:
True if the internal 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_);
    }
template<typename T>
bool nux::ObjectWeakPtr< T >::operator() ( ) const [inline]

Return true is the hosted pointer is not null or has not been destroyed.

Returns:
True if the internal pointer is not null.

Definition at line 614 of file ObjectPtr.h.

    {
      return bool(ptr_);
    }
template<typename T>
template<typename O >
ObjectWeakPtr& nux::ObjectWeakPtr< T >::operator= ( const ObjectWeakPtr< O > &  other) [inline]

Assignment of a weak smart pointer of Type O that inherits from type T.

Parameters:
otherWeak 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;
    }
template<typename T>
ObjectWeakPtr& nux::ObjectWeakPtr< T >::operator= ( T *  ptr) [inline]

Construction with a base pointer of type T.

Parameters:
ptrStart maintaining a reference count of the passed pointer.
WarnMissuseIf 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;
    }
template<typename T>
template<typename O >
ObjectWeakPtr& nux::ObjectWeakPtr< T >::operator= ( const ObjectPtr< O > &  other) [inline]

Assignment of a smart pointer of Type O that inherits from type T.

Parameters:
otherMaintains 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;
    }
template<typename T>
ObjectWeakPtr& nux::ObjectWeakPtr< T >::operator= ( ObjectWeakPtr< T > const &  other) [inline]

Assignment of a weak smart pointer of type T.

Parameters:
otherWeak smart pointer of type T.

Definition at line 456 of file ObjectPtr.h.

    {
      Disconnect();
      ptr_ = other.ptr_;
      ConnectListener();
      return *this;
    }
template<typename T>
template<typename U >
bool nux::ObjectWeakPtr< T >::operator== ( const ObjectWeakPtr< U > &  other) const [inline]

A weak pointer

Returns:
True is this weak pointer host the same pointer as the weak pointer passed as parameter.

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_);
    }
template<typename T>
template<typename U >
bool nux::ObjectWeakPtr< T >::operator== ( const ObjectPtr< U > &  other) const [inline]

An object pointer

Returns:
True is this weak pointer host the same pointer as the object pointer passed as parameter.

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_);
    }
template<typename T>
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.

Returns:
True this was the last weak reference on the hosted object.

Definition at line 647 of file ObjectPtr.h.

    {
        Disconnect();
        ptr_ = nullptr;
        return false;
    }

The documentation for this class was generated from the following file:
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends