diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2021-11-11 19:08:17 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-11-13 06:26:52 +0100 |
commit | 98a2cef1ee9c76897af64ff0a1e1efd280796f36 (patch) | |
tree | 7b72937636b52abfb430335015b882aa5a8c461c /include | |
parent | 0dbde576f57395c9315e5da8c43e9aedf9094953 (diff) |
modernise IdPropArrayHelper a little
Change-Id: I73bbb59d41ba752e5bbb798ae590e60fdb550d8b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125115
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'include')
-rw-r--r-- | include/comphelper/IdPropArrayHelper.hxx | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/include/comphelper/IdPropArrayHelper.hxx b/include/comphelper/IdPropArrayHelper.hxx index 34e403b3ab0a..c702acb98065 100644 --- a/include/comphelper/IdPropArrayHelper.hxx +++ b/include/comphelper/IdPropArrayHelper.hxx @@ -16,40 +16,32 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_COMPHELPER_IDPROPARRAYHELPER_HXX -#define INCLUDED_COMPHELPER_IDPROPARRAYHELPER_HXX +#pragma once #include <sal/config.h> -#include <map> - #include <osl/mutex.hxx> -#include <osl/diagnose.h> #include <rtl/instance.hxx> #include <cppuhelper/propshlp.hxx> +#include <cassert> +#include <unordered_map> namespace comphelper { - // OIdPropertyArrayUsageHelper - template <typename TYPE> struct OIdPropertyArrayUsageHelperMutex : public rtl::Static< ::osl::Mutex, OIdPropertyArrayUsageHelperMutex<TYPE> > {}; - typedef std::map< sal_Int32, ::cppu::IPropertyArrayHelper* > OIdPropertyArrayMap; + typedef std::unordered_map< sal_Int32, ::cppu::IPropertyArrayHelper* > OIdPropertyArrayMap; template <class TYPE> class OIdPropertyArrayUsageHelper { - protected: - static sal_Int32 s_nRefCount; - static OIdPropertyArrayMap* s_pMap; - public: OIdPropertyArrayUsageHelper(); virtual ~OIdPropertyArrayUsageHelper() { ::osl::MutexGuard aGuard(OIdPropertyArrayUsageHelperMutex<TYPE>::get()); - OSL_ENSURE(s_nRefCount > 0, "OIdPropertyArrayUsageHelper::~OIdPropertyArrayUsageHelper : suspicious call : have a refcount of 0 !"); + assert(s_nRefCount > 0 && "OIdPropertyArrayUsageHelper::~OIdPropertyArrayUsageHelper : suspicious call : have a refcount of 0 !"); if (!--s_nRefCount) { // delete the element @@ -73,42 +65,41 @@ namespace comphelper @return a pointer to the newly created array helper. Must not be NULL. */ virtual ::cppu::IPropertyArrayHelper* createArrayHelper(sal_Int32 nId) const = 0; + private: + static sal_Int32 s_nRefCount; + static OIdPropertyArrayMap* s_pMap; }; - template<class TYPE> sal_Int32 OIdPropertyArrayUsageHelper< TYPE >::s_nRefCount = 0; template<class TYPE> OIdPropertyArrayMap* OIdPropertyArrayUsageHelper< TYPE >::s_pMap = nullptr; - template <class TYPE> OIdPropertyArrayUsageHelper<TYPE>::OIdPropertyArrayUsageHelper() { ::osl::MutexGuard aGuard(OIdPropertyArrayUsageHelperMutex<TYPE>::get()); // create the map if necessary - if (s_pMap == nullptr) + if (!s_pMap) s_pMap = new OIdPropertyArrayMap; ++s_nRefCount; } - template <class TYPE> ::cppu::IPropertyArrayHelper* OIdPropertyArrayUsageHelper<TYPE>::getArrayHelper(sal_Int32 nId) { - OSL_ENSURE(s_nRefCount, "OIdPropertyArrayUsageHelper::getArrayHelper : suspicious call : have a refcount of 0 !"); + assert(s_nRefCount && "OIdPropertyArrayUsageHelper::getArrayHelper : suspicious call : have a refcount of 0 !"); ::osl::MutexGuard aGuard(OIdPropertyArrayUsageHelperMutex<TYPE>::get()); // do we have the array already? auto& rEntry = (*s_pMap)[nId]; if (!rEntry) { rEntry = createArrayHelper(nId); - OSL_ENSURE((*s_pMap)[nId], "OIdPropertyArrayUsageHelper::getArrayHelper : createArrayHelper returned nonsense !"); + assert(rEntry && "OIdPropertyArrayUsageHelper::getArrayHelper : createArrayHelper returned nonsense !"); } return (*s_pMap)[nId]; } } -#endif // INCLUDED_COMPHELPER_IDPROPARRAYHELPER_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |