glibmm 2.66.5
Public Member Functions | Static Public Member Functions | Related Functions | List of all members
Glib::WeakRef< T_CppObject > Class Template Reference

WeakRef<> is a weak reference smartpointer. More...

#include <glibmm/weakref.h>

Public Member Functions

 WeakRef () noexcept
 Default constructor. More...
 
 WeakRef (const WeakRef & src) noexcept
 Copy constructor. More...
 
 WeakRef (WeakRef && src) noexcept
 Move constructor. More...
 
template<typename T_CastFrom >
 WeakRef (const WeakRef< T_CastFrom > & src) noexcept
 Copy constructor from different, but castable type. More...
 
template<typename T_CastFrom >
 WeakRef (WeakRef< T_CastFrom > && src) noexcept
 Move constructor from different, but castable type. More...
 
template<typename T_CastFrom >
 WeakRef (const RefPtr< T_CastFrom > & src) noexcept
 Constructor from a RefPtr of the same or a castable type. More...
 
 ~WeakRef () noexcept
 Destructor. More...
 
void swap (WeakRef & other) noexcept
 Swap the contents of two WeakRef<>. More...
 
WeakRefoperator= (const WeakRef & src) noexcept
 Copy assignment operator. More...
 
WeakRefoperator= (WeakRef && src) noexcept
 Move assignment operator. More...
 
template<typename T_CastFrom >
WeakRefoperator= (const WeakRef< T_CastFrom > & src) noexcept
 Copy assignment from different, but castable type. More...
 
template<typename T_CastFrom >
WeakRefoperator= (WeakRef< T_CastFrom > && src) noexcept
 Move assignment from different, but castable type. More...
 
template<typename T_CastFrom >
WeakRefoperator= (const RefPtr< T_CastFrom > & src) noexcept
 Assignment from a RefPtr of the same or a castable type. More...
 
 operator bool () const noexcept
 Test whether the WeakRef<> points to any underlying instance. More...
 
RefPtr< T_CppObject > get () const noexcept
 Create a strong reference to the underlying object. More...
 
void reset () noexcept
 Make this WeakRef empty. More...
 

Static Public Member Functions

template<typename T_CastFrom >
static WeakRef cast_dynamic (const WeakRef< T_CastFrom > & src) noexcept
 Dynamic cast to derived class. More...
 
template<typename T_CastFrom >
static WeakRef cast_static (const WeakRef< T_CastFrom > & src) noexcept
 Static cast to derived class. More...
 
template<typename T_CastFrom >
static WeakRef cast_const (const WeakRef< T_CastFrom > & src) noexcept
 Cast to non-const. More...
 

Related Functions

(Note that these are not member functions.)

template<class T_CppObject >
void swap (WeakRef< T_CppObject > & lhs, WeakRef< T_CppObject > & rhs) noexcept
 Swap the contents of two WeakRef<>. More...
 

Detailed Description

template<typename T_CppObject>
class Glib::WeakRef< T_CppObject >

WeakRef<> is a weak reference smartpointer.

WeakRef can store a pointer to any class that is derived from Glib::ObjectBase, and whose reference() method is noexcept. In glibmm and gtkmm, that is anything derived from Glib::ObjectBase.

Unlike a RefPtr, a WeakRef does not contribute to the reference counting of the underlying object.

Since glibmm 2.46:

Constructor & Destructor Documentation

◆ WeakRef() [1/6]

template <typename T_CppObject >
Glib::WeakRef< T_CppObject >::WeakRef ( )
inlinenoexcept

Default constructor.

Create an empty weak reference.

◆ WeakRef() [2/6]

template <typename T_CppObject >
Glib::WeakRef< T_CppObject >::WeakRef ( const WeakRef< T_CppObject > &  src)
inlinenoexcept

Copy constructor.

◆ WeakRef() [3/6]

template <typename T_CppObject >
Glib::WeakRef< T_CppObject >::WeakRef ( WeakRef< T_CppObject > &&  src)
inlinenoexcept

Move constructor.

◆ WeakRef() [4/6]

template <typename T_CppObject >
template <typename T_CastFrom >
Glib::WeakRef< T_CppObject >::WeakRef ( const WeakRef< T_CastFrom > &  src)
inlinenoexcept

Copy constructor from different, but castable type.

◆ WeakRef() [5/6]

template <typename T_CppObject >
template <typename T_CastFrom >
Glib::WeakRef< T_CppObject >::WeakRef ( WeakRef< T_CastFrom > &&  src)
inlinenoexcept

Move constructor from different, but castable type.

◆ WeakRef() [6/6]

template <typename T_CppObject >
template <typename T_CastFrom >
Glib::WeakRef< T_CppObject >::WeakRef ( const RefPtr< T_CastFrom > &  src)
inlinenoexcept

Constructor from a RefPtr of the same or a castable type.

Create a weak reference from a RefPtr of the same or a castable type. If the RefPtr references nothing, an empty weak reference will be constructed.

◆ ~WeakRef()

template <typename T_CppObject >
Glib::WeakRef< T_CppObject >::~WeakRef ( )
inlinenoexcept

Destructor.

Member Function Documentation

◆ cast_const()

template <typename T_CppObject >
template <typename T_CastFrom >
static WeakRef Glib::WeakRef< T_CppObject >::cast_const ( const WeakRef< T_CastFrom > &  src)
inlinestaticnoexcept

Cast to non-const.

The WeakRef can't be cast with the usual notation so instead you can use

ptr_nonconst = Glib::WeakRef<NonConstType>::cast_const(ptr_const);
static WeakRef cast_const(const WeakRef< T_CastFrom > &src) noexcept
Cast to non-const.

◆ cast_dynamic()

template <typename T_CppObject >
template <typename T_CastFrom >
static WeakRef Glib::WeakRef< T_CppObject >::cast_dynamic ( const WeakRef< T_CastFrom > &  src)
inlinestaticnoexcept

Dynamic cast to derived class.

The WeakRef can't be cast with the usual notation so instead you can use

ptr_derived = Glib::WeakRef<Derived>::cast_dynamic(ptr_base);
static WeakRef cast_dynamic(const WeakRef< T_CastFrom > &src) noexcept
Dynamic cast to derived class.

◆ cast_static()

template <typename T_CppObject >
template <typename T_CastFrom >
static WeakRef Glib::WeakRef< T_CppObject >::cast_static ( const WeakRef< T_CastFrom > &  src)
inlinestaticnoexcept

Static cast to derived class.

The WeakRef can't be cast with the usual notation so instead you can use

ptr_derived = Glib::WeakRef<Derived>::cast_static(ptr_base);
static WeakRef cast_static(const WeakRef< T_CastFrom > &src) noexcept
Static cast to derived class.

◆ get()

template <typename T_CppObject >
RefPtr< T_CppObject > Glib::WeakRef< T_CppObject >::get ( ) const
inlinenoexcept

Create a strong reference to the underlying object.

This is a thread-safe way to acquire a strong reference to the underlying object. If the WeakRef is empty, the returned RefPtr will reference nothing.

◆ operator bool()

template <typename T_CppObject >
Glib::WeakRef< T_CppObject >::operator bool ( ) const
inlineexplicitnoexcept

Test whether the WeakRef<> points to any underlying instance.

Mimics usage of ordinary pointers:

if (ptr)
do_something();

In a multi-threaded program a true return value can become obsolete at any time, even before the caller has a chance to test it, because the underlying instance may lose its last reference in another thread. Use get() if this is not acceptable.

◆ operator=() [1/5]

template <typename T_CppObject >
template <typename T_CastFrom >
WeakRef & Glib::WeakRef< T_CppObject >::operator= ( const RefPtr< T_CastFrom > &  src)
inlinenoexcept

Assignment from a RefPtr of the same or a castable type.

◆ operator=() [2/5]

template <typename T_CppObject >
WeakRef & Glib::WeakRef< T_CppObject >::operator= ( const WeakRef< T_CppObject > &  src)
inlinenoexcept

Copy assignment operator.

◆ operator=() [3/5]

template <typename T_CppObject >
template <typename T_CastFrom >
WeakRef & Glib::WeakRef< T_CppObject >::operator= ( const WeakRef< T_CastFrom > &  src)
inlinenoexcept

Copy assignment from different, but castable type.

◆ operator=() [4/5]

template <typename T_CppObject >
WeakRef & Glib::WeakRef< T_CppObject >::operator= ( WeakRef< T_CppObject > &&  src)
inlinenoexcept

Move assignment operator.

◆ operator=() [5/5]

template <typename T_CppObject >
template <typename T_CastFrom >
WeakRef & Glib::WeakRef< T_CppObject >::operator= ( WeakRef< T_CastFrom > &&  src)
inlinenoexcept

Move assignment from different, but castable type.

◆ reset()

template <typename T_CppObject >
void Glib::WeakRef< T_CppObject >::reset ( )
inlinenoexcept

Make this WeakRef empty.

◆ swap()

template <typename T_CppObject >
void Glib::WeakRef< T_CppObject >::swap ( WeakRef< T_CppObject > &  other)
inlinenoexcept

Swap the contents of two WeakRef<>.

Friends And Related Function Documentation

◆ swap()

template <class T_CppObject >
void swap ( WeakRef< T_CppObject > &  lhs,
WeakRef< T_CppObject > &  rhs 
)
related

Swap the contents of two WeakRef<>.