System::WeakPtr< T > Class Template Reference

Subclass of System::SmartPtr which sets itself to weak mode at construction. Please note that this class doesn't guarantee that its instance will always remain in weak mode as set_Mode() is still accessible. This type is a pointer to manage other object's deletion. It should be allocated on stack and passed to functions either by value or by const reference. More...

Inherits System::SmartPtr< T >.

Public Types

typedef SmartPtr< T > SmartPtr_
 Alias for corresponding SmartPtr class. More...
 
typedef WeakPtr< T > WeakPtr_
 Alias for self type. More...
 
typedef T Pointee_
 Pointed type. More...
 
- Public Types inherited from System::SmartPtr< T >
typedef T Pointee_
 Pointed type. More...
 
typedef SmartPtr< T > SmartPtr_
 Specialized smart pointer type. More...
 
typedef System::Details::ArrayTypeResolver< T >::type ArrayType
 Same as Pointee_, if it is a specialization of System::Array, and void otherwise. More...
 
using ValueType = typename System::Details::SelectType< typename System::Details::ArrayTypeResolver< T >::value_type >::type
 Storage type of pointed array. Only meaningful if T is a specialization of System::Array. More...
 

Public Member Functions

 WeakPtr (std::nullptr_t=nullptr)
 Creates null pointer. More...
 
 WeakPtr (Pointee_ *object)
 Creates weak pointer to given object. More...
 
 WeakPtr (const SmartPtr_ &ptr)
 Creates weak pointer referencing same pointer ptr points to. More...
 
template<class Q , typename = typename std::enable_if<std::is_convertible<Q*, Pointee_*>::value>::type>
 WeakPtr (const SmartPtr< Q > &x)
 Creates weak pointer referencing same pointer x points to. More...
 
 WeakPtr (const WeakPtr_ &ptr)
 Copy-constructs weak pointer. More...
 
template<class Q , typename = typename std::enable_if<std::is_convertible<Q*, Pointee_*>::value>::type>
 WeakPtr (const WeakPtr< Q > &x)
 Copy-constructs weak pointer. More...
 
 WeakPtr (SmartPtr_ &&x)
 Move-constructs weak pointer. More...
 
template<typename Q >
WeakPtroperator= (Q &&value)
 Assigns value to weak pointer. Calls into specific assignment operator of SmartPtr_. More...
 
bool operator== (std::nullptr_t) const
 Checks if weak pointer is null. More...
 
bool expired () const
 Checks if referenced object was already deleted. More...
 
Objectget_weak () const
 Gets referenced object. Asserts that pointer is in weak mode. More...
 
- Public Member Functions inherited from System::SmartPtr< T >
 SmartPtr (SmartPtrMode mode)
 Creates SmartPtr object of required mode. More...
 
 SmartPtr (std::nullptr_t=nullptr, SmartPtrMode mode=SmartPtrMode::Shared)
 Creates null-pointer SmartPtr object of required mode. More...
 
 SmartPtr (Pointee_ *object, SmartPtrMode mode=SmartPtrMode::Shared)
 Creates SmartPtr pointing to specified object, or converts raw pointer to SmartPtr. More...
 
 SmartPtr (const SmartPtr_ &ptr, SmartPtrMode mode=SmartPtrMode::Shared)
 Copy constructs SmartPtr object. Both pointers point to the same object afterwards. More...
 
template<class Q , typename = typename std::enable_if<System::detail::is_pointer_convertible<Q, Pointee_>::type::value>::type>
 SmartPtr (const SmartPtr< Q > &x, SmartPtrMode mode=SmartPtrMode::Shared)
 Copy constructs SmartPtr object. Both pointers point to the same object afterwards. Performs type conversion if allowed. More...
 
 SmartPtr (SmartPtr_ &&x, SmartPtrMode mode=SmartPtrMode::Shared) noexcept
 Move constructs SmartPtr object. Effectively, swaps two pointers, if they are both of same mode. x may be unusable after call. More...
 
template<typename Y >
 SmartPtr (const SmartPtr< Array< Y >> &src, SmartPtrMode mode=SmartPtrMode::Shared)
 Converts type of referenced array by creating a new array of different type. Useful if in C# there is an array type cast which is unsupported in C++. More...
 
template<typename Y , typename = typename std::enable_if<std::is_same<Y, EmptyArrayInitializer>::value, void>::type>
 SmartPtr (const Y &)
 Initializes empty array. Used to translate some C# code constructs. More...
 
