19 #ifndef _CPPUHELPER_INTERFACECONTAINER_H_
20 #define _CPPUHELPER_INTERFACECONTAINER_H_
26 #include <com/sun/star/uno/XInterface.hpp>
27 #ifndef _COM_SUN_STAR_LANG_EVENTOBJECT_HXX_
28 #include <com/sun/star/lang/EventObject.hpp>
31 #ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HXX_
32 #include "com/sun/star/lang/DisposedException.hpp"
52 class OInterfaceContainerHelper;
85 {
return nRemain != 0; }
90 ::com::sun::star::uno::XInterface * SAL_CALL next()
SAL_THROW(());
103 detail::element_alias aData;
122 inline static void * SAL_CALL
operator new(
size_t nSize )
SAL_THROW(())
124 inline static void SAL_CALL
operator delete(
void * pMem )
SAL_THROW(())
126 inline static void * SAL_CALL
operator new( size_t,
void * pMem )
SAL_THROW(())
128 inline static void SAL_CALL
operator delete(
void *,
void * )
SAL_THROW(())
143 ~OInterfaceContainerHelper() SAL_THROW(());
148 sal_Int32 SAL_CALL getLength() const SAL_THROW(());
153 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > > SAL_CALL getElements() const SAL_THROW(());
171 sal_Int32 SAL_CALL addInterface( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rxIFace ) SAL_THROW(());
179 sal_Int32 SAL_CALL removeInterface( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rxIFace ) SAL_THROW(());
184 void SAL_CALL disposeAndClear( const ::com::sun::star::lang::EventObject & rEvt ) SAL_THROW(());
188 void SAL_CALL clear() SAL_THROW(());
201 template <typename ListenerT, typename FuncT>
202 inline
void forEach( FuncT const& func );
225 template< typename ListenerT, typename EventT >
226 inline
void notifyEach(
void ( SAL_CALL ListenerT::*NotificationMethod )( const EventT& ), const EventT& Event );
234 detail::element_alias aData;
235 ::osl::Mutex & rMutex;
241 OInterfaceContainerHelper( const OInterfaceContainerHelper & ) SAL_THROW(());
242 OInterfaceContainerHelper & operator = ( const OInterfaceContainerHelper & ) SAL_THROW(());
248 void copyAndResetInUse() SAL_THROW(());
251 template< typename ListenerT, typename EventT >
252 class NotifySingleListener
255 typedef void ( SAL_CALL ListenerT::*NotificationMethod )(
const EventT& );
256 NotificationMethod m_pMethod;
257 const EventT& m_rEvent;
259 NotifySingleListener( NotificationMethod method,
const EventT& event ) : m_pMethod( method ), m_rEvent( event ) { }
261 void operator()( const ::com::sun::star::uno::Reference<ListenerT>& listener )
const
263 (listener.get()->*m_pMethod)( m_rEvent );
268 template <
typename ListenerT,
typename FuncT>
275 if (xListener.is()) {
276 #if defined(EXCEPTIONS_OFF)
282 catch (::com::sun::star::lang::DisposedException
const& exc) {
283 if (exc.Context == xListener)
291 template<
typename ListenerT,
typename EventT >
294 forEach< ListenerT, NotifySingleListener< ListenerT, EventT > >( NotifySingleListener< ListenerT, EventT >( NotificationMethod, Event ) );
304 template<
class key ,
class hashImpl ,
class equalImpl >
309 inline static void * SAL_CALL
operator new(
size_t nSize )
SAL_THROW(())
311 inline static void SAL_CALL
operator delete(
void * pMem )
SAL_THROW(())
313 inline static void * SAL_CALL
operator new( size_t,
void * pMem )
SAL_THROW(())
315 inline static void SAL_CALL
operator delete(
void *,
void * )
SAL_THROW(())
334 inline ::com::sun::star::uno::Sequence< key > SAL_CALL getContainedTypes() const SAL_THROW(());
342 inline OInterfaceContainerHelper * SAL_CALL getContainer( const key & ) const SAL_THROW(());
362 inline sal_Int32 SAL_CALL addInterface(
364 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & r )
377 inline sal_Int32 SAL_CALL removeInterface(
379 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rxIFace )
387 inline
void SAL_CALL disposeAndClear( const ::com::sun::star::lang::EventObject & rEvt ) SAL_THROW(());
391 inline
void SAL_CALL clear() SAL_THROW(());
395 typedef ::std::vector< std::pair < key ,
void* > > InterfaceMap;
396 InterfaceMap *m_pMap;
397 ::osl::Mutex & rMutex;
399 inline typename InterfaceMap::iterator find(const key &rKey)
const
401 typename InterfaceMap::iterator iter = m_pMap->begin();
402 typename InterfaceMap::iterator end = m_pMap->end();
407 if( equal( iter->first, rKey ) )
430 template < class container , class keyType >
456 inline void addListener(
458 const ::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface > &r )
462 OSL_ENSURE( !bInDispose,
"do not add listeners in the dispose call" );
463 OSL_ENSURE( !bDisposed,
"object is disposed" );
464 if( ! bInDispose && ! bDisposed )
465 aLC.addInterface( key , r );
471 inline void removeListener(
473 const ::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface > & r )
477 OSL_ENSURE( !bDisposed,
"object is disposed" );
478 if( ! bInDispose && ! bDisposed )
479 aLC.removeInterface( key , r );
488 inline OInterfaceContainerHelper * SAL_CALL getContainer(
const keyType &key )
const SAL_THROW(())
489 {
return aLC.getContainer( key ); }
502 size_t operator()(const ::com::sun::star::uno::Type & s)
const SAL_THROW(())
503 {
return (
size_t) s.getTypeName().hashCode(); }
514 inline static void * SAL_CALL
operator new(
size_t nSize )
SAL_THROW(())
516 inline static void SAL_CALL
operator delete(
void * pMem )
SAL_THROW(())
518 inline static void * SAL_CALL
operator new( size_t,
void * pMem )
SAL_THROW(())
520 inline static void SAL_CALL
operator delete(
void *,
void * )
SAL_THROW(())
539 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getContainedTypes() const SAL_THROW(());
546 OInterfaceContainerHelper * SAL_CALL getContainer( const ::com::sun::star::uno::Type & rKey ) const SAL_THROW(());
566 sal_Int32 SAL_CALL addInterface(
567 const ::com::sun::star::uno::Type & rKey,
568 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & r )
581 sal_Int32 SAL_CALL removeInterface(
582 const ::com::sun::star::uno::Type & rKey,
583 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rxIFace )
590 void SAL_CALL disposeAndClear( const ::com::sun::star::lang::EventObject & rEvt ) SAL_THROW(());
594 void SAL_CALL clear() SAL_THROW(());
599 ::osl::Mutex & rMutex;