LibreOffice LibreOffice 25.8 SDK C/C++ API Reference

Loading...
Searching...
No Matches
cppu::OInterfaceContainerHelper Class Reference

A container of interfaces. More...

`#include <interfacecontainer.h>`

## Public Member Functions
| OInterfaceContainerHelper (::osl::Mutex &rMutex)
| Create an interface container.
| ~OInterfaceContainerHelper ()
| Release all interfaces.
sal_Int32 | getLength () const
| Return the number of Elements in the container.
css::uno::Sequence< css::uno::Reference< css::uno::XInterface > > | getElements () const
| Return all interfaces added to this container.
sal_Int32 | addInterface (const css::uno::Reference< css::uno::XInterface > &rxIFace)
| Inserts an element into the container.
sal_Int32 | removeInterface (const css::uno::Reference< css::uno::XInterface > &rxIFace)
| Removes an element from the container.
void | disposeAndClear (const css::lang::EventObject &rEvt)
| Call disposing on all object in the container that support XEventListener.
void | clear ()
| Clears the container without calling disposing().
template<typename ListenerT, typename FuncT>
void | forEach (FuncT const &func)
| Executes a functor for each contained listener of specified type, e.g.
template<typename ListenerT, typename EventT>
void | notifyEach (void(ListenerT::*NotificationMethod)(const EventT &), const EventT &Event)
| Calls a UNO listener method for each contained listener.

## Static Public Member Functions
static void * | operator new (size_t nSize)
static void | operator delete (void *pMem)
static void * | operator new (size_t, void *pMem)
static void | operator delete (void *, void *)

## Friends
class | OInterfaceIteratorHelper

## Detailed Description

A container of interfaces.

To access the elements use an iterator. This implementation is thread save.

See also
  OInterfaceIteratorHelper

## Constructor & Destructor Documentation

## ◆ OInterfaceContainerHelper()

cppu::OInterfaceContainerHelper::OInterfaceContainerHelper | ( | ::osl::Mutex & | rMutex | ) |

Create an interface container.

Parameters

  rMutex | the mutex to protect multi thread access. The lifetime must be longer than the lifetime of this object.

## ◆ ~OInterfaceContainerHelper()

cppu::OInterfaceContainerHelper::~OInterfaceContainerHelper | ( |  | ) |

Release all interfaces.

All iterators must be destroyed before the container is destructed.

## Member Function Documentation

## ◆ addInterface()

sal_Int32 cppu::OInterfaceContainerHelper::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.

Attention
  If you add the same interface more than once, then it will be added to the elements list more than once and thus if you want to remove that interface from the list, you have to call removeInterface() the same number of times. In the latter case, you will also get events fired more than once (if the interface is a listener interface).

Parameters

  rxIFace | interface to be added; it is allowed to insert null or the same interface more than once

Returns
  the new count of elements in the container

## ◆ clear()

void cppu::OInterfaceContainerHelper::clear | ( |  | ) |

Clears the container without calling disposing().

## ◆ disposeAndClear()

void cppu::OInterfaceContainerHelper::disposeAndClear | ( | const css::lang::EventObject & | rEvt | ) |

Call disposing on all object in the container that support XEventListener.

Then clear the container.

## ◆ forEach()

template<typename ListenerT, typename FuncT>

void cppu::OInterfaceContainerHelper::forEach | ( | FuncT const & | func | ) |
| 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.

Template Parameters

  ListenerT | listener type
  FuncT | unary functor type, let your compiler deduce this for you

Parameters

  func | unary functor object expecting an argument of type css::uno::Reference<ListenerT>

## ◆ getElements()

css::uno::Sequence< css::uno::Reference< css::uno::XInterface > > cppu::OInterfaceContainerHelper::getElements | ( |  | ) | const

Return all interfaces added to this container.

## ◆ getLength()

sal_Int32 cppu::OInterfaceContainerHelper::getLength | ( |  | ) | const

Return the number of Elements in the container.

Only useful if you have acquired the mutex.

## ◆ notifyEach()

template<typename ListenerT, typename EventT>

void cppu::OInterfaceContainerHelper::notifyEach | ( | void(ListenerT::* | NotificationMethod )(const EventT &),
|  | const EventT & | Event )
| 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.

Template Parameters

  ListenerT | UNO event listener type, let your compiler deduce this for you
  EventT | event type, let your compiler deduce this for you

Parameters

  NotificationMethod | Pointer to a method of a ListenerT interface.
  Event | Event to notify to all contained listeners

Example:

awt::PaintEvent aEvent( static_cast< cppu::OWeakObject* >( this ), ... );
listeners.notifyEach( &XPaintListener::windowPaint, aEvent );
cppu::OWeakObject
Base class to implement a UNO object supporting weak references, i.e.
Definition weak.hxx:48

## ◆ operator delete() [1/2]

void cppu::OInterfaceContainerHelper::operator delete | ( | void * | ,
|  | void * | )
| inline static

## ◆ operator delete() [2/2]

void cppu::OInterfaceContainerHelper::operator delete | ( | void * | pMem | ) |
| inline static

## ◆ operator new() [1/2]

void * cppu::OInterfaceContainerHelper::operator new | ( | size_t | nSize | ) |
| inline static

## ◆ operator new() [2/2]

void * cppu::OInterfaceContainerHelper::operator new | ( | size_t | ,
|  | void * | pMem )
| inline static

## ◆ removeInterface()

sal_Int32 cppu::OInterfaceContainerHelper::removeInterface | ( | const css::uno::Reference< css::uno::XInterface > & | rxIFace | ) |

Removes an element from the container.

It uses interface equality to remove the interface.

Parameters

  rxIFace | interface to be removed

Returns
  the new count of elements in the container

## Friends And Related Symbol Documentation

## ◆ OInterfaceIteratorHelper

friend class OInterfaceIteratorHelper
| friend

The documentation for this class was generated from the following file:

- cppuhelper/interfacecontainer.h