template<typename P >
 SmartPtr (const SmartPtr< P > &ptr, Pointee_ *p, SmartPtrMode mode=SmartPtrMode::Shared)
 Constructs a SmartPtr which shares ownership information with the initial value of ptr, but holds an unrelated and unmanaged pointer p. More...
 
 ~SmartPtr ()
 Destroys SmartPtr object. If required, decreases pointed object's reference counter and deletes object. More...
 
SmartPtr_operator= (SmartPtr_ &&x) noexcept
 Move-assigns SmartPtr object. x becomes unusable. More...
 
SmartPtr_operator= (const SmartPtr_ &x)
 Copy-assigns SmartPtr object. More...
 
template<typename Q >
SmartPtr_operator= (const SmartPtr< Q > &x)
 Copy-assigns SmartPtr object. Does required type conversions. More...
 
SmartPtr_operator= (Pointee_ *p)
 Assigns raw pointer to SmartPtr object. More...
 
SmartPtr_operator= (std::nullptr_t)
 Sets pointer value to nullptr. More...
 
Pointee_operator-> () const
 Allows to access members of referenced object. More...
 
bool operator== (std::nullptr_t) const
 Checks if pointer points to nullptr. More...
 
Pointee_get () const
 Gets pointed object. More...
 
Pointee_get_shared () const
 Gets pointed object, but asserts that pointer is in shared mode. More...
 
void reset (Pointee_ *ptr)
 Sets pointed object. More...
 
void reset ()
 Makes pointer pointing to nullptr. More...
 
SmartPtrMode get_Mode () const
 Gets pointer mode. More...
 
bool IsShared () const
 Checks if pointer is in shared mode. More...
 
bool IsWeak () const
 Checks if pointer is in weak mode. More...
 
bool IsAliasingPtr () const
 Checks if pointer is pointed to another object than owned (created by an aliasing constructor). More...
 
ObjectGetObjectOwner () const
 Gets referenced object. More...
 
SmartPtr_ RemoveAliasing () const
 Removes aliasing (created by an aliasing constructor) from pointer, makes sure it manages (if shared) or tracks (if weak) the same object it points to. More...
 
void set_Mode (SmartPtrMode mode)
 Sets pointer mode. May alter referenced object's reference counts. More...
 
Pointee_operator* () const
 Gets reference to pointed object. Asserts that pointer is not null. More...
 
 operator bool () const noexcept
 Checks if pointer is not null. More...
 
bool operator! () const noexcept
 Checks if pointer is null. More...
 
template<class Y >
bool operator< (Y *p) const
 Provides less-compare semantics for SmartPtr class. More...
 
template<class Y >
bool operator< (SmartPtr< Y > const &x) const
 Provides less-compare semantics for SmartPtr class. More...
 
template<class Y >
SmartPtr< Y > static_pointer_cast () const
 Casts pointer to different type using static_cast on pointed object. More...
 
template<class Y >
SmartPtr< Y > dynamic_pointer_cast () const
 Casts pointer to different type using dynamic_cast on pointed object. More...
 
template<class Y >
SmartPtr< Y > const_pointer_cast () const
 Casts pointer to different type using const_cast on pointed object. More...
 
template<class Y , typename Check = std::false_type>
std::enable_if_t< std::is_same< Y, T >::value, SmartPtr< Y > > Cast () const
 Casts pointer to its type itself. More...
 
template<class Y , typename Check = std::false_type>
std::enable_if_t<!std::is_same< Y, T >::value &&std::is_base_of< Y, T >::value, SmartPtr< Y > > Cast () const
 Casts pointer to base type using static_cast. More...
 
template<class Y , typename Check = std::false_type>
std::enable_if_t< Check::value &&!std::is_same< Y, T >::value &&!std::is_base_of< Y, T >::value, SmartPtr< Y > > Cast () const
 Casts pointer to derived type dynamic_cast. More...
 
template<class Y , typename Check = std::false_type>
std::enable_if_t<!Check::value &&!std::is_same< Y, T >::value &&!std::is_base_of< Y, T >::value, SmartPtr< Y > > Cast () const
 Casts pointer to derived type dynamic_cast. More...
 
bool Is (const System::TypeInfo &target) const
 Checks if pointed object is of specific type or its child type. Follows C# 'is' semantics. More...
 
ObjectGetObjectOrNull () const
 Gets pointed object (if any) or nullptr. Same as get(). More...
 
SmartPtr< ObjectToObjectPtr () const
 Converts any pointer type to pointer to Object. Doesn't require Pointee_ type to be complete. More...
 
Pointee_GetPointer () const
 Gets pointed object (if any) or nullptr. Same as get(). More...
 
