LibreOffice Module comphelper (master) 1
|
A container of interfaces. More...
#include <interfacecontainer2.hxx>
Classes | |
class | NotifySingleListener |
Public Member Functions | |
OInterfaceContainerHelper2 (::osl::Mutex &rMutex) | |
Create an interface container. More... | |
~OInterfaceContainerHelper2 () | |
Release all interfaces. More... | |
sal_Int32 | getLength () const |
Return the number of Elements in the container. More... | |
std::vector< css::uno::Reference< css::uno::XInterface > > | getElements () const |
Return all interfaces added to this container. More... | |
sal_Int32 | addInterface (const css::uno::Reference< css::uno::XInterface > &rxIFace) |
Inserts an element into the container. More... | |
sal_Int32 | removeInterface (const css::uno::Reference< css::uno::XInterface > &rxIFace) |
Removes an element from the container. More... | |
css::uno::Reference< css::uno::XInterface > | getInterface (sal_Int32 nIndex) const |
Return an interface by index. More... | |
void | disposeAndClear (const css::lang::EventObject &rEvt) |
Call disposing on all object in the container that support XEventListener. More... | |
void | clear () |
Clears the container without calling disposing(). More... | |
template<typename ListenerT , typename FuncT > | |
void | forEach (FuncT const &func) |
Executes a functor for each contained listener of specified type, e.g. More... | |
template<typename ListenerT , typename EventT > | |
void | notifyEach (void(SAL_CALL ListenerT::*NotificationMethod)(const EventT &), const EventT &Event) |
Calls a UNO listener method for each contained listener. More... | |
Private Member Functions | |
OInterfaceContainerHelper2 (const OInterfaceContainerHelper2 &)=delete | |
OInterfaceContainerHelper2 & | operator= (const OInterfaceContainerHelper2 &)=delete |
void | copyAndResetInUse () |
Private Attributes | |
detail::element_alias2 | aData |
bIsList == TRUE -> aData.pAsVector of type vector< XInterfaceSequence >, otherwise aData.pAsInterface == of type (XEventListener *) More... | |
::osl::Mutex & | rMutex |
bool | bInUse |
TRUE -> used by an iterator. More... | |
bool | bIsList |
TRUE -> aData.pAsVector is of type Sequence< XInterfaceSequence >. More... | |
Friends | |
class | OInterfaceIteratorHelper2 |
A container of interfaces.
To access the elements use an iterator. This implementation is thread-safe.
This is a copy of the code at include/cppuhelper/interfacecontainer.h, Except that it uses a std::vector instead of a Sequence for the mutable listener list, which provides far better performance.
Definition at line 121 of file interfacecontainer2.hxx.
comphelper::OInterfaceContainerHelper2::OInterfaceContainerHelper2 | ( | ::osl::Mutex & | rMutex | ) |
Create an interface container.
rMutex | the mutex to protect multi thread access. The lifetime must be longer than the lifetime of this object. |
References getLength().
comphelper::OInterfaceContainerHelper2::~OInterfaceContainerHelper2 | ( | ) |
Release all interfaces.
All iterators must be destroyed before the container is destructed.
Definition at line 124 of file interfacecontainer2.cxx.
References aData, bInUse, bIsList, comphelper::detail::element_alias2::pAsInterface, and comphelper::detail::element_alias2::pAsVector.
|
privatedelete |
sal_Int32 comphelper::OInterfaceContainerHelper2::addInterface | ( | const css::uno::Reference< css::uno::XInterface > & | rxIFace | ) |
Inserts an element into the container.
The position is not specified, thus it is not specified in which order events are fired.
rxIFace | interface to be added; it is allowed to insert null or the same interface more than once |
Definition at line 172 of file interfacecontainer2.cxx.
References aData, bInUse, bIsList, copyAndResetInUse(), comphelper::detail::element_alias2::pAsInterface, comphelper::detail::element_alias2::pAsVector, and rMutex.
Referenced by comphelper::OMultiTypeInterfaceContainerHelper2::addInterface().
void comphelper::OInterfaceContainerHelper2::clear | ( | ) |
Clears the container without calling disposing().
Definition at line 288 of file interfacecontainer2.cxx.
References aData, bInUse, bIsList, copyAndResetInUse(), comphelper::detail::element_alias2::pAsInterface, comphelper::detail::element_alias2::pAsVector, and rMutex.
|
private |
Definition at line 156 of file interfacecontainer2.cxx.
References aData, bInUse, bIsList, comphelper::detail::element_alias2::pAsInterface, and comphelper::detail::element_alias2::pAsVector.
Referenced by addInterface(), clear(), comphelper::OInterfaceIteratorHelper2::OInterfaceIteratorHelper2(), and removeInterface().
void comphelper::OInterfaceContainerHelper2::disposeAndClear | ( | const css::lang::EventObject & | rEvt | ) |
Call disposing on all object in the container that support XEventListener.
Then clear the container.
Definition at line 258 of file interfacecontainer2.cxx.
References aData, bInUse, bIsList, comphelper::OInterfaceIteratorHelper2::hasMoreElements(), comphelper::OInterfaceIteratorHelper2::next(), comphelper::detail::element_alias2::pAsInterface, and rMutex.
|
inline |
Executes a functor for each contained listener of specified type, e.g.
forEach<awt::XPaintListener>(...
.
If a css::lang::DisposedException occurs which relates to the called listener, then that listener is removed from the container.
ListenerT | listener type |
FuncT | unary functor type, let your compiler deduce this for you |
func | unary functor object expecting an argument of type css::uno::Reference<ListenerT> |
Definition at line 264 of file interfacecontainer2.hxx.
References comphelper::OInterfaceIteratorHelper2::hasMoreElements(), comphelper::OInterfaceIteratorHelper2::next(), and comphelper::OInterfaceIteratorHelper2::remove().
std::vector< Reference< XInterface > > comphelper::OInterfaceContainerHelper2::getElements | ( | ) | const |
Return all interfaces added to this container.
Definition at line 143 of file interfacecontainer2.cxx.
References aData, bIsList, comphelper::detail::element_alias2::pAsInterface, comphelper::detail::element_alias2::pAsVector, and rMutex.
Reference< XInterface > comphelper::OInterfaceContainerHelper2::getInterface | ( | sal_Int32 | nIndex | ) | const |
Return an interface by index.
Definition at line 244 of file interfacecontainer2.cxx.
References aData, bIsList, nIndex, comphelper::detail::element_alias2::pAsInterface, comphelper::detail::element_alias2::pAsVector, and rMutex.
sal_Int32 comphelper::OInterfaceContainerHelper2::getLength | ( | ) | const |
Return the number of Elements in the container.
Only useful if you have acquired the mutex.
Definition at line 133 of file interfacecontainer2.cxx.
References aData, bIsList, comphelper::detail::element_alias2::pAsInterface, comphelper::detail::element_alias2::pAsVector, and rMutex.
|
inline |
Calls a UNO listener method for each contained listener.
The listener method must take a single argument of type EventT, and return void
.
If a css::lang::DisposedException occurs which relates to the called listener, then that listener is removed from the container.
ListenerT | UNO event listener type, let your compiler deduce this for you |
EventT | event type, let your compiler deduce this for you |
NotificationMethod | Pointer to a method of a ListenerT interface. |
Event | Event to notify to all contained listeners |
Example:
Definition at line 282 of file interfacecontainer2.hxx.
|
privatedelete |
sal_Int32 comphelper::OInterfaceContainerHelper2::removeInterface | ( | const css::uno::Reference< css::uno::XInterface > & | rxIFace | ) |
Removes an element from the container.
It uses interface equality to remove the interface.
rxIFace | interface to be removed |
Definition at line 203 of file interfacecontainer2.cxx.
References aData, bInUse, bIsList, copyAndResetInUse(), find(), get(), p, comphelper::detail::element_alias2::pAsInterface, comphelper::detail::element_alias2::pAsVector, and rMutex.
Referenced by comphelper::OInterfaceIteratorHelper2::remove().
|
friend |
Definition at line 224 of file interfacecontainer2.hxx.
|
private |
bIsList == TRUE -> aData.pAsVector of type vector< XInterfaceSequence >, otherwise aData.pAsInterface == of type (XEventListener *)
Definition at line 229 of file interfacecontainer2.hxx.
Referenced by addInterface(), clear(), copyAndResetInUse(), disposeAndClear(), getElements(), getInterface(), getLength(), comphelper::OInterfaceIteratorHelper2::OInterfaceIteratorHelper2(), removeInterface(), ~OInterfaceContainerHelper2(), and comphelper::OInterfaceIteratorHelper2::~OInterfaceIteratorHelper2().
|
private |
TRUE -> used by an iterator.
Definition at line 232 of file interfacecontainer2.hxx.
Referenced by addInterface(), clear(), copyAndResetInUse(), disposeAndClear(), comphelper::OInterfaceIteratorHelper2::OInterfaceIteratorHelper2(), removeInterface(), ~OInterfaceContainerHelper2(), and comphelper::OInterfaceIteratorHelper2::~OInterfaceIteratorHelper2().
|
private |
TRUE -> aData.pAsVector is of type Sequence< XInterfaceSequence >.
Definition at line 234 of file interfacecontainer2.hxx.
Referenced by addInterface(), clear(), copyAndResetInUse(), disposeAndClear(), getElements(), getInterface(), getLength(), comphelper::OInterfaceIteratorHelper2::OInterfaceIteratorHelper2(), removeInterface(), ~OInterfaceContainerHelper2(), and comphelper::OInterfaceIteratorHelper2::~OInterfaceIteratorHelper2().
|
private |
Definition at line 230 of file interfacecontainer2.hxx.
Referenced by addInterface(), clear(), disposeAndClear(), getElements(), getInterface(), getLength(), comphelper::OInterfaceIteratorHelper2::OInterfaceIteratorHelper2(), removeInterface(), and comphelper::OInterfaceIteratorHelper2::~OInterfaceIteratorHelper2().