diff options
author | Oliver Bolte <obo@openoffice.org> | 2005-12-21 12:19:23 +0000 |
---|---|---|
committer | Oliver Bolte <obo@openoffice.org> | 2005-12-21 12:19:23 +0000 |
commit | 5dd324bdc727ac38fa3a4cfd50cc09f2323200c3 (patch) | |
tree | 2c8ee575bccfd619627d0f6f82aad3f669556923 /cppuhelper/inc | |
parent | d5d6b6b9d35f37460a430fa41618cdc2b68c622e (diff) |
INTEGRATION: CWS dba202a (1.17.10); FILE MERGED
2005/11/28 14:49:21 fs 1.17.10.2: don't use OWeakObject::operator*, as per Daniel Boelzle's suggestion, but make casting explicit
2005/11/25 13:34:38 fs 1.17.10.1: +notifyEach: simplify calling forEach for a fixed-signature class of UNO listener methods
Diffstat (limited to 'cppuhelper/inc')
-rw-r--r-- | cppuhelper/inc/cppuhelper/interfacecontainer.h | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/cppuhelper/inc/cppuhelper/interfacecontainer.h b/cppuhelper/inc/cppuhelper/interfacecontainer.h index 8c00e31bf..929c0e991 100644 --- a/cppuhelper/inc/cppuhelper/interfacecontainer.h +++ b/cppuhelper/inc/cppuhelper/interfacecontainer.h @@ -4,9 +4,9 @@ * * $RCSfile: interfacecontainer.h,v $ * - * $Revision: 1.17 $ + * $Revision: 1.18 $ * - * last change: $Author: dbo $ $Date: 2005-10-28 09:13:27 $ + * last change: $Author: obo $ $Date: 2005-12-21 13:19:23 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -215,6 +215,30 @@ public: template <typename ListenerT, typename FuncT> inline void forEach( FuncT const& func ); + /** Calls a UNO listener method for each contained listener. + + The listener method must take a single argument of type EventT, + and return <code>void</code>. + + If a com::sun::star::lang::DisposedException occurs which relates to + the called listener, then that listener is removed from the container. + + @tpl ListenerT UNO event listener type, let your compiler deduce this for you + @tpl EventT event type, let your compiler deduce this for you + @param NotificationMethod + Pointer to a method of a ListenerT interface. + @param Event + Event to notify to all contained listeners + + @example +<pre> + awt::PaintEvent aEvent( static_cast< ::cppu::OWeakObject* >( this ), ... ); + listeners.notifyEach( &XPaintListener::windowPaint, aEvent ); +</pre> + */ + template< typename ListenerT, typename EventT > + inline void notifyEach( void ( SAL_CALL ListenerT::*NotificationMethod )( const EventT& ), const EventT& Event ); + private: friend class OInterfaceIteratorHelper; /** @@ -236,7 +260,23 @@ friend class OInterfaceIteratorHelper; The mutex must be locked and the memberbInUse must be true. */ void copyAndResetInUse() SAL_THROW( () ); -public: + +private: + template< typename ListenerT, typename EventT > + class NotifySingleListener + { + private: + typedef void ( SAL_CALL ListenerT::*NotificationMethod )( const EventT& ); + NotificationMethod m_pMethod; + const EventT& m_rEvent; + public: + NotifySingleListener( NotificationMethod method, const EventT& event ) : m_pMethod( method ), m_rEvent( event ) { } + + void operator()( const ::com::sun::star::uno::Reference<ListenerT>& listener ) const + { + (listener.get()->*m_pMethod)( m_rEvent ); + } + }; }; template <typename ListenerT, typename FuncT> @@ -262,6 +302,12 @@ inline void OInterfaceContainerHelper::forEach( FuncT const& func ) } } +template< typename ListenerT, typename EventT > +inline void OInterfaceContainerHelper::notifyEach( void ( SAL_CALL ListenerT::*NotificationMethod )( const EventT& ), const EventT& Event ) +{ + forEach< ListenerT, NotifySingleListener< ListenerT, EventT > >( NotifySingleListener< ListenerT, EventT >( NotificationMethod, Event ) ); +} + //=================================================================== /** A helper class to store interface references of different types. |