19 #ifndef _CPPUHELPER_INTERFACECONTAINER_H_
20 #define _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()) {
272 #if defined(EXCEPTIONS_OFF)
278 catch (::com::sun::star::lang::DisposedException
const& exc) {
279 if (exc.Context == xListener)
287 template<
typename ListenerT,
typename EventT >
290 forEach< ListenerT, NotifySingleListener< ListenerT, EventT > >( NotifySingleListener< ListenerT, EventT >( NotificationMethod, Event ) );
300 template<
class key ,
class hashImpl ,
class equalImpl >
305 inline static void * SAL_CALL
operator new(
size_t nSize )
SAL_THROW(())
307 inline static void SAL_CALL
operator delete(
void * pMem )
SAL_THROW(())
309 inline static void * SAL_CALL
operator new( size_t,
void * pMem )
SAL_THROW(())
311 inline static void SAL_CALL
operator delete(
void *,
void * )
SAL_THROW(())
330 inline ::com::sun::star::uno::Sequence< key > SAL_CALL getContainedTypes() const SAL_THROW(());
338 inline OInterfaceContainerHelper * SAL_CALL getContainer( const key & ) const SAL_THROW(());
358 inline sal_Int32 SAL_CALL addInterface(
360 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & r )
373 inline sal_Int32 SAL_CALL removeInterface(
375 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rxIFace )
383 inline
void SAL_CALL disposeAndClear( const ::com::sun::star::lang::EventObject & rEvt ) SAL_THROW(());
387 inline
void SAL_CALL clear() SAL_THROW(());
391 typedef ::std::vector< std::pair < key ,
void* > > InterfaceMap;
392 InterfaceMap *m_pMap;
393 ::osl::Mutex & rMutex;
395 inline typename InterfaceMap::iterator find(const key &rKey)
const
397 typename InterfaceMap::iterator iter = m_pMap->begin();
398 typename InterfaceMap::iterator end = m_pMap->end();
403 if( equal( iter->first, rKey ) )
426 template < class container , class keyType >
454 const ::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface > &r )
458 OSL_ENSURE( !bInDispose,
"do not add listeners in the dispose call" );
459 OSL_ENSURE( !bDisposed,
"object is disposed" );
460 if( ! bInDispose && ! bDisposed )
461 aLC.addInterface( key , r );
469 const ::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface > & r )
473 OSL_ENSURE( !bDisposed,
"object is disposed" );
474 if( ! bInDispose && ! bDisposed )
475 aLC.removeInterface( key , r );
485 {
return aLC.getContainer( key ); }
499 {
return (
size_t) s.getTypeName().hashCode(); }
510 inline static void * SAL_CALL
operator new(
size_t nSize )
SAL_THROW(())
512 inline static void SAL_CALL
operator delete(
void * pMem )
SAL_THROW(())
514 inline static void * SAL_CALL
operator new( size_t,
void * pMem )
SAL_THROW(())
516 inline static void SAL_CALL
operator delete(
void *,
void * )
SAL_THROW(())
535 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getContainedTypes() const SAL_THROW(());
542 OInterfaceContainerHelper * SAL_CALL getContainer( const ::com::sun::star::uno::Type & rKey ) const SAL_THROW(());
562 sal_Int32 SAL_CALL addInterface(
563 const ::com::sun::star::uno::Type & rKey,
564 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & r )
577 sal_Int32 SAL_CALL removeInterface(
578 const ::com::sun::star::uno::Type & rKey,
579 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rxIFace )
586 void SAL_CALL disposeAndClear( const ::com::sun::star::lang::EventObject & rEvt ) SAL_THROW(());
590 void SAL_CALL clear() SAL_THROW(());
595 ::osl::Mutex & rMutex;
::com::sun::star::uno::XInterface * next()
Return the next element of the iterator.
::com::sun::star::uno::XInterface * pAsInterface
Definition: interfacecontainer.h:41
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
::osl::Mutex & rMutex
The shared mutex.
Definition: interfacecontainer.h:430
Specialized class for key type com::sun::star::uno::Type, without explicit usage of STL symbols...
Definition: interfacecontainer.h:506
key keyType
Definition: interfacecontainer.h:389
A container of interfaces.
Definition: interfacecontainer.h:114
size_t operator()(const ::com::sun::star::uno::Type &s) const
Definition: interfacecontainer.h:498
This enum value can be used for implicit interface query.
Definition: Reference.h:140
#define OSL_ENSURE(c, m)
Definition: diagnose.h:154
void removeListener(const keyType &key, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > &r)
removes a listener threadsafe
Definition: interfacecontainer.h:467
A mutual exclusion synchronization object.
Definition: mutex.hxx:32
Template reference class for interface type derived from BaseReference.
Definition: unotype.hxx:32
This is the iterator of a InterfaceContainerHelper.
Definition: interfacecontainer.h:56
Definition: interfacecontainer.h:496
OBroadcastHelperVar(::osl::Mutex &rMutex_)
Initialize the structur.
Definition: interfacecontainer.h:442
void addListener(const keyType &key, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > &r)
adds a listener threadsafe.
Definition: interfacecontainer.h:452
This struct contains the standard variables of a broadcaster.
Definition: interfacecontainer.h:427
::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > > * pAsSequence
Definition: interfacecontainer.h:40
OInterfaceContainerHelper * getContainer(const keyType &key) const
Return the container created under this key.
Definition: interfacecontainer.h:484
element_alias()
Definition: interfacecontainer.h:42
#define CPPUHELPER_DLLPUBLIC
Definition: cppuhelperdllapi.h:28
sal_Bool bInDispose
In dispose call.
Definition: interfacecontainer.h:436
container aLC
ListenerContainer class is thread safe.
Definition: interfacecontainer.h:432
Definition: interfacecontainer.h:38
A helper class to store interface references of different types.
Definition: interfacecontainer.h:301
unsigned char sal_Bool
Definition: types.h:37
#define sal_False
Definition: types.h:38
sal_Bool bDisposed
Dispose call ready.
Definition: interfacecontainer.h:434
SAL_DLLPUBLIC void * rtl_allocateMemory(sal_Size Bytes) SAL_THROW_EXTERN_C()
Allocate memory.
void remove()
Removes the current element (the last one returned by next()) from the underlying container...
Template C++ class representing an IDL sequence.
Definition: unotype.hxx:33
void notifyEach(void(ListenerT::*NotificationMethod)(const EventT &), const EventT &Event)
Calls a UNO listener method for each contained listener.
Definition: interfacecontainer.h:288
void forEach(FuncT const &func)
Executes a functor for each contained listener of specified type, e.g.
Definition: interfacecontainer.h:265
sal_Bool hasMoreElements() const
Return sal_True, if there are more elements in the iterator.
Definition: interfacecontainer.h:80
#define SAL_THROW(exc)
Definition of function throw clause macros.
Definition: types.h:356
C++ class representing an IDL meta type.
Definition: Type.h:55
A helper class for mutex objects and interfaces.
Definition: mutex.hxx:123