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>
54 class OInterfaceContainerHelper;
87 {
return nRemain != 0; }
92 ::com::sun::star::uno::XInterface * SAL_CALL next();
99 void SAL_CALL
remove();
124 inline static void * SAL_CALL
operator new(
size_t nSize )
126 inline static void SAL_CALL
operator delete(
void * pMem )
128 inline static void * SAL_CALL
operator new( size_t,
void * pMem )
130 inline static void SAL_CALL
operator delete(
void *,
void * )
150 sal_Int32 SAL_CALL getLength()
const;
173 sal_Int32 SAL_CALL addInterface( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rxIFace );
181 sal_Int32 SAL_CALL removeInterface( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rxIFace );
186 void SAL_CALL disposeAndClear( const ::com::sun::star::lang::EventObject & rEvt );
190 void SAL_CALL clear();
203 template <
typename ListenerT,
typename FuncT>
204 inline void forEach( FuncT
const& func );
227 template<
typename ListenerT,
typename EventT >
228 inline void notifyEach(
void ( SAL_CALL ListenerT::*NotificationMethod )(
const EventT& ),
const EventT& Event );
250 void copyAndResetInUse();
253 template<
typename ListenerT,
typename EventT >
254 class NotifySingleListener
257 typedef void ( SAL_CALL ListenerT::*NotificationMethod )(
const EventT& );
258 NotificationMethod m_pMethod;
259 const EventT& m_rEvent;
261 NotifySingleListener( NotificationMethod method,
const EventT& event ) : m_pMethod( method ), m_rEvent( event ) { }
263 void operator()( const ::com::sun::star::uno::Reference<ListenerT>& listener )
const
265 (listener.get()->*m_pMethod)( m_rEvent );
270 template <
typename ListenerT,
typename FuncT>
277 if (xListener.is()) {
281 catch (::com::sun::star::lang::DisposedException
const& exc) {
282 if (exc.Context == xListener)
289 template<
typename ListenerT,
typename EventT >
292 forEach< ListenerT, NotifySingleListener< ListenerT, EventT > >( NotifySingleListener< ListenerT, EventT >( NotificationMethod, Event ) );
302 template<
class key,
class hashImpl =
void,
class equalImpl = std::equal_to<key> >
307 inline static void * SAL_CALL
operator new(
size_t nSize )
309 inline static void SAL_CALL
operator delete(
void * pMem )
311 inline static void * SAL_CALL
operator new( size_t,
void * pMem )
313 inline static void SAL_CALL
operator delete(
void *,
void * )
332 inline ::com::sun::star::uno::Sequence< key > SAL_CALL
getContainedTypes()
const;
362 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & r );
376 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 );
387 inline void SAL_CALL
clear();
391 typedef ::std::vector< std::pair < key , void* > > InterfaceMap;
392 InterfaceMap *m_pMap;
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 )
457 OSL_ENSURE( !bInDispose,
"do not add listeners in the dispose call" );
458 OSL_ENSURE( !bDisposed,
"object is disposed" );
459 if( ! bInDispose && ! bDisposed )
460 aLC.addInterface( key , r );
468 const ::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface > & r )
471 OSL_ENSURE( !bDisposed,
"object is disposed" );
472 if( ! bInDispose && ! bDisposed )
473 aLC.removeInterface( key , r );
483 {
return aLC.getContainer( key ); }
496 size_t operator()(const ::com::sun::star::uno::Type & s)
const
497 {
return (
size_t) s.getTypeName().hashCode(); }
508 inline static void * SAL_CALL
operator new(
size_t nSize )
510 inline static void SAL_CALL
operator delete(
void * pMem )
512 inline static void * SAL_CALL
operator new( size_t,
void * pMem )
514 inline static void SAL_CALL
operator delete(
void *,
void * )
560 sal_Int32 SAL_CALL addInterface(
561 const ::com::sun::star::uno::Type & rKey,
562 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & r );
574 sal_Int32 SAL_CALL removeInterface(
575 const ::com::sun::star::uno::Type & rKey,
576 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rxIFace );
582 void SAL_CALL disposeAndClear( const ::com::sun::star::lang::EventObject & rEvt );
586 void SAL_CALL clear();
sal_Int32 removeInterface(const key &rKey, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > &rxIFace)
Removes an element from the container with the specified key.
Definition: interfacecontainer.hxx:116
void forEach(FuncT const &func)
Executes a functor for each contained listener of specified type, e.g.
Definition: interfacecontainer.h:271
unsigned char sal_Bool
Definition: types.h:48
This enum value can be used for implicit interface query.
Definition: Reference.h:139
A helper class for mutex objects and interfaces.
Definition: mutex.hxx:121
void remove()
Removes the current element (the last one returned by next()) from the underlying container...
Specialized class for key type com::sun::star::uno::Type, without explicit usage of STL symbols...
Definition: interfacecontainer.h:504
sal_Bool bInDispose
In dispose call.
Definition: interfacecontainer.h:436
sal_Int32 addInterface(const key &rKey, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > &r)
Inserts an element into the container with the specified key.
Definition: interfacecontainer.hxx:98
element_alias()
Definition: interfacecontainer.h:48
Definition: Enterable.hxx:26
~OMultiTypeInterfaceContainerHelperVar()
Deletes all containers.
Definition: interfacecontainer.hxx:37
#define sal_False
Definition: types.h:49
A mutual exclusion synchronization object.
Definition: mutex.hxx:30
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
inline::com::sun::star::uno::Sequence< key > getContainedTypes() const
Return all id's under which at least one interface is added.
Definition: interfacecontainer.hxx:53
OBroadcastHelperVar< OMultiTypeInterfaceContainerHelper, OMultiTypeInterfaceContainerHelper::keyType > OBroadcastHelper
Definition: interfacecontainer.h:597
key keyType
Definition: interfacecontainer.h:389
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
::com::sun::star::uno::XInterface * pAsInterface
Definition: interfacecontainer.h:47
container aLC
ListenerContainer class is thread safe.
Definition: interfacecontainer.h:432
OMultiTypeInterfaceContainerHelperVar(::osl::Mutex &rMutex)
Create a container of interface containers.
Definition: interfacecontainer.hxx:29
::osl::Mutex & rMutex
The shared mutex.
Definition: interfacecontainer.h:430
A helper class to store interface references of different types.
Definition: interfacecontainer.h:303
::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > > * pAsSequence
Definition: interfacecontainer.h:46
This is the iterator of a InterfaceContainerHelper.
Definition: interfacecontainer.h:62
::com::sun::star::uno::XInterface * next()
Return the next element of the iterator.
OInterfaceContainerHelper * getContainer(const key &) const
Return the container created under this key.
Definition: interfacecontainer.hxx:85
Definition: interfacecontainer.h:494
size_t operator()(const ::com::sun::star::uno::Type &s) const
Definition: interfacecontainer.h:496
Template C++ class representing an IDL sequence.
Definition: unotype.hxx:33
void clear()
Remove all elements of all containers.
Definition: interfacecontainer.hxx:171
OBroadcastHelperVar(::osl::Mutex &rMutex_)
Initialize the structure.
Definition: interfacecontainer.h:442
#define CPPUHELPER_DLLPUBLIC
Definition: cppuhelperdllapi.h:28
bool hasMoreElements() const
Return true, if there are more elements in the iterator.
Definition: interfacecontainer.h:86
A container of interfaces.
Definition: interfacecontainer.h:120
OInterfaceContainerHelper * getContainer(const keyType &key) const
Return the container created under this key.
Definition: interfacecontainer.h:482
#define OSL_ENSURE(c, m)
Definition: diagnose.h:106
void disposeAndClear(const ::com::sun::star::lang::EventObject &rEvt)
Call disposing on all references in the container, that support XEventListener.
Definition: interfacecontainer.hxx:134
This struct contains the standard variables of a broadcaster.
Definition: interfacecontainer.h:427
void removeListener(const keyType &key, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > &r)
removes a listener threadsafe
Definition: interfacecontainer.h:466
void notifyEach(void(ListenerT::*NotificationMethod)(const EventT &), const EventT &Event)
Calls a UNO listener method for each contained listener.
Definition: interfacecontainer.h:290
SAL_DLLPUBLIC void * rtl_allocateMemory(sal_Size Bytes) SAL_THROW_EXTERN_C()
Allocate memory.
Definition: interfacecontainer.h:44
::com::sun::star::uno::Type keyType
Definition: interfacecontainer.h:588
Template reference class for interface type derived from BaseReference.
Definition: unotype.hxx:32
sal_Bool bDisposed
Dispose call ready.
Definition: interfacecontainer.h:434