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();
void removeListener(const keyType &key, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > &r)
removes a listener threadsafe
Definition: interfacecontainer.h:474
A helper class for mutex objects and interfaces.
Definition: mutex.hxx:108
container aLC
ListenerContainer class is thread safe.
Definition: interfacecontainer.h:440
::com::sun::star::uno::Type keyType
Definition: interfacecontainer.h:596
void remove()
Removes the current element (the last one returned by next()) from the underlying container...
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition: types.h:404
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
element_alias()
Definition: interfacecontainer.h:52
This enum value can be used for implicit interface query.
Definition: Reference.h:139
key keyType
Definition: interfacecontainer.h:397
::com::sun::star::uno::XInterface * next()
Return the next element of the iterator.
unsigned char sal_Bool
Definition: types.h:48
::com::sun::star::uno::XInterface * pAsInterface
Definition: interfacecontainer.h:51
::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > > * pAsSequence
Definition: interfacecontainer.h:50
Specialized class for key type com::sun::star::uno::Type, without explicit usage of STL symbols...
Definition: interfacecontainer.h:512
SAL_DLLPUBLIC void * rtl_allocateMemory(sal_Size Bytes) SAL_THROW_EXTERN_C()
Allocate memory.
Definition: interfacecontainer.h:502
sal_Bool bDisposed
Dispose call ready.
Definition: interfacecontainer.h:442
bool hasMoreElements() const
Return true, if there are more elements in the iterator.
Definition: interfacecontainer.h:90
size_t operator()(const ::com::sun::star::uno::Type &s) const
Definition: interfacecontainer.h:504
A mutual exclusion synchronization object.
Definition: mutex.hxx:30
OBroadcastHelperVar(::osl::Mutex &rMutex_)
Initialize the structure.
Definition: interfacecontainer.h:450
This struct contains the standard variables of a broadcaster.
Definition: interfacecontainer.h:435
sal_Bool bInDispose
In dispose call.
Definition: interfacecontainer.h:444
This is the iterator of a InterfaceContainerHelper.
Definition: interfacecontainer.h:66
void addListener(const keyType &key, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > &r)
adds a listener threadsafe.
Definition: interfacecontainer.h:460
A helper class to store interface references of different types.
Definition: interfacecontainer.h:311
Template reference class for interface type derived from BaseReference.
Definition: unotype.hxx:37
#define sal_False
Definition: types.h:49
#define CPPUHELPER_DLLPUBLIC
Definition: cppuhelperdllapi.h:28
This is here to optimise space in the common case that there are zero or one listeners.
Definition: interfacecontainer.h:48
::osl::Mutex & rMutex
The shared mutex.
Definition: interfacecontainer.h:438
void notifyEach(void(ListenerT::*NotificationMethod)(const EventT &), const EventT &Event)
Calls a UNO listener method for each contained listener.
Definition: interfacecontainer.h:298
Template C++ class representing an IDL sequence.
Definition: unotype.hxx:38
OInterfaceContainerHelper * getContainer(const keyType &key) const
Return the container created under this key.
Definition: interfacecontainer.h:490
#define OSL_ENSURE(c, m)
Definition: diagnose.h:106
Definition: Enterable.hxx:26
void forEach(FuncT const &func)
Executes a functor for each contained listener of specified type, e.g.
Definition: interfacecontainer.h:279
A container of interfaces.
Definition: interfacecontainer.h:126