LibreOffice Module unotools (master) 1
Public Member Functions | List of all members
unotools::WeakReference< interface_type > Class Template Reference

The WeakReference<> holds a weak reference to an object. More...

#include <weakref.hxx>

Inheritance diagram for unotools::WeakReference< interface_type >:
[legend]
Collaboration diagram for unotools::WeakReference< interface_type >:
[legend]

Public Member Functions

 WeakReference ()
 Default ctor. More...
 
 WeakReference (const rtl::Reference< interface_type > &rRef)
 Copy ctor. More...
 
 WeakReference (interface_type &rRef)
 Copy ctor. More...
 
 WeakReference (interface_type *pRef)
 Copy ctor. More...
 
WeakReferenceoperator= (const rtl::Reference< interface_type > &xInt)
 Releases this reference and takes over hard reference xInt. More...
 
WeakReferenceoperator= (rtl::Reference< interface_type > &&xInt)
 
WeakReferenceoperator= (interface_type *pInt)
 
rtl::Reference< interface_type > SAL_CALL get () const
 Gets a hard reference to the object. More...
 
 operator::rtl::Reference () const
 Gets a hard reference to the object. More...
 
- Public Member Functions inherited from com::sun::star::uno::WeakReferenceHelper
 WeakReferenceHelper ()
 
 WeakReferenceHelper (const WeakReferenceHelper &rWeakRef)
 
 WeakReferenceHelper (const css::uno::Reference< css::uno::XInterface > &xInt)
 
 ~WeakReferenceHelper ()
 
WeakReferenceHelper &SAL_CALL operator= (const WeakReferenceHelper &rWeakRef)
 
WeakReferenceHelper &SAL_CALL operator= (const css::uno::Reference< css::uno::XInterface > &xInt)
 
bool SAL_CALL operator== (const WeakReferenceHelper &rObj) const
 
css::uno::Reference< css::uno::XInterface > SAL_CALL get () const
 
SAL_CALL operator Reference< XInterface > () const
 
void SAL_CALL clear ()
 

Detailed Description

template<class interface_type>
class unotools::WeakReference< interface_type >

The WeakReference<> holds a weak reference to an object.

That object must implement the css::uno::XWeak interface.

The WeakReference itself is not thread safe, just as Reference itself isn't, but the implementation of the listeners etc. behind it is thread-safe, so multiple threads can have their own WeakReferences to the same XWeak object.

Template Parameters
interface_typeMust be a C++ implementation class type, not a UNO interface type. (See the C++20 requires-clause on the get member. That clause is not put on the class as a whole to avoid overly tight requirements on when interface_type needs to be complete.)

Definition at line 50 of file weakref.hxx.

Constructor & Destructor Documentation

◆ WeakReference() [1/4]

template<class interface_type >
unotools::WeakReference< interface_type >::WeakReference ( )
inline

Default ctor.

Creates an empty weak reference.

Definition at line 55 of file weakref.hxx.

◆ WeakReference() [2/4]

template<class interface_type >
unotools::WeakReference< interface_type >::WeakReference ( const rtl::Reference< interface_type > &  rRef)
inline

Copy ctor.

Initialize this reference with a hard reference.

Parameters
rRefanother hard ref

Definition at line 64 of file weakref.hxx.

References Reference.

◆ WeakReference() [3/4]

template<class interface_type >
unotools::WeakReference< interface_type >::WeakReference ( interface_type &  rRef)
inline

Copy ctor.

Initialize this reference with a hard reference.

Parameters
rRefanother hard ref

Definition at line 73 of file weakref.hxx.

◆ WeakReference() [4/4]

template<class interface_type >
unotools::WeakReference< interface_type >::WeakReference ( interface_type *  pRef)
inline

Copy ctor.

Initialize this reference with a hard reference.

Parameters
rRefanother hard ref

Definition at line 82 of file weakref.hxx.

References Reference.

Member Function Documentation

◆ get()

template<class interface_type >
rtl::Reference< interface_type > SAL_CALL unotools::WeakReference< interface_type >::get ( ) const
inline

Gets a hard reference to the object.

Returns
hard reference or null, if the weakly referenced interface has gone

Definition at line 117 of file weakref.hxx.

References Translate::get().

◆ operator::rtl::Reference()

template<class interface_type >
unotools::WeakReference< interface_type >::operator::rtl::Reference ( ) const
inline

Gets a hard reference to the object.

Returns
hard reference or null, if the weakly referenced interface has gone

Definition at line 117 of file weakref.hxx.

◆ operator=() [1/3]

template<class interface_type >
WeakReference & unotools::WeakReference< interface_type >::operator= ( const rtl::Reference< interface_type > &  xInt)
inline

Releases this reference and takes over hard reference xInt.

If the implementation behind xInt does not support XWeak or XInt is null, then this reference is null.

Parameters
xIntanother hard reference

Definition at line 94 of file weakref.hxx.

◆ operator=() [2/3]

template<class interface_type >
WeakReference & unotools::WeakReference< interface_type >::operator= ( interface_type *  pInt)
inline

Definition at line 106 of file weakref.hxx.

◆ operator=() [3/3]

template<class interface_type >
WeakReference & unotools::WeakReference< interface_type >::operator= ( rtl::Reference< interface_type > &&  xInt)
inline

Definition at line 100 of file weakref.hxx.


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