28 #ifndef _CPPUHELPER_INTERFACECONTAINER_H_
29 #define _CPPUHELPER_INTERFACECONTAINER_H_
35 #include <com/sun/star/uno/XInterface.hpp>
36 #ifndef _COM_SUN_STAR_LANG_EVENTOBJECT_HXX_
37 #include <com/sun/star/lang/EventObject.hpp>
40 #ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HXX_
41 #include "com/sun/star/lang/DisposedException.hpp"
61 class OInterfaceContainerHelper;
94 {
return nRemain != 0; }
99 ::com::sun::star::uno::XInterface * SAL_CALL next()
SAL_THROW(());
112 detail::element_alias aData;
131 inline static void * SAL_CALL
operator new(
size_t nSize )
SAL_THROW(())
133 inline static void SAL_CALL
operator delete(
void * pMem )
SAL_THROW(())
135 inline static void * SAL_CALL
operator new( size_t,
void * pMem )
SAL_THROW(())
137 inline static void SAL_CALL
operator delete(
void *,
void * )
SAL_THROW(())
152 ~OInterfaceContainerHelper() SAL_THROW(());
157 sal_Int32 SAL_CALL getLength() const SAL_THROW(());
162 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > > SAL_CALL getElements() const SAL_THROW(());
180 sal_Int32 SAL_CALL addInterface( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rxIFace ) SAL_THROW(());
188 sal_Int32 SAL_CALL removeInterface( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rxIFace ) SAL_THROW(());
193 void SAL_CALL disposeAndClear( const ::com::sun::star::lang::EventObject & rEvt ) SAL_THROW(());
197 void SAL_CALL clear() SAL_THROW(());
210 template <typename ListenerT, typename FuncT>
211 inline
void forEach( FuncT const& func );
234 template< typename ListenerT, typename EventT >
235 inline
void notifyEach(
void ( SAL_CALL ListenerT::*NotificationMethod )( const EventT& ), const EventT& Event );
243 detail::element_alias aData;
244 ::osl::Mutex & rMutex;
250 OInterfaceContainerHelper( const OInterfaceContainerHelper & ) SAL_THROW(());
251 OInterfaceContainerHelper & operator = ( const OInterfaceContainerHelper & ) SAL_THROW(());
257 void copyAndResetInUse() SAL_THROW(());
260 template< typename ListenerT, typename EventT >
261 class NotifySingleListener
264 typedef void ( SAL_CALL ListenerT::*NotificationMethod )(
const EventT& );
265 NotificationMethod m_pMethod;
266 const EventT& m_rEvent;
268 NotifySingleListener( NotificationMethod method,
const EventT& event ) : m_pMethod( method ), m_rEvent( event ) { }
270 void operator()( const ::com::sun::star::uno::Reference<ListenerT>& listener )
const
272 (listener.get()->*m_pMethod)( m_rEvent );
277 template <
typename ListenerT,
typename FuncT>
284 if (xListener.is()) {
285 #if defined(EXCEPTIONS_OFF)
291 catch (::com::sun::star::lang::DisposedException
const& exc) {
292 if (exc.Context == xListener)
300 template<
typename ListenerT,
typename EventT >
303 forEach< ListenerT, NotifySingleListener< ListenerT, EventT > >( NotifySingleListener< ListenerT, EventT >( NotificationMethod, Event ) );
313 template<
class key ,
class hashImpl ,
class equalImpl >
318 inline static void * SAL_CALL
operator new(
size_t nSize )
SAL_THROW(())
320 inline static void SAL_CALL
operator delete(
void * pMem )
SAL_THROW(())
322 inline static void * SAL_CALL
operator new( size_t,
void * pMem )
SAL_THROW(())
324 inline static void SAL_CALL
operator delete(
void *,
void * )
SAL_THROW(())
343 inline ::com::sun::star::uno::Sequence< key > SAL_CALL getContainedTypes() const SAL_THROW(());
351 inline OInterfaceContainerHelper * SAL_CALL getContainer( const key & ) const SAL_THROW(());
371 inline sal_Int32 SAL_CALL addInterface(
373 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & r )
386 inline sal_Int32 SAL_CALL removeInterface(
388 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rxIFace )
396 inline
void SAL_CALL disposeAndClear( const ::com::sun::star::lang::EventObject & rEvt ) SAL_THROW(());
400 inline
void SAL_CALL clear() SAL_THROW(());
404 typedef ::std::vector< std::pair < key ,
void* > > InterfaceMap;
405 InterfaceMap *m_pMap;
406 ::osl::Mutex & rMutex;
408 inline typename InterfaceMap::iterator find(const key &rKey)
const
410 typename InterfaceMap::iterator iter = m_pMap->begin();
411 typename InterfaceMap::iterator end = m_pMap->end();
416 if( equal( iter->first, rKey ) )
439 template < class container , class keyType >
465 inline void addListener(
467 const ::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface > &r )
471 OSL_ENSURE( !bInDispose,
"do not add listeners in the dispose call" );
472 OSL_ENSURE( !bDisposed,
"object is disposed" );
473 if( ! bInDispose && ! bDisposed )
474 aLC.addInterface( key , r );
480 inline void removeListener(
482 const ::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface > & r )
486 OSL_ENSURE( !bDisposed,
"object is disposed" );
487 if( ! bInDispose && ! bDisposed )
488 aLC.removeInterface( key , r );
497 inline OInterfaceContainerHelper * SAL_CALL getContainer(
const keyType &key )
const SAL_THROW(())
498 {
return aLC.getContainer( key ); }
511 size_t operator()(const ::com::sun::star::uno::Type & s)
const SAL_THROW(())
512 {
return (
size_t) s.getTypeName().hashCode(); }
523 inline static void * SAL_CALL
operator new(
size_t nSize )
SAL_THROW(())
525 inline static void SAL_CALL
operator delete(
void * pMem )
SAL_THROW(())
527 inline static void * SAL_CALL
operator new( size_t,
void * pMem )
SAL_THROW(())
529 inline static void SAL_CALL
operator delete(
void *,
void * )
SAL_THROW(())
548 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getContainedTypes() const SAL_THROW(());
555 OInterfaceContainerHelper * SAL_CALL getContainer( const ::com::sun::star::uno::Type & rKey ) const SAL_THROW(());
575 sal_Int32 SAL_CALL addInterface(
576 const ::com::sun::star::uno::Type & rKey,
577 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & r )
590 sal_Int32 SAL_CALL removeInterface(
591 const ::com::sun::star::uno::Type & rKey,
592 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rxIFace )
599 void SAL_CALL disposeAndClear( const ::com::sun::star::lang::EventObject & rEvt ) SAL_THROW(());
603 void SAL_CALL clear() SAL_THROW(());
608 ::osl::Mutex & rMutex;