19#ifndef INCLUDED_CPPUHELPER_INTERFACECONTAINER_H
20#define INCLUDED_CPPUHELPER_INTERFACECONTAINER_H
33#include "com/sun/star/lang/EventObject.hpp"
35#include "com/sun/star/lang/DisposedException.hpp"
38namespace com {
namespace sun {
namespace star {
namespace uno {
class XInterface; } } } }
52 std::vector< css::uno::Reference< css::uno::XInterface > > *
pAsVector;
60class OInterfaceContainerHelper;
93 {
return nRemain != 0; }
98 css::uno::XInterface * SAL_CALL
next();
132 static void * SAL_CALL
operator new(
size_t nSize )
134 static void SAL_CALL
operator delete(
void * pMem )
136 static void * SAL_CALL
operator new( size_t,
void * pMem )
138 static void SAL_CALL
operator delete(
void *,
void * )
163 css::uno::Sequence< css::uno::Reference< css::uno::XInterface > > SAL_CALL
getElements()
const;
181 sal_Int32 SAL_CALL
addInterface(
const css::uno::Reference< css::uno::XInterface > & rxIFace );
189 sal_Int32 SAL_CALL
removeInterface(
const css::uno::Reference< css::uno::XInterface > & rxIFace );
211 template <
typename ListenerT,
typename FuncT>
212 inline void forEach( FuncT
const& func );
235 template<
typename ListenerT,
typename EventT >
236 inline void notifyEach(
void ( SAL_CALL ListenerT::*NotificationMethod )(
const EventT& ),
const EventT& Event );
260 void copyAndResetInUse();
263 template<
typename ListenerT,
typename EventT >
264 class NotifySingleListener
267 typedef void ( SAL_CALL ListenerT::*NotificationMethod )(
const EventT& );
268 NotificationMethod m_pMethod;
269 const EventT& m_rEvent;
271 NotifySingleListener( NotificationMethod method,
const EventT& event ) : m_pMethod( method ), m_rEvent( event ) { }
273 void operator()(
const css::uno::Reference<ListenerT>& listener )
const
275 (listener.get()->*m_pMethod)( m_rEvent );
280template <
typename ListenerT,
typename FuncT>
286 if (xListener.is()) {
290 catch (css::lang::DisposedException
const& exc) {
291 if (exc.Context == xListener)
298template<
typename ListenerT,
typename EventT >
301 forEach< ListenerT, NotifySingleListener< ListenerT, EventT > >( NotifySingleListener< ListenerT, EventT >( NotificationMethod, Event ) );
311template<
class key,
class hashImpl =
void,
class equalImpl = std::equal_to<key> >
316 static void * SAL_CALL
operator new(
size_t nSize )
318 static void SAL_CALL
operator delete(
void * pMem )
320 static void * SAL_CALL
operator new( size_t,
void * pMem )
322 static void SAL_CALL
operator delete(
void *,
void * )
371 const css::uno::Reference< css::uno::XInterface > & r );
385 const css::uno::Reference< css::uno::XInterface > & rxIFace );
392 inline void SAL_CALL
disposeAndClear(
const css::lang::EventObject & rEvt );
396 inline void SAL_CALL
clear();
400 typedef ::std::vector< std::pair < key , void* > > InterfaceMap;
401 InterfaceMap *m_pMap;
404 typename InterfaceMap::iterator find(
const key &rKey)
const
406 typename InterfaceMap::iterator iter = m_pMap->begin();
407 typename InterfaceMap::iterator end = m_pMap->end();
412 if( equal( iter->first, rKey ) )
435template <
class container ,
class keyType >
455 , bInDispose( false )
463 const css::uno::Reference < css::uno::XInterface > &r )
466 OSL_ENSURE( !bInDispose,
"do not add listeners in the dispose call" );
467 OSL_ENSURE( !bDisposed,
"object is disposed" );
468 if( ! bInDispose && ! bDisposed )
469 aLC.addInterface( key , r );
477 const css::uno::Reference < css::uno::XInterface > & r )
480 if( ! bInDispose && ! bDisposed )
481 aLC.removeInterface( key , r );
491 {
return aLC.getContainer( key ); }
505 {
return static_cast<size_t>(s.getTypeName().hashCode()); }
516 static void * SAL_CALL
operator new(
size_t nSize )
518 static void SAL_CALL
operator delete(
void * pMem )
520 static void * SAL_CALL
operator new( size_t,
void * pMem )
522 static void SAL_CALL
operator delete(
void *,
void * )
569 const css::uno::Type & rKey,
570 const css::uno::Reference< css::uno::XInterface > & r );
583 const css::uno::Type & rKey,
584 const css::uno::Reference< css::uno::XInterface > & rxIFace );
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition: types.h:374
unsigned char sal_Bool
Definition: types.h:34
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:558
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
SAL_DLLPUBLIC void * rtl_allocateMemory(sal_Size Bytes) SAL_THROW_EXTERN_C()
Allocate memory.
Provides simple diagnostic support.
#define CPPUHELPER_DLLPUBLIC
Definition: cppuhelperdllapi.h:28
#define OSL_ENSURE(c, m)
If cond is false, reports an error with message msg.
Definition: diagnose.h:84
Definition: Enterable.hxx:27
OBroadcastHelperVar< OMultiTypeInterfaceContainerHelper, OMultiTypeInterfaceContainerHelper::keyType > OBroadcastHelper
Definition: interfacecontainer.h:605
Definition: unotype.hxx:35
@ UNO_QUERY
This enum value can be used for implicit interface query.
Definition: Reference.h:153
This is here to optimise space in the common case that there are zero or one listeners.
Definition: interfacecontainer.h:51
std::vector< css::uno::Reference< css::uno::XInterface > > * pAsVector
Definition: interfacecontainer.h:52
css::uno::XInterface * pAsInterface
Definition: interfacecontainer.h:53
element_alias()
Definition: interfacecontainer.h:54
This is the iterator of an InterfaceContainerHelper.
Definition: interfacecontainer.h:69
~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:92
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:129
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:299
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:281
~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:313
~OMultiTypeInterfaceContainerHelperVar()
Deletes all containers.
Definition: interfacecontainer.hxx:41
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:102
OInterfaceContainerHelper * getContainer(const key &) const
Return the container created under this key.
Definition: interfacecontainer.hxx:89
void clear()
Remove all elements of all containers.
Definition: interfacecontainer.hxx:175
void disposeAndClear(const css::lang::EventObject &rEvt)
Call disposing on all references in the container, that support XEventListener.
Definition: interfacecontainer.hxx:138
key keyType
Definition: interfacecontainer.h:398
OMultiTypeInterfaceContainerHelperVar(::osl::Mutex &rMutex)
Create a container of interface containers.
Definition: interfacecontainer.hxx:33
css::uno::Sequence< key > getContainedTypes() const
Return all id's under which at least one interface is added.
Definition: interfacecontainer.hxx:57
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:120
This struct contains the standard variables of a broadcaster.
Definition: interfacecontainer.h:437
OInterfaceContainerHelper * getContainer(const keyType &key) const
Return the container created under this key.
Definition: interfacecontainer.h:490
void addListener(const keyType &key, const css::uno::Reference< css::uno::XInterface > &r)
adds a listener threadsafe.
Definition: interfacecontainer.h:461
container aLC
ListenerContainer class is thread safe.
Definition: interfacecontainer.h:441
::osl::Mutex & rMutex
The shared mutex.
Definition: interfacecontainer.h:439
sal_Bool bInDispose
In dispose call.
Definition: interfacecontainer.h:445
void removeListener(const keyType &key, const css::uno::Reference< css::uno::XInterface > &r)
removes a listener threadsafe
Definition: interfacecontainer.h:475
sal_Bool bDisposed
Dispose call ready.
Definition: interfacecontainer.h:443
OBroadcastHelperVar(::osl::Mutex &rMutex_)
Initialize the structure.
Definition: interfacecontainer.h:451
Definition: interfacecontainer.h:503
size_t operator()(const css::uno::Type &s) const
Definition: interfacecontainer.h:504
Specialized class for key type css::uno::Type, without explicit usage of STL symbols.
Definition: interfacecontainer.h:513
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:596
A mutual exclusion synchronization object.
Definition: mutex.hxx:31
Object lifetime scoped mutex object or interface lock.
Definition: mutex.hxx:115