3 #ifndef INCLUDED_CPPUHELPER_INTERFACECONTAINER_H
4 #define INCLUDED_CPPUHELPER_INTERFACECONTAINER_H
17 #include "com/sun/star/lang/EventObject.hpp"
19 #include "com/sun/star/lang/DisposedException.hpp"
22 namespace com {
namespace sun {
namespace star {
namespace uno {
class XInterface; } } } }
35 std::vector< css::uno::Reference< css::uno::XInterface > > *
pAsVector;
43 class OInterfaceContainerHelper;
76 {
return nRemain != 0; }
81 css::uno::XInterface * SAL_CALL
next();
115 static void * SAL_CALL
operator new(
size_t nSize )
117 static void SAL_CALL
operator delete(
void * pMem )
119 static void * SAL_CALL
operator new( size_t,
void * pMem )
121 static void SAL_CALL
operator delete(
void *,
void * )
146 css::uno::Sequence< css::uno::Reference< css::uno::XInterface > > SAL_CALL
getElements()
const;
164 sal_Int32 SAL_CALL
addInterface(
const css::uno::Reference< css::uno::XInterface > & rxIFace );
172 sal_Int32 SAL_CALL
removeInterface(
const css::uno::Reference< css::uno::XInterface > & rxIFace );
194 template <
typename ListenerT,
typename FuncT>
195 inline void forEach( FuncT
const& func );
218 template<
typename ListenerT,
typename EventT >
219 inline void notifyEach(
void ( SAL_CALL ListenerT::*NotificationMethod )(
const EventT& ),
const EventT& Event );
243 void copyAndResetInUse();
246 template<
typename ListenerT,
typename EventT >
247 class NotifySingleListener
250 typedef void ( SAL_CALL ListenerT::*NotificationMethod )(
const EventT& );
251 NotificationMethod m_pMethod;
252 const EventT& m_rEvent;
254 NotifySingleListener( NotificationMethod method,
const EventT& event ) : m_pMethod( method ), m_rEvent( event ) { }
256 void operator()(
const css::uno::Reference<ListenerT>& listener )
const
258 (listener.get()->*m_pMethod)( m_rEvent );
263 template <
typename ListenerT,
typename FuncT>
269 if (xListener.is()) {
273 catch (css::lang::DisposedException
const& exc) {
274 if (exc.Context == xListener)
281 template<
typename ListenerT,
typename EventT >
284 forEach< ListenerT, NotifySingleListener< ListenerT, EventT > >( NotifySingleListener< ListenerT, EventT >( NotificationMethod, Event ) );
294 template<
class key,
class hashImpl =
void,
class equalImpl = std::equal_to<key> >
299 static void * SAL_CALL
operator new(
size_t nSize )
301 static void SAL_CALL
operator delete(
void * pMem )
303 static void * SAL_CALL
operator new( size_t,
void * pMem )
305 static void SAL_CALL
operator delete(
void *,
void * )
354 const css::uno::Reference< css::uno::XInterface > & r );
368 const css::uno::Reference< css::uno::XInterface > & rxIFace );
375 inline void SAL_CALL
disposeAndClear(
const css::lang::EventObject & rEvt );
379 inline void SAL_CALL
clear();
383 typedef ::std::vector< std::pair < key , void* > > InterfaceMap;
384 InterfaceMap *m_pMap;
387 typename InterfaceMap::iterator find(
const key &rKey)
const
389 typename InterfaceMap::iterator iter = m_pMap->begin();
390 typename InterfaceMap::iterator end = m_pMap->end();
395 if( equal( iter->first, rKey ) )
418 template <
class container ,
class keyType >
438 , bInDispose( false )
446 const css::uno::Reference < css::uno::XInterface > &r )
449 OSL_ENSURE( !bInDispose,
"do not add listeners in the dispose call" );
450 OSL_ENSURE( !bDisposed,
"object is disposed" );
451 if( ! bInDispose && ! bDisposed )
452 aLC.addInterface( key , r );
460 const css::uno::Reference < css::uno::XInterface > & r )
463 if( ! bInDispose && ! bDisposed )
464 aLC.removeInterface( key , r );
474 {
return aLC.getContainer( key ); }
488 {
return static_cast<size_t>(s.getTypeName().hashCode()); }
499 static void * SAL_CALL
operator new(
size_t nSize )
501 static void SAL_CALL
operator delete(
void * pMem )
503 static void * SAL_CALL
operator new( size_t,
void * pMem )
505 static void SAL_CALL
operator delete(
void *,
void * )
552 const css::uno::Type & rKey,
553 const css::uno::Reference< css::uno::XInterface > & r );
566 const css::uno::Type & rKey,
567 const css::uno::Reference< css::uno::XInterface > & rxIFace );
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition: types.h:358
unsigned char sal_Bool
Definition: types.h:18
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:567
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:12
#define OSL_ENSURE(c, m)
If cond is false, reports an error with message msg.
Definition: diagnose.h:67
@ UNO_QUERY
This enum value can be used for implicit interface query.
Definition: Reference.h:137
Definition: Enterable.hxx:11
OBroadcastHelperVar< OMultiTypeInterfaceContainerHelper, OMultiTypeInterfaceContainerHelper::keyType > OBroadcastHelper
Definition: interfacecontainer.h:588
A mutual exclusion synchronization object.
Definition: mutex.hxx:15
Object lifetime scoped mutex object or interface lock.
Definition: mutex.hxx:104
This is here to optimise space in the common case that there are zero or one listeners.
Definition: interfacecontainer.h:34
std::vector< css::uno::Reference< css::uno::XInterface > > * pAsVector
Definition: interfacecontainer.h:35
css::uno::XInterface * pAsInterface
Definition: interfacecontainer.h:36
element_alias()
Definition: interfacecontainer.h:37
This is the iterator of an InterfaceContainerHelper.
Definition: interfacecontainer.h:52
~OInterfaceIteratorHelper()
Releases the connection to the container.
void remove()
Removes the current element (the last one returned by next()) from the underlying container.
css::uno::XInterface * next()
Return the next element of the iterator.
bool hasMoreElements() const
Return true, if there are more elements in the iterator.
Definition: interfacecontainer.h:75
OInterfaceIteratorHelper(OInterfaceContainerHelper &rCont)
Create an iterator over the elements of the container.
A container of interfaces.
Definition: interfacecontainer.h:112
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:282
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:264
~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:296
~OMultiTypeInterfaceContainerHelperVar()
Deletes all containers.
Definition: interfacecontainer.hxx:25
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:86
OInterfaceContainerHelper * getContainer(const key &) const
Return the container created under this key.
Definition: interfacecontainer.hxx:73
void clear()
Remove all elements of all containers.
Definition: interfacecontainer.hxx:159
void disposeAndClear(const css::lang::EventObject &rEvt)
Call disposing on all references in the container, that support XEventListener.
Definition: interfacecontainer.hxx:122
key keyType
Definition: interfacecontainer.h:381
OMultiTypeInterfaceContainerHelperVar(::osl::Mutex &rMutex)
Create a container of interface containers.
Definition: interfacecontainer.hxx:17
css::uno::Sequence< key > getContainedTypes() const
Return all id's under which at least one interface is added.
Definition: interfacecontainer.hxx:41
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:104
This struct contains the standard variables of a broadcaster.
Definition: interfacecontainer.h:420
void addListener(const keyType &key, const css::uno::Reference< css::uno::XInterface > &r)
adds a listener threadsafe.
Definition: interfacecontainer.h:444
container aLC
ListenerContainer class is thread safe.
Definition: interfacecontainer.h:424
::osl::Mutex & rMutex
The shared mutex.
Definition: interfacecontainer.h:422
sal_Bool bInDispose
In dispose call.
Definition: interfacecontainer.h:428
OInterfaceContainerHelper * getContainer(const keyType &key) const
Return the container created under this key.
Definition: interfacecontainer.h:473
void removeListener(const keyType &key, const css::uno::Reference< css::uno::XInterface > &r)
removes a listener threadsafe
Definition: interfacecontainer.h:458
sal_Bool bDisposed
Dispose call ready.
Definition: interfacecontainer.h:426
OBroadcastHelperVar(::osl::Mutex &rMutex_)
Initialize the structure.
Definition: interfacecontainer.h:434
Definition: interfacecontainer.h:486
size_t operator()(const css::uno::Type &s) const
Definition: interfacecontainer.h:487
Specialized class for key type css::uno::Type, without explicit usage of STL symbols.
Definition: interfacecontainer.h:496
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.
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:579
OInterfaceContainerHelper * getContainer(const css::uno::Type &rKey) const
Return the container created under this key.