19 #ifndef INCLUDED_CPPUHELPER_INTERFACECONTAINER_H 20 #define INCLUDED_CPPUHELPER_INTERFACECONTAINER_H 33 #include <com/sun/star/uno/XInterface.hpp> 34 #include <com/sun/star/lang/EventObject.hpp> 36 #include <com/sun/star/lang/DisposedException.hpp> 51 css::uno::Sequence< css::uno::Reference< css::uno::XInterface > > *
pAsSequence;
92 {
return nRemain != 0; }
97 css::uno::XInterface * SAL_CALL next();
104 void SAL_CALL
remove();
131 static void * SAL_CALL
operator new(
size_t nSize )
133 static void SAL_CALL
operator delete(
void * pMem )
135 static void * SAL_CALL
operator new( size_t,
void * pMem )
137 static void SAL_CALL
operator delete(
void *,
void * )
157 sal_Int32 SAL_CALL getLength()
const;
162 css::uno::Sequence< css::uno::Reference< css::uno::XInterface > > SAL_CALL getElements()
const;
180 sal_Int32 SAL_CALL addInterface(
const css::uno::Reference< css::uno::XInterface > & rxIFace );
188 sal_Int32 SAL_CALL removeInterface(
const css::uno::Reference< css::uno::XInterface > & rxIFace );
193 void SAL_CALL disposeAndClear(
const css::lang::EventObject & rEvt );
197 void SAL_CALL clear();
210 template <
typename ListenerT,
typename FuncT>
211 inline void forEach( FuncT
const& func );
234 template<
typename ListenerT,
typename EventT >
235 inline void notifyEach(
void ( SAL_CALL ListenerT::*NotificationMethod )(
const EventT& ),
const EventT& Event );
259 void copyAndResetInUse();
262 template<
typename ListenerT,
typename EventT >
263 class NotifySingleListener
266 typedef void ( SAL_CALL ListenerT::*NotificationMethod )(
const EventT& );
267 NotificationMethod m_pMethod;
268 const EventT& m_rEvent;
270 NotifySingleListener( NotificationMethod method,
const EventT& event ) : m_pMethod( method ), m_rEvent( event ) { }
272 void operator()(
const css::uno::Reference<ListenerT>& listener )
const 274 (listener.get()->*m_pMethod)( m_rEvent );
279 template <
typename ListenerT,
typename FuncT>
285 if (xListener.is()) {
289 catch (css::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 static void * SAL_CALL
operator new(
size_t nSize )
317 static void SAL_CALL
operator delete(
void * pMem )
319 static void * SAL_CALL
operator new( size_t,
void * pMem )
321 static void SAL_CALL
operator delete(
void *,
void * )
340 inline css::uno::Sequence< key > SAL_CALL getContainedTypes()
const;
368 inline sal_Int32 SAL_CALL addInterface(
370 const css::uno::Reference< css::uno::XInterface > & r );
382 inline sal_Int32 SAL_CALL removeInterface(
384 const css::uno::Reference< css::uno::XInterface > & rxIFace );
391 inline void SAL_CALL disposeAndClear(
const css::lang::EventObject & rEvt );
395 inline void SAL_CALL clear();
399 typedef ::std::vector< std::pair < key , void* > > InterfaceMap;
400 InterfaceMap *m_pMap;
403 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 >
454 , bInDispose( false )
462 const css::uno::Reference < css::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 css::uno::Reference < css::uno::XInterface > & r )
479 if( ! bInDispose && ! bDisposed )
480 aLC.removeInterface( key , r );
490 {
return aLC.getContainer( key ); }
504 {
return (
size_t) s.getTypeName().hashCode(); }
515 static void * SAL_CALL
operator new(
size_t nSize )
517 static void SAL_CALL
operator delete(
void * pMem )
519 static void * SAL_CALL
operator new( size_t,
void * pMem )
521 static void SAL_CALL
operator delete(
void *,
void * )
540 css::uno::Sequence< css::uno::Type > SAL_CALL getContainedTypes()
const;
567 sal_Int32 SAL_CALL addInterface(
568 const css::uno::Type & rKey,
569 const css::uno::Reference< css::uno::XInterface > & r );
581 sal_Int32 SAL_CALL removeInterface(
582 const css::uno::Type & rKey,
583 const css::uno::Reference< css::uno::XInterface > & rxIFace );
589 void SAL_CALL disposeAndClear(
const css::lang::EventObject & rEvt );
593 void SAL_CALL clear();
key keyType
Definition: interfacecontainer.h:397
size_t operator()(const css::uno::Type &s) const
Definition: interfacecontainer.h:503
Specialized class for key type css::uno::Type, without explicit usage of STL symbols.
Definition: interfacecontainer.h:511
A helper class to store interface references of different types.
Definition: interfacecontainer.h:311
css::uno::Sequence< css::uno::Reference< css::uno::XInterface > > * pAsSequence
Definition: interfacecontainer.h:51
This is the iterator of a InterfaceContainerHelper.
Definition: interfacecontainer.h:67
#define CPPUHELPER_DLLPUBLIC
Definition: cppuhelperdllapi.h:28
container aLC
ListenerContainer class is thread safe.
Definition: interfacecontainer.h:440
sal_Bool bInDispose
In dispose call.
Definition: interfacecontainer.h:444
Definition: interfacecontainer.h:501
bool hasMoreElements() const
Return true, if there are more elements in the iterator.
Definition: interfacecontainer.h:91
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:392
css::uno::Type keyType
Definition: interfacecontainer.h:595
element_alias()
Definition: interfacecontainer.h:53
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:598
void forEach(FuncT const &func)
Executes a functor for each contained listener of specified type, e.g.
Definition: interfacecontainer.h:280
SAL_DLLPUBLIC void * rtl_allocateMemory(sal_Size Bytes) SAL_THROW_EXTERN_C()
Allocate memory.
void removeListener(const keyType &key, const css::uno::Reference< css::uno::XInterface > &r)
removes a listener threadsafe
Definition: interfacecontainer.h:474
::osl::Mutex & rMutex
The shared mutex.
Definition: interfacecontainer.h:438
unsigned char sal_Bool
Definition: types.h:39
css::uno::XInterface * next()
Return the next element of the iterator.
A mutual exclusion synchronization object.
Definition: mutex.hxx:30
Definition: Enterable.hxx:26
css::uno::XInterface * pAsInterface
Definition: interfacecontainer.h:52
#define OSL_ENSURE(c, m)
Definition: diagnose.h:101
This enum value can be used for implicit interface query.
Definition: Reference.h:149
OBroadcastHelperVar(::osl::Mutex &rMutex_)
Initialize the structure.
Definition: interfacecontainer.h:450
OBroadcastHelperVar< OMultiTypeInterfaceContainerHelper, OMultiTypeInterfaceContainerHelper::keyType > OBroadcastHelper
Definition: interfacecontainer.h:604
sal_Bool bDisposed
Dispose call ready.
Definition: interfacecontainer.h:442
A helper class for mutex objects and interfaces.
Definition: mutex.hxx:108
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
OInterfaceContainerHelper * getContainer(const keyType &key) const
Return the container created under this key.
Definition: interfacecontainer.h:489
This is here to optimise space in the common case that there are zero or one listeners.
Definition: interfacecontainer.h:49
void notifyEach(void(ListenerT::*NotificationMethod)(const EventT &), const EventT &Event)
Calls a UNO listener method for each contained listener.
Definition: interfacecontainer.h:298
This struct contains the standard variables of a broadcaster.
Definition: interfacecontainer.h:435
A container of interfaces.
Definition: interfacecontainer.h:127
void addListener(const keyType &key, const css::uno::Reference< css::uno::XInterface > &r)
adds a listener threadsafe.
Definition: interfacecontainer.h:460