summaryrefslogtreecommitdiff
path: root/cppuhelper
diff options
context:
space:
mode:
authorOliver Bolte <obo@openoffice.org>2005-10-11 07:20:32 +0000
committerOliver Bolte <obo@openoffice.org>2005-10-11 07:20:32 +0000
commit83ad3990372b41a33be707ac9ca39db28a4c8f01 (patch)
treecfc9d892f8eec7138fa4cda3f9fb7e3408cacb13 /cppuhelper
parent11a5abb0021ff5219a2889823276c7d5859873cb (diff)
INTEGRATION: CWS presfixes08 (1.14.28); FILE MERGED
2005/09/01 09:09:46 dbo 1.14.28.1: #i51786# added forEach()
Diffstat (limited to 'cppuhelper')
-rw-r--r--cppuhelper/inc/cppuhelper/interfacecontainer.h40
1 files changed, 37 insertions, 3 deletions
diff --git a/cppuhelper/inc/cppuhelper/interfacecontainer.h b/cppuhelper/inc/cppuhelper/interfacecontainer.h
index f0a253f89332..54bd2279dcbb 100644
--- a/cppuhelper/inc/cppuhelper/interfacecontainer.h
+++ b/cppuhelper/inc/cppuhelper/interfacecontainer.h
@@ -4,9 +4,9 @@
*
* $RCSfile: interfacecontainer.h,v $
*
- * $Revision: 1.15 $
+ * $Revision: 1.16 $
*
- * last change: $Author: rt $ $Date: 2005-09-08 09:18:52 $
+ * last change: $Author: obo $ $Date: 2005-10-11 08:20:32 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
@@ -56,6 +56,9 @@
#include <com/sun/star/lang/EventObject.hpp>
#endif
+#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HXX_
+#include "com/sun/star/lang/DisposedException.hpp"
+#endif
/** */ //for docpp
namespace cppu
@@ -198,6 +201,20 @@ public:
*/
void SAL_CALL clear() SAL_THROW( () );
+ /** Executes a functor for each contained listener of specified type, e.g.
+ <code>forEach<awt::XPaintListener>(...</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 listener type
+ @tpl FuncT unary functor type, let your compiler deduce this for you
+ @param func unary functor object expecting an argument of type
+ ::com::sun::star::uno::Reference<ListenerT>
+ */
+ template <typename ListenerT, typename FuncT>
+ inline void forEach( FuncT const& func );
+
private:
friend class OInterfaceIteratorHelper;
/**
@@ -222,7 +239,24 @@ friend class OInterfaceIteratorHelper;
public:
};
-
+template <typename ListenerT, typename FuncT>
+inline void OInterfaceContainerHelper::forEach( FuncT const& func )
+{
+ OInterfaceIteratorHelper iter( *this );
+ while (iter.hasMoreElements()) {
+ ::com::sun::star::uno::Reference<ListenerT> const xListener(
+ iter.next(), ::com::sun::star::uno::UNO_QUERY );
+ if (xListener.is()) {
+ try {
+ func( xListener );
+ }
+ catch (::com::sun::star::lang::DisposedException const& exc) {
+ if (exc.Context == xListener)
+ iter.remove();
+ }
+ }
+ }
+}
//===================================================================
/**