23#ifndef INCLUDED_CPPUHELPER_INTERFACECONTAINER_H
24#define INCLUDED_CPPUHELPER_INTERFACECONTAINER_H
37#include "com/sun/star/lang/EventObject.hpp"
39#include "com/sun/star/lang/DisposedException.hpp"
42namespace com {
namespace sun {
namespace star {
namespace uno {
class XInterface; } } } }
56 std::vector< css::uno::Reference< css::uno::XInterface > > *
pAsVector;
64class OInterfaceContainerHelper;
97 {
return nRemain != 0; }
102 css::uno::XInterface * SAL_CALL
next();
136 static void * SAL_CALL
operator new(
size_t nSize )
137 { return ::rtl_allocateMemory( nSize ); }
138 static void SAL_CALL
operator delete(
void * pMem )
140 static void * SAL_CALL
operator new( size_t,
void * pMem )
142 static void SAL_CALL
operator delete(
void *,
void * )
167 css::uno::Sequence< css::uno::Reference< css::uno::XInterface > > SAL_CALL
getElements()
const;
185 sal_Int32 SAL_CALL
addInterface(
const css::uno::Reference< css::uno::XInterface > & rxIFace );
193 sal_Int32 SAL_CALL
removeInterface(
const css::uno::Reference< css::uno::XInterface > & rxIFace );
215 template <
typename ListenerT,
typename FuncT>
216 inline void forEach( FuncT
const& func );
239 template<
typename ListenerT,
typename EventT >
240 inline void notifyEach(
void ( SAL_CALL ListenerT::*NotificationMethod )( const EventT& ), const EventT& Event );
264 void copyAndResetInUse();
267 template<
typename ListenerT,
typename EventT >
268 class NotifySingleListener
271 typedef void ( SAL_CALL ListenerT::*NotificationMethod )( const EventT& );
272 NotificationMethod m_pMethod;
273 const EventT& m_rEvent;
275 NotifySingleListener( NotificationMethod method,
const EventT& event ) : m_pMethod( method ), m_rEvent( event ) { }
277 void operator()(
const css::uno::Reference<ListenerT>& listener )
const
279 (listener.get()->*m_pMethod)( m_rEvent );
284template <
typename ListenerT,
typename FuncT>
289 css::uno::Reference<ListenerT>
const xListener( iter.
next(), css::uno::UNO_QUERY );
290 if (xListener.is()) {
294 catch (css::lang::DisposedException
const& exc) {
295 if (exc.Context == xListener)
302template<
typename ListenerT,
typename EventT >
305 forEach< ListenerT, NotifySingleListener< ListenerT, EventT > >( NotifySingleListener< ListenerT, EventT >( NotificationMethod, Event ) );
315template<
class key,
class hashImpl =
void,
class equalImpl = std::equal_to<key> >
320 static void * SAL_CALL
operator new(
size_t nSize )
321 { return ::rtl_allocateMemory( nSize ); }
322 static void SAL_CALL
operator delete(
void * pMem )
324 static void * SAL_CALL
operator new( size_t,
void * pMem )
326 static void SAL_CALL
operator delete(
void *,
void * )
375 const css::uno::Reference< css::uno::XInterface > & r );
389 const css::uno::Reference< css::uno::XInterface > & rxIFace );
396 inline void SAL_CALL
disposeAndClear(
const css::lang::EventObject & rEvt );
400 inline void SAL_CALL
clear();
404 typedef ::std::vector< std::pair < key , void* > > InterfaceMap;
405 InterfaceMap *m_pMap;
408 typename InterfaceMap::iterator find(
const key &rKey)
const
410 typename InterfaceMap::iterator iter = m_pMap->begin();
411 typename InterfaceMap::iterator end = m_pMap->end();
416 if( equal( iter->first, rKey ) )
439template <
class container ,
class keyType >
459 , bInDispose( false )
467 const css::uno::Reference < css::uno::XInterface > &r )
470 OSL_ENSURE( !bInDispose,
"do not add listeners in the dispose call" );
471 OSL_ENSURE( !bDisposed,
"object is disposed" );
472 if( ! bInDispose && ! bDisposed )
473 aLC.addInterface( key , r );
481 const css::uno::Reference < css::uno::XInterface > & r )
484 if( ! bInDispose && ! bDisposed )
485 aLC.removeInterface( key , r );
495 {
return aLC.getContainer( key ); }
509 {
return static_cast<size_t>(s.getTypeName().hashCode()); }
520 static void * SAL_CALL
operator new(
size_t nSize )
521 { return ::rtl_allocateMemory( nSize ); }
522 static void SAL_CALL
operator delete(
void * pMem )
524 static void * SAL_CALL
operator new( size_t,
void * pMem )
526 static void SAL_CALL
operator delete(
void *,
void * )
573 const css::uno::Type & rKey,
574 const css::uno::Reference< css::uno::XInterface > & r );
587 const css::uno::Type & rKey,
588 const css::uno::Reference< css::uno::XInterface > & rxIFace );
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition types.h:378
unsigned char sal_Bool
Definition types.h:38
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition types.h:587
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
Provides simple diagnostic support.
#define CPPUHELPER_DLLPUBLIC
Definition cppuhelperdllapi.h:32
#define OSL_ENSURE(c, m)
If cond is false, reports an error with message msg.
Definition diagnose.h:87
Definition Enterable.hxx:31
OBroadcastHelperVar< OMultiTypeInterfaceContainerHelper, OMultiTypeInterfaceContainerHelper::keyType > OBroadcastHelper
Definition interfacecontainer.h:609
A mutual exclusion synchronization object.
Definition mutex.hxx:35
Object lifetime scoped mutex object or interface lock.
Definition mutex.hxx:122
This is here to optimise space in the common case that there are zero or one listeners.
Definition interfacecontainer.h:55
std::vector< css::uno::Reference< css::uno::XInterface > > * pAsVector
Definition interfacecontainer.h:56
css::uno::XInterface * pAsInterface
Definition interfacecontainer.h:57
element_alias()
Definition interfacecontainer.h:58
This is the iterator of an InterfaceContainerHelper.
Definition interfacecontainer.h:73
~OInterfaceIteratorHelper()
Releases the connection to the container.
void remove()
Removes the current element (the last one returned by next()) from the underlying container.
bool hasMoreElements() const
Return true, if there are more elements in the iterator.
Definition interfacecontainer.h:96
OInterfaceIteratorHelper(OInterfaceContainerHelper &rCont)
Create an iterator over the elements of the container.
css::uno::XInterface * next()
Return the next element of the iterator.
A container of interfaces.
Definition interfacecontainer.h:133
sal_Int32 getLength() const
Return the number of Elements in the container.
void notifyEach(void(ListenerT::*NotificationMethod)(const EventT &), const EventT &Event)
Calls a UNO listener method for each contained listener.
Definition interfacecontainer.h:303
void disposeAndClear(const css::lang::EventObject &rEvt)
Call disposing on all object in the container that support XEventListener.
sal_Int32 removeInterface(const css::uno::Reference< css::uno::XInterface > &rxIFace)
Removes an element from the container.
void forEach(FuncT const &func)
Executes a functor for each contained listener of specified type, e.g.
Definition interfacecontainer.h:285
~OInterfaceContainerHelper()
Release all interfaces.
sal_Int32 addInterface(const css::uno::Reference< css::uno::XInterface > &rxIFace)
Inserts an element into the container.
void clear()
Clears the container without calling disposing().
OInterfaceContainerHelper(::osl::Mutex &rMutex)
Create an interface container.
css::uno::Sequence< css::uno::Reference< css::uno::XInterface > > getElements() const
Return all interfaces added to this container.
A helper class to store interface references of different types.
Definition interfacecontainer.h:317
~OMultiTypeInterfaceContainerHelperVar()
Deletes all containers.
Definition interfacecontainer.hxx:45
sal_Int32 addInterface(const key &rKey, const css::uno::Reference< css::uno::XInterface > &r)
Inserts an element into the container with the specified key.
Definition interfacecontainer.hxx:106
OInterfaceContainerHelper * getContainer(const key &) const
Return the container created under this key.
Definition interfacecontainer.hxx:93
void clear()
Remove all elements of all containers.
Definition interfacecontainer.hxx:179
void disposeAndClear(const css::lang::EventObject &rEvt)
Call disposing on all references in the container, that support XEventListener.
Definition interfacecontainer.hxx:142
key keyType
Definition interfacecontainer.h:402
css::uno::Sequence< key > getContainedTypes() const
Return all id's under which at least one interface is added.
Definition interfacecontainer.hxx:61
sal_Int32 removeInterface(const key &rKey, const css::uno::Reference< css::uno::XInterface > &rxIFace)
Removes an element from the container with the specified key.
Definition interfacecontainer.hxx:124
This struct contains the standard variables of a broadcaster.
Definition interfacecontainer.h:441
OInterfaceContainerHelper * getContainer(const keyType &key) const
Return the container created under this key.
Definition interfacecontainer.h:494
void addListener(const keyType &key, const css::uno::Reference< css::uno::XInterface > &r)
adds a listener threadsafe.
Definition interfacecontainer.h:465
container aLC
ListenerContainer class is thread safe.
Definition interfacecontainer.h:445
::osl::Mutex & rMutex
The shared mutex.
Definition interfacecontainer.h:443
sal_Bool bInDispose
In dispose call.
Definition interfacecontainer.h:449
void removeListener(const keyType &key, const css::uno::Reference< css::uno::XInterface > &r)
removes a listener threadsafe
Definition interfacecontainer.h:479
sal_Bool bDisposed
Dispose call ready.
Definition interfacecontainer.h:447
OBroadcastHelperVar(::osl::Mutex &rMutex_)
Initialize the structure.
Definition interfacecontainer.h:455
Definition interfacecontainer.h:507
size_t operator()(const css::uno::Type &s) const
Definition interfacecontainer.h:508
Specialized class for key type css::uno::Type, without explicit usage of STL symbols.
Definition interfacecontainer.h:517
void disposeAndClear(const css::lang::EventObject &rEvt)
Call disposing on all object in the container that support XEventListener.
OMultiTypeInterfaceContainerHelper(::osl::Mutex &rMutex)
Create a container of interface containers.
void clear()
Remove all elements of all containers.
~OMultiTypeInterfaceContainerHelper()
Delete all containers.
css::uno::Sequence< css::uno::Type > getContainedTypes() const
Return all id's under which at least one interface is added.
sal_Int32 removeInterface(const css::uno::Type &rKey, const css::uno::Reference< css::uno::XInterface > &rxIFace)
Removes an element from the container with the specified key.
OInterfaceContainerHelper * getContainer(const css::uno::Type &rKey) const
Return the container created under this key.
sal_Int32 addInterface(const css::uno::Type &rKey, const css::uno::Reference< css::uno::XInterface > &r)
Inserts an element into the container with the specified key.
css::uno::Type keyType
Definition interfacecontainer.h:600