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"
42 namespace com {
namespace sun {
namespace star {
namespace uno {
class XInterface; } } } }
55 std::vector< css::uno::Reference< css::uno::XInterface > > *
pAsVector;
63 class OInterfaceContainerHelper;
96 {
return nRemain != 0; }
101 css::uno::XInterface * SAL_CALL next();
108 void SAL_CALL
remove();
121 SAL_DELETED_FUNCTION;
135 static void * SAL_CALL
operator new(
size_t nSize )
137 static void SAL_CALL
operator delete(
void * pMem )
139 static void * SAL_CALL
operator new( size_t,
void * pMem )
141 static void SAL_CALL
operator delete(
void *,
void * )
151 OInterfaceContainerHelper( ::
osl::Mutex & rMutex );
156 ~OInterfaceContainerHelper();
161 sal_Int32 SAL_CALL getLength()
const;
166 css::uno::Sequence< css::uno::Reference< css::uno::XInterface > > SAL_CALL getElements()
const;
184 sal_Int32 SAL_CALL addInterface(
const css::uno::Reference< css::uno::XInterface > & rxIFace );
192 sal_Int32 SAL_CALL removeInterface(
const css::uno::Reference< css::uno::XInterface > & rxIFace );
197 void SAL_CALL disposeAndClear(
const css::lang::EventObject & rEvt );
201 void SAL_CALL clear();
214 template <
typename ListenerT,
typename FuncT>
215 inline void forEach( FuncT
const& func );
238 template<
typename ListenerT,
typename EventT >
239 inline void notifyEach(
void ( SAL_CALL ListenerT::*NotificationMethod )(
const EventT& ),
const EventT& Event );
254 OInterfaceContainerHelper(
const OInterfaceContainerHelper & )
255 SAL_DELETED_FUNCTION;
256 OInterfaceContainerHelper & operator = ( const OInterfaceContainerHelper & )
257 SAL_DELETED_FUNCTION;
263 void copyAndResetInUse();
266 template< typename ListenerT, typename EventT >
267 class NotifySingleListener
270 typedef void ( SAL_CALL ListenerT::*NotificationMethod )(
const EventT& );
271 NotificationMethod m_pMethod;
272 const EventT& m_rEvent;
274 NotifySingleListener( NotificationMethod method,
const EventT& event ) : m_pMethod( method ), m_rEvent( event ) { }
276 void operator()(
const css::uno::Reference<ListenerT>& listener )
const
278 (listener.get()->*m_pMethod)( m_rEvent );
283 template <
typename ListenerT,
typename FuncT>
289 if (xListener.is()) {
293 catch (css::lang::DisposedException
const& exc) {
294 if (exc.Context == xListener)
301 template<
typename ListenerT,
typename EventT >
304 forEach< ListenerT, NotifySingleListener< ListenerT, EventT > >( NotifySingleListener< ListenerT, EventT >( NotificationMethod, Event ) );
314 template<
class key,
class hashImpl =
void,
class equalImpl = std::equal_to<key> >
319 static void * SAL_CALL
operator new(
size_t nSize )
321 static void SAL_CALL
operator delete(
void * pMem )
323 static void * SAL_CALL
operator new( size_t,
void * pMem )
325 static void SAL_CALL
operator delete(
void *,
void * )
344 inline css::uno::Sequence< key > SAL_CALL getContainedTypes()
const;
352 inline OInterfaceContainerHelper * SAL_CALL getContainer(
const key & )
const;
372 inline sal_Int32 SAL_CALL addInterface(
374 const css::uno::Reference< css::uno::XInterface > & r );
386 inline sal_Int32 SAL_CALL removeInterface(
388 const css::uno::Reference< css::uno::XInterface > & rxIFace );
395 inline void SAL_CALL disposeAndClear(
const css::lang::EventObject & rEvt );
399 inline void SAL_CALL clear();
403 typedef ::std::vector< std::pair < key , void* > > InterfaceMap;
404 InterfaceMap *m_pMap;
407 typename InterfaceMap::iterator find(
const key &rKey)
const
409 typename InterfaceMap::iterator iter = m_pMap->begin();
410 typename InterfaceMap::iterator end = m_pMap->end();
415 if( equal( iter->first, rKey ) )
438 template < class container , class keyType >
458 , bInDispose( false )
466 const css::uno::Reference < css::uno::XInterface > &r )
469 OSL_ENSURE( !bInDispose,
"do not add listeners in the dispose call" );
470 OSL_ENSURE( !bDisposed,
"object is disposed" );
471 if( ! bInDispose && ! bDisposed )
472 aLC.addInterface( key , r );
480 const css::uno::Reference < css::uno::XInterface > & r )
483 if( ! bInDispose && ! bDisposed )
484 aLC.removeInterface( key , r );
493 OInterfaceContainerHelper * SAL_CALL
getContainer(
const keyType &key )
const
494 {
return aLC.getContainer( key ); }
508 {
return static_cast<size_t>(s.getTypeName().hashCode()); }
519 static void * SAL_CALL
operator new(
size_t nSize )
521 static void SAL_CALL
operator delete(
void * pMem )
523 static void * SAL_CALL
operator new( size_t,
void * pMem )
525 static void SAL_CALL
operator delete(
void *,
void * )
544 css::uno::Sequence< css::uno::Type > SAL_CALL getContainedTypes()
const;
551 OInterfaceContainerHelper * SAL_CALL getContainer(
const css::uno::Type & rKey )
const;
571 sal_Int32 SAL_CALL addInterface(
572 const css::uno::Type & rKey,
573 const css::uno::Reference< css::uno::XInterface > & r );
585 sal_Int32 SAL_CALL removeInterface(
586 const css::uno::Type & rKey,
587 const css::uno::Reference< css::uno::XInterface > & rxIFace );
593 void SAL_CALL disposeAndClear(
const css::lang::EventObject & rEvt );
597 void SAL_CALL clear();
OBroadcastHelperVar(::osl::Mutex &rMutex_)
Initialize the structure.
Definition: interfacecontainer.h:454
sal_Bool bDisposed
Dispose call ready.
Definition: interfacecontainer.h:446
A mutual exclusion synchronization object.
Definition: mutex.hxx:35
This enum value can be used for implicit interface query.
Definition: Reference.h:157
css::uno::Type keyType
Definition: interfacecontainer.h:599
This struct contains the standard variables of a broadcaster.
Definition: interfacecontainer.h:439
sal_Bool bInDispose
In dispose call.
Definition: interfacecontainer.h:448
OInterfaceContainerHelper * getContainer(const keyType &key) const
Return the container created under this key.
Definition: interfacecontainer.h:493
::osl::Mutex & rMutex
The shared mutex.
Definition: interfacecontainer.h:442
element_alias()
Definition: interfacecontainer.h:57
std::vector< css::uno::Reference< css::uno::XInterface > > * pAsVector
Definition: interfacecontainer.h:55
Object lifetime scoped mutex object or interface lock.
Definition: mutex.hxx:123
key keyType
Definition: interfacecontainer.h:401
A helper class to store interface references of different types.
Definition: interfacecontainer.h:315
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition: types.h:396
#define CPPUHELPER_DLLPUBLIC
Definition: cppuhelperdllapi.h:32
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
css::uno::XInterface * pAsInterface
Definition: interfacecontainer.h:56
Definition: interfacecontainer.h:505
#define OSL_ENSURE(c, m)
If cond is false, reports an error with message msg.
Definition: diagnose.h:87
void forEach(FuncT const &func)
Executes a functor for each contained listener of specified type, e.g.
Definition: interfacecontainer.h:284
void removeListener(const keyType &key, const css::uno::Reference< css::uno::XInterface > &r)
removes a listener threadsafe
Definition: interfacecontainer.h:478
Provides simple diagnostic support.
This is the iterator of an InterfaceContainerHelper.
Definition: interfacecontainer.h:71
void addListener(const keyType &key, const css::uno::Reference< css::uno::XInterface > &r)
adds a listener threadsafe.
Definition: interfacecontainer.h:464
css::uno::XInterface * next()
Return the next element of the iterator.
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:611
size_t operator()(const css::uno::Type &s) const
Definition: interfacecontainer.h:507
unsigned char sal_Bool
Definition: types.h:38
SAL_DLLPUBLIC void * rtl_allocateMemory(sal_Size Bytes) SAL_THROW_EXTERN_C()
Allocate memory.
Specialized class for key type css::uno::Type, without explicit usage of STL symbols.
Definition: interfacecontainer.h:515
void remove()
Removes the current element (the last one returned by next()) from the underlying container...
A container of interfaces.
Definition: interfacecontainer.h:131
bool hasMoreElements() const
Return true, if there are more elements in the iterator.
Definition: interfacecontainer.h:95
This is here to optimise space in the common case that there are zero or one listeners.
Definition: interfacecontainer.h:53
void notifyEach(void(ListenerT::*NotificationMethod)(const EventT &), const EventT &Event)
Calls a UNO listener method for each contained listener.
Definition: interfacecontainer.h:302
container aLC
ListenerContainer class is thread safe.
Definition: interfacecontainer.h:444