The CYIWeakPtr is a smart pointer that does not take any ownership of a dynamically allocated object. It will never delete the object. When the object is deleted by the last strong reference, CYIWeakPtr will automatically point to nullptr.
CYIWeakPtr can serve as an object lifetime tracker while retaining the ability to access the object while being alive.
Consider the following example:
#include <smartptr/YiSharedPtr.h>

Public Member Functions | |
| CYIWeakPtr () | |
| CYIWeakPtr (const CYIWeakPtr< YI_PTR_TYPE > &rOther) | |
| template<typename YI_OTHER_PTR_TYPE > | |
| CYIWeakPtr (const CYIWeakPtr< YI_OTHER_PTR_TYPE > &rOther) | |
| CYIWeakPtr (const CYISharedPtr< YI_PTR_TYPE > &rOther) | |
| CYIWeakPtr (const std::shared_ptr< YI_PTR_TYPE > &rOther) | |
| template<typename YI_OTHER_PTR_TYPE > | |
| CYIWeakPtr (const std::weak_ptr< YI_OTHER_PTR_TYPE > &rOther) | |
| template<typename YI_OTHER_PTR_TYPE > | |
| CYIWeakPtr (const CYISharedPtr< YI_OTHER_PTR_TYPE > &rOther) | |
| ~CYIWeakPtr () | |
| void | Reset () |
| YI_PTR_TYPE * | Get () const |
| bool | IsNull () const |
| uint32_t | GetUseCount () const |
| void | Swap (CYIWeakPtr< YI_PTR_TYPE > &rPtr) |
| CYISharedPtr< YI_PTR_TYPE > | ToStrongPtr () const |
| bool | operator! () const |
| operator bool () const | |
| template<typename YI_OTHER_PTR_TYPE > | |
| operator std::weak_ptr< YI_OTHER_PTR_TYPE > () const | |
| CYIWeakPtr< YI_PTR_TYPE > & | operator= (const CYIWeakPtr< YI_PTR_TYPE > &rOther) |
| template<typename YI_OTHER_PTR_TYPE > | |
| CYIWeakPtr< YI_PTR_TYPE > & | operator= (const CYIWeakPtr< YI_OTHER_PTR_TYPE > &rOther) |
| CYIWeakPtr< YI_PTR_TYPE > & | operator= (const CYISharedPtr< YI_PTR_TYPE > &rOther) |
| template<typename YI_OTHER_PTR_TYPE > | |
| CYIWeakPtr< YI_PTR_TYPE > & | operator= (const CYISharedPtr< YI_OTHER_PTR_TYPE > &rOther) |
| template<typename YI_OTHER_PTR_TYPE > | |
| CYIWeakPtr< YI_PTR_TYPE > & | operator= (const std::shared_ptr< YI_OTHER_PTR_TYPE > &rOther) |
Friends | |
| template<typename YI_OTHER_PTR_TYPE > | |
| class | CYISharedPtr |
| template<typename YI_OTHER_PTR_TYPE > | |
| class | CYIWeakPtr |
| CYIWeakPtr< YI_PTR_TYPE >::CYIWeakPtr | ( | ) |
Constructs CYIWeakPtr and sets its internal object to nullptr
| CYIWeakPtr< YI_PTR_TYPE >::CYIWeakPtr | ( | const CYIWeakPtr< YI_PTR_TYPE > & | rOther | ) |
Copy-Constructor that constructs CYIWeakPtr and sets its internal object to the provided parameter
| rOther | the data to take shared ownership |
| CYIWeakPtr< YI_PTR_TYPE >::CYIWeakPtr | ( | const CYIWeakPtr< YI_OTHER_PTR_TYPE > & | rOther | ) |
Constructs CYIWeakPtr and sets its internal object to the provided parameter
| rOther | the data to take shared ownership |
| CYIWeakPtr< YI_PTR_TYPE >::CYIWeakPtr | ( | const CYISharedPtr< YI_PTR_TYPE > & | rOther | ) |
Constructs CYIWeakPtr and sets its internal object to the provided parameter
| rOther | the data to take shared ownership |
| CYIWeakPtr< YI_PTR_TYPE >::CYIWeakPtr | ( | const std::shared_ptr< YI_PTR_TYPE > & | rOther | ) |
Constructs CYIWeakPtr and sets its internal object to the provided parameter
| rOther | the data to take shared ownership |
| CYIWeakPtr< YI_PTR_TYPE >::CYIWeakPtr | ( | const std::weak_ptr< YI_OTHER_PTR_TYPE > & | rOther | ) |
Constructs CYIWeakPtr and sets its internal object to the provided parameter
| rOther | the data to take shared ownership |
| CYIWeakPtr< YI_PTR_TYPE >::CYIWeakPtr | ( | const CYISharedPtr< YI_OTHER_PTR_TYPE > & | rOther | ) |
Constructs CYIWeakPtr and sets its internal object to the provided parameter
| rOther | the data to take shared ownership |
| CYIWeakPtr< YI_PTR_TYPE >::~CYIWeakPtr | ( | ) |
Destructor that will never delete the object
| YI_PTR_TYPE* CYIWeakPtr< YI_PTR_TYPE >::Get | ( | ) | const |
Accesses the internal object without taking ownership. Mostly for legacy code compatibility.
Example:
| uint32_t CYIWeakPtr< YI_PTR_TYPE >::GetUseCount | ( | ) | const |
Returns the number of CYISharedPtr<T> objects that manage the object T.
| bool CYIWeakPtr< YI_PTR_TYPE >::IsNull | ( | ) | const |
Syntactic sugar for the operator!()
Example:
| CYIWeakPtr< YI_PTR_TYPE >::operator bool | ( | ) | const |
This function tests if the internal object is not set to nullptr.
Example:
| CYIWeakPtr< YI_PTR_TYPE >::operator std::weak_ptr< YI_OTHER_PTR_TYPE > | ( | ) | const |
This function is used to implicitely convert from CYIWeakPtr to std::weak_ptr for backwards compatibility.
| bool CYIWeakPtr< YI_PTR_TYPE >::operator! | ( | ) | const |
This function tests if the internal object is set to nullptr.
Example:
| CYIWeakPtr<YI_PTR_TYPE>& CYIWeakPtr< YI_PTR_TYPE >::operator= | ( | const CYIWeakPtr< YI_PTR_TYPE > & | rOther | ) |
This function resets the internal object to the one provided as a parameter.
| rOther | the pointer to share ownership of its object with. |
| CYIWeakPtr<YI_PTR_TYPE>& CYIWeakPtr< YI_PTR_TYPE >::operator= | ( | const CYIWeakPtr< YI_OTHER_PTR_TYPE > & | rOther | ) |
This function resets the internal object to the one provided as a parameter.
| rOther | the pointer to share ownership of its object with. |
| CYIWeakPtr<YI_PTR_TYPE>& CYIWeakPtr< YI_PTR_TYPE >::operator= | ( | const CYISharedPtr< YI_PTR_TYPE > & | rOther | ) |
This function resets the internal object to the one provided as a parameter.
| rOther | the pointer to share ownership of its object with. |
| CYIWeakPtr<YI_PTR_TYPE>& CYIWeakPtr< YI_PTR_TYPE >::operator= | ( | const CYISharedPtr< YI_OTHER_PTR_TYPE > & | rOther | ) |
This function resets the internal object to the one provided as a parameter.
| rOther | the pointer to share ownership of its object with. |
| CYIWeakPtr<YI_PTR_TYPE>& CYIWeakPtr< YI_PTR_TYPE >::operator= | ( | const std::shared_ptr< YI_OTHER_PTR_TYPE > & | rOther | ) |
This function resets the internal object to the one provided as a parameter.
| rOther | the pointer to share ownership of its object with. |
| void CYIWeakPtr< YI_PTR_TYPE >::Reset | ( | ) |
This function resets its internal object to nullptr. It will never delete the object
| void CYIWeakPtr< YI_PTR_TYPE >::Swap | ( | CYIWeakPtr< YI_PTR_TYPE > & | rPtr | ) |
Swap function that will move the weak reference of a object to a different CYIWeakPtr that could be living in a completely different scope.
Example:
| rPtr | the CYIScopedPtr to swap ownership with |
| CYISharedPtr<YI_PTR_TYPE> CYIWeakPtr< YI_PTR_TYPE >::ToStrongPtr | ( | ) | const |
This function generates a strong reference to the object. A strong reference takes ownership and will delete the object if it is the last reference to go out-of-scope.
Example :
|
friend |