int get_shared_count () const
 Gets number of shared pointers existing to referenced object, including current one. Asserts current pointer being in shared mode. More...
 
void SetContainedTemplateWeakPtr (uint32_t argument) const
 Calls SetTemplateWeakPtr() method on pointed object (if any). More...
 
template<typename Q = T>
auto begin () -> decltype(std::declval< Q >().begin())
 Accessor for begin() method of an underling collection. Only compiles if SmartPtr_ is specialization type with begin() method. More...
 
template<typename Q = T>
auto end () -> decltype(std::declval< Q >().end())
 Accessor for end() method of an underling collection. Only compiles if SmartPtr_ is specialization type with end() method. More...
 
template<typename Q = T>
auto begin () const -> decltype(std::declval< const Q >().begin())
 Accessor for begin() method of an underling collection. Only compiles if SmartPtr_ is specialization type with begin() method. More...
 
template<typename Q = T>
auto end () const -> decltype(std::declval< const Q >().end())
 Accessor for end() method of an underling collection. Only compiles if SmartPtr_ is specialization type with end() method. More...
 
template<typename Q = T>
auto cbegin () const -> decltype(std::declval< const Q >().cbegin())
 Accessor for cbegin() method of an underling collection. Only compiles if SmartPtr_ is specialization type with cbegin() method. More...
 
template<typename Q = T>
auto cend () const -> decltype(std::declval< const Q >().cend())
 Accessor for cend() method of an underling collection. Only compiles if SmartPtr_ is specialization type with cend() method. More...
 
int GetHashCode () const
 Calls GetHashCode() on pointed object. More...
 
T * GetObjectNotNull () const
 Gets currently referenced object (if any) or throws. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from System::SmartPtr< T >
static const System::TypeInfoType ()
 Shortcut to get System::TypeInfo object for the Pointee_ type. More...
 
- Public Attributes inherited from System::SmartPtr< T >
template<typename IdxType >
decltype(System::Details::GetByIndex(std::declval< const SmartPtr_ * >(), std::declval< IdxType >()) operator[] )(IdxType idx) const
 Accessor for array elements. Only compiles if SmartPtr_ is specialization of System::Array. More...
 
- Protected Types inherited from System::SmartPtr< T >
typedef Object SharedRefReleaser
 Type to use to release shared pointers. Depends on whether external refcount is on or off. More...
 
- Protected Member Functions inherited from System::SmartPtr< T >
void Lock (Pointee_ *object)
 Sets pointee object. Increments shared or weak reference count, depending on pointer mode. More...
 
template<class Q >
void Lock (const SmartPtr< Q > &ptr)
 Sets pointee object. Increments shared or weak reference count, depending on pointer mode. More...
 
template<typename Q >
void LockSharedFromShared (const SmartPtr< Q > &ptr)
 Sets pointee object. Asserts that both current object and ptr are in shared mode. More...
 
template<typename Q >
void LockSharedFromWeak (const SmartPtr< Q > &ptr)
 Sets pointee object. Asserts that current object is in shared mode and ptr is in weak mode. More...
 
template<typename Q >
void LockWeakFromShared (const SmartPtr< Q > &ptr)
 Sets pointee object. Asserts that current object is in weak mode and ptr is in shared mode. More...
 
template<typename Q >
void LockWeakFromWeak (const SmartPtr< Q > &ptr)
 Sets pointee object. Asserts that both current object and ptr are in weak mode. More...
 
ObjectReleaseAndGetObjectToDelete ()
 Decrements currently referenced object's shared or weak pointer counter, depending on current pointer mode. More...
 
SharedRefReleaserGetSharedReleaser () const
 Gets object to use to release shared pointer to. More...
 
ObjectReleaseSharedAndGetObjectToDelete ()
 Decrements currently referenced object's shared pointer counter. More...
 
void ReleaseWeak ()
 Decrements currently referenced object's weak pointer counter. More...
 
void MoveSharedFromWeak (SmartPtr &&x)
 Implements move semantics. Asserts that current object is in shared mode and x is in weak mode. More...
 
void MoveWeakFromShared (SmartPtr &&x)
 Implements move semantics. Asserts that current object is in weak mode and x is in shared mode. More...
 
template<typename Q , typename R = decltype(std::declval<Q*>()->GetHashCode())>
GetHashCodeImpl (Q *) const
 Calls into GetHashCode() method if it is available on Pointee_ type (which is true if it is a complete type). More...
 
int GetHashCodeImpl (void *) const
 Calls GetHashCode() method from Object if it is not available on Pointee_ type (e. g. if it is incomplete). More...
 
template<typename Q >
void Assign (const SmartPtr< Q > &x)
 Copy-assigns SmartPtr object. Does type conversions, if required. More...
 
- Static Protected Member Functions inherited from System::SmartPtr< T >
static ObjectReleaseSharedAndGetObjectToDelete (SharedRefReleaser *releaser)
 Removes shared pointer of a specific object, possibly deleting it. More...
 
static void ReleaseWeak (System::Detail::SmartPtrCounter *counter)
 Decrements weak pointer counter. More...
 
template<typename X , typename Y >
static void InitArray (SmartPtr< Array< X >> *ptr, const SmartPtr< Array< Y >> &src)
 Performs actual array copying on cast constructor calls. More...
 
- Protected Attributes inherited from System::SmartPtr< T >
class System::SmartPtr::Data m_data
 An instance of Data class. More...
 

Detailed Description

template<class T>
class System::WeakPtr< T >

Subclass of System::SmartPtr which sets itself to weak mode at construction. Please note that this class doesn't guarantee that its instance will always remain in weak mode as set_Mode() is still accessible. This type is a pointer to manage other object's deletion. It should be allocated on stack and passed to functions either by value or by const reference.

Template Parameters
TPointee type.

Member Typedef Documentation

◆ Pointee_

template<class T>
typedef T System::SmartPtr< T >::Pointee_

Pointed type.

◆ SmartPtr_

template<class T>
typedef SmartPtr<T> System::WeakPtr< T >::SmartPtr_

Alias for corresponding SmartPtr class.

◆ WeakPtr_

template<class T>
typedef WeakPtr<T> System::WeakPtr< T >::WeakPtr_

Alias for self type.

Constructor & Destructor Documentation

◆ WeakPtr() [1/7]

template<class T>
System::WeakPtr< T >::WeakPtr ( std::nullptr_t  = nullptr)
inline

Creates null pointer.

◆ WeakPtr() [2/7]

template<class T>
System::WeakPtr< T >::WeakPtr ( Pointee_ object)
inline

Creates weak pointer to given object.

Parameters
objectObject to create weak pointer to.

◆ WeakPtr() [3/7]

template<class T>
System::WeakPtr< T >::WeakPtr ( const SmartPtr_ ptr)
inline

Creates weak pointer referencing same pointer ptr points to.

Parameters
ptrPointer to copy pointee value from.

◆ WeakPtr() [4/7]

template<class T>
template<class Q , typename = typename std::enable_if<std::is_convertible<Q*, Pointee_*>::value>::type>
System::WeakPtr< T >::WeakPtr ( const SmartPtr< Q > &  x)
inline

Creates weak pointer referencing same pointer x points to.

Template Parameters
QPointee type of source pointer.
Parameters
xPointer to copy pointee value from.

◆ WeakPtr() [5/7]

template<class T>
System::WeakPtr< T >::WeakPtr ( const WeakPtr_ ptr)
inline

Copy-constructs weak pointer.

Parameters
ptrPointer to copy pointee value from.

◆ WeakPtr() [6/7]

template<class T>
template<class Q , typename = typename std::enable_if<std::is_convertible<Q*, Pointee_*>::value>::type>
System::WeakPtr< T >::WeakPtr ( const WeakPtr< Q > &  x)
inline

Copy-constructs weak pointer.

Template Parameters
QSource pointee type.
Parameters
xPointer to copy pointee value from.

◆ WeakPtr() [7/7]

template<class T>
System::WeakPtr< T >::WeakPtr ( SmartPtr_ &&  x)
inline

Move-constructs weak pointer.

Parameters
xPointer to move pointee value from.

Member Function Documentation

◆ expired()

template<class T>
bool System::WeakPtr< T >::expired ( ) const
inline

Checks if referenced object was already deleted.

Returns
True if referenced object was already deleted, false otherwise.

◆ get_weak()

template<class T>
Object* System::WeakPtr< T >::get_weak ( ) const
inline

Gets referenced object. Asserts that pointer is in weak mode.

Returns
Raw pointer to referenced object (if assigned and not expired) or nullptr.

◆ operator=()

template<class T>
template<typename Q >
WeakPtr& System::WeakPtr< T >::operator= ( Q &&  value)
inline

Assigns value to weak pointer. Calls into specific assignment operator of SmartPtr_.

Template Parameters
QArgument type supported by System::SmartPtr assignment operators.
Parameters
valuePointer to copy pointee value from.

◆ operator==()

template<class T>
bool System::WeakPtr< T >::operator== ( std::nullptr_t  ) const
inline

Checks if weak pointer is null.

Returns
True if weak pointer is null and false otherwise.