summaryrefslogtreecommitdiffstats
path: root/cppuhelper
diff options
context:
space:
mode:
authorArkadiy Illarionov <qarkai@gmail.com>2019-03-03 13:10:45 +0300
committerNoel Grandin <noel.grandin@collabora.co.uk>2019-03-03 16:27:08 +0100
commit5af9e26ae8b463e85cb84f79a366c61d49a2d52b (patch)
treed8e001ed45e2a441e19864f8e2613317c9019ffa /cppuhelper
parentMore test cases for FOURIER formula (diff)
downloadcore-5af9e26ae8b463e85cb84f79a366c61d49a2d52b.tar.gz
core-5af9e26ae8b463e85cb84f79a366c61d49a2d52b.zip
Simplify containers iterations in cppcanvas, cppu, cppuhelper
Use range-based loop or replace with STL functions Change-Id: I72bf7cdb632c04e2fc8d4f7ab85cb6571222aa07 Reviewed-on: https://gerrit.libreoffice.org/68636 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'cppuhelper')
-rw-r--r--cppuhelper/source/component_context.cxx23
-rw-r--r--cppuhelper/source/interfacecontainer.cxx92
-rw-r--r--cppuhelper/source/propertysetmixin.cxx44
-rw-r--r--cppuhelper/source/servicemanager.cxx249
-rw-r--r--cppuhelper/source/typemanager.cxx40
-rw-r--r--cppuhelper/source/weak.cxx12
6 files changed, 165 insertions, 295 deletions
diff --git a/cppuhelper/source/component_context.cxx b/cppuhelper/source/component_context.cxx
index e278302fbfcc..ba0c0635dc89 100644
--- a/cppuhelper/source/component_context.cxx
+++ b/cppuhelper/source/component_context.cxx
@@ -40,6 +40,8 @@
#include <com/sun/star/uno/DeploymentException.hpp>
#include <com/sun/star/uno/RuntimeException.hpp>
+#include <comphelper/sequence.hxx>
+
#include <memory>
#define SMGR_SINGLETON "/singletons/com.sun.star.lang.theServiceManager"
@@ -232,14 +234,7 @@ Any ComponentContext::getByName( OUString const & name )
Sequence<OUString> ComponentContext::getElementNames()
{
MutexGuard guard( m_mutex );
- Sequence<OUString> ret( m_map.size() );
- OUString * pret = ret.getArray();
- sal_Int32 pos = 0;
- t_map::const_iterator iPos( m_map.begin() );
- t_map::const_iterator const iEnd( m_map.end() );
- for ( ; iPos != iEnd; ++iPos )
- pret[pos++] = iPos->first;
- return ret;
+ return comphelper::mapKeysToSequence(m_map);
}
@@ -393,16 +388,12 @@ void ComponentContext::disposing()
Reference< lang::XComponent > xTDMgr, xAC; // to be disposed separately
// dispose all context objects
- t_map::iterator iPos( m_map.begin() );
- t_map::iterator const iEnd( m_map.end() );
- for ( ; iPos != iEnd; ++iPos )
+ for ( auto& [rName, rEntry] : m_map )
{
// service manager disposed separately
if (!m_xSMgr.is() ||
- !iPos->first.startsWith( SMGR_SINGLETON ))
+ !rName.startsWith( SMGR_SINGLETON ))
{
- ContextEntry& rEntry = iPos->second;
-
if (rEntry.lateInit)
{
// late init
@@ -419,11 +410,11 @@ void ComponentContext::disposing()
rEntry.value >>= xComp;
if (xComp.is())
{
- if ( iPos->first == TDMGR_SINGLETON )
+ if ( rName == TDMGR_SINGLETON )
{
xTDMgr = xComp;
}
- else if ( iPos->first == AC_SINGLETON )
+ else if ( rName == AC_SINGLETON )
{
xAC = xComp;
}
diff --git a/cppuhelper/source/interfacecontainer.cxx b/cppuhelper/source/interfacecontainer.cxx
index 175526945e21..7f49682e410b 100644
--- a/cppuhelper/source/interfacecontainer.cxx
+++ b/cppuhelper/source/interfacecontainer.cxx
@@ -332,14 +332,11 @@ OMultiTypeInterfaceContainerHelper::OMultiTypeInterfaceContainerHelper( Mutex &
OMultiTypeInterfaceContainerHelper::~OMultiTypeInterfaceContainerHelper()
{
t_type2ptr * pMap = static_cast<t_type2ptr *>(m_pMap);
- t_type2ptr::iterator iter = pMap->begin();
- t_type2ptr::iterator end = pMap->end();
- while( iter != end )
+ for (auto& rItem : *pMap)
{
- delete static_cast<OInterfaceContainerHelper*>((*iter).second);
- (*iter).second = nullptr;
- ++iter;
+ delete static_cast<OInterfaceContainerHelper*>(rItem.second);
+ rItem.second = nullptr;
}
delete pMap;
}
@@ -356,17 +353,13 @@ Sequence< Type > OMultiTypeInterfaceContainerHelper::getContainedTypes() const
css::uno::Sequence< Type > aInterfaceTypes( nSize );
Type * pArray = aInterfaceTypes.getArray();
- t_type2ptr::iterator iter = pMap->begin();
- t_type2ptr::iterator end = pMap->end();
-
sal_Int32 i = 0;
- while( iter != end )
+ for (const auto& rItem : *pMap)
{
// are interfaces added to this container?
- if( static_cast<OInterfaceContainerHelper*>((*iter).second)->getLength() )
+ if( static_cast<OInterfaceContainerHelper*>(rItem.second)->getLength() )
// yes, put the type in the array
- pArray[i++] = (*iter).first;
- ++iter;
+ pArray[i++] = rItem.first;
}
if( static_cast<t_type2ptr::size_type>(i) != nSize ) {
// may be empty container, reduce the sequence to the right size
@@ -379,16 +372,8 @@ Sequence< Type > OMultiTypeInterfaceContainerHelper::getContainedTypes() const
static t_type2ptr::iterator findType(t_type2ptr *pMap, const Type & rKey )
{
- t_type2ptr::iterator iter = pMap->begin();
- t_type2ptr::iterator end = pMap->end();
-
- while( iter != end )
- {
- if (iter->first == rKey)
- break;
- ++iter;
- }
- return iter;
+ return std::find_if(pMap->begin(), pMap->end(),
+ [&rKey](const t_type2ptr::value_type& rItem) { return rItem.first == rKey; });
}
OInterfaceContainerHelper * OMultiTypeInterfaceContainerHelper::getContainer( const Type & rKey ) const
@@ -447,14 +432,10 @@ void OMultiTypeInterfaceContainerHelper::disposeAndClear( const EventObject & rE
ppListenerContainers.reset(new ppp[nSize]);
//ppListenerContainers = new (ListenerContainer*)[nSize];
- t_type2ptr::iterator iter = pMap->begin();
- t_type2ptr::iterator end = pMap->end();
-
t_type2ptr::size_type i = 0;
- while( iter != end )
+ for (const auto& rItem : *pMap)
{
- ppListenerContainers[i++] = static_cast<OInterfaceContainerHelper*>((*iter).second);
- ++iter;
+ ppListenerContainers[i++] = static_cast<OInterfaceContainerHelper*>(rItem.second);
}
}
}
@@ -472,13 +453,10 @@ void OMultiTypeInterfaceContainerHelper::clear()
{
::osl::MutexGuard aGuard( rMutex );
t_type2ptr * pMap = static_cast<t_type2ptr *>(m_pMap);
- t_type2ptr::iterator iter = pMap->begin();
- t_type2ptr::iterator end = pMap->end();
- while( iter != end )
+ for (auto& rItem : *pMap)
{
- static_cast<OInterfaceContainerHelper*>((*iter).second)->clear();
- ++iter;
+ static_cast<OInterfaceContainerHelper*>(rItem.second)->clear();
}
}
@@ -488,16 +466,8 @@ typedef std::vector< std::pair < sal_Int32 , void* > > t_long2ptr;
static t_long2ptr::iterator findLong(t_long2ptr *pMap, sal_Int32 nKey )
{
- t_long2ptr::iterator iter = pMap->begin();
- t_long2ptr::iterator end = pMap->end();
-
- while( iter != end )
- {
- if (iter->first == nKey)
- break;
- ++iter;
- }
- return iter;
+ return std::find_if(pMap->begin(), pMap->end(),
+ [&nKey](const t_long2ptr::value_type& rItem) { return rItem.first == nKey; });
}
OMultiTypeInterfaceContainerHelperInt32::OMultiTypeInterfaceContainerHelperInt32( Mutex & rMutex_ )
@@ -513,14 +483,11 @@ OMultiTypeInterfaceContainerHelperInt32::~OMultiTypeInterfaceContainerHelperInt3
return;
t_long2ptr * pMap = static_cast<t_long2ptr *>(m_pMap);
- t_long2ptr::iterator iter = pMap->begin();
- t_long2ptr::iterator end = pMap->end();
- while( iter != end )
+ for (auto& rItem : *pMap)
{
- delete static_cast<OInterfaceContainerHelper*>((*iter).second);
- (*iter).second = nullptr;
- ++iter;
+ delete static_cast<OInterfaceContainerHelper*>(rItem.second);
+ rItem.second = nullptr;
}
delete pMap;
}
@@ -537,17 +504,13 @@ Sequence< sal_Int32 > OMultiTypeInterfaceContainerHelperInt32::getContainedTypes
css::uno::Sequence< sal_Int32 > aInterfaceTypes( nSize );
sal_Int32 * pArray = aInterfaceTypes.getArray();
- t_long2ptr::iterator iter = pMap->begin();
- t_long2ptr::iterator end = pMap->end();
-
sal_Int32 i = 0;
- while( iter != end )
+ for (const auto& rItem : *pMap)
{
// are interfaces added to this container?
- if( static_cast<OInterfaceContainerHelper*>((*iter).second)->getLength() )
+ if( static_cast<OInterfaceContainerHelper*>(rItem.second)->getLength() )
// yes, put the type in the array
- pArray[i++] = (*iter).first;
- ++iter;
+ pArray[i++] = rItem.first;
}
if( static_cast<t_long2ptr::size_type>(i) != nSize ) {
// may be empty container, reduce the sequence to the right size
@@ -622,14 +585,10 @@ void OMultiTypeInterfaceContainerHelperInt32::disposeAndClear( const EventObject
typedef OInterfaceContainerHelper* ppp;
ppListenerContainers.reset(new ppp[nSize]);
- t_long2ptr::iterator iter = pMap->begin();
- t_long2ptr::iterator end = pMap->end();
-
t_long2ptr::size_type i = 0;
- while( iter != end )
+ for (const auto& rItem : *pMap)
{
- ppListenerContainers[i++] = static_cast<OInterfaceContainerHelper*>((*iter).second);
- ++iter;
+ ppListenerContainers[i++] = static_cast<OInterfaceContainerHelper*>(rItem.second);
}
}
}
@@ -649,13 +608,10 @@ void OMultiTypeInterfaceContainerHelperInt32::clear()
if (!m_pMap)
return;
t_long2ptr * pMap = static_cast<t_long2ptr *>(m_pMap);
- t_long2ptr::iterator iter = pMap->begin();
- t_long2ptr::iterator end = pMap->end();
- while( iter != end )
+ for (auto& rItem : *pMap)
{
- static_cast<OInterfaceContainerHelper*>((*iter).second)->clear();
- ++iter;
+ static_cast<OInterfaceContainerHelper*>(rItem.second)->clear();
}
}
diff --git a/cppuhelper/source/propertysetmixin.cxx b/cppuhelper/source/propertysetmixin.cxx
index 4c31beaa286d..7201d49def1a 100644
--- a/cppuhelper/source/propertysetmixin.cxx
+++ b/cppuhelper/source/propertysetmixin.cxx
@@ -291,11 +291,10 @@ css::uno::Sequence< css::beans::Property > Info::getProperties()
css::uno::Sequence< css::beans::Property > s(
static_cast< sal_Int32 >(m_data->properties.size()));
sal_Int32 n = 0;
- for (Data::PropertyMap::iterator i(m_data->properties.begin());
- i != m_data->properties.end(); ++i)
+ for (const auto& rEntry : m_data->properties)
{
- if (i->second.present) {
- s[n++] = i->second.property;
+ if (rEntry.second.present) {
+ s[n++] = rEntry.second.property;
}
}
s.realloc(n);
@@ -334,19 +333,16 @@ PropertySetMixinImpl::BoundListeners::~BoundListeners() {
}
void PropertySetMixinImpl::BoundListeners::notify() const {
- for (BoundListenerBag::const_iterator i(m_impl->specificListeners.begin());
- i != m_impl->specificListeners.end(); ++i)
+ for (const auto& rxListener : m_impl->specificListeners)
{
try {
- (*i)->propertyChange(m_impl->event);
+ rxListener->propertyChange(m_impl->event);
} catch (css::lang::DisposedException &) {}
}
- for (BoundListenerBag::const_iterator i(
- m_impl->unspecificListeners.begin());
- i != m_impl->unspecificListeners.end(); ++i)
+ for (const auto& rxListener : m_impl->unspecificListeners)
{
try {
- (*i)->propertyChange(m_impl->event);
+ rxListener->propertyChange(m_impl->event);
} catch (css::lang::DisposedException &) {}
}
}
@@ -898,18 +894,16 @@ void PropertySetMixinImpl::prepareSet(
css::beans::PropertyChangeEvent event(
static_cast< css::beans::XPropertySet * >(this), propertyName,
false, it->second.property.Handle, oldValue, newValue);
- for (Impl::VetoListenerBag::iterator i(specificVeto.begin());
- i != specificVeto.end(); ++i)
+ for (auto& rxVetoListener : specificVeto)
{
try {
- (*i)->vetoableChange(event);
+ rxVetoListener->vetoableChange(event);
} catch (css::lang::DisposedException &) {}
}
- for (Impl::VetoListenerBag::iterator i(unspecificVeto.begin());
- i != unspecificVeto.end(); ++i)
+ for (auto& rxVetoListener : unspecificVeto)
{
try {
- (*i)->vetoableChange(event);
+ rxVetoListener->vetoableChange(event);
} catch (css::lang::DisposedException &) {}
}
}
@@ -934,22 +928,18 @@ void PropertySetMixinImpl::dispose() {
}
css::lang::EventObject event(
static_cast< css::beans::XPropertySet * >(this));
- for (Impl::BoundListenerMap::iterator i(boundListeners.begin());
- i != boundListeners.end(); ++i)
+ for (auto& rEntry : boundListeners)
{
- for (BoundListenerBag::iterator j(i->second.begin());
- j != i->second.end(); ++j)
+ for (auto& rxBoundListener : rEntry.second)
{
- (*j)->disposing(event);
+ rxBoundListener->disposing(event);
}
}
- for (Impl::VetoListenerMap::iterator i(vetoListeners.begin());
- i != vetoListeners.end(); ++i)
+ for (auto& rEntry : vetoListeners)
{
- for (Impl::VetoListenerBag::iterator j(i->second.begin());
- j != i->second.end(); ++j)
+ for (auto& rxVetoListener : rEntry.second)
{
- (*j)->disposing(event);
+ rxVetoListener->disposing(event);
}
}
}
diff --git a/cppuhelper/source/servicemanager.cxx b/cppuhelper/source/servicemanager.cxx
index 68db3c102329..765204301e1f 100644
--- a/cppuhelper/source/servicemanager.cxx
+++ b/cppuhelper/source/servicemanager.cxx
@@ -28,6 +28,7 @@
#include <com/sun/star/uno/DeploymentException.hpp>
#include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/uno/XComponentContext.hpp>
+#include <comphelper/sequence.hxx>
#include <cppuhelper/bootstrap.hxx>
#include <cppuhelper/component_context.hxx>
#include <cppuhelper/implbase.hxx>
@@ -58,15 +59,13 @@ void insertImplementationMap(
cppuhelper::ServiceManager::Data::ImplementationMap const & source)
{
assert(destination != nullptr);
- for (cppuhelper::ServiceManager::Data::ImplementationMap::const_iterator i(
- source.begin());
- i != source.end(); ++i)
+ for (const auto& [rName, rImpls] : source)
{
std::vector<
std::shared_ptr<
cppuhelper::ServiceManager::Data::Implementation > > & impls
- = (*destination)[i->first];
- impls.insert(impls.end(), i->second.begin(), i->second.end());
+ = (*destination)[rName];
+ impls.insert(impls.end(), rImpls.begin(), rImpls.end());
}
}
@@ -79,11 +78,10 @@ void removeFromImplementationMap(
// The underlying data structures make this function somewhat inefficient,
// but the assumption is that it is rarely called:
assert(map != nullptr);
- for (std::vector< OUString >::const_iterator i(elements.begin());
- i != elements.end(); ++i)
+ for (const auto& rElement : elements)
{
cppuhelper::ServiceManager::Data::ImplementationMap::iterator j(
- map->find(*i));
+ map->find(rElement));
assert(j != map->end());
std::vector<
std::shared_ptr<
@@ -637,16 +635,7 @@ ImplementationWrapper::getSupportedServiceNames()
+ " supports too many services"),
static_cast< cppu::OWeakObject * >(this));
}
- css::uno::Sequence< OUString > names(
- static_cast< sal_Int32 >(impl->info->services.size()));
- sal_Int32 i = 0;
- for (std::vector< OUString >::const_iterator j(
- impl->info->services.begin());
- j != impl->info->services.end(); ++j)
- {
- names[i++] = *j;
- }
- return names;
+ return comphelper::containerToSequence(impl->info->services);
}
}
@@ -730,21 +719,20 @@ void cppuhelper::ServiceManager::addSingletonContextEntries(
std::vector< cppu::ContextEntry_Init > * entries)
{
assert(entries != nullptr);
- for (Data::ImplementationMap::const_iterator i(data_.singletons.begin());
- i != data_.singletons.end(); ++i)
+ for (const auto& [rName, rImpls] : data_.singletons)
{
- assert(!i->second.empty());
- assert(i->second[0].get() != nullptr);
+ assert(!rImpls.empty());
+ assert(rImpls[0].get() != nullptr);
SAL_INFO_IF(
- i->second.size() > 1, "cppuhelper",
- "Arbitrarily choosing " << i->second[0]->info->name
- << " among multiple implementations for " << i->first);
+ rImpls.size() > 1, "cppuhelper",
+ "Arbitrarily choosing " << rImpls[0]->info->name
+ << " among multiple implementations for " << rName);
entries->push_back(
cppu::ContextEntry_Init(
- "/singletons/" + i->first,
+ "/singletons/" + rName,
css::uno::makeAny<
css::uno::Reference<css::lang::XSingleComponentFactory> >(
- new SingletonFactory(this, i->second[0])),
+ new SingletonFactory(this, rImpls[0])),
true));
}
}
@@ -848,31 +836,27 @@ void cppuhelper::ServiceManager::disposing() {
Data clear;
{
osl::MutexGuard g(rBHelper.rMutex);
- for (Data::NamedImplementations::const_iterator i(
- data_.namedImplementations.begin());
- i != data_.namedImplementations.end(); ++i)
+ for (const auto& rEntry : data_.namedImplementations)
{
- assert(i->second.get() != nullptr);
- if (!i->second->info->singletons.empty()) {
- osl::MutexGuard g2(i->second->mutex);
- if (i->second->disposeSingleton.is()) {
- sngls.push_back(i->second->disposeSingleton);
+ assert(rEntry.second.get() != nullptr);
+ if (!rEntry.second->info->singletons.empty()) {
+ osl::MutexGuard g2(rEntry.second->mutex);
+ if (rEntry.second->disposeSingleton.is()) {
+ sngls.push_back(rEntry.second->disposeSingleton);
}
}
}
- for (Data::DynamicImplementations::const_iterator i(
- data_.dynamicImplementations.begin());
- i != data_.dynamicImplementations.end(); ++i)
+ for (const auto& rEntry : data_.dynamicImplementations)
{
- assert(i->second.get() != nullptr);
- if (!i->second->info->singletons.empty()) {
- osl::MutexGuard g2(i->second->mutex);
- if (i->second->disposeSingleton.is()) {
- sngls.push_back(i->second->disposeSingleton);
+ assert(rEntry.second.get() != nullptr);
+ if (!rEntry.second->info->singletons.empty()) {
+ osl::MutexGuard g2(rEntry.second->mutex);
+ if (rEntry.second->disposeSingleton.is()) {
+ sngls.push_back(rEntry.second->disposeSingleton);
}
}
- if (i->second->component.is()) {
- comps.push_back(i->second->component);
+ if (rEntry.second->component.is()) {
+ comps.push_back(rEntry.second->component);
}
}
data_.namedImplementations.swap(clear.namedImplementations);
@@ -880,23 +864,17 @@ void cppuhelper::ServiceManager::disposing() {
data_.services.swap(clear.services);
data_.singletons.swap(clear.singletons);
}
- for (std::vector<
- css::uno::Reference<css::lang::XComponent> >::const_iterator i(
- sngls.begin());
- i != sngls.end(); ++i)
+ for (const auto& rxSngl : sngls)
{
try {
- (*i)->dispose();
+ rxSngl->dispose();
} catch (css::uno::RuntimeException & e) {
SAL_WARN("cppuhelper", "Ignoring " << e << " while disposing singleton");
}
}
- for (std::vector<
- css::uno::Reference< css::lang::XComponent > >::const_iterator i(
- comps.begin());
- i != comps.end(); ++i)
+ for (const auto& rxComp : comps)
{
- removeEventListenerFromComponent(*i);
+ removeEventListenerFromComponent(rxComp);
}
}
@@ -960,21 +938,12 @@ cppuhelper::ServiceManager::getAvailableServiceNames()
if (isDisposed()) {
return css::uno::Sequence< OUString >();
}
- Data::ImplementationMap::size_type n = data_.services.size();
- if (n > static_cast< sal_uInt32 >(SAL_MAX_INT32)) {
+ if (data_.services.size() > static_cast< sal_uInt32 >(SAL_MAX_INT32)) {
throw css::uno::RuntimeException(
"getAvailableServiceNames: too many services",
static_cast< cppu::OWeakObject * >(this));
}
- css::uno::Sequence< OUString > names(static_cast< sal_Int32 >(n));
- sal_Int32 i = 0;
- for (Data::ImplementationMap::const_iterator j(data_.services.begin());
- j != data_.services.end(); ++j)
- {
- names[i++] = j->first;
- }
- assert(i == names.getLength());
- return names;
+ return comphelper::mapKeysToSequence(data_.services);
}
css::uno::Reference< css::uno::XInterface >
@@ -1146,12 +1115,9 @@ cppuhelper::ServiceManager::createContentEnumeration(
}
}
std::vector< css::uno::Any > factories;
- for (std::vector<
- std::shared_ptr< Data::Implementation > >::const_iterator i(
- impls.begin());
- i != impls.end(); ++i)
+ for (const auto& rxImpl : impls)
{
- Data::Implementation * impl = i->get();
+ Data::Implementation * impl = rxImpl.get();
assert(impl != nullptr);
{
osl::MutexGuard g(rBHelper.rMutex);
@@ -1166,11 +1132,11 @@ cppuhelper::ServiceManager::createContentEnumeration(
// synchronous error dialog when no JVM is specified, and
// showing the dialog while hovering over a menu can cause
// trouble):
- impl->factory1 = new ImplementationWrapper(this, *i);
+ impl->factory1 = new ImplementationWrapper(this, rxImpl);
impl->status = Data::Implementation::STATUS_WRAPPER;
}
if (impl->constructor != nullptr && !impl->factory1.is()) {
- impl->factory1 = new ImplementationWrapper(this, *i);
+ impl->factory1 = new ImplementationWrapper(this, rxImpl);
}
}
if (impl->factory1.is()) {
@@ -1440,19 +1406,15 @@ bool cppuhelper::ServiceManager::readLegacyRdbFile(OUString const & uri) {
}
readLegacyRdbStrings(
uri, implKey, "UNO/SERVICES", &impl->info->services);
- for (std::vector< OUString >::const_iterator j(
- impl->info->services.begin());
- j != impl->info->services.end(); ++j)
+ for (const auto& rService : impl->info->services)
{
- data_.services[*j].push_back(impl);
+ data_.services[rService].push_back(impl);
}
readLegacyRdbStrings(
uri, implKey, "UNO/SINGLETONS", &impl->info->singletons);
- for (std::vector< OUString >::const_iterator j(
- impl->info->singletons.begin());
- j != impl->info->singletons.end(); ++j)
+ for (const auto& rSingleton : impl->info->singletons)
{
- data_.singletons[*j].push_back(impl);
+ data_.singletons[rSingleton].push_back(impl);
}
}
return true;
@@ -1525,14 +1487,13 @@ void cppuhelper::ServiceManager::insertRdbFiles(
css::uno::Reference< css::uno::XComponentContext > const & alienContext)
{
Data extra;
- for (std::vector< OUString >::const_iterator i(uris.begin());
- i != uris.end(); ++i)
+ for (const auto& rUri : uris)
{
try {
- Parser(*i, alienContext, &extra);
+ Parser(rUri, alienContext, &extra);
} catch (css::container::NoSuchElementException &) {
throw css::lang::IllegalArgumentException(
- *i + ": no such file", static_cast< cppu::OWeakObject * >(this),
+ rUri + ": no such file", static_cast< cppu::OWeakObject * >(this),
0);
} catch (css::registry::InvalidRegistryException & e) {
throw css::lang::IllegalArgumentException(
@@ -1586,29 +1547,23 @@ bool cppuhelper::ServiceManager::insertExtraData(Data const & extra) {
if (isDisposed()) {
return false;
}
- for (Data::NamedImplementations::const_iterator i(
- extra.namedImplementations.begin());
- i != extra.namedImplementations.end(); ++i)
+ auto i = std::find_if(extra.namedImplementations.begin(), extra.namedImplementations.end(),
+ [this](const Data::NamedImplementations::value_type& rEntry) {
+ return data_.namedImplementations.find(rEntry.first) != data_.namedImplementations.end(); });
+ if (i != extra.namedImplementations.end())
{
- if (data_.namedImplementations.find(i->first)
- != data_.namedImplementations.end())
- {
- throw css::lang::IllegalArgumentException(
- "Insert duplicate implementation name " + i->first,
- static_cast< cppu::OWeakObject * >(this), 0);
- }
+ throw css::lang::IllegalArgumentException(
+ "Insert duplicate implementation name " + i->first,
+ static_cast< cppu::OWeakObject * >(this), 0);
}
- for (Data::DynamicImplementations::const_iterator i(
- extra.dynamicImplementations.begin());
- i != extra.dynamicImplementations.end(); ++i)
+ bool bDuplicate = std::any_of(extra.dynamicImplementations.begin(), extra.dynamicImplementations.end(),
+ [this](const Data::DynamicImplementations::value_type& rEntry) {
+ return data_.dynamicImplementations.find(rEntry.first) != data_.dynamicImplementations.end(); });
+ if (bDuplicate)
{
- if (data_.dynamicImplementations.find(i->first)
- != data_.dynamicImplementations.end())
- {
- throw css::lang::IllegalArgumentException(
- "Insert duplicate factory object",
- static_cast< cppu::OWeakObject * >(this), 0);
- }
+ throw css::lang::IllegalArgumentException(
+ "Insert duplicate factory object",
+ static_cast< cppu::OWeakObject * >(this), 0);
}
//TODO: The below leaves data_ in an inconsistent state upon exceptions:
data_.namedImplementations.insert(
@@ -1626,33 +1581,31 @@ bool cppuhelper::ServiceManager::insertExtraData(Data const & extra) {
assert(context_.is());
css::uno::Reference< css::container::XNameContainer > cont(
context_, css::uno::UNO_QUERY_THROW);
- for (Data::ImplementationMap::const_iterator i(
- extra.singletons.begin());
- i != extra.singletons.end(); ++i)
+ for (const auto& [rName, rImpls] : extra.singletons)
{
- OUString name("/singletons/" + i->first);
+ OUString name("/singletons/" + rName);
//TODO: Update should be atomic:
try {
cont->removeByName(name + "/arguments");
} catch (const css::container::NoSuchElementException &) {}
- assert(!i->second.empty());
- assert(i->second[0].get() != nullptr);
+ assert(!rImpls.empty());
+ assert(rImpls[0].get() != nullptr);
SAL_INFO_IF(
- i->second.size() > 1, "cppuhelper",
- "Arbitrarily choosing " << i->second[0]->info->name
+ rImpls.size() > 1, "cppuhelper",
+ "Arbitrarily choosing " << rImpls[0]->info->name
<< " among multiple implementations for singleton "
- << i->first);
+ << rName);
try {
cont->insertByName(
- name + "/service", css::uno::Any(i->second[0]->info->name));
+ name + "/service", css::uno::Any(rImpls[0]->info->name));
} catch (css::container::ElementExistException &) {
cont->replaceByName(
- name + "/service", css::uno::Any(i->second[0]->info->name));
+ name + "/service", css::uno::Any(rImpls[0]->info->name));
}
try {
cont->insertByName(name, css::uno::Any());
} catch (css::container::ElementExistException &) {
- SAL_INFO("cppuhelper", "Overwriting singleton " << i->first);
+ SAL_INFO("cppuhelper", "Overwriting singleton " << rName);
cont->replaceByName(name, css::uno::Any());
}
}
@@ -1669,15 +1622,14 @@ void cppuhelper::ServiceManager::removeRdbFiles(
std::vector< std::shared_ptr< Data::Implementation > > clear;
{
osl::MutexGuard g(rBHelper.rMutex);
- for (std::vector< OUString >::const_iterator i(uris.begin());
- i != uris.end(); ++i)
+ for (const auto& rUri : uris)
{
for (Data::NamedImplementations::iterator j(
data_.namedImplementations.begin());
j != data_.namedImplementations.end();)
{
assert(j->second.get() != nullptr);
- if (j->second->info->rdbFile == *i) {
+ if (j->second->info->rdbFile == rUri) {
clear.push_back(j->second);
//TODO: The below leaves data_ in an inconsistent state upon
// exceptions:
@@ -1754,15 +1706,10 @@ void cppuhelper::ServiceManager::removeImplementation(const OUString & name) {
&data_.services, i->second->info->services, i->second);
removeFromImplementationMap(
&data_.singletons, i->second->info->singletons, i->second);
- for (Data::DynamicImplementations::iterator j(
- data_.dynamicImplementations.begin());
- j != data_.dynamicImplementations.end(); ++j)
- {
- if (j->second == i->second) {
- data_.dynamicImplementations.erase(j);
- break;
- }
- }
+ auto j = std::find_if(data_.dynamicImplementations.begin(), data_.dynamicImplementations.end(),
+ [&i](const Data::DynamicImplementations::value_type& rEntry) { return rEntry.second == i->second; });
+ if (j != data_.dynamicImplementations.end())
+ data_.dynamicImplementations.erase(j);
data_.namedImplementations.erase(i);
}
}
@@ -1844,13 +1791,11 @@ void cppuhelper::ServiceManager::preloadImplementations() {
std::vector<OUString> aReported;
// loop all implementations
- for (Data::NamedImplementations::const_iterator iterator(
- data_.namedImplementations.begin());
- iterator != data_.namedImplementations.end(); ++iterator)
+ for (const auto& rEntry : data_.namedImplementations)
{
try
{
- const OUString &aLibrary = iterator->second->info->uri;
+ const OUString &aLibrary = rEntry.second->info->uri;
if (aLibrary.isEmpty())
continue;
@@ -1868,12 +1813,12 @@ void cppuhelper::ServiceManager::preloadImplementations() {
catch (css::lang::IllegalArgumentException& aError)
{
throw css::uno::DeploymentException(
- "Cannot expand URI" + iterator->second->info->uri + ": " + aError.Message,
+ "Cannot expand URI" + rEntry.second->info->uri + ": " + aError.Message,
static_cast< cppu::OWeakObject * >(this));
}
- if (iterator->second->info->loader == "com.sun.star.loader.SharedLibrary" &&
- iterator->second->status != Data::Implementation::STATUS_LOADED)
+ if (rEntry.second->info->loader == "com.sun.star.loader.SharedLibrary" &&
+ rEntry.second->status != Data::Implementation::STATUS_LOADED)
{
// load component library
osl::Module aModule(aUri, SAL_LOADMODULE_NOW | SAL_LOADMODULE_GLOBAL);
@@ -1885,20 +1830,20 @@ void cppuhelper::ServiceManager::preloadImplementations() {
}
if (aModule.is() &&
- !iterator->second->info->environment.isEmpty())
+ !rEntry.second->info->environment.isEmpty())
{
OUString aSymFactory;
oslGenericFunction fpFactory;
css::uno::Environment aTargetEnv;
css::uno::Reference<css::uno::XInterface> xFactory;
- if(iterator->second->info->constructor.isEmpty())
+ if(rEntry.second->info->constructor.isEmpty())
{
// expand full name component factory symbol
- if (iterator->second->info->prefix == "direct")
- aSymFactory = iterator->second->info->name.replace('.', '_') + "_" COMPONENT_GETFACTORY;
- else if (!iterator->second->info->prefix.isEmpty())
- aSymFactory = iterator->second->info->prefix + "_" COMPONENT_GETFACTORY;
+ if (rEntry.second->info->prefix == "direct")
+ aSymFactory = rEntry.second->info->name.replace('.', '_') + "_" COMPONENT_GETFACTORY;
+ else if (!rEntry.second->info->prefix.isEmpty())
+ aSymFactory = rEntry.second->info->prefix + "_" COMPONENT_GETFACTORY;
else
aSymFactory = COMPONENT_GETFACTORY;
@@ -1911,13 +1856,13 @@ void cppuhelper::ServiceManager::preloadImplementations() {
css::uno::Reference<css::uno::XInterface>());
}
- aTargetEnv = cppuhelper::detail::getEnvironment(iterator->second->info->environment, iterator->second->info->name);
+ aTargetEnv = cppuhelper::detail::getEnvironment(rEntry.second->info->environment, rEntry.second->info->name);
component_getFactoryFunc fpComponentFactory = reinterpret_cast<component_getFactoryFunc>(fpFactory);
if (aSourceEnv.get() == aTargetEnv.get())
{
// invoke function component factory
- OString aImpl(OUStringToOString(iterator->second->info->name, RTL_TEXTENCODING_ASCII_US));
+ OString aImpl(OUStringToOString(rEntry.second->info->name, RTL_TEXTENCODING_ASCII_US));
xFactory.set(css::uno::Reference<css::uno::XInterface>(static_cast<css::uno::XInterface *>(
(*fpComponentFactory)(aImpl.getStr(), this, nullptr)), SAL_NO_ACQUIRE));
}
@@ -1925,10 +1870,10 @@ void cppuhelper::ServiceManager::preloadImplementations() {
else
{
// get function symbol component factory
- aTargetEnv = cppuhelper::detail::getEnvironment(iterator->second->info->environment, iterator->second->info->name);
+ aTargetEnv = cppuhelper::detail::getEnvironment(rEntry.second->info->environment, rEntry.second->info->name);
if (aSourceEnv.get() == aTargetEnv.get())
{
- fpFactory = aModule.getFunctionSymbol(iterator->second->info->constructor);
+ fpFactory = aModule.getFunctionSymbol(rEntry.second->info->constructor);
}
else
{
@@ -1949,19 +1894,19 @@ void cppuhelper::ServiceManager::preloadImplementations() {
if (!xSSFactory.is())
{
throw css::uno::DeploymentException(
- ("Implementation " + iterator->second->info->name
+ ("Implementation " + rEntry.second->info->name
+ " does not provide a constructor or factory"),
static_cast< cppu::OWeakObject * >(this));
}
}
}
- if (!iterator->second->info->constructor.isEmpty() && fpFactory)
- iterator->second->constructor = WrapperConstructorFn(reinterpret_cast<ImplementationConstructorFn *>(fpFactory));
+ if (!rEntry.second->info->constructor.isEmpty() && fpFactory)
+ rEntry.second->constructor = WrapperConstructorFn(reinterpret_cast<ImplementationConstructorFn *>(fpFactory));
- iterator->second->factory1 = xSCFactory;
- iterator->second->factory2 = xSSFactory;
- iterator->second->status = Data::Implementation::STATUS_LOADED;
+ rEntry.second->factory1 = xSCFactory;
+ rEntry.second->factory2 = xSSFactory;
+ rEntry.second->status = Data::Implementation::STATUS_LOADED;
}
diff --git a/cppuhelper/source/typemanager.cxx b/cppuhelper/source/typemanager.cxx
index 9faf4d0b2de0..3d4f474f89f0 100644
--- a/cppuhelper/source/typemanager.cxx
+++ b/cppuhelper/source/typemanager.cxx
@@ -494,14 +494,10 @@ InstantiatedPolymorphicStructTypeDescription::getMemberTypes()
for (sal_Int32 i = 0; i != n; ++i) {
OUString type(entity_->getMembers()[i].type);
if (entity_->getMembers()[i].parameterized) {
- for (std::vector< OUString >::const_iterator j(
- entity_->getTypeParameters().begin());
- j != entity_->getTypeParameters().end(); ++j)
- {
- if (*j == type) {
- type = arguments_[j - entity_->getTypeParameters().begin()];
- goto found;
- }
+ auto j = std::find(entity_->getTypeParameters().begin(), entity_->getTypeParameters().end(), type);
+ if (j != entity_->getTypeParameters().end()) {
+ type = arguments_[j - entity_->getTypeParameters().begin()];
+ goto found;
}
assert(false); // this cannot happen //TODO!
found:;
@@ -2247,14 +2243,10 @@ css::uno::Any cppuhelper::TypeManager::getEnumMember(
rtl::Reference< unoidl::EnumTypeEntity > const & entity,
OUString const & member)
{
- for (std::vector< unoidl::EnumTypeEntity::Member >::const_iterator i(
- entity->getMembers().begin());
- i != entity->getMembers().end(); ++i)
- {
- if (i->name == member) {
- return css::uno::makeAny(i->value);
- }
- }
+ auto i = std::find_if(entity->getMembers().begin(), entity->getMembers().end(),
+ [&member](const unoidl::EnumTypeEntity::Member& rMember) { return rMember.name == member; });
+ if (i != entity->getMembers().end())
+ return css::uno::makeAny(i->value);
return css::uno::Any();
}
@@ -2263,16 +2255,12 @@ css::uno::Any cppuhelper::TypeManager::getConstant(
rtl::Reference< unoidl::ConstantGroupEntity > const & entity,
OUString const & member)
{
- for (std::vector< unoidl::ConstantGroupEntity::Member >::const_iterator i(
- entity->getMembers().begin());
- i != entity->getMembers().end(); ++i)
- {
- if (i->name == member) {
- return css::uno::makeAny<
- css::uno::Reference< css::reflection::XTypeDescription > >(
- new ConstantDescription(constantGroupName, *i));
- }
- }
+ auto i = std::find_if(entity->getMembers().begin(), entity->getMembers().end(),
+ [&member](const unoidl::ConstantGroupEntity::Member& rMember) { return rMember.name == member; });
+ if (i != entity->getMembers().end())
+ return css::uno::makeAny<
+ css::uno::Reference< css::reflection::XTypeDescription > >(
+ new ConstantDescription(constantGroupName, *i));
return css::uno::Any();
}
diff --git a/cppuhelper/source/weak.cxx b/cppuhelper/source/weak.cxx
index 57f22880adfc..cfb455f54488 100644
--- a/cppuhelper/source/weak.cxx
+++ b/cppuhelper/source/weak.cxx
@@ -183,14 +183,14 @@ void SAL_CALL OWeakConnectionPoint::removeReference(const Reference< XReference
// Search from end because the thing that last added a ref is most likely to be the
// first to remove a ref.
// It's not really valid to compare the pointer directly, but it's faster.
- for (auto it = m_aReferences.rbegin(); it != m_aReferences.rend(); ++it) {
- if (it->get() == rRef.get()) {
- m_aReferences.erase( it.base()-1 );
- return;
- }
+ auto it = std::find_if(m_aReferences.rbegin(), m_aReferences.rend(),
+ [&rRef](const Reference<XReference>& rxRef) { return rxRef.get() == rRef.get(); });
+ if (it != m_aReferences.rend()) {
+ m_aReferences.erase( it.base()-1 );
+ return;
}
// interface not found, use the correct compare method
- auto it = std::find(m_aReferences.rbegin(), m_aReferences.rend(), rRef);
+ it = std::find(m_aReferences.rbegin(), m_aReferences.rend(), rRef);
if ( it != m_aReferences.rend() )
m_aReferences.erase( it.base()-1 );
}