19 #ifndef INCLUDED_CPPUHELPER_INTERFACECONTAINER_H
20 #define INCLUDED_CPPUHELPER_INTERFACECONTAINER_H
32 #include <com/sun/star/uno/XInterface.hpp>
33 #include <com/sun/star/lang/EventObject.hpp>
35 #include <com/sun/star/lang/DisposedException.hpp>
58 class OInterfaceContainerHelper;
91 {
return nRemain != 0; }
96 ::com::sun::star::uno::XInterface * SAL_CALL next();
103 void SAL_CALL
remove();
116 SAL_DELETED_FUNCTION;
130 inline static void * SAL_CALL
operator new(
size_t nSize )
132 inline static void SAL_CALL
operator delete(
void * pMem )
134 inline static void * SAL_CALL
operator new( size_t,
void * pMem )
136 inline static void SAL_CALL
operator delete(
void *,
void * )
146 OInterfaceContainerHelper( ::
osl::Mutex & rMutex );
151 ~OInterfaceContainerHelper();
156 sal_Int32 SAL_CALL getLength()
const;
179 sal_Int32 SAL_CALL addInterface( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rxIFace );
187 sal_Int32 SAL_CALL removeInterface( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rxIFace );
192 void SAL_CALL disposeAndClear( const ::com::sun::star::lang::EventObject & rEvt );
196 void SAL_CALL clear();
209 template <
typename ListenerT,
typename FuncT>
210 inline void forEach( FuncT
const& func );
233 template<
typename ListenerT,
typename EventT >
234 inline void notifyEach(
void ( SAL_CALL ListenerT::*NotificationMethod )(
const EventT& ),
const EventT& Event );
249 OInterfaceContainerHelper(
const OInterfaceContainerHelper & )
250 SAL_DELETED_FUNCTION;
251 OInterfaceContainerHelper & operator = ( const OInterfaceContainerHelper & )
252 SAL_DELETED_FUNCTION;
258 void copyAndResetInUse();
261 template< typename ListenerT, typename EventT >
262 class NotifySingleListener
265 typedef void ( SAL_CALL ListenerT::*NotificationMethod )(
const EventT& );
266 NotificationMethod m_pMethod;
267 const EventT& m_rEvent;
269 NotifySingleListener( NotificationMethod method,
const EventT& event ) : m_pMethod( method ), m_rEvent( event ) { }
271 void operator()( const ::com::sun::star::uno::Reference<ListenerT>& listener )
const
273 (listener.get()->*m_pMethod)( m_rEvent );
278 template <
typename ListenerT,
typename FuncT>
285 if (xListener.is()) {
289 catch (::com::sun::star::lang::DisposedException
const& exc) {
290 if (exc.Context == xListener)
297 template<
typename ListenerT,
typename EventT >
300 forEach< ListenerT, NotifySingleListener< ListenerT, EventT > >( NotifySingleListener< ListenerT, EventT >( NotificationMethod, Event ) );
310 template<
class key,
class hashImpl =
void,
class equalImpl = std::equal_to<key> >
315 inline static void * SAL_CALL
operator new(
size_t nSize )
317 inline static void SAL_CALL
operator delete(
void * pMem )
319 inline static void * SAL_CALL
operator new( size_t,
void * pMem )
321 inline static void SAL_CALL
operator delete(
void *,
void * )
340 inline ::com::sun::star::uno::Sequence< key > SAL_CALL getContainedTypes()
const;
348 inline OInterfaceContainerHelper * SAL_CALL getContainer(
const key & )
const;
368 inline sal_Int32 SAL_CALL addInterface(
370 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & r );
382 inline sal_Int32 SAL_CALL removeInterface(
384 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rxIFace );
391 inline void SAL_CALL disposeAndClear( const ::com::sun::star::lang::EventObject & rEvt );
395 inline void SAL_CALL clear();
399 typedef ::std::vector< std::pair < key , void* > > InterfaceMap;
400 InterfaceMap *m_pMap;
403 inline typename InterfaceMap::iterator find(
const key &rKey)
const
405 typename InterfaceMap::iterator iter = m_pMap->begin();
406 typename InterfaceMap::iterator end = m_pMap->end();
411 if( equal( iter->first, rKey ) )
434 template < class container , class keyType >
462 const ::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface > &r )
465 OSL_ENSURE( !bInDispose,
"do not add listeners in the dispose call" );
466 OSL_ENSURE( !bDisposed,
"object is disposed" );
467 if( ! bInDispose && ! bDisposed )
468 aLC.addInterface( key , r );
476 const ::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface > & r )
479 OSL_ENSURE( !bDisposed,
"object is disposed" );
480 if( ! bInDispose && ! bDisposed )
481 aLC.removeInterface( key , r );
490 inline OInterfaceContainerHelper * SAL_CALL
getContainer(
const keyType &key )
const
491 {
return aLC.getContainer( key ); }
504 size_t operator()(const ::com::sun::star::uno::Type & s)
const
505 {
return (
size_t) s.getTypeName().hashCode(); }
516 inline static void * SAL_CALL
operator new(
size_t nSize )
518 inline static void SAL_CALL
operator delete(
void * pMem )
520 inline static void * SAL_CALL
operator new( size_t,
void * pMem )
522 inline static void SAL_CALL
operator delete(
void *,
void * )
548 OInterfaceContainerHelper * SAL_CALL getContainer( const ::com::sun::star::uno::Type & rKey )
const;
568 sal_Int32 SAL_CALL addInterface(
569 const ::com::sun::star::uno::Type & rKey,
570 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & r );
582 sal_Int32 SAL_CALL removeInterface(
583 const ::com::sun::star::uno::Type & rKey,
584 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rxIFace );
590 void SAL_CALL disposeAndClear( const ::com::sun::star::lang::EventObject & rEvt );
594 void SAL_CALL clear();