Spicy
Public Types | Public Member Functions | List of all members
hilti::rt::WeakReference< T > Class Template Reference

#include <reference.h>

Inheritance diagram for hilti::rt::WeakReference< T >:

Public Types

using Base = std::weak_ptr< T >
 

Public Member Functions

 WeakReference ()=default
 
 WeakReference (const ValueReference< T > &t)
 
 WeakReference (const StrongReference< T > &t)
 
 WeakReference (std::nullptr_t)
 
 WeakReference (const WeakReference &other)=default
 
 WeakReference (WeakReference &&other) noexcept=default
 
 ~WeakReference ()=default
 
bool isNull () const
 
bool isExpired () const
 
const T * get () const
 
ValueReference< T > derefAsValue () const
 
void reset ()
 
const T & operator* () const
 
T & operator* ()
 
const T * operator-> () const
 
T * operator-> ()
 
 operator bool () const
 
WeakReferenceoperator= (const ValueReference< T > &other)
 
WeakReferenceoperator= (const StrongReference< T > &other)
 
WeakReferenceoperator= (std::nullptr_t) noexcept
 
WeakReferenceoperator= (const WeakReference &other)
 
WeakReferenceoperator= (WeakReference &&other) noexcept
 

Detailed Description

template<typename T>
class hilti::rt::WeakReference< T >

A weak reference to a shared value. This is essentially a weak_ptr that can bind to the values of ValueReference or StrongReference. The weak reference will remain valid until all linked strong/value references have ceased to exist.

Note that different from ValueReference, a weak reference can explicitly be null.

Constructor & Destructor Documentation

◆ WeakReference() [1/6]

template<typename T>
hilti::rt::WeakReference< T >::WeakReference ( )
default

Default constructor creating a null reference.

◆ WeakReference() [2/6]

template<typename T>
hilti::rt::WeakReference< T >::WeakReference ( const ValueReference< T > &  t)
inlineexplicit

Instantiates a reference pointing to the value referred to be an existing ValueReference. This does not copy the value, it will be shared afterwards.

◆ WeakReference() [3/6]

template<typename T>
hilti::rt::WeakReference< T >::WeakReference ( const StrongReference< T > &  t)
inlineexplicit

Instantiates a reference pointing to the value referred to be an existing StrongReference. This does not copy the value, it will be shared afterwards.

◆ WeakReference() [4/6]

template<typename T>
hilti::rt::WeakReference< T >::WeakReference ( std::nullptr_t  )
inlineexplicit

Instantiate an unset reference.

◆ WeakReference() [5/6]

template<typename T>
hilti::rt::WeakReference< T >::WeakReference ( const WeakReference< T > &  other)
default

Copy constructor. This copies the reference, not the value, which will be shared afterwards.

◆ WeakReference() [6/6]

template<typename T>
hilti::rt::WeakReference< T >::WeakReference ( WeakReference< T > &&  other)
defaultnoexcept

Move constructor.

◆ ~WeakReference()

template<typename T>
hilti::rt::WeakReference< T >::~WeakReference ( )
default

Destructor.

Member Function Documentation

◆ derefAsValue()

template<typename T>
ValueReference<T> hilti::rt::WeakReference< T >::derefAsValue ( ) const
inline

Returns a value reference that is linked to the referred value. If the weak reference is null or expired, the returned reference will be null.

◆ get()

template<typename T>
const T* hilti::rt::WeakReference< T >::get ( ) const
inline

Returns a pointer to the value being referred to. This will be null if the weak point is null or expired.

◆ isExpired()

template<typename T>
bool hilti::rt::WeakReference< T >::isExpired ( ) const
inline

Returns true if the reference was pointing to a non-null value that has now expired.

◆ isNull()

template<typename T>
bool hilti::rt::WeakReference< T >::isNull ( ) const
inline

Returns true if the reference is either null or expired.

◆ operator bool()

template<typename T>
hilti::rt::WeakReference< T >::operator bool ( ) const
inlineexplicit

Returns true if the reference is not null or expired.

◆ operator*() [1/2]

template<typename T>
const T& hilti::rt::WeakReference< T >::operator* ( ) const
inline

Returns the contained value.

Exceptions
NullReferenceor ExpiredReference if the instance is null or expired, respectively.

◆ operator*() [2/2]

template<typename T>
T& hilti::rt::WeakReference< T >::operator* ( )
inline

Returns the contained value.

Exceptions
NullReferenceor ExpiredReference if the instance is null or expired, respectively.

◆ operator->() [1/2]

template<typename T>
const T* hilti::rt::WeakReference< T >::operator-> ( ) const
inline

Returns a pointer to the contained value.

Exceptions
NullReferenceor ExpiredReference if the instance is null or expired, respectively.

◆ operator->() [2/2]

template<typename T>
T* hilti::rt::WeakReference< T >::operator-> ( )
inline

Returns a pointer to the contained value.

Exceptions
NullReferenceor ExpiredReference if the instance is null or expired, respectively.

◆ operator=() [1/5]

template<typename T>
WeakReference& hilti::rt::WeakReference< T >::operator= ( const ValueReference< T > &  other)
inline

Reinitialize the reference to now point to to the value referred to be an existing ValueReference. This does not copy that value, it will be shared afterwards.

◆ operator=() [2/5]

template<typename T>
WeakReference& hilti::rt::WeakReference< T >::operator= ( const StrongReference< T > &  other)
inline

Reinitialize the reference to now point to to the value referred to be an existing StrongReference. This does not copy that value, it will be shared afterwards.

◆ operator=() [3/5]

template<typename T>
WeakReference& hilti::rt::WeakReference< T >::operator= ( std::nullptr_t  )
inlinenoexcept

Reset pointer.

◆ operator=() [4/5]

template<typename T>
WeakReference& hilti::rt::WeakReference< T >::operator= ( const WeakReference< T > &  other)
inline

Copy assignment. This will share ownership, not copy the value.

◆ operator=() [5/5]

template<typename T>
WeakReference& hilti::rt::WeakReference< T >::operator= ( WeakReference< T > &&  other)
inlinenoexcept

Move assignment.

◆ reset()

template<typename T>
void hilti::rt::WeakReference< T >::reset ( )
inline

Resets the reference to a null value.


The documentation for this class was generated from the following file: