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

A container of interfaces. More...

#include <interfacecontainer3.hxx>

Inheritance diagram for comphelper::OInterfaceContainerHelper3< ListenerT >:
[legend]
Collaboration diagram for comphelper::OInterfaceContainerHelper3< ListenerT >:
[legend]

Classes

class  NotifySingleListener
 

Public Member Functions

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

Private Member Functions

 OInterfaceContainerHelper3 (const OInterfaceContainerHelper3 &)=delete
 
OInterfaceContainerHelper3operator= (const OInterfaceContainerHelper3 &)=delete
 

Private Attributes

o3tl::cow_wrapper< std::vector< css::uno::Reference< ListenerT > > > maData
 
::osl::Mutex & rMutex
 

Friends

class OInterfaceIteratorHelper3< ListenerT >
 

Detailed Description

template<class ListenerT>
class comphelper::OInterfaceContainerHelper3< ListenerT >

A container of interfaces.

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

Template Parameters
ListenerTUNO event listener type
See also
OInterfaceIteratorHelper

Definition at line 51 of file interfacecontainer3.hxx.

Constructor & Destructor Documentation

template<class ListenerT>
comphelper::OInterfaceContainerHelper3< ListenerT >::OInterfaceContainerHelper3 ( ::osl::Mutex &  rMutex_)
inline

Create an interface container.

Parameters
rMutexthe mutex to protect multi thread access. The lifetime must be longer than the lifetime of this object.

Definition at line 134 of file interfacecontainer3.hxx.

template<class ListenerT>
comphelper::OInterfaceContainerHelper3< ListenerT >::OInterfaceContainerHelper3 ( const OInterfaceContainerHelper3< ListenerT > &  )
privatedelete

Member Function Documentation

template<class ListenerT>
sal_Int32 comphelper::OInterfaceContainerHelper3< ListenerT >::addInterface ( 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:

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 the same interface more than once
Returns
the new count of elements in the container

Definition at line 295 of file interfacecontainer3.hxx.

References maData.

template<class ListenerT >
void comphelper::OInterfaceContainerHelper3< ListenerT >::clear ( )

Clears the container without calling disposing().

Definition at line 348 of file interfacecontainer3.hxx.

References maData.

template<class ListenerT >
void comphelper::OInterfaceContainerHelper3< ListenerT >::disposeAndClear ( const css::lang::EventObject &  rEvt)

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

Then clear the container.

Definition at line 328 of file interfacecontainer3.hxx.

References comphelper::OInterfaceIteratorHelper3< ListenerT >::hasMoreElements(), maData, and comphelper::OInterfaceIteratorHelper3< ListenerT >::next().

template<class T >
template<typename FuncT >
void comphelper::OInterfaceContainerHelper3< T >::forEach ( FuncT const &  func)
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>

Definition at line 251 of file interfacecontainer3.hxx.

References comphelper::OInterfaceIteratorHelper3< ListenerT >::hasMoreElements(), comphelper::OInterfaceIteratorHelper3< ListenerT >::next(), and comphelper::OInterfaceIteratorHelper3< ListenerT >::remove().

template<class ListenerT >
std::vector< css::uno::Reference< ListenerT > > comphelper::OInterfaceContainerHelper3< ListenerT >::getElements ( ) const

Return all interfaces added to this container.

Definition at line 285 of file interfacecontainer3.hxx.

References maData.

template<class ListenerT >
sal_Int32 comphelper::OInterfaceContainerHelper3< ListenerT >::getLength ( ) const

Return the number of Elements in the container.

Only useful if you have acquired the mutex.

Definition at line 277 of file interfacecontainer3.hxx.

References maData.

template<class ListenerT>
template<typename EventT >
void comphelper::OInterfaceContainerHelper3< ListenerT >::notifyEach ( void(SAL_CALL ListenerT::*)(const EventT &)  NotificationMethod,
const EventT &  Event 
)
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

Example:

awt::PaintEvent aEvent( static_cast< cppu::OWeakObject* >( this ), ... );
listeners.notifyEach( &XPaintListener::windowPaint, aEvent );

Definition at line 271 of file interfacecontainer3.hxx.

template<class ListenerT>
OInterfaceContainerHelper3& comphelper::OInterfaceContainerHelper3< ListenerT >::operator= ( const OInterfaceContainerHelper3< ListenerT > &  )
privatedelete
template<class ListenerT>
sal_Int32 comphelper::OInterfaceContainerHelper3< ListenerT >::removeInterface ( 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
Returns
the new count of elements in the container

Definition at line 305 of file interfacecontainer3.hxx.

References maData.

Friends And Related Function Documentation

template<class ListenerT>
friend class OInterfaceIteratorHelper3< ListenerT >
friend

Definition at line 221 of file interfacecontainer3.hxx.

Member Data Documentation

template<class ListenerT>
o3tl::cow_wrapper<std::vector<css::uno::Reference<ListenerT> > > comphelper::OInterfaceContainerHelper3< ListenerT >::maData
private

Definition at line 222 of file interfacecontainer3.hxx.

template<class ListenerT>
::osl::Mutex& comphelper::OInterfaceContainerHelper3< ListenerT >::rMutex
private

Definition at line 223 of file interfacecontainer3.hxx.


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