LibreOffice Module comphelper (master)
1
|
defines a collection of UNO components, where every component will get its own unique number. More...
#include <numberedcollection.hxx>
Classes | |
struct | TNumberedItem |
Public Member Functions | |
NumberedCollection () | |
lightweight constructor. More... | |
virtual | ~NumberedCollection () override |
free all internally used resources. More... | |
void | setOwner (const css::uno::Reference< css::uno::XInterface > &xOwner) |
set an outside component which uses this container and must be set as source of all broadcasted messages, exceptions. More... | |
void | setUntitledPrefix (const OUString &sPrefix) |
set the localized prefix to be used for untitled components. More... | |
virtual ::sal_Int32 SAL_CALL | leaseNumber (const css::uno::Reference< css::uno::XInterface > &xComponent) override |
virtual void SAL_CALL | releaseNumber (::sal_Int32 nNumber) override |
virtual void SAL_CALL | releaseNumberForComponent (const css::uno::Reference< css::uno::XInterface > &xComponent) override |
virtual OUString SAL_CALL | getUntitledPrefix () override |
Private Types | |
typedef std::unordered_map< sal_IntPtr, TNumberedItem > | TNumberedItemHash |
typedef ::std::vector< sal_IntPtr > | TDeadItemList |
Private Member Functions | |
::sal_Int32 | impl_searchFreeNumber () |
tries to find a unique number not already used within this collection. More... | |
Static Private Member Functions | |
static void | impl_cleanUpDeadItems (TNumberedItemHash &lItems, const TDeadItemList &lDeadItems) |
Private Attributes | |
OUString | m_sUntitledPrefix |
localized string to be used for untitled components More... | |
TNumberedItemHash | m_lComponents |
cache of all "leased numbers" and its bound components More... | |
css::uno::WeakReference< css::uno::XInterface > | m_xOwner |
used as source of broadcasted messages or exceptions (can be null !) More... | |
![]() | |
mutable::osl::Mutex | m_aMutex |
defines a collection of UNO components, where every component will get its own unique number.
Such number will be unique at runtime only... but it supports fragmentation. Note: This collection uses weak references only to know her components. So lifetime of these components must be controlled outside.
Definition at line 47 of file numberedcollection.hxx.
|
private |
Definition at line 64 of file numberedcollection.hxx.
|
private |
Definition at line 62 of file numberedcollection.hxx.
comphelper::NumberedCollection::NumberedCollection | ( | ) |
lightweight constructor.
Definition at line 30 of file numberedcollection.cxx.
|
overridevirtual |
free all internally used resources.
Definition at line 39 of file numberedcollection.cxx.
|
overridevirtual |
Definition at line 160 of file numberedcollection.cxx.
References aLock, cppu::BaseMutex::m_aMutex, and m_sUntitledPrefix.
|
staticprivate |
Definition at line 229 of file numberedcollection.cxx.
Referenced by impl_searchFreeNumber(), and releaseNumber().
|
private |
tries to find a unique number not already used within this collection.
create an ordered list of all possible numbers ...
It reuses the smallest number which isn't used by any component of this collection. (fragmentation!) If collection is full (means there is no free number) the special value INVALID_NUMBER will be returned.
So the outside code has to make sure that retrieving and using of those numbers will be an atomic operation.
e.g. {1,2,3,...,N} Max size of these list will be current size of component list + 1 .
"+1" ... because in case all numbers in range 1..n are in use we need a new number n+1 :-)
Every item which is already used as unique number will be removed. At the end a list of e.g. {3,6,...,M} exists where the first item represent the lowest free number (in this example 3).
Definition at line 183 of file numberedcollection.cxx.
References aLock, find(), i, impl_cleanUpDeadItems(), cppu::BaseMutex::m_aMutex, and m_lComponents.
Referenced by leaseNumber().
|
override |
Definition at line 66 of file numberedcollection.cxx.
References aLock, impl_searchFreeNumber(), cppu::BaseMutex::m_aMutex, m_lComponents, m_xOwner, comphelper::NumberedCollection::TNumberedItem::nNumber, and comphelper::NumberedCollection::TNumberedItem::xItem.
|
overridevirtual |
Definition at line 101 of file numberedcollection.cxx.
References aLock, impl_cleanUpDeadItems(), cppu::BaseMutex::m_aMutex, m_lComponents, m_xOwner, comphelper::NumberedCollection::TNumberedItem::nNumber, and comphelper::NumberedCollection::TNumberedItem::xItem.
|
overridevirtual |
Definition at line 138 of file numberedcollection.cxx.
References aLock, cppu::BaseMutex::m_aMutex, m_lComponents, and m_xOwner.
void comphelper::NumberedCollection::setOwner | ( | const css::uno::Reference< css::uno::XInterface > & | xOwner | ) |
set an outside component which uses this container and must be set as source of all broadcasted messages, exceptions.
It's holded weak only so we do not need any complex dispose sessions.
Note: Passing NULL as parameter will be allowed. It will reset the internal member reference only.
xOwner | the new owner of this collection. |
Definition at line 44 of file numberedcollection.cxx.
References aLock, cppu::BaseMutex::m_aMutex, and m_xOwner.
void comphelper::NumberedCollection::setUntitledPrefix | ( | const OUString & | sPrefix | ) |
set the localized prefix to be used for untitled components.
Localization has to be done outside. This container will return those value then. There are no further checks. Its up to you to define a suitable string here :-)
sPrefix | the new prefix for untitled components. |
Definition at line 55 of file numberedcollection.cxx.
References aLock, cppu::BaseMutex::m_aMutex, m_sUntitledPrefix, and sPrefix.
|
private |
cache of all "leased numbers" and its bound components
Definition at line 156 of file numberedcollection.hxx.
Referenced by impl_searchFreeNumber(), leaseNumber(), releaseNumber(), and releaseNumberForComponent().
|
private |
localized string to be used for untitled components
Definition at line 153 of file numberedcollection.hxx.
Referenced by getUntitledPrefix(), and setUntitledPrefix().
|
private |
used as source of broadcasted messages or exceptions (can be null !)
Definition at line 159 of file numberedcollection.hxx.
Referenced by leaseNumber(), releaseNumber(), releaseNumberForComponent(), and setOwner().