LibreOffice Module cppuhelper (master) 1
Classes | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
cppuhelper::OInterfaceContainerHelper4< ListenerT > Class Template Reference

A container of interfaces. More...

#include <interfacecontainer4.hxx>

Collaboration diagram for cppuhelper::OInterfaceContainerHelper4< ListenerT >:
[legend]

Classes

class  NotifySingleListener
 

Public Member Functions

 OInterfaceContainerHelper4 ()
 
sal_Int32 getLength (std::unique_lock< std::mutex > &rGuard) const
 Return the number of Elements in the container. More...
 
std::vector< css::uno::Reference< ListenerT > > getElements (std::unique_lock< std::mutex > &rGuard) const
 Return all interfaces added to this container. More...
 
sal_Int32 addInterface (std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< ListenerT > &rxIFace)
 Inserts an element into the container. More...
 
sal_Int32 removeInterface (std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< ListenerT > &rxIFace)
 Removes an element from the container. More...
 
void disposeAndClear (::std::unique_lock<::std::mutex > &rGuard, const css::lang::EventObject &rEvt)
 Call disposing on all object in the container that support XEventListener. More...
 
void clear (::std::unique_lock<::std::mutex > &rGuard)
 Clears the container without calling disposing(). More...
 
template<typename FuncT >
void forEach (std::unique_lock< std::mutex > &rGuard, FuncT const &func) const
 Executes a functor for each contained listener of specified type, e.g. More...
 
template<typename EventT >
void notifyEach (std::unique_lock< std::mutex > &rGuard, void(SAL_CALL ListenerT::*NotificationMethod)(const EventT &), const EventT &Event) const
 Calls a UNO listener method for each contained listener. More...
 
 OInterfaceContainerHelper4 (OInterfaceContainerHelper4 &&)=default
 
OInterfaceContainerHelper4operator= (OInterfaceContainerHelper4 &&)=default
 

Private Member Functions

 OInterfaceContainerHelper4 (const OInterfaceContainerHelper4 &)=delete
 
OInterfaceContainerHelper4operator= (const OInterfaceContainerHelper4 &)=delete
 

Static Private Member Functions

static o3tl::cow_wrapper< std::vector< css::uno::Reference< ListenerT > >, o3tl::ThreadSafeRefCountingPolicy > & DEFAULT ()
 

Private Attributes

o3tl::cow_wrapper< std::vector< css::uno::Reference< ListenerT > >, o3tl::ThreadSafeRefCountingPolicymaData
 

Friends

class OInterfaceIteratorHelper4< ListenerT >
 

Detailed Description

template<class ListenerT>
class cppuhelper::OInterfaceContainerHelper4< ListenerT >

A container of interfaces.

To access the elements use an iterator. This implementation is thread-safe.

This is a copy of the code at include/comphelper/interfacecontainer3.hxx, except that it (a) uses std::mutex instead of osl::Mutex and (b) does not store a reference to the mutex, but relies on the calling class to take a lock around using it.

Template Parameters
ListenerTUNO event listener type
See also
OInterfaceIteratorHelper

Definition at line 131 of file interfacecontainer4.hxx.

Constructor & Destructor Documentation

◆ OInterfaceContainerHelper4() [1/3]

template<class T >
cppuhelper::OInterfaceContainerHelper4< T >::OInterfaceContainerHelper4
inline

Definition at line 285 of file interfacecontainer4.hxx.

References DEFAULT, and maData.

◆ OInterfaceContainerHelper4() [2/3]

template<class ListenerT >
cppuhelper::OInterfaceContainerHelper4< ListenerT >::OInterfaceContainerHelper4 ( OInterfaceContainerHelper4< ListenerT > &&  )
default

◆ OInterfaceContainerHelper4() [3/3]

template<class ListenerT >
cppuhelper::OInterfaceContainerHelper4< ListenerT >::OInterfaceContainerHelper4 ( const OInterfaceContainerHelper4< ListenerT > &  )
privatedelete

Member Function Documentation

◆ addInterface()

template<class ListenerT >
sal_Int32 cppuhelper::OInterfaceContainerHelper4< ListenerT >::addInterface ( std::unique_lock< std::mutex > &  rGuard,
const css::uno::Reference< ListenerT > &  rxIFace 
)

Inserts an element into the container.

The position is not specified, thus it is not specified in which order events are fired.

Attention: \n
If you add the same interface more than once, then it will be added to the elements list more than once and thus if you want to remove that interface from the list, you have to call removeInterface() the same number of times. In the latter case, you will also get events fired more than once (if the interface is a listener interface).
Parameters
rxIFaceinterface to be added; it is allowed to insert the same interface more than once
rGuardthis parameter only here to make that this container is accessed while locked
Returns
the new count of elements in the container

Definition at line 354 of file interfacecontainer4.hxx.

References maData.

◆ clear()

template<class ListenerT >
void cppuhelper::OInterfaceContainerHelper4< ListenerT >::clear ( ::std::unique_lock<::std::mutex > &  rGuard)

Clears the container without calling disposing().

Parameters
rGuardthis parameter only here to make that this container is accessed while locked

Definition at line 418 of file interfacecontainer4.hxx.

References maData.

◆ DEFAULT()

template<class ListenerT >
static o3tl::cow_wrapper< std::vector< css::uno::Reference< ListenerT > >, o3tl::ThreadSafeRefCountingPolicy > & cppuhelper::OInterfaceContainerHelper4< ListenerT >::DEFAULT ( )
inlinestaticprivate

Definition at line 253 of file interfacecontainer4.hxx.

◆ disposeAndClear()

template<class ListenerT >
void cppuhelper::OInterfaceContainerHelper4< ListenerT >::disposeAndClear ( ::std::unique_lock<::std::mutex > &  rGuard,
const css::lang::EventObject &  rEvt 
)

Call disposing on all object in the container that support XEventListener.

Then clear the container. The guard is unlock()'ed before calling the listeners.

◆ forEach()

template<class T >
template<typename FuncT >
void cppuhelper::OInterfaceContainerHelper4< T >::forEach ( std::unique_lock< std::mutex > &  rGuard,
FuncT const &  func 
) const
inline

Executes a functor for each contained listener of specified type, e.g.

forEach<awt::XPaintListener>(....

If a css::lang::DisposedException occurs which relates to the called listener, then that listener is removed from the container.

Template Parameters
FuncTunary functor type, let your compiler deduce this for you
Parameters
funcunary functor object expecting an argument of type css::uno::Reference<ListenerT>
rGuardthis parameter only here to make that this container is accessed while locked

Definition at line 292 of file interfacecontainer4.hxx.

References cppuhelper::OInterfaceIteratorHelper4< ListenerT >::hasMoreElements(), cppuhelper::OInterfaceContainerHelper4< ListenerT >::maData, maData, o3tl::cow_wrapper< typename T, class MTPolicy >::make_unique(), cppuhelper::OInterfaceIteratorHelper4< ListenerT >::next(), cppuhelper::OInterfaceIteratorHelper4< ListenerT >::remove(), and size.

◆ getElements()

template<class ListenerT >
std::vector< css::uno::Reference< ListenerT > > cppuhelper::OInterfaceContainerHelper4< ListenerT >::getElements ( std::unique_lock< std::mutex > &  rGuard) const

Return all interfaces added to this container.

Parameters
rGuardthis parameter only here to make that this container is accessed while locked

Definition at line 345 of file interfacecontainer4.hxx.

References maData.

◆ getLength()

template<class ListenerT >
sal_Int32 cppuhelper::OInterfaceContainerHelper4< ListenerT >::getLength ( std::unique_lock< std::mutex > &  rGuard) const

Return the number of Elements in the container.

Only useful if you have acquired the mutex.

Parameters
rGuardthis parameter only here to make that this container is accessed while locked

Definition at line 336 of file interfacecontainer4.hxx.

References maData.

◆ notifyEach()

template<class ListenerT >
template<typename EventT >
void cppuhelper::OInterfaceContainerHelper4< ListenerT >::notifyEach ( std::unique_lock< std::mutex > &  rGuard,
void(SAL_CALL ListenerT::*)(const EventT &)  NotificationMethod,
const EventT &  Event 
) const
inline

Calls a UNO listener method for each contained listener.

The listener method must take a single argument of type EventT, and return void.

If a css::lang::DisposedException occurs which relates to the called listener, then that listener is removed from the container.

Template Parameters
EventTevent type, let your compiler deduce this for you
Parameters
NotificationMethodPointer to a method of a ListenerT interface.
EventEvent to notify to all contained listeners
rGuardthis parameter only here to make that this container is accessed while locked

Example:

awt::PaintEvent aEvent( static_cast< cppu::OWeakObject* >( this ), ... );
listeners.notifyEach( &XPaintListener::windowPaint, aEvent );
AnyEventRef aEvent
Base class to implement a UNO object supporting weak references, i.e.
Definition: weak.hxx:48

Definition at line 326 of file interfacecontainer4.hxx.

◆ operator=() [1/2]

template<class ListenerT >
OInterfaceContainerHelper4 & cppuhelper::OInterfaceContainerHelper4< ListenerT >::operator= ( const OInterfaceContainerHelper4< ListenerT > &  )
privatedelete

◆ operator=() [2/2]

template<class ListenerT >
OInterfaceContainerHelper4 & cppuhelper::OInterfaceContainerHelper4< ListenerT >::operator= ( OInterfaceContainerHelper4< ListenerT > &&  )
default

◆ removeInterface()

template<class ListenerT >
sal_Int32 cppuhelper::OInterfaceContainerHelper4< ListenerT >::removeInterface ( std::unique_lock< std::mutex > &  rGuard,
const css::uno::Reference< ListenerT > &  rxIFace 
)

Removes an element from the container.

It uses interface equality to remove the interface.

Parameters
rxIFaceinterface to be removed
rGuardthis parameter only here to make that this container is accessed while locked
Returns
the new count of elements in the container

Definition at line 365 of file interfacecontainer4.hxx.

References maData.

Friends And Related Function Documentation

◆ OInterfaceIteratorHelper4< ListenerT >

template<class ListenerT >
friend class OInterfaceIteratorHelper4< ListenerT >
friend

Definition at line 241 of file interfacecontainer4.hxx.

Member Data Documentation

◆ maData

template<class ListenerT >
o3tl::cow_wrapper<std::vector<css::uno::Reference<ListenerT> >, o3tl::ThreadSafeRefCountingPolicy> cppuhelper::OInterfaceContainerHelper4< ListenerT >::maData
private

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