19 #ifndef INCLUDED_CPPUHELPER_INTERFACECONTAINER_H
20 #define INCLUDED_CPPUHELPER_INTERFACECONTAINER_H
26 #include <com/sun/star/uno/XInterface.hpp>
27 #include <com/sun/star/lang/EventObject.hpp>
29 #include <com/sun/star/lang/DisposedException.hpp>
48 class OInterfaceContainerHelper;
81 {
return nRemain != 0; }
86 ::com::sun::star::uno::XInterface * SAL_CALL next()
SAL_THROW(());
99 detail::element_alias aData;
118 inline static void * SAL_CALL
operator new(
size_t nSize )
SAL_THROW(())
120 inline static void SAL_CALL
operator delete(
void * pMem )
SAL_THROW(())
122 inline static void * SAL_CALL
operator new( size_t,
void * pMem )
SAL_THROW(())
124 inline static void SAL_CALL
operator delete(
void *,
void * )
SAL_THROW(())
139 ~OInterfaceContainerHelper() SAL_THROW(());
144 sal_Int32 SAL_CALL getLength() const SAL_THROW(());
149 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > > SAL_CALL getElements() const SAL_THROW(());
167 sal_Int32 SAL_CALL addInterface( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rxIFace ) SAL_THROW(());
175 sal_Int32 SAL_CALL removeInterface( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rxIFace ) SAL_THROW(());
180 void SAL_CALL disposeAndClear( const ::com::sun::star::lang::EventObject & rEvt ) SAL_THROW(());
184 void SAL_CALL clear() SAL_THROW(());
197 template <typename ListenerT, typename FuncT>
198 inline
void forEach( FuncT const& func );
221 template< typename ListenerT, typename EventT >
222 inline
void notifyEach(
void ( SAL_CALL ListenerT::*NotificationMethod )( const EventT& ), const EventT& Event );
230 detail::element_alias aData;
231 ::osl::Mutex & rMutex;
237 OInterfaceContainerHelper( const OInterfaceContainerHelper & ) SAL_THROW(());
238 OInterfaceContainerHelper & operator = ( const OInterfaceContainerHelper & ) SAL_THROW(());
244 void copyAndResetInUse() SAL_THROW(());
247 template< typename ListenerT, typename EventT >
248 class NotifySingleListener
251 typedef void ( SAL_CALL ListenerT::*NotificationMethod )(
const EventT& );
252 NotificationMethod m_pMethod;
253 const EventT& m_rEvent;
255 NotifySingleListener( NotificationMethod method,
const EventT& event ) : m_pMethod( method ), m_rEvent( event ) { }
257 void operator()( const ::com::sun::star::uno::Reference<ListenerT>& listener )
const
259 (listener.get()->*m_pMethod)( m_rEvent );
264 template <
typename ListenerT,
typename FuncT>
271 if (xListener.is()) {
275 catch (::com::sun::star::lang::DisposedException
const& exc) {
276 if (exc.Context == xListener)
283 template<
typename ListenerT,
typename EventT >
286 forEach< ListenerT, NotifySingleListener< ListenerT, EventT > >( NotifySingleListener< ListenerT, EventT >( NotificationMethod, Event ) );
296 template<
class key ,
class hashImpl ,
class equalImpl >
301 inline static void * SAL_CALL
operator new(
size_t nSize )
SAL_THROW(())
303 inline static void SAL_CALL
operator delete(
void * pMem )
SAL_THROW(())
305 inline static void * SAL_CALL
operator new( size_t,
void * pMem )
SAL_THROW(())
307 inline static void SAL_CALL
operator delete(
void *,
void * )
SAL_THROW(())
326 inline ::com::sun::star::uno::Sequence< key > SAL_CALL getContainedTypes() const SAL_THROW(());
334 inline OInterfaceContainerHelper * SAL_CALL getContainer( const key & ) const SAL_THROW(());
354 inline sal_Int32 SAL_CALL addInterface(
356 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & r )
369 inline sal_Int32 SAL_CALL removeInterface(
371 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rxIFace )
379 inline
void SAL_CALL disposeAndClear( const ::com::sun::star::lang::EventObject & rEvt ) SAL_THROW(());
383 inline
void SAL_CALL clear() SAL_THROW(());
387 typedef ::std::vector< std::pair < key ,
void* > > InterfaceMap;
388 InterfaceMap *m_pMap;
389 ::osl::Mutex & rMutex;
391 inline typename InterfaceMap::iterator find(const key &rKey)
const
393 typename InterfaceMap::iterator iter = m_pMap->begin();
394 typename InterfaceMap::iterator end = m_pMap->end();
399 if( equal( iter->first, rKey ) )
422 template < class container , class keyType >
450 const ::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface > &r )
454 OSL_ENSURE( !bInDispose,
"do not add listeners in the dispose call" );
455 OSL_ENSURE( !bDisposed,
"object is disposed" );
456 if( ! bInDispose && ! bDisposed )
457 aLC.addInterface( key , r );
465 const ::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface > & r )
469 OSL_ENSURE( !bDisposed,
"object is disposed" );
470 if( ! bInDispose && ! bDisposed )
471 aLC.removeInterface( key , r );
481 {
return aLC.getContainer( key ); }
495 {
return (
size_t) s.getTypeName().hashCode(); }
506 inline static void * SAL_CALL
operator new(
size_t nSize )
SAL_THROW(())
508 inline static void SAL_CALL
operator delete(
void * pMem )
SAL_THROW(())
510 inline static void * SAL_CALL
operator new( size_t,
void * pMem )
SAL_THROW(())
512 inline static void SAL_CALL
operator delete(
void *,
void * )
SAL_THROW(())
531 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getContainedTypes() const SAL_THROW(());
538 OInterfaceContainerHelper * SAL_CALL getContainer( const ::com::sun::star::uno::Type & rKey ) const SAL_THROW(());
558 sal_Int32 SAL_CALL addInterface(
559 const ::com::sun::star::uno::Type & rKey,
560 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & r )
573 sal_Int32 SAL_CALL removeInterface(
574 const ::com::sun::star::uno::Type & rKey,
575 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rxIFace )
582 void SAL_CALL disposeAndClear( const ::com::sun::star::lang::EventObject & rEvt ) SAL_THROW(());
586 void SAL_CALL clear() SAL_THROW(());
591 ::osl::Mutex & rMutex;
void remove()
Removes the current element (the last one returned by next()) from the underlying container...
OInterfaceContainerHelper * getContainer(const keyType &key) const
Return the container created under this key.
Definition: interfacecontainer.h:480
::com::sun::star::uno::XInterface * pAsInterface
Definition: interfacecontainer.h:41
size_t operator()(const ::com::sun::star::uno::Type &s) const
Definition: interfacecontainer.h:494
This is the iterator of a InterfaceContainerHelper.
Definition: interfacecontainer.h:56
C++ class representing an IDL meta type.
Definition: Type.h:55
void removeListener(const keyType &key, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > &r)
removes a listener threadsafe
Definition: interfacecontainer.h:463
SAL_DLLPUBLIC void * rtl_allocateMemory(sal_Size Bytes) SAL_THROW_EXTERN_C()
Allocate memory.
void notifyEach(void(ListenerT::*NotificationMethod)(const EventT &), const EventT &Event)
Calls a UNO listener method for each contained listener.
Definition: interfacecontainer.h:284
OBroadcastHelperVar(::osl::Mutex &rMutex_)
Initialize the structur.
Definition: interfacecontainer.h:438
A helper class for mutex objects and interfaces.
Definition: mutex.hxx:123
Specialized class for key type com::sun::star::uno::Type, without explicit usage of STL symbols...
Definition: interfacecontainer.h:502
A container of interfaces.
Definition: interfacecontainer.h:114
#define CPPUHELPER_DLLPUBLIC
Definition: cppuhelperdllapi.h:28
#define OSL_ENSURE(c, m)
Definition: diagnose.h:154
key keyType
Definition: interfacecontainer.h:385
sal_Bool bDisposed
Dispose call ready.
Definition: interfacecontainer.h:430
void forEach(FuncT const &func)
Executes a functor for each contained listener of specified type, e.g.
Definition: interfacecontainer.h:265
::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > > * pAsSequence
Definition: interfacecontainer.h:40
::com::sun::star::uno::XInterface * next()
Return the next element of the iterator.
element_alias()
Definition: interfacecontainer.h:42
void addListener(const keyType &key, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > &r)
adds a listener threadsafe.
Definition: interfacecontainer.h:448
A mutual exclusion synchronization object.
Definition: mutex.hxx:32
Template reference class for interface type derived from BaseReference.
Definition: unotype.hxx:32
This struct contains the standard variables of a broadcaster.
Definition: interfacecontainer.h:423
sal_Bool hasMoreElements() const
Return sal_True, if there are more elements in the iterator.
Definition: interfacecontainer.h:80
This enum value can be used for implicit interface query.
Definition: Reference.h:138
Definition: interfacecontainer.h:492
unsigned char sal_Bool
Definition: types.h:46
sal_Bool bInDispose
In dispose call.
Definition: interfacecontainer.h:432
A helper class to store interface references of different types.
Definition: interfacecontainer.h:297
#define sal_False
Definition: types.h:47
Definition: interfacecontainer.h:38
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
container aLC
ListenerContainer class is thread safe.
Definition: interfacecontainer.h:428
Template C++ class representing an IDL sequence.
Definition: unotype.hxx:33
::osl::Mutex & rMutex
The shared mutex.
Definition: interfacecontainer.h:426
#define SAL_THROW(exc)
Definition of function throw clause macros.
Definition: types.h:358