26#include <osl/diagnose.h>
27#include <osl/mutex.hxx>
32#include <com/sun/star/lang/XEventListener.hpp>
74 OSL_ENSURE(
rCont.
bInUse,
"OInterfaceContainerHelper must be in use" );
130 OSL_ENSURE( !
bInUse,
"~OInterfaceContainerHelper but is in use" );
139 MutexGuard aGuard(
rMutex );
149 MutexGuard aGuard(
rMutex );
162 OSL_ENSURE(
bInUse,
"OInterfaceContainerHelper not in use" );
178 SAL_WARN_IF( !rListener.is(),
"cppuhelper",
"rListener is empty" );
179 MutexGuard aGuard(
rMutex );
200 rListener->acquire();
206 SAL_WARN_IF( !rListener.is(),
"cppuhelper",
"rListener is empty" );
207 MutexGuard aGuard(
rMutex );
216 { return r.get() == rListener.get(); });
226 if( *it == rListener )
255 ClearableMutexGuard aGuard(
rMutex );
258 OSL_ENSURE( !
bIsList ||
bInUse,
"OInterfaceContainerHelper not in use" );
272 xLst->disposing( rEvt );
285 MutexGuard aGuard(
rMutex );
287 OSL_ENSURE( !
bIsList ||
bInUse,
"OInterfaceContainerHelper not in use" );
308OMultiTypeInterfaceContainerHelper::~OMultiTypeInterfaceContainerHelper()
312 for (
auto& rItem : *pMap)
315 rItem.second =
nullptr;
323 t_type2ptr::size_type nSize;
325 ::osl::MutexGuard aGuard( rMutex );
326 nSize = pMap->size();
329 css::uno::Sequence< Type > aInterfaceTypes( nSize );
330 Type * pArray = aInterfaceTypes.getArray();
333 for (
const auto& rItem : *pMap)
338 pArray[
i++] = rItem.first;
340 if(
static_cast<t_type2ptr::size_type
>(
i) != nSize ) {
342 aInterfaceTypes = css::uno::Sequence< Type >( pArray,
i );
344 return aInterfaceTypes;
346 return css::uno::Sequence< Type >();
351 return std::find_if(pMap->begin(), pMap->end(),
352 [&rKey](
const t_type2ptr::value_type& rItem) { return rItem.first == rKey; });
357 ::osl::MutexGuard aGuard( rMutex );
360 t_type2ptr::iterator iter =
findType( pMap, rKey );
361 if( iter != pMap->end() )
366sal_Int32 OMultiTypeInterfaceContainerHelper::addInterface(
369 ::osl::MutexGuard aGuard( rMutex );
371 t_type2ptr::iterator iter =
findType( pMap, rKey );
372 if( iter == pMap->end() )
375 pMap->push_back(std::pair<Type, void*>(rKey, pLC));
381sal_Int32 OMultiTypeInterfaceContainerHelper::removeInterface(
384 ::osl::MutexGuard aGuard( rMutex );
388 t_type2ptr::iterator iter =
findType( pMap, rKey );
390 if( iter != pMap->end() )
397void OMultiTypeInterfaceContainerHelper::disposeAndClear(
const EventObject & rEvt )
399 t_type2ptr::size_type nSize = 0;
400 std::unique_ptr<OInterfaceContainerHelper *[]> ppListenerContainers;
402 ::osl::MutexGuard aGuard( rMutex );
404 nSize = pMap->size();
408 ppListenerContainers.reset(
new ppp[nSize]);
411 t_type2ptr::size_type
i = 0;
412 for (
const auto& rItem : *pMap)
420 for( t_type2ptr::size_type
i = 0;
423 if( ppListenerContainers[
i] )
428void OMultiTypeInterfaceContainerHelper::clear()
430 ::osl::MutexGuard aGuard( rMutex );
433 for (
auto& rItem : *pMap)
441typedef std::vector< std::pair < sal_Int32 , void* > >
t_long2ptr;
445 return std::find_if(pMap->begin(), pMap->end(),
446 [&nKey](
const t_long2ptr::value_type& rItem) { return rItem.first == nKey; });
449OMultiTypeInterfaceContainerHelperInt32::OMultiTypeInterfaceContainerHelperInt32( Mutex & rMutex_ )
456OMultiTypeInterfaceContainerHelperInt32::~OMultiTypeInterfaceContainerHelperInt32()
463 for (
auto& rItem : *pMap)
466 rItem.second =
nullptr;
474 t_long2ptr::size_type nSize;
476 ::osl::MutexGuard aGuard( rMutex );
477 nSize = pMap ? pMap->size() : 0;
480 css::uno::Sequence< sal_Int32 > aInterfaceTypes( nSize );
481 sal_Int32 * pArray = aInterfaceTypes.getArray();
484 for (
const auto& rItem : *pMap)
489 pArray[
i++] = rItem.first;
491 if(
static_cast<t_long2ptr::size_type
>(
i) != nSize ) {
493 aInterfaceTypes = css::uno::Sequence< sal_Int32 >( pArray,
i );
495 return aInterfaceTypes;
497 return css::uno::Sequence< sal_Int32 >();
502 ::osl::MutexGuard aGuard( rMutex );
507 t_long2ptr::iterator iter =
findLong( pMap, rKey );
508 if( iter != pMap->end() )
513sal_Int32 OMultiTypeInterfaceContainerHelperInt32::addInterface(
516 ::osl::MutexGuard aGuard( rMutex );
520 t_long2ptr::iterator iter =
findLong( pMap, rKey );
521 if( iter == pMap->end() )
524 pMap->push_back(std::pair< sal_Int32, void* >(rKey, pLC));
530sal_Int32 OMultiTypeInterfaceContainerHelperInt32::removeInterface(
533 ::osl::MutexGuard aGuard( rMutex );
539 t_long2ptr::iterator iter =
findLong( pMap, rKey );
541 if( iter != pMap->end() )
548void OMultiTypeInterfaceContainerHelperInt32::disposeAndClear(
const EventObject & rEvt )
550 t_long2ptr::size_type nSize = 0;
551 std::unique_ptr<OInterfaceContainerHelper *[]> ppListenerContainers;
553 ::osl::MutexGuard aGuard( rMutex );
558 nSize = pMap->size();
562 ppListenerContainers.reset(
new ppp[nSize]);
564 t_long2ptr::size_type
i = 0;
565 for (
const auto& rItem : *pMap)
573 for( t_long2ptr::size_type
i = 0;
576 if( ppListenerContainers[
i] )
581void OMultiTypeInterfaceContainerHelperInt32::clear()
583 ::osl::MutexGuard aGuard( rMutex );
588 for (
auto& rItem : *pMap)
A container of interfaces.
sal_Bool bInUse
TRUE -> used by an iterator.
sal_Int32 SAL_CALL getLength() const
Return the number of Elements in the container.
sal_Bool bIsList
TRUE -> aData.pAsSequence is of type Sequence< XInterfaceSequence >.
css::uno::Sequence< css::uno::Reference< css::uno::XInterface > > SAL_CALL getElements() const
Return all interfaces added to this container.
void SAL_CALL disposeAndClear(const css::lang::EventObject &rEvt)
Call disposing on all object in the container that support XEventListener.
sal_Int32 SAL_CALL removeInterface(const css::uno::Reference< css::uno::XInterface > &rxIFace)
Removes an element from the container.
detail::element_alias aData
bIsList == TRUE -> aData.pAsSequence of type Sequence< XInterfaceSequence >, otherwise aData....
~OInterfaceContainerHelper()
Release all interfaces.
sal_Int32 SAL_CALL addInterface(const css::uno::Reference< css::uno::XInterface > &rxIFace)
Inserts an element into the container.
void SAL_CALL clear()
Clears the container without calling disposing().
OInterfaceContainerHelper(::osl::Mutex &rMutex)
Create an interface container.
This is the iterator of an InterfaceContainerHelper.
OInterfaceContainerHelper & rCont
~OInterfaceIteratorHelper()
Releases the connection to the container.
css::uno::XInterface *SAL_CALL next()
Return the next element of the iterator.
detail::element_alias aData
bool SAL_CALL hasMoreElements() const
Return true, if there are more elements in the iterator.
void SAL_CALL remove()
Removes the current element (the last one returned by next()) from the underlying container.
OInterfaceIteratorHelper(OInterfaceContainerHelper &rCont)
Create an iterator over the elements of the container.
OMultiTypeInterfaceContainerHelper(::osl::Mutex &rMutex)
Create a container of interface containers.
#define SAL_WARN_IF(condition, area, stream)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
std::vector< std::pair< sal_Int32, void * > > t_long2ptr
static t_long2ptr::iterator findLong(t_long2ptr *pMap, sal_Int32 nKey)
static t_type2ptr::iterator findType(t_type2ptr *pMap, const Type &rKey)
std::vector< std::pair< Type, void * > > t_type2ptr
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
std::vector< css::uno::Reference< css::uno::XInterface > > * pAsVector
css::uno::XInterface * pAsInterface