diff options
author | Arkadiy Illarionov <qarkai@gmail.com> | 2019-03-09 15:54:13 +0300 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-03-09 18:31:12 +0100 |
commit | 31f96c3e0d13180447c45212158ee69e791c645a (patch) | |
tree | 3ec7744b25a3929cafd4bbdffd018a5036055ad7 /connectivity/source | |
parent | 4e25914b165d7ed64b3026af758fb857676aacd5 (diff) |
Simplify containers iterations in connectivity
Use range-based loop or replace with STL functions
Change-Id: I1f7c1ea19cdc8d450b7ed88a663ba9ccb3249304
Reviewed-on: https://gerrit.libreoffice.org/68974
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'connectivity/source')
42 files changed, 341 insertions, 498 deletions
diff --git a/connectivity/source/commontools/DriversConfig.cxx b/connectivity/source/commontools/DriversConfig.cxx index 380fe321930b..e165763d5e5e 100644 --- a/connectivity/source/commontools/DriversConfig.cxx +++ b/connectivity/source/commontools/DriversConfig.cxx @@ -149,15 +149,13 @@ OUString DriversConfig::getDriverFactoryName(const OUString& _sURL) const const TInstalledDrivers& rDrivers = m_aNode->getInstalledDrivers(m_xORB); OUString sRet; OUString sOldPattern; - TInstalledDrivers::const_iterator aIter = rDrivers.begin(); - TInstalledDrivers::const_iterator aEnd = rDrivers.end(); - for(;aIter != aEnd;++aIter) + for(const auto& [rPattern, rDriver] : rDrivers) { - WildCard aWildCard(aIter->first); - if ( sOldPattern.getLength() < aIter->first.getLength() && aWildCard.Matches(_sURL) ) + WildCard aWildCard(rPattern); + if ( sOldPattern.getLength() < rPattern.getLength() && aWildCard.Matches(_sURL) ) { - sRet = aIter->second.sDriverFactory; - sOldPattern = aIter->first; + sRet = rDriver.sDriverFactory; + sOldPattern = rPattern; } } @@ -169,15 +167,13 @@ OUString DriversConfig::getDriverTypeDisplayName(const OUString& _sURL) const const TInstalledDrivers& rDrivers = m_aNode->getInstalledDrivers(m_xORB); OUString sRet; OUString sOldPattern; - TInstalledDrivers::const_iterator aIter = rDrivers.begin(); - TInstalledDrivers::const_iterator aEnd = rDrivers.end(); - for(;aIter != aEnd;++aIter) + for(const auto& [rPattern, rDriver] : rDrivers) { - WildCard aWildCard(aIter->first); - if ( sOldPattern.getLength() < aIter->first.getLength() && aWildCard.Matches(_sURL) ) + WildCard aWildCard(rPattern); + if ( sOldPattern.getLength() < rPattern.getLength() && aWildCard.Matches(_sURL) ) { - sRet = aIter->second.sDriverTypeDisplayName; - sOldPattern = aIter->first; + sRet = rDriver.sDriverTypeDisplayName; + sOldPattern = rPattern; } } @@ -204,26 +200,24 @@ const ::comphelper::NamedValueCollection& DriversConfig::impl_get(const OUString const TInstalledDrivers& rDrivers = m_aNode->getInstalledDrivers(m_xORB); const ::comphelper::NamedValueCollection* pRet = nullptr; OUString sOldPattern; - TInstalledDrivers::const_iterator aIter = rDrivers.begin(); - TInstalledDrivers::const_iterator aEnd = rDrivers.end(); - for(;aIter != aEnd;++aIter) + for(const auto& [rPattern, rDriver] : rDrivers) { - WildCard aWildCard(aIter->first); - if ( sOldPattern.getLength() < aIter->first.getLength() && aWildCard.Matches(_sURL) ) + WildCard aWildCard(rPattern); + if ( sOldPattern.getLength() < rPattern.getLength() && aWildCard.Matches(_sURL) ) { switch(_nProps) { case 0: - pRet = &aIter->second.aFeatures; + pRet = &rDriver.aFeatures; break; case 1: - pRet = &aIter->second.aProperties; + pRet = &rDriver.aProperties; break; case 2: - pRet = &aIter->second.aMetaData; + pRet = &rDriver.aMetaData; break; } - sOldPattern = aIter->first; + sOldPattern = rPattern; } } // for(;aIter != aEnd;++aIter) if ( pRet == nullptr ) diff --git a/connectivity/source/commontools/TTableHelper.cxx b/connectivity/source/commontools/TTableHelper.cxx index a52bb4e97642..b08b33eec751 100644 --- a/connectivity/source/commontools/TTableHelper.cxx +++ b/connectivity/source/commontools/TTableHelper.cxx @@ -221,11 +221,8 @@ namespace // collect all used ordinals std::set< OrdinalPosition > aUsedOrdinals; - for ( std::vector< ColumnDesc >::const_iterator collect = _rColumns.begin(); - collect != _rColumns.end(); - ++collect - ) - aUsedOrdinals.insert( collect->nOrdinalPosition ); + for ( const auto& collect : _rColumns ) + aUsedOrdinals.insert( collect.nOrdinalPosition ); // we need to have as much different ordinals as we have different columns bool bDuplicates = aUsedOrdinals.size() != _rColumns.size(); @@ -239,22 +236,16 @@ namespace OSL_FAIL( "lcl_sanitizeColumnDescs: database did provide invalid ORDINAL_POSITION values!" ); OrdinalPosition nNormalizedPosition = 1; - for ( std::vector< ColumnDesc >::iterator normalize = _rColumns.begin(); - normalize != _rColumns.end(); - ++normalize - ) - normalize->nOrdinalPosition = nNormalizedPosition++; + for ( auto& normalize : _rColumns ) + normalize.nOrdinalPosition = nNormalizedPosition++; return; } // what's left is that the range might not be from 1 to <column count>, but for instance // 0 to <column count>-1. size_t nOffset = *aUsedOrdinals.begin() - 1; - for ( std::vector< ColumnDesc >::iterator offset = _rColumns.begin(); - offset != _rColumns.end(); - ++offset - ) - offset->nOrdinalPosition -= nOffset; + for ( auto& offset : _rColumns ) + offset.nOrdinalPosition -= nOffset; } } @@ -284,11 +275,8 @@ void OTableHelper::refreshColumns() // sort by ordinal position std::map< OrdinalPosition, OUString > aSortedColumns; - for ( std::vector< ColumnDesc >::const_iterator copy = m_pImpl->m_aColumnDesc.begin(); - copy != m_pImpl->m_aColumnDesc.end(); - ++copy - ) - aSortedColumns[ copy->nOrdinalPosition ] = copy->sName; + for (const auto& copy : m_pImpl->m_aColumnDesc) + aSortedColumns[ copy.nOrdinalPosition ] = copy.sName; // copy them to aVector, now that we have the proper ordering std::transform( @@ -308,15 +296,10 @@ void OTableHelper::refreshColumns() const ColumnDesc* OTableHelper::getColumnDescription(const OUString& _sName) const { const ColumnDesc* pRet = nullptr; - std::vector< ColumnDesc >::const_iterator aEnd = m_pImpl->m_aColumnDesc.end(); - for (std::vector< ColumnDesc >::const_iterator aIter = m_pImpl->m_aColumnDesc.begin();aIter != aEnd;++aIter) - { - if ( aIter->sName == _sName ) - { - pRet = &*aIter; - break; - } - } // for (std::vector< ColumnDesc >::const_iterator aIter = m_pImpl->m_aColumnDesc.begin();aIter != aEnd;++aIter) + auto aIter = std::find_if(m_pImpl->m_aColumnDesc.begin(), m_pImpl->m_aColumnDesc.end(), + [&_sName](const ColumnDesc& rColumnDesc) { return rColumnDesc.sName == _sName; }); + if (aIter != m_pImpl->m_aColumnDesc.end()) + pRet = &*aIter; return pRet; } diff --git a/connectivity/source/commontools/dbtools.cxx b/connectivity/source/commontools/dbtools.cxx index b2788d134e0a..af71cb431ed1 100644 --- a/connectivity/source/commontools/dbtools.cxx +++ b/connectivity/source/commontools/dbtools.cxx @@ -1640,15 +1640,14 @@ namespace std::vector<bool, std::allocator<bool> >::const_iterator aIter = m_aSet.begin(); std::vector<bool, std::allocator<bool> >::const_iterator aEnd = m_aSet.end(); sal_Int32 i = 0; - sal_Int32 nParamPos = -1; for(; aIter != aEnd && i <= Index; ++aIter) { - ++nParamPos; if ( !*aIter ) { ++i; } } + auto nParamPos = static_cast<sal_Int32>(std::distance(m_aSet.cbegin(), aIter)) - 1; return m_xSource->getByIndex(nParamPos); } }; @@ -1735,13 +1734,11 @@ void askForParameters(const Reference< XSingleSelectQueryComposer >& _xComposer, xParamColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE)) >>= nScale; // (the index of the parameters is one-based) TParameterPositions::const_iterator aFind = aParameterNames.find(pFinalValues->Name); - std::vector<sal_Int32>::const_iterator aIterPos = aFind->second.begin(); - std::vector<sal_Int32>::const_iterator aEndPos = aFind->second.end(); - for(;aIterPos != aEndPos;++aIterPos) + for(const auto& rItem : aFind->second) { - if ( _aParametersSet.empty() || !_aParametersSet[(*aIterPos)-1] ) + if ( _aParametersSet.empty() || !_aParametersSet[rItem-1] ) { - _xParameters->setObjectWithInfo(*aIterPos, pFinalValues->Value, nParamType, nScale); + _xParameters->setObjectWithInfo(rItem, pFinalValues->Value, nParamType, nScale); } } } diff --git a/connectivity/source/commontools/paramwrapper.cxx b/connectivity/source/commontools/paramwrapper.cxx index 16493fddfe66..57db44200a4e 100644 --- a/connectivity/source/commontools/paramwrapper.cxx +++ b/connectivity/source/commontools/paramwrapper.cxx @@ -203,9 +203,9 @@ namespace param if ( m_xValueDestination.is() ) { - for ( std::vector< sal_Int32 >::const_iterator aIter = m_aIndexes.begin(); aIter != m_aIndexes.end(); ++aIter ) + for ( const auto& rIndex : m_aIndexes ) { - m_xValueDestination->setObjectWithInfo( *aIter + 1, rValue, nParamType, nScale ); + m_xValueDestination->setObjectWithInfo( rIndex + 1, rValue, nParamType, nScale ); // (the index of the parameters is one-based) } } @@ -338,12 +338,9 @@ namespace param ::osl::MutexGuard aGuard( m_aMutex ); impl_checkDisposed_throw(); - for ( Parameters::const_iterator param = m_aParameters.begin(); - param != m_aParameters.end(); - ++param - ) + for (const auto& rxParam : m_aParameters) { - (*param)->dispose(); + rxParam->dispose(); } Parameters aEmpty; diff --git a/connectivity/source/cpool/ZConnectionPool.cxx b/connectivity/source/cpool/ZConnectionPool.cxx index c1c3cf44322e..7ac1845911a1 100644 --- a/connectivity/source/cpool/ZConnectionPool.cxx +++ b/connectivity/source/cpool/ZConnectionPool.cxx @@ -237,13 +237,9 @@ void OConnectionPool::invalidatePooledConnections() aIter->second.aConnections.clear(); // look if the iterator aIter is still present in the active connection map - TActiveConnectionMap::const_iterator aActIter = m_aActiveConnections.begin(); - for (; aActIter != m_aActiveConnections.end(); ++aActIter) - { - if(aIter == aActIter->second.aPos) - break; - } - if(aActIter == m_aActiveConnections.end()) + bool isPresent = std::any_of(m_aActiveConnections.begin(), m_aActiveConnections.end(), + [&aIter](const TActiveConnectionMap::value_type& rEntry) { return rEntry.second.aPos == aIter; }); + if(!isPresent) {// he isn't so we can delete him aIter = m_aPool.erase(aIter); } diff --git a/connectivity/source/cpool/ZPoolCollection.cxx b/connectivity/source/cpool/ZPoolCollection.cxx index 86393c6319ce..7ae66038bdf7 100644 --- a/connectivity/source/cpool/ZPoolCollection.cxx +++ b/connectivity/source/cpool/ZPoolCollection.cxx @@ -181,15 +181,12 @@ Reference< XDriver > SAL_CALL OPoolCollection::getDriverByURL( const OUString& _ { Reference< XDriver > xExistentProxy; // look if we already have a proxy for this driver - for ( MapDriver2DriverRef::const_iterator aLookup = m_aDriverProxies.begin(); - aLookup != m_aDriverProxies.end(); - ++aLookup - ) + for (const auto& [rxDriver, rxDriverRef] : m_aDriverProxies) { // hold the proxy alive as long as we're in this loop round - xExistentProxy = aLookup->second; + xExistentProxy = rxDriverRef; - if (xExistentProxy.is() && (aLookup->first.get() == xDriver.get())) + if (xExistentProxy.is() && (rxDriver.get() == xDriver.get())) // already created a proxy for this break; } @@ -284,11 +281,9 @@ bool OPoolCollection::isPoolingEnabledByUrl(const OUString& _sUrl, void OPoolCollection::clearConnectionPools(bool _bDispose) { - OConnectionPools::const_iterator aIter = m_aPools.begin(); - while(aIter != m_aPools.end()) + for(auto& rEntry : m_aPools) { - aIter->second->clear(_bDispose); - ++aIter; + rEntry.second->clear(_bDispose); } m_aPools.clear(); } @@ -442,10 +437,9 @@ void SAL_CALL OPoolCollection::propertyChange( const css::beans::PropertyChangeE { m_aDriverProxies.clear(); m_aDriverProxies = MapDriver2DriverRef(); - OConnectionPools::iterator aIter = m_aPools.begin(); - for(;aIter != m_aPools.end();++aIter) + for(auto& rEntry : m_aPools) { - aIter->second->clear(false); + rEntry.second->clear(false); } m_aPools.clear(); } diff --git a/connectivity/source/drivers/ado/AConnection.cxx b/connectivity/source/drivers/ado/AConnection.cxx index 049989f44786..32e0bcd4d2b6 100644 --- a/connectivity/source/drivers/ado/AConnection.cxx +++ b/connectivity/source/drivers/ado/AConnection.cxx @@ -476,9 +476,8 @@ void OConnection::disposing() m_pAdoConnection->Close(); - OTypeInfoMap::iterator aIter = m_aTypeInfo.begin(); - for (; aIter != m_aTypeInfo.end(); ++aIter) - delete aIter->second; + for (auto& rEntry : m_aTypeInfo) + delete rEntry.second; m_aTypeInfo.clear(); diff --git a/connectivity/source/drivers/ado/ADriver.cxx b/connectivity/source/drivers/ado/ADriver.cxx index 934c3a2a47ea..69381285eb7d 100644 --- a/connectivity/source/drivers/ado/ADriver.cxx +++ b/connectivity/source/drivers/ado/ADriver.cxx @@ -66,9 +66,9 @@ void ODriver::disposing() ::osl::MutexGuard aGuard(m_aMutex); - for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i) + for (auto& rxConnection : m_xConnections) { - Reference< XComponent > xComp(i->get(), UNO_QUERY); + Reference< XComponent > xComp(rxConnection.get(), UNO_QUERY); if (xComp.is()) xComp->dispose(); } @@ -204,15 +204,11 @@ Reference< XTablesSupplier > SAL_CALL ODriver::getDataDefinitionByConnection( co { OConnection* pSearchConnection = reinterpret_cast< OConnection* >( xTunnel->getSomething(OConnection::getUnoTunnelImplementationId()) ); - for (OWeakRefArray::const_iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i) - { - if (static_cast<OConnection*>(Reference< XConnection >::query(i->get().get()).get()) == pSearchConnection) - { - pConnection = pSearchConnection; - break; - } - } - + auto foundConnection = std::any_of(m_xConnections.begin(), m_xConnections.end(), + [&pSearchConnection](const css::uno::WeakReferenceHelper& rxConnection) { + return static_cast<OConnection*>(Reference< XConnection >::query(rxConnection.get().get()).get()) == pSearchConnection; }); + if (foundConnection) + pConnection = pSearchConnection; } Reference< XTablesSupplier > xTab; diff --git a/connectivity/source/drivers/ado/AStatement.cxx b/connectivity/source/drivers/ado/AStatement.cxx index f2ed68a78070..01fea934cd19 100644 --- a/connectivity/source/drivers/ado/AStatement.cxx +++ b/connectivity/source/drivers/ado/AStatement.cxx @@ -34,6 +34,7 @@ #undef max #include <algorithm> +#include <numeric> using namespace ::comphelper; @@ -348,10 +349,9 @@ Sequence< sal_Int32 > SAL_CALL OStatement::executeBatch( ) reset(); - OUString aBatchSql; - sal_Int32 nLen = 0; - for(std::vector< OUString>::const_iterator i=m_aBatchVector.begin();i != m_aBatchVector.end();++i,++nLen) - aBatchSql = aBatchSql + *i + ";"; + OUString aBatchSql = std::accumulate(m_aBatchVector.begin(), m_aBatchVector.end(), OUString(), + [](const OUString& rRes, const OUString& rStr) { return rRes + rStr + ";"; }); + sal_Int32 nLen = m_aBatchVector.size(); if ( m_RecordSet.IsValid() ) diff --git a/connectivity/source/drivers/calc/CTable.cxx b/connectivity/source/drivers/calc/CTable.cxx index 72997c72c615..850b20475507 100644 --- a/connectivity/source/drivers/calc/CTable.cxx +++ b/connectivity/source/drivers/calc/CTable.cxx @@ -645,11 +645,8 @@ bool OCalcTable::fetchRow( OValueRefRow& _rRow, const OSQLColumns & _rCols, // fields - OSQLColumns::Vector::const_iterator aIter = _rCols.get().begin(); - OSQLColumns::Vector::const_iterator aEnd = _rCols.get().end(); - const OValueRefVector::Vector::size_type nCount = _rRow->get().size(); - for (OValueRefVector::Vector::size_type i = 1; aIter != aEnd && i < nCount; - ++aIter, i++) + const OValueRefVector::Vector::size_type nCount = std::min(_rRow->get().size(), _rCols.get().size() + 1); + for (OValueRefVector::Vector::size_type i = 1; i < nCount; i++) { if ( (_rRow->get())[i]->isBound() ) { diff --git a/connectivity/source/drivers/component/CTable.cxx b/connectivity/source/drivers/component/CTable.cxx index c02635bf1fc1..b260843b7c16 100644 --- a/connectivity/source/drivers/component/CTable.cxx +++ b/connectivity/source/drivers/component/CTable.cxx @@ -83,9 +83,8 @@ void OComponentTable::refreshColumns() ::std::vector< OUString> aVector; - OSQLColumns::Vector::const_iterator aEnd = m_aColumns->get().end(); - for(OSQLColumns::Vector::const_iterator aIter = m_aColumns->get().begin();aIter != aEnd;++aIter) - aVector.push_back(Reference< XNamed>(*aIter,UNO_QUERY)->getName()); + for(const auto& rxColumn : m_aColumns->get()) + aVector.push_back(Reference< XNamed>(rxColumn,UNO_QUERY)->getName()); if(m_xColumns) m_xColumns->reFill(aVector); diff --git a/connectivity/source/drivers/dbase/DTable.cxx b/connectivity/source/drivers/dbase/DTable.cxx index b23ec40e3204..4139f35acb24 100644 --- a/connectivity/source/drivers/dbase/DTable.cxx +++ b/connectivity/source/drivers/dbase/DTable.cxx @@ -1568,16 +1568,13 @@ bool ODbaseTable::DeleteRow(const OSQLColumns& _rCols) ODbaseIndex* pIndex = reinterpret_cast< ODbaseIndex* >( xTunnel->getSomething(ODbaseIndex::getUnoTunnelImplementationId()) ); OSL_ENSURE(pIndex,"ODbaseTable::DeleteRow: No Index returned!"); - OSQLColumns::Vector::const_iterator aIter = _rCols.get().begin(); - sal_Int32 nPos = 1; - for(;aIter != _rCols.get().end();++aIter,++nPos) - { - if(aCase(getString((*aIter)->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME))),aColName)) - break; - } + OSQLColumns::Vector::const_iterator aIter = std::find_if(_rCols.get().begin(), _rCols.get().end(), + [&aCase, &aColName](const OSQLColumns::Vector::value_type& rxCol) { + return aCase(getString(rxCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME))), aColName); }); if (aIter == _rCols.get().end()) continue; + auto nPos = static_cast<sal_Int32>(std::distance(_rCols.get().begin(), aIter)) + 1; pIndex->Delete(m_nFilePos,*(aRow->get())[nPos]); } } diff --git a/connectivity/source/drivers/evoab2/NDriver.cxx b/connectivity/source/drivers/evoab2/NDriver.cxx index 79a42103c01e..c0e37f9f7beb 100644 --- a/connectivity/source/drivers/evoab2/NDriver.cxx +++ b/connectivity/source/drivers/evoab2/NDriver.cxx @@ -55,9 +55,9 @@ void OEvoabDriver::disposing() ::osl::MutexGuard aGuard(m_aMutex); // when driver will be destroyed so all our connections have to be destroyed as well - for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i) + for (auto& rxConnection : m_xConnections) { - Reference< XComponent > xComp(i->get(), UNO_QUERY); + Reference< XComponent > xComp(rxConnection.get(), UNO_QUERY); if (xComp.is()) { try diff --git a/connectivity/source/drivers/evoab2/NResultSet.cxx b/connectivity/source/drivers/evoab2/NResultSet.cxx index 7681ded2da34..38c51fa89375 100644 --- a/connectivity/source/drivers/evoab2/NResultSet.cxx +++ b/connectivity/source/drivers/evoab2/NResultSet.cxx @@ -313,12 +313,9 @@ static int CompareContacts( gconstpointer _lhs, gconstpointer _rhs, gpointer _us bool bLhs(false), bRhs(false); const ComparisonData& rCompData = *static_cast< const ComparisonData* >( _userData ); - for ( SortDescriptor::const_iterator sortCol = rCompData.rSortOrder.begin(); - sortCol != rCompData.rSortOrder.end(); - ++sortCol - ) + for ( const auto& sortCol : rCompData.rSortOrder ) { - sal_Int32 nField = sortCol->nField; + sal_Int32 nField = sortCol.nField; GType eFieldType = evoab::getGFieldType( nField ); bool success = getValue( lhs, nField, eFieldType, &aLhsValue, bLhsNull ) diff --git a/connectivity/source/drivers/evoab2/NResultSetMetaData.cxx b/connectivity/source/drivers/evoab2/NResultSetMetaData.cxx index 2d201c4be8cf..7d9f0d152d76 100644 --- a/connectivity/source/drivers/evoab2/NResultSetMetaData.cxx +++ b/connectivity/source/drivers/evoab2/NResultSetMetaData.cxx @@ -41,14 +41,13 @@ OEvoabResultSetMetaData::~OEvoabResultSetMetaData() void OEvoabResultSetMetaData::setEvoabFields(const ::rtl::Reference<connectivity::OSQLColumns> &xColumns) { - OSQLColumns::Vector::const_iterator aIter; static const char aName[] = "Name"; - for (aIter = xColumns->get().begin(); aIter != xColumns->get().end(); ++aIter) + for (const auto& rxColumn : xColumns->get()) { OUString aFieldName; - (*aIter)->getPropertyValue(aName) >>= aFieldName; + rxColumn->getPropertyValue(aName) >>= aFieldName; guint nFieldNumber = findEvoabField(aFieldName); if (nFieldNumber == guint(-1)) { diff --git a/connectivity/source/drivers/file/FResultSet.cxx b/connectivity/source/drivers/file/FResultSet.cxx index fe8f8f4d79ba..d1f7bedd9151 100644 --- a/connectivity/source/drivers/file/FResultSet.cxx +++ b/connectivity/source/drivers/file/FResultSet.cxx @@ -1323,17 +1323,12 @@ void OResultSet::OpenImpl() nKey = (m_pFileSet->get())[j-1]; ExecuteRow(IResultSetHelper::BOOKMARK,nKey,false); m_pSQLAnalyzer->setSelectionEvaluationResult(m_aSelectRow,m_aColMapping); - OValueRefVector::Vector::const_iterator loopInRow = m_aSelectRow->get().begin(); - OValueVector::Vector::const_iterator existentInSearchRow = aSearchRow->get().begin(); - for ( ++loopInRow,++existentInSearchRow; // the first column is the bookmark column - loopInRow != m_aSelectRow->get().end(); - ++loopInRow,++existentInSearchRow) - { - if ( (*loopInRow)->isBound() && !( *(*loopInRow) == *existentInSearchRow) ) - break; - } + auto rowsMismatchIters = std::mismatch(std::next(m_aSelectRow->get().begin()), m_aSelectRow->get().end(), + std::next(aSearchRow->get().begin()), // the first column is the bookmark column + [](const OValueRefVector::Vector::value_type& a, const OValueVector::Vector::value_type& b) { + return !a->isBound() || (*a == b); }); - if(loopInRow == m_aSelectRow->get().end()) + if(rowsMismatchIters.first == m_aSelectRow->get().end()) (m_pFileSet->get())[j] = 0; // Rows match -- Mark for deletion by setting key to 0 #if OSL_DEBUG_LEVEL > 1 else @@ -1341,8 +1336,7 @@ void OResultSet::OpenImpl() #endif } - m_pFileSet->get().erase(std::remove_if(m_pFileSet->get().begin(),m_pFileSet->get().end(), - [](sal_Int32 n) { return n == 0; }) + m_pFileSet->get().erase(std::remove(m_pFileSet->get().begin(),m_pFileSet->get().end(),0) ,m_pFileSet->get().end()); } } @@ -1551,18 +1545,17 @@ void OResultSet::doTableSpecials(const OSQLTable& _xTable) void OResultSet::clearInsertRow() { m_aRow->setDeleted(false); // set to false here because this is the new row - OValueRefVector::Vector::iterator aIter = m_aInsertRow->get().begin(); - const OValueRefVector::Vector::const_iterator aEnd = m_aInsertRow->get().end(); - for(sal_Int32 nPos = 0;aIter != aEnd;++aIter,++nPos) + sal_Int32 nPos = 0; + for(ORowSetValueDecoratorRef& rValue : m_aInsertRow->get()) { - ORowSetValueDecoratorRef& rValue = *aIter; if ( rValue->isBound() ) { - (m_aRow->get())[nPos]->setValue( (*aIter)->getValue() ); + (m_aRow->get())[nPos]->setValue( rValue->getValue() ); } rValue->setBound(nPos == 0); rValue->setModified(false); rValue->setNull(); + ++nPos; } } diff --git a/connectivity/source/drivers/file/FStringFunctions.cxx b/connectivity/source/drivers/file/FStringFunctions.cxx index 27dbdbfcc695..c8d9977472a6 100644 --- a/connectivity/source/drivers/file/FStringFunctions.cxx +++ b/connectivity/source/drivers/file/FStringFunctions.cxx @@ -99,13 +99,9 @@ ORowSetValue OOp_Concat::operate(const std::vector<ORowSetValue>& lhs) const ORowSetValue OOp_Locate::operate(const std::vector<ORowSetValue>& lhs) const { - std::vector<ORowSetValue>::const_iterator aIter = lhs.begin(); - std::vector<ORowSetValue>::const_iterator aEnd = lhs.end(); - for (; aIter != aEnd; ++aIter) - { - if ( aIter->isNull() ) - return ORowSetValue(); - } + if (std::any_of(lhs.begin(), lhs.end(), [](const ORowSetValue& rValue) { return rValue.isNull(); })) + return ORowSetValue(); + if ( lhs.size() == 2 ) return OUString::number(lhs[0].getString().indexOf(lhs[1].getString())+1); @@ -117,13 +113,9 @@ ORowSetValue OOp_Locate::operate(const std::vector<ORowSetValue>& lhs) const ORowSetValue OOp_SubString::operate(const std::vector<ORowSetValue>& lhs) const { - std::vector<ORowSetValue>::const_iterator aIter = lhs.begin(); - std::vector<ORowSetValue>::const_iterator aEnd = lhs.end(); - for (; aIter != aEnd; ++aIter) - { - if ( aIter->isNull() ) - return ORowSetValue(); - } + if (std::any_of(lhs.begin(), lhs.end(), [](const ORowSetValue& rValue) { return rValue.isNull(); })) + return ORowSetValue(); + if ( lhs.size() == 2 && static_cast<sal_Int32>(lhs[0]) >= sal_Int32(0) ) return lhs[1].getString().copy(static_cast<sal_Int32>(lhs[0])-1); diff --git a/connectivity/source/drivers/file/fcode.cxx b/connectivity/source/drivers/file/fcode.cxx index 52c6099f9442..90b7bbdd8c43 100644 --- a/connectivity/source/drivers/file/fcode.cxx +++ b/connectivity/source/drivers/file/fcode.cxx @@ -355,12 +355,10 @@ void ONthOperator::Exec(OCodeStack& rCodeStack) rCodeStack.push(new OOperandResult(operate(aValues))); - std::vector<OOperand*>::iterator aIter = aOperands.begin(); - std::vector<OOperand*>::const_iterator aEnd = aOperands.end(); - for (; aIter != aEnd; ++aIter) + for (auto& rpOperand : aOperands) { - if (typeid(OOperandResult) == typeid(*(*aIter))) - delete *aIter; + if (typeid(OOperandResult) == typeid(*rpOperand)) + delete rpOperand; } } diff --git a/connectivity/source/drivers/hsqldb/HDriver.cxx b/connectivity/source/drivers/hsqldb/HDriver.cxx index a6ee1e714b62..4e495204e75a 100644 --- a/connectivity/source/drivers/hsqldb/HDriver.cxx +++ b/connectivity/source/drivers/hsqldb/HDriver.cxx @@ -109,9 +109,9 @@ namespace connectivity try { - for (TWeakPairVector::iterator i = m_aConnections.begin(); m_aConnections.end() != i; ++i) + for (auto& rConnection : m_aConnections) { - Reference<XInterface > xTemp = i->first.get(); + Reference<XInterface > xTemp = rConnection.first.get(); ::comphelper::disposeComponent(xTemp); } } @@ -451,18 +451,16 @@ namespace connectivity Reference< XTablesSupplier > xTab; - TWeakPairVector::const_iterator aEnd = m_aConnections.end(); - for (TWeakPairVector::iterator i = m_aConnections.begin(); aEnd != i; ++i) + TWeakPairVector::iterator i = std::find_if(m_aConnections.begin(), m_aConnections.end(), + [&connection](const TWeakPairVector::value_type& rConnection) { + return rConnection.second.second.first.get() == connection.get(); }); + if (i != m_aConnections.end()) { - if ( i->second.second.first.get() == connection.get() ) + xTab.set(i->second.second.second.get().get(),UNO_QUERY); + if ( !xTab.is() ) { - xTab.set(i->second.second.second.get().get(),UNO_QUERY); - if ( !xTab.is() ) - { - xTab = new OHCatalog(connection); - i->second.second.second = WeakReferenceHelper(xTab); - } - break; + xTab = new OHCatalog(connection); + i->second.second.second = WeakReferenceHelper(xTab); } } @@ -559,15 +557,11 @@ namespace connectivity Reference<XConnection> xCon(Source.Source,UNO_QUERY); if ( xCon.is() ) { - TWeakPairVector::iterator i = m_aConnections.begin(); - for (; m_aConnections.end() != i; ++i) - { - if ( i->first.get() == xCon.get() ) - { - shutdownConnection(i); - break; - } - } + TWeakPairVector::iterator i = std::find_if(m_aConnections.begin(), m_aConnections.end(), + [&xCon](const TWeakPairVector::value_type& rConnection) { return rConnection.first.get() == xCon.get(); }); + + if (i != m_aConnections.end()) + shutdownConnection(i); } else { @@ -589,12 +583,11 @@ namespace connectivity void ODriverDelegator::shutdownConnections() { m_bInShutDownConnections = true; - TWeakPairVector::const_iterator aEnd = m_aConnections.end(); - for (TWeakPairVector::iterator i = m_aConnections.begin(); aEnd != i; ++i) + for (auto& rConnection : m_aConnections) { try { - Reference<XConnection> xCon(i->first,UNO_QUERY); + Reference<XConnection> xCon(rConnection.first,UNO_QUERY); ::comphelper::disposeComponent(xCon); } catch(Exception&) @@ -607,12 +600,11 @@ namespace connectivity void ODriverDelegator::flushConnections() { - TWeakPairVector::const_iterator aEnd = m_aConnections.end(); - for (TWeakPairVector::iterator i = m_aConnections.begin(); aEnd != i; ++i) + for (auto& rConnection : m_aConnections) { try { - Reference<XFlushable> xCon(i->second.second.first.get(),UNO_QUERY); + Reference<XFlushable> xCon(rConnection.second.second.first.get(),UNO_QUERY); if (xCon.is()) xCon->flush(); } diff --git a/connectivity/source/drivers/jdbc/DatabaseMetaData.cxx b/connectivity/source/drivers/jdbc/DatabaseMetaData.cxx index 62d41a42d7e0..2422f44bd299 100644 --- a/connectivity/source/drivers/jdbc/DatabaseMetaData.cxx +++ b/connectivity/source/drivers/jdbc/DatabaseMetaData.cxx @@ -466,15 +466,13 @@ Reference< XResultSet > SAL_CALL java_sql_DatabaseMetaData::getTablePrivileges( ODatabaseMetaDataResultSet::ORow aRow(8); while ( xRow.is() && xTemp->next() ) { - std::map<sal_Int32,sal_Int32>::const_iterator aIter = aColumnMatching.begin(); - std::map<sal_Int32,sal_Int32>::const_iterator aEnd = aColumnMatching.end(); - for (;aIter != aEnd ; ++aIter) + for (const auto& [nCol, nPriv] : aColumnMatching) { - sValue = xRow->getString(aIter->first); + sValue = xRow->getString(nCol); if ( xRow->wasNull() ) - aRow[aIter->second] = ODatabaseMetaDataResultSet::getEmptyValue(); + aRow[nPriv] = ODatabaseMetaDataResultSet::getEmptyValue(); else - aRow[aIter->second] = new ORowSetValueDecorator(sValue); + aRow[nPriv] = new ORowSetValueDecorator(sValue); } aRows.push_back(aRow); diff --git a/connectivity/source/drivers/macab/MacabAddressBook.cxx b/connectivity/source/drivers/macab/MacabAddressBook.cxx index 93795cbc7d89..46570ef5ff57 100644 --- a/connectivity/source/drivers/macab/MacabAddressBook.cxx +++ b/connectivity/source/drivers/macab/MacabAddressBook.cxx @@ -93,14 +93,8 @@ MacabAddressBook::~MacabAddressBook() m_xMacabRecords = nullptr; } - if(!m_xMacabGroups.empty()) - { - std::vector<MacabGroup *>::iterator iter, end; - iter = m_xMacabGroups.begin(); - end = m_xMacabGroups.end(); - for( ; iter != end; ++iter) - delete *iter; - } + for(MacabGroup* pMacabGroup : m_xMacabGroups) + delete pMacabGroup; m_bRetrievedGroups = false; } diff --git a/connectivity/source/drivers/macab/MacabConnection.cxx b/connectivity/source/drivers/macab/MacabConnection.cxx index e55d342584d8..e52edf085412 100644 --- a/connectivity/source/drivers/macab/MacabConnection.cxx +++ b/connectivity/source/drivers/macab/MacabConnection.cxx @@ -259,9 +259,9 @@ void MacabConnection::disposing() // we noticed that we should be destroyed in near future so we have to dispose our statements ::osl::MutexGuard aGuard(m_aMutex); - for (OWeakRefArray::iterator i = m_aStatements.begin(); m_aStatements.end() != i; ++i) + for (auto& rxStatement : m_aStatements) { - Reference< XComponent > xComp(i->get(), UNO_QUERY); + Reference< XComponent > xComp(rxStatement.get(), UNO_QUERY); if (xComp.is()) xComp->dispose(); } diff --git a/connectivity/source/drivers/macab/MacabDriver.cxx b/connectivity/source/drivers/macab/MacabDriver.cxx index c1252c8bc1e5..73629973434e 100644 --- a/connectivity/source/drivers/macab/MacabDriver.cxx +++ b/connectivity/source/drivers/macab/MacabDriver.cxx @@ -204,9 +204,9 @@ void MacabDriver::disposing() ::osl::MutexGuard aGuard(m_aMutex); // when driver will be destroyed so all our connections have to be destroyed as well - for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i) + for (auto& rxConnection : m_xConnections) { - Reference< XComponent > xComp(i->get(), UNO_QUERY); + Reference< XComponent > xComp(rxConnection.get(), UNO_QUERY); if (xComp.is()) xComp->dispose(); } diff --git a/connectivity/source/drivers/macab/MacabResultSetMetaData.cxx b/connectivity/source/drivers/macab/MacabResultSetMetaData.cxx index f3f2d5483f4f..e5a851d69dd2 100644 --- a/connectivity/source/drivers/macab/MacabResultSetMetaData.cxx +++ b/connectivity/source/drivers/macab/MacabResultSetMetaData.cxx @@ -43,7 +43,6 @@ MacabResultSetMetaData::~MacabResultSetMetaData() void MacabResultSetMetaData::setMacabFields(const ::rtl::Reference<connectivity::OSQLColumns> &xColumns) { - OSQLColumns::Vector::const_iterator aIter; static const char aName[] = "Name"; MacabRecords *aRecords; MacabHeader *aHeader; @@ -58,12 +57,12 @@ void MacabResultSetMetaData::setMacabFields(const ::rtl::Reference<connectivity: aHeader = aRecords->getHeader(); - for (aIter = xColumns->get().begin(); aIter != xColumns->get().end(); ++aIter) + for (const auto& rxColumn : xColumns->get()) { OUString aFieldName; sal_uInt32 nFieldNumber; - (*aIter)->getPropertyValue(aName) >>= aFieldName; + rxColumn->getPropertyValue(aName) >>= aFieldName; nFieldNumber = aHeader->getColumnNumber(aFieldName); m_aMacabFields.push_back(nFieldNumber); } diff --git a/connectivity/source/drivers/mork/MColumnAlias.cxx b/connectivity/source/drivers/mork/MColumnAlias.cxx index b564cc93eb1e..a5b178d47178 100644 --- a/connectivity/source/drivers/mork/MColumnAlias.cxx +++ b/connectivity/source/drivers/mork/MColumnAlias.cxx @@ -92,32 +92,30 @@ void OColumnAlias::initialize( const css::uno::Reference< css::lang::XMultiServi comphelper::getComponentContext(_rxORB)), UNO_QUERY_THROW); Sequence< OUString > aProgrammaticNames(xAliasesNode->getElementNames()); - for (sal_Int32 i = 0; i != aProgrammaticNames.getLength(); ++i) { + for (const auto& rProgrammaticName : aProgrammaticNames) { OString sAsciiProgrammaticName( OUStringToOString( - aProgrammaticNames[i], RTL_TEXTENCODING_ASCII_US)); - bool bFound = false; - for (AliasMap::const_iterator j(m_aAliasMap.begin()); j != m_aAliasMap.end(); - ++j) - { - if (j->second.programmaticAsciiName == sAsciiProgrammaticName) { - OUString sAssignedAlias; - xAliasesNode->getByName(aProgrammaticNames[i]) >>= - sAssignedAlias; - if (sAssignedAlias.isEmpty()) { - sAssignedAlias = aProgrammaticNames[i]; - } - AliasEntry entry(j->second); - m_aAliasMap.erase(j); - m_aAliasMap[sAssignedAlias] = entry; - bFound = true; - break; + rProgrammaticName, RTL_TEXTENCODING_ASCII_US)); + auto j = std::find_if(m_aAliasMap.begin(), m_aAliasMap.end(), + [&sAsciiProgrammaticName](const AliasMap::value_type& rEntry) { + return rEntry.second.programmaticAsciiName == sAsciiProgrammaticName; }); + if (j != m_aAliasMap.end()) { + OUString sAssignedAlias; + xAliasesNode->getByName(rProgrammaticName) >>= + sAssignedAlias; + if (sAssignedAlias.isEmpty()) { + sAssignedAlias = rProgrammaticName; } + AliasEntry entry(j->second); + m_aAliasMap.erase(j); + m_aAliasMap[sAssignedAlias] = entry; + } + else { + SAL_WARN( + "connectivity.mork", + "unknown programmatic name " << rProgrammaticName + <<" from configuration"); } - SAL_WARN_IF( - !bFound, "connectivity.mork", - "unknown programmatic name " << aProgrammaticNames[i] - <<" from configuration"); } } diff --git a/connectivity/source/drivers/mork/MConnection.cxx b/connectivity/source/drivers/mork/MConnection.cxx index 0ca4b1712ea9..954812fe9242 100644 --- a/connectivity/source/drivers/mork/MConnection.cxx +++ b/connectivity/source/drivers/mork/MConnection.cxx @@ -136,14 +136,13 @@ void OConnection::construct(const OUString& url) // check that we can retrieve the tables: MorkTableMap *Tables = m_pBook->getTables( defaultScope ); - MorkTableMap::Map::const_iterator tableIter; if (Tables) { // Iterate all tables - for ( tableIter = Tables->map.begin(); tableIter != Tables->map.end(); ++tableIter ) + for ( const auto& rEntry : Tables->map ) { - if ( 0 == tableIter->first ) continue; - SAL_INFO("connectivity.mork", "table->first : " << tableIter->first); + if ( 0 == rEntry.first ) continue; + SAL_INFO("connectivity.mork", "table->first : " << rEntry.first); } } // check that we can retrieve the history tables: @@ -151,10 +150,10 @@ void OConnection::construct(const OUString& url) if (Tables_hist) { // Iterate all tables - for ( tableIter = Tables_hist->map.begin(); tableIter != Tables_hist->map.end(); ++tableIter ) + for ( const auto& rEntry : Tables_hist->map ) { - if ( 0 == tableIter->first ) continue; - SAL_INFO("connectivity.mork", "table->first : " << tableIter->first); + if ( 0 == rEntry.first ) continue; + SAL_INFO("connectivity.mork", "table->first : " << rEntry.first); } } } diff --git a/connectivity/source/drivers/mork/MDatabaseMetaData.cxx b/connectivity/source/drivers/mork/MDatabaseMetaData.cxx index 49103220a76a..104a89c2d8c4 100644 --- a/connectivity/source/drivers/mork/MDatabaseMetaData.cxx +++ b/connectivity/source/drivers/mork/MDatabaseMetaData.cxx @@ -110,19 +110,16 @@ ODatabaseMetaDataResultSet::ORows ODatabaseMetaData::getColumnRows( SAL_INFO("connectivity.mork", "\tTableName = : " << table); // Iterate over all columns in the table. - for ( OColumnAlias::AliasMap::const_iterator compare = colNames.begin(); - compare != colNames.end(); - ++compare - ) + for (const auto& [rName, rAlias] : colNames) { - if ( match( columnNamePattern, compare->first, '\0' ) ) + if ( match( columnNamePattern, rName, '\0' ) ) { - SAL_INFO("connectivity.mork", "\t\tColumnNam : " << compare->first); + SAL_INFO("connectivity.mork", "\t\tColumnNam : " << rName); // COLUMN_NAME - aRow[4] = new ORowSetValueDecorator( compare->first ); + aRow[4] = new ORowSetValueDecorator( rName ); // ORDINAL_POSITION - aRow[17] = new ORowSetValueDecorator( static_cast< sal_Int32 >( compare->second.columnPosition ) + 1 ); + aRow[17] = new ORowSetValueDecorator( static_cast< sal_Int32 >( rAlias.columnPosition ) + 1 ); aRows.push_back(aRow); } } diff --git a/connectivity/source/drivers/mork/MResultSet.cxx b/connectivity/source/drivers/mork/MResultSet.cxx index bd280b10b558..3ece446530f6 100644 --- a/connectivity/source/drivers/mork/MResultSet.cxx +++ b/connectivity/source/drivers/mork/MResultSet.cxx @@ -943,14 +943,15 @@ void OResultSet::fillRowData() OSL_ENSURE(m_xColumns.is(), "Need the Columns!!"); - OSQLColumns::Vector::const_iterator aIter = m_xColumns->get().begin(); const OUString sPropertyName = OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME); OUString sName; - for (sal_Int32 i = 1; aIter != m_xColumns->get().end();++aIter, i++) + sal_Int32 i = 1; + for (const auto& rxColumn : m_xColumns->get()) { - (*aIter)->getPropertyValue(sPropertyName) >>= sName; + rxColumn->getPropertyValue(sPropertyName) >>= sName; SAL_INFO( "connectivity.mork", "Query Columns : (" << i << ") " << sName); + i++; } // Generate Match Conditions for Query @@ -992,21 +993,9 @@ void OResultSet::fillRowData() static bool matchRow( OValueRow const & row1, OValueRow const & row2 ) { - OValueVector::Vector::const_iterator row1Iter = row1->get().begin(); - OValueVector::Vector::const_iterator row2Iter = row2->get().begin(); - for ( ++row1Iter,++row2Iter; // the first column is the bookmark column - row1Iter != row1->get().end(); ++row1Iter,++row2Iter) - { - if ( row1Iter->isBound()) - { - // Compare values, if at anytime there's a mismatch return false - if ( *row1Iter != *row2Iter ) - return false; - } - } - - // If we get to here the rows match - return true; + // the first column is the bookmark column + return std::equal(std::next(row1->get().begin()), row1->get().end(), std::next(row2->get().begin()), + [](const ORowSetValue& a, const ORowSetValue& b) { return !a.isBound() || a == b; }); } sal_Int32 OResultSet::getRowForCardNumber(sal_Int32 nCardNum) @@ -1077,15 +1066,15 @@ void OResultSet::executeQuery() } OSortIndex::TKeyTypeVector eKeyType(m_aOrderbyColumnNumber.size()); - std::vector<sal_Int32>::const_iterator aOrderByIter = m_aOrderbyColumnNumber.begin(); - for ( std::vector<sal_Int16>::size_type i = 0; aOrderByIter != m_aOrderbyColumnNumber.end(); ++aOrderByIter,++i) + std::vector<sal_Int16>::size_type index = 0; + for (const auto& rColIndex : m_aOrderbyColumnNumber) { - OSL_ENSURE(static_cast<sal_Int32>(m_aRow->get().size()) > *aOrderByIter,"Invalid Index"); - switch ((m_aRow->get().begin()+*aOrderByIter)->getTypeKind()) + OSL_ENSURE(static_cast<sal_Int32>(m_aRow->get().size()) > rColIndex,"Invalid Index"); + switch ((m_aRow->get().begin()+rColIndex)->getTypeKind()) { case DataType::CHAR: case DataType::VARCHAR: - eKeyType[i] = OKeyType::String; + eKeyType[index] = OKeyType::String; break; case DataType::OTHER: @@ -1100,15 +1089,16 @@ void OResultSet::executeQuery() case DataType::TIME: case DataType::TIMESTAMP: case DataType::BIT: - eKeyType[i] = OKeyType::Double; + eKeyType[index] = OKeyType::Double; break; // Other types aren't implemented (so they are always FALSE) default: - eKeyType[i] = OKeyType::NONE; + eKeyType[index] = OKeyType::NONE; OSL_FAIL("MResultSet::executeQuery: Order By Data Type not implemented"); break; } + ++index; } if (IsSorted()) @@ -1131,14 +1121,13 @@ void OResultSet::executeQuery() std::unique_ptr<OKeyValue> pKeyValue = OKeyValue::createKeyValue(nRow); - std::vector<sal_Int32>::const_iterator aIter = m_aOrderbyColumnNumber.begin(); - for (;aIter != m_aOrderbyColumnNumber.end(); ++aIter) + for (const auto& rColIndex : m_aOrderbyColumnNumber) { - const ORowSetValue& value = getValue(nRow, *aIter); + const ORowSetValue& value = getValue(nRow, rColIndex); SAL_INFO( "connectivity.mork", - "Adding Value: (" << nRow << "," << *aIter + "Adding Value: (" << nRow << "," << rColIndex << ") : " << value.getString()); pKeyValue->pushKey(new ORowSetValueDecorator(value)); @@ -1235,19 +1224,16 @@ void OResultSet::setBoundedColumns(const OValueRow& _rRow, // look if we have such a select column // TODO: would like to have a O(log n) search here ... sal_Int32 nColumnPos = 0; - for ( OSQLColumns::Vector::const_iterator aIter = _rxColumns->get().begin(); - aIter != _rxColumns->get().end(); - ++aIter,++nColumnPos - ) + for (const auto& rxColumn : _rxColumns->get()) { if ( nColumnPos < static_cast<sal_Int32>(aColumnNames.size()) ) sSelectColumnRealName = aColumnNames[nColumnPos]; else { - if((*aIter)->getPropertySetInfo()->hasPropertyByName(sRealName)) - (*aIter)->getPropertyValue(sRealName) >>= sSelectColumnRealName; + if(rxColumn->getPropertySetInfo()->hasPropertyByName(sRealName)) + rxColumn->getPropertyValue(sRealName) >>= sSelectColumnRealName; else - (*aIter)->getPropertyValue(sName) >>= sSelectColumnRealName; + rxColumn->getPropertyValue(sName) >>= sSelectColumnRealName; aColumnNames.push_back(sSelectColumnRealName); } @@ -1255,7 +1241,7 @@ void OResultSet::setBoundedColumns(const OValueRow& _rRow, { if(_bSetColumnMapping) { - sal_Int32 nSelectColumnPos = static_cast<sal_Int32>(aIter - _rxColumns->get().begin() + 1); + sal_Int32 nSelectColumnPos = nColumnPos + 1; // the getXXX methods are 1-based ... sal_Int32 nTableColumnPos = i + 1; // get first table column is the bookmark column @@ -1270,6 +1256,8 @@ void OResultSet::setBoundedColumns(const OValueRow& _rRow, aRowIter->setBound(true); aRowIter->setTypeKind(DataType::VARCHAR); } + + ++nColumnPos; } } catch (Exception&) diff --git a/connectivity/source/drivers/mork/MStatement.cxx b/connectivity/source/drivers/mork/MStatement.cxx index 63f78e36805c..447facf4f879 100644 --- a/connectivity/source/drivers/mork/MStatement.cxx +++ b/connectivity/source/drivers/mork/MStatement.cxx @@ -135,7 +135,7 @@ OCommonStatement::StatementType OCommonStatement::parseSql( const OUString& sql // at this moment we support only one table per select statement - OSL_ENSURE( rTabs.begin() != rTabs.end(), "Need a Table"); + OSL_ENSURE( !rTabs.empty(), "Need a Table"); m_pTable = static_cast< OTable* > (rTabs.begin()->second.get()); m_xColNames = m_pTable->getColumns(); diff --git a/connectivity/source/drivers/mork/MorkParser.cxx b/connectivity/source/drivers/mork/MorkParser.cxx index 676488cb209d..60fec845815f 100644 --- a/connectivity/source/drivers/mork/MorkParser.cxx +++ b/connectivity/source/drivers/mork/MorkParser.cxx @@ -599,35 +599,27 @@ void MorkParser::retrieveLists(std::set<std::string>& lists) MorkTableMap* tables = getTables(defaultScope_); if (!tables) return; - for (MorkTableMap::Map::iterator TableIter = tables->map.begin(); - TableIter != tables->map.end(); ++TableIter ) + for (auto& rTable : tables->map) { #ifdef VERBOSE std::cout << "\t Table:" - << ( ( int ) TableIter->first < 0 ? "-" : " " ) - << TableIter->first << std::endl; + << ( ( int ) rTable.first < 0 ? "-" : " " ) + << rTable.first << std::endl; #endif - MorkRowMap* rows = getRows( 0x81/*defaultListScope*/, &TableIter->second ); + MorkRowMap* rows = getRows( 0x81/*defaultListScope*/, &rTable.second ); if (!rows) return; - for ( MorkRowMap::Map::const_iterator RowIter = rows->map.begin(); - RowIter != rows->map.end(); ++RowIter ) + for ( const auto& rRow : rows->map ) { #ifdef VERBOSE std::cout << "\t\t\t Row Id:" - << ( ( int ) RowIter->first < 0 ? "-" : " ") - << RowIter->first << std::endl; + << ( ( int ) rRow.first < 0 ? "-" : " ") + << rRow.first << std::endl; std::cout << "\t\t\t\t Cells:\r\n"; #endif // Get cells - for ( MorkCells::const_iterator cellsIter = RowIter->second.begin(); - cellsIter != RowIter->second.end(); ++cellsIter ) - { - if (cellsIter->first == 0xC1) - { - lists.insert(getValue( cellsIter->second )); - break; - } - } + MorkCells::const_iterator cellsIter = rRow.second.find(0xC1); + if (cellsIter != rRow.second.end()) + lists.insert(getValue( cellsIter->second )); } } } @@ -641,41 +633,38 @@ void MorkParser::getRecordKeysForListTable(std::string const & listName, std::se MorkTableMap* tables = getTables(defaultScope_); if (!tables) return; - for (MorkTableMap::Map::iterator TableIter = tables->map.begin(); - TableIter != tables->map.end(); ++TableIter ) + for (auto& rTable : tables->map) { #ifdef VERBOSE std::cout << "\t Table:" - << ( ( int ) TableIter->first < 0 ? "-" : " " ) - << TableIter->first << std::endl; + << ( ( int ) rTable.first < 0 ? "-" : " " ) + << rTable.first << std::endl; #endif - MorkRowMap* rows = getRows( 0x81, &TableIter->second ); + MorkRowMap* rows = getRows( 0x81, &rTable.second ); if (!rows) return; - for ( MorkRowMap::Map::const_iterator RowIter = rows->map.begin(); - RowIter != rows->map.end(); ++RowIter ) + for ( const auto& rRow : rows->map ) { #ifdef VERBOSE std::cout << "\t\t\t Row Id:" - << ( ( int ) RowIter->first < 0 ? "-" : " ") - << RowIter->first << std::endl; + << ( ( int ) rRow.first < 0 ? "-" : " ") + << rRow.first << std::endl; std::cout << "\t\t\t\t Cells:\r\n"; #endif // Get cells bool isListFound = false; - for ( MorkCells::const_iterator cellsIter = RowIter->second.begin(); - cellsIter != RowIter->second.end(); ++cellsIter ) + for ( const auto& [rColumnId, rValueId] : rRow.second ) { if (isListFound) { - if (cellsIter->first >= 0xC7) + if (rColumnId >= 0xC7) { - std::string value = getValue(cellsIter->second); + std::string value = getValue(rValueId); int id = strtoul(value.c_str(), nullptr, 16); records.insert(id); } } - else if ((cellsIter->first == 0xC1) && - listName == getValue( cellsIter->second )) + else if ((rColumnId == 0xC1) && + listName == getValue( rValueId )) { isListFound = true; } @@ -694,12 +683,11 @@ void MorkParser::dump() std::cout << "=============================================\r\n\r\n"; //// columns dict - for ( MorkDict::const_iterator iter = columns_.begin(); - iter != columns_.end(); ++iter ) + for ( const auto& [rColumnId, rText] : columns_ ) { - std::cout << iter->first + std::cout << rColumnId << " : " - << iter->second + << rText << std::endl; } @@ -707,16 +695,15 @@ void MorkParser::dump() std::cout << "\r\nValues Dict:\r\n"; std::cout << "=============================================\r\n\r\n"; - for ( MorkDict::const_iterator iter = values_.begin(); - iter != values_.end(); ++iter ) + for ( const auto& [rValueId, rText] : values_ ) { - if (iter->first >= nextAddValueId_) { + if (rValueId >= nextAddValueId_) { continue; } - std::cout << iter->first + std::cout << rValueId << " : " - << iter->second + << rText << "\r\n"; } @@ -725,47 +712,42 @@ void MorkParser::dump() << std::endl << std::endl; //// Mork data - for ( TableScopeMap::Map::const_iterator iter = mork_.map.begin(); - iter != mork_.map.end(); ++iter ) + for ( const auto& [rTableScopeId, rTableScope] : mork_.map ) { - std::cout << "\r\n Scope:" << iter->first << std::endl; + std::cout << "\r\n Scope:" << rTableScopeId << std::endl; - for ( MorkTableMap::Map::const_iterator TableIter = iter->second.map.begin(); - TableIter != iter->second.map.end(); ++TableIter ) + for ( const auto& [rTableId, rTable] : rTableScope.map ) { std::cout << "\t Table:" - << ( TableIter->first < 0 ? "-" : " " ) - << TableIter->first << std::endl; + << ( rTableId < 0 ? "-" : " " ) + << rTableId << std::endl; - for (RowScopeMap::Map::const_iterator RowScopeIter = TableIter->second.map.begin(); - RowScopeIter != TableIter->second.map.end(); ++RowScopeIter ) + for (const auto& [rRowScopeId, rRowScope] : rTable.map) { std::cout << "\t\t RowScope:" - << RowScopeIter->first << std::endl; + << rRowScopeId << std::endl; - for (MorkRowMap::Map::const_iterator RowIter = RowScopeIter->second.map.begin(); - RowIter != RowScopeIter->second.map.end(); ++RowIter ) + for (const auto& [rRowId, rRow] : rRowScope.map) { std::cout << "\t\t\t Row Id:" - << (RowIter->first < 0 ? "-" : " ") - << RowIter->first << std::endl; + << (rRowId < 0 ? "-" : " ") + << rRowId << std::endl; std::cout << "\t\t\t\t Cells:" << std::endl; - for (MorkCells::const_iterator CellsIter = RowIter->second.begin(); - CellsIter != RowIter->second.end(); ++CellsIter ) + for (const auto& [rColumnId, rValueId] : rRow) { // Write ids std::cout << "\t\t\t\t\t" - << CellsIter->first + << rColumnId << " : " - << CellsIter->second + << rValueId << " => "; - MorkDict::const_iterator FoundIter = values_.find( CellsIter->second ); + MorkDict::const_iterator FoundIter = values_.find( rValueId ); if ( FoundIter != values_.end() ) { // Write string values - std::cout << columns_[ CellsIter->first ].c_str() + std::cout << columns_[ rColumnId ].c_str() << " : " << FoundIter->second.c_str() << std::endl; diff --git a/connectivity/source/drivers/mozab/bootstrap/MNSProfileDiscover.cxx b/connectivity/source/drivers/mozab/bootstrap/MNSProfileDiscover.cxx index e3996f067c7f..b34eaafc3e46 100644 --- a/connectivity/source/drivers/mozab/bootstrap/MNSProfileDiscover.cxx +++ b/connectivity/source/drivers/mozab/bootstrap/MNSProfileDiscover.cxx @@ -75,37 +75,33 @@ namespace connectivity IniParser parser( profilesIni ); IniSectionMap &rAllSection = parser.getAllSection(); - IniSectionMap::iterator iBegin = rAllSection.begin(); - IniSectionMap::const_iterator iEnd = rAllSection.end(); - for(;iBegin != iEnd;++iBegin) + for(auto& rSection : rAllSection) { - ini_Section *aSection = &(*iBegin).second; + ini_Section *aSection = &rSection.second; OUString profileName; OUString profilePath; OUString sIsRelative; OUString sIsDefault; - for(NameValueVector::iterator itor=aSection->vVector.begin(); - itor != aSection->vVector.end(); - ++itor) + for(auto& rValue : aSection->vVector) { - struct ini_NameValue * aValue = &(*itor); - if ( aValue->sName == "Name" ) - { - profileName = aValue->sValue; - } - else if ( aValue->sName == "IsRelative" ) - { - sIsRelative = aValue->sValue; - } - else if ( aValue->sName == "Path" ) - { - profilePath = aValue->sValue; - } - else if ( aValue->sName == "Default" ) - { - sIsDefault = aValue->sValue; - } + struct ini_NameValue * aValue = &rValue; + if ( aValue->sName == "Name" ) + { + profileName = aValue->sValue; + } + else if ( aValue->sName == "IsRelative" ) + { + sIsRelative = aValue->sValue; + } + else if ( aValue->sName == "Path" ) + { + profilePath = aValue->sValue; + } + else if ( aValue->sName == "Default" ) + { + sIsDefault = aValue->sValue; + } } if (!(profileName.isEmpty() && profilePath.isEmpty())) { @@ -165,11 +161,9 @@ namespace connectivity ProductStruct &rProduct = m_ProductProfileList[index]; list.realloc(static_cast<sal_Int32>(rProduct.mProfileList.size())); sal_Int32 i=0; - for(ProfileList::const_iterator itor=rProduct.mProfileList.begin(); - itor != rProduct.mProfileList.end(); - ++itor) + for(const auto& rEntry : rProduct.mProfileList) { - const ProfileStruct& rProfile = (*itor).second; + const ProfileStruct& rProfile = rEntry.second; list[i] = rProfile.getProfileName(); i++; } diff --git a/connectivity/source/drivers/mysql_jdbc/YDriver.cxx b/connectivity/source/drivers/mysql_jdbc/YDriver.cxx index b6345f401615..1f6b595cec03 100644 --- a/connectivity/source/drivers/mysql_jdbc/YDriver.cxx +++ b/connectivity/source/drivers/mysql_jdbc/YDriver.cxx @@ -70,10 +70,8 @@ ODriverDelegator::~ODriverDelegator() { ::comphelper::disposeComponent(m_xODBCDriver); ::comphelper::disposeComponent(m_xNativeDriver); - TJDBCDrivers::iterator aIter = m_aJdbcDrivers.begin(); - TJDBCDrivers::const_iterator aEnd = m_aJdbcDrivers.end(); - for (; aIter != aEnd; ++aIter) - ::comphelper::disposeComponent(aIter->second); + for (auto& rEntry : m_aJdbcDrivers) + ::comphelper::disposeComponent(rEntry.second); } catch (const Exception&) { @@ -350,37 +348,37 @@ ODriverDelegator::getDataDefinitionByConnection(const Reference<XConnection>& co xTunnel->getSomething(OMetaConnection::getUnoTunnelImplementationId())); if (pConnection) { - TWeakPairVector::const_iterator aEnd = m_aConnections.end(); - for (TWeakPairVector::iterator i = m_aConnections.begin(); aEnd != i; ++i) + TWeakPairVector::iterator i + = std::find_if(m_aConnections.begin(), m_aConnections.end(), + [&pConnection](const TWeakPairVector::value_type& rConnection) { + return rConnection.second.second == pConnection; + }); + if (i != m_aConnections.end()) { - if (i->second.second == pConnection) + xTab.set(i->second.first.get().get(), UNO_QUERY); + if (!xTab.is()) { - xTab.set(i->second.first.get().get(), UNO_QUERY); - if (!xTab.is()) - { - xTab = new OMySQLCatalog(connection); - i->second.first = WeakReferenceHelper(xTab); - } - break; + xTab = new OMySQLCatalog(connection); + i->second.first = WeakReferenceHelper(xTab); } } } } // if ( xTunnel.is() ) if (!xTab.is()) { - TWeakPairVector::const_iterator aEnd = m_aConnections.end(); - for (TWeakPairVector::iterator i = m_aConnections.begin(); aEnd != i; ++i) + TWeakPairVector::iterator i + = std::find_if(m_aConnections.begin(), m_aConnections.end(), + [&connection](const TWeakPairVector::value_type& rConnection) { + Reference<XConnection> xTemp(rConnection.first.get(), UNO_QUERY); + return xTemp == connection; + }); + if (i != m_aConnections.end()) { - Reference<XConnection> xTemp(i->first.get(), UNO_QUERY); - if (xTemp == connection) + xTab.set(i->second.first.get().get(), UNO_QUERY); + if (!xTab.is()) { - xTab.set(i->second.first.get().get(), UNO_QUERY); - if (!xTab.is()) - { - xTab = new OMySQLCatalog(connection); - i->second.first = WeakReferenceHelper(xTab); - } - break; + xTab = new OMySQLCatalog(connection); + i->second.first = WeakReferenceHelper(xTab); } } } diff --git a/connectivity/source/drivers/mysqlc/mysqlc_databasemetadata.cxx b/connectivity/source/drivers/mysqlc/mysqlc_databasemetadata.cxx index 890f31de666a..3bdc27e7744b 100644 --- a/connectivity/source/drivers/mysqlc/mysqlc_databasemetadata.cxx +++ b/connectivity/source/drivers/mysqlc/mysqlc_databasemetadata.cxx @@ -28,6 +28,7 @@ #include <com/sun/star/sdbc/BestRowScope.hpp> #include <com/sun/star/sdbc/ColumnType.hpp> #include <com/sun/star/lang/XInitialization.hpp> +#include <comphelper/sequence.hxx> #include <sal/log.hxx> #include <rtl/ustrbuf.hxx> @@ -56,16 +57,14 @@ static void lcl_setRows_throw(const Reference<XResultSet>& _xResultSet, sal_Int3 Sequence<Sequence<Any>> aRows(_rRows.size()); - std::vector<std::vector<Any>>::const_iterator aIter = _rRows.begin(); Sequence<Any>* pRowsIter = aRows.getArray(); - Sequence<Any>* pRowsEnd = pRowsIter + aRows.getLength(); - for (; pRowsIter != pRowsEnd; ++pRowsIter, ++aIter) + for (const auto& rRow : _rRows) { - if (!aIter->empty()) + if (!rRow.empty()) { - Sequence<Any> aSeq(&(*aIter->begin()), aIter->size()); - (*pRowsIter) = aSeq; + (*pRowsIter) = comphelper::containerToSequence(rRow); } + ++pRowsIter; } aArgs[1] <<= aRows; xIni->initialize(aArgs); diff --git a/connectivity/source/drivers/odbc/OResultSet.cxx b/connectivity/source/drivers/odbc/OResultSet.cxx index d343ed9fbee1..ea89c75de684 100644 --- a/connectivity/source/drivers/odbc/OResultSet.cxx +++ b/connectivity/source/drivers/odbc/OResultSet.cxx @@ -192,60 +192,58 @@ SQLRETURN OResultSet::unbind(bool _bUnbindHandle) if ( !m_aBindVector.empty() ) { - TVoidVector::iterator pValue = m_aBindVector.begin(); - TVoidVector::const_iterator pEnd = m_aBindVector.end(); - for(; pValue != pEnd; ++pValue) + for(auto& [rPtrAddr, rType] : m_aBindVector) { - switch (pValue->second) + switch (rType) { case DataType::CHAR: case DataType::VARCHAR: - delete static_cast< OString* >(reinterpret_cast< void * >(pValue->first)); + delete static_cast< OString* >(reinterpret_cast< void * >(rPtrAddr)); break; case DataType::BIGINT: - delete static_cast< sal_Int64* >(reinterpret_cast< void * >(pValue->first)); + delete static_cast< sal_Int64* >(reinterpret_cast< void * >(rPtrAddr)); break; case DataType::DECIMAL: case DataType::NUMERIC: - delete static_cast< OString* >(reinterpret_cast< void * >(pValue->first)); + delete static_cast< OString* >(reinterpret_cast< void * >(rPtrAddr)); break; case DataType::REAL: case DataType::DOUBLE: - delete static_cast< double* >(reinterpret_cast< void * >(pValue->first)); + delete static_cast< double* >(reinterpret_cast< void * >(rPtrAddr)); break; case DataType::LONGVARCHAR: case DataType::CLOB: - delete [] static_cast< char* >(reinterpret_cast< void * >(pValue->first)); + delete [] static_cast< char* >(reinterpret_cast< void * >(rPtrAddr)); break; case DataType::LONGVARBINARY: case DataType::BLOB: - delete [] static_cast< char* >(reinterpret_cast< void * >(pValue->first)); + delete [] static_cast< char* >(reinterpret_cast< void * >(rPtrAddr)); break; case DataType::DATE: - delete static_cast< DATE_STRUCT* >(reinterpret_cast< void * >(pValue->first)); + delete static_cast< DATE_STRUCT* >(reinterpret_cast< void * >(rPtrAddr)); break; case DataType::TIME: - delete static_cast< TIME_STRUCT* >(reinterpret_cast< void * >(pValue->first)); + delete static_cast< TIME_STRUCT* >(reinterpret_cast< void * >(rPtrAddr)); break; case DataType::TIMESTAMP: - delete static_cast< TIMESTAMP_STRUCT* >(reinterpret_cast< void * >(pValue->first)); + delete static_cast< TIMESTAMP_STRUCT* >(reinterpret_cast< void * >(rPtrAddr)); break; case DataType::BIT: case DataType::TINYINT: - delete static_cast< sal_Int8* >(reinterpret_cast< void * >(pValue->first)); + delete static_cast< sal_Int8* >(reinterpret_cast< void * >(rPtrAddr)); break; case DataType::SMALLINT: - delete static_cast< sal_Int16* >(reinterpret_cast< void * >(pValue->first)); + delete static_cast< sal_Int16* >(reinterpret_cast< void * >(rPtrAddr)); break; case DataType::INTEGER: - delete static_cast< sal_Int32* >(reinterpret_cast< void * >(pValue->first)); + delete static_cast< sal_Int32* >(reinterpret_cast< void * >(rPtrAddr)); break; case DataType::FLOAT: - delete static_cast< float* >(reinterpret_cast< void * >(pValue->first)); + delete static_cast< float* >(reinterpret_cast< void * >(rPtrAddr)); break; case DataType::BINARY: case DataType::VARBINARY: - delete static_cast< sal_Int8* >(reinterpret_cast< void * >(pValue->first)); + delete static_cast< sal_Int8* >(reinterpret_cast< void * >(rPtrAddr)); break; } } @@ -402,10 +400,9 @@ void OResultSet::ensureCacheForColumn(sal_Int32 columnIndex) } void OResultSet::invalidateCache() { - const TDataRow::const_iterator end = m_aRow.end(); - for(TDataRow::iterator i=m_aRow.begin(); i!=end; ++i) + for(auto& rItem : m_aRow) { - i->setBound(false); + rItem.setBound(false); } } @@ -953,16 +950,10 @@ void SAL_CALL OResultSet::deleteRow( ) m_bRowDeleted = ( m_pRowStatusArray[0] == SQL_ROW_DELETED ); if ( m_bRowDeleted ) { - TBookmarkPosMap::iterator aIter = m_aPosToBookmarks.begin(); - TBookmarkPosMap::const_iterator aEnd = m_aPosToBookmarks.end(); - for (; aIter != aEnd; ++aIter) - { - if ( aIter->second == nPos ) - { - m_aPosToBookmarks.erase(aIter); - break; - } - } + TBookmarkPosMap::iterator aIter = std::find_if(m_aPosToBookmarks.begin(), m_aPosToBookmarks.end(), + [&nPos](const TBookmarkPosMap::value_type& rEntry) { return rEntry.second == nPos; }); + if (aIter != m_aPosToBookmarks.end()) + m_aPosToBookmarks.erase(aIter); } if ( m_pSkipDeletedSet ) m_pSkipDeletedSet->deletePosition(nPos); @@ -1652,13 +1643,10 @@ bool OResultSet::move(IResultSetHelper::Movement _eCursorPosition, sal_Int32 _nO break; case IResultSetHelper::BOOKMARK: // special case here because we are only called with position numbers { - TBookmarkPosMap::const_iterator aIter = m_aPosToBookmarks.begin(); - TBookmarkPosMap::const_iterator aEnd = m_aPosToBookmarks.end(); - for (; aIter != aEnd; ++aIter) - { - if ( aIter->second == _nOffset ) - return moveToBookmark(makeAny(aIter->first)); - } + TBookmarkPosMap::const_iterator aIter = std::find_if(m_aPosToBookmarks.begin(), m_aPosToBookmarks.end(), + [&_nOffset](const TBookmarkPosMap::value_type& rEntry) { return rEntry.second == _nOffset; }); + if (aIter != m_aPosToBookmarks.end()) + return moveToBookmark(makeAny(aIter->first)); SAL_WARN( "connectivity.odbc", "Bookmark not found!"); } return false; diff --git a/connectivity/source/drivers/postgresql/pq_connection.cxx b/connectivity/source/drivers/postgresql/pq_connection.cxx index 0e196d302e6d..74afc570154d 100644 --- a/connectivity/source/drivers/postgresql/pq_connection.cxx +++ b/connectivity/source/drivers/postgresql/pq_connection.cxx @@ -403,12 +403,13 @@ public: ~cstr_vector () { OSL_ENSURE(values.size() == acquired.size(), "pq_connection: cstr_vector values and acquired size mismatch"); - std::vector<char*>::iterator pv = values.begin(); std::vector<bool>::const_iterator pa = acquired.begin(); - const std::vector<char*>::const_iterator pve = values.end(); - for( ; pv != pve ; ++pv, ++pa ) + for( const auto& v : values ) + { if (*pa) - free(*pv); + free(v); + ++pa; + } } void push_back(const char* s, __sal_NoAcquire) { diff --git a/connectivity/source/drivers/postgresql/pq_statement.cxx b/connectivity/source/drivers/postgresql/pq_statement.cxx index 471bded3330c..773ca6ba66bc 100644 --- a/connectivity/source/drivers/postgresql/pq_statement.cxx +++ b/connectivity/source/drivers/postgresql/pq_statement.cxx @@ -739,7 +739,7 @@ Reference< XResultSet > getGeneratedValuesFromLastInsert( // check, if a column of the primary key was not inserted explicitly, if( !bColumnMatchNamedValue ) { - if( autoValues.begin() == autoValues.end() ) + if( autoValues.empty() ) { getAutoValues( autoValues, connection, schemaName, tableName ); } diff --git a/connectivity/source/drivers/postgresql/pq_xcontainer.cxx b/connectivity/source/drivers/postgresql/pq_xcontainer.cxx index f38ab65e112b..3163c662ad3c 100644 --- a/connectivity/source/drivers/postgresql/pq_xcontainer.cxx +++ b/connectivity/source/drivers/postgresql/pq_xcontainer.cxx @@ -162,13 +162,10 @@ Any Container::getByName( const OUString& aName ) Sequence< OUString > Container::getElementNames( ) { Sequence< OUString > ret( m_values.size() ); - for( String2IntMap::const_iterator ii = m_name2index.begin(); - ii != m_name2index.end() ; - ++ ii ) + for( const auto& [rName, rIndex] : m_name2index ) { // give element names in index order ! - ret[ii->second] = ii->first; -// ret[i] = ii->first; + ret[rIndex] = rName; } return ret; } @@ -308,16 +305,12 @@ void Container::dropByIndex( sal_Int32 index ) } OUString name; - for( String2IntMap::iterator ii = m_name2index.begin() ; - ii != m_name2index.end() ; - ++ ii ) + String2IntMap::iterator ii = std::find_if(m_name2index.begin(), m_name2index.end(), + [&index](const String2IntMap::value_type& rEntry) { return rEntry.second == index; }); + if (ii != m_name2index.end()) { - if( ii->second == index ) - { - name = ii->first; - m_name2index.erase( ii ); - break; - } + name = ii->first; + m_name2index.erase( ii ); } for( int i = index +1 ; i < static_cast<int>(m_values.size()) ; i ++ ) @@ -325,15 +318,11 @@ void Container::dropByIndex( sal_Int32 index ) m_values[i-1] = m_values[i]; // I know, this is expensive, but don't want to maintain another map ... - for( String2IntMap::iterator ii = m_name2index.begin() ; - ii != m_name2index.end() ; - ++ ii ) + ii = std::find_if(m_name2index.begin(), m_name2index.end(), + [&i](const String2IntMap::value_type& rEntry) { return rEntry.second == i; }); + if (ii != m_name2index.end()) { - if( ii->second == i ) - { - ii->second = i-1; - break; - } + ii->second = i-1; } } m_values.resize( m_values.size() - 1 ); diff --git a/connectivity/source/drivers/writer/WTable.cxx b/connectivity/source/drivers/writer/WTable.cxx index 445ec79bc6da..75778eb939e7 100644 --- a/connectivity/source/drivers/writer/WTable.cxx +++ b/connectivity/source/drivers/writer/WTable.cxx @@ -249,10 +249,9 @@ bool OWriterTable::fetchRow(OValueRefRow& _rRow, const OSQLColumns& _rCols, bool // fields - auto aIter = _rCols.get().begin(); - auto aEnd = _rCols.get().end(); - const OValueRefVector::Vector::size_type nCount = _rRow->get().size(); - for (OValueRefVector::Vector::size_type i = 1; aIter != aEnd && i < nCount; ++aIter, i++) + const OValueRefVector::Vector::size_type nCount + = std::min(_rRow->get().size(), _rCols.get().size() + 1); + for (OValueRefVector::Vector::size_type i = 1; i < nCount; i++) { if ((_rRow->get())[i]->isBound()) { diff --git a/connectivity/source/manager/mdrivermanager.cxx b/connectivity/source/manager/mdrivermanager.cxx index b1824d338efb..2a1a31f9d575 100644 --- a/connectivity/source/manager/mdrivermanager.cxx +++ b/connectivity/source/manager/mdrivermanager.cxx @@ -349,18 +349,18 @@ void OSDBCDriverManager::initializeDriverPrecedence() // sort our bootstrapped drivers std::sort( m_aDriversBS.begin(), m_aDriversBS.end(), CompareDriverAccessByName() ); - // loop through the names in the precedence order - const OUString* pDriverOrder = aDriverOrder.getConstArray(); - const OUString* pDriverOrderEnd = pDriverOrder + aDriverOrder.getLength(); - // the first driver for which there is no preference DriverAccessArray::iterator aNoPrefDriversStart = m_aDriversBS.begin(); // at the moment this is the first of all drivers we know - for ( ; ( pDriverOrder < pDriverOrderEnd ) && ( aNoPrefDriversStart != m_aDriversBS.end() ); ++pDriverOrder ) + // loop through the names in the precedence order + for ( const OUString& rDriverOrder : aDriverOrder ) { + if (aNoPrefDriversStart == m_aDriversBS.end()) + break; + DriverAccess driver_order; - driver_order.sImplementationName = *pDriverOrder; + driver_order.sImplementationName = rDriverOrder; // look for the impl name in the DriverAccess array std::pair< DriverAccessArray::iterator, DriverAccessArray::iterator > aPos = diff --git a/connectivity/source/parse/sqlnode.cxx b/connectivity/source/parse/sqlnode.cxx index b4890a25b46d..82b8c75b60e7 100644 --- a/connectivity/source/parse/sqlnode.cxx +++ b/connectivity/source/parse/sqlnode.cxx @@ -2401,13 +2401,13 @@ OSQLParseNode* OSQLParseNode::replace(OSQLParseNode* pOldSubNode, OSQLParseNode* pOldSubNode->setParent( nullptr ); pNewSubNode->setParent( this ); - for (auto it = m_aChildren.begin(); it != m_aChildren.end(); ++it) - if (it->get() == pOldSubNode) - { - it->release(); - it->reset(pNewSubNode); - break; - } + auto it = std::find_if(m_aChildren.begin(), m_aChildren.end(), + [&pOldSubNode](const std::unique_ptr<OSQLParseNode>& rxChild) { return rxChild.get() == pOldSubNode; }); + if (it != m_aChildren.end()) + { + it->release(); + it->reset(pNewSubNode); + } return pOldSubNode; } diff --git a/connectivity/source/resource/sharedresources.cxx b/connectivity/source/resource/sharedresources.cxx index 0beba630a76f..a5841ef3952a 100644 --- a/connectivity/source/resource/sharedresources.cxx +++ b/connectivity/source/resource/sharedresources.cxx @@ -175,10 +175,8 @@ namespace connectivity const std::vector< std::pair<const sal_Char* , OUString > >& _rStringToSubstitutes) const { OUString sString( SharedResources_Impl::getInstance().getResourceString(pResId) ); - std::vector< std::pair<const sal_Char* , OUString > >::const_iterator aIter = _rStringToSubstitutes.begin(); - std::vector< std::pair<const sal_Char* , OUString > >::const_iterator aEnd = _rStringToSubstitutes.end(); - for(;aIter != aEnd; ++aIter) - OSL_VERIFY( lcl_substitute( sString, aIter->first, aIter->second ) ); + for(const auto& [rPattern, rReplace] : _rStringToSubstitutes) + OSL_VERIFY( lcl_substitute( sString, rPattern, rReplace ) ); return sString; } diff --git a/connectivity/source/sdbcx/VCollection.cxx b/connectivity/source/sdbcx/VCollection.cxx index f620f5ebdf50..e9a6ab922521 100644 --- a/connectivity/source/sdbcx/VCollection.cxx +++ b/connectivity/source/sdbcx/VCollection.cxx @@ -139,9 +139,11 @@ namespace Sequence< OUString > aNameList(m_aElements.size()); OUString* pStringArray = aNameList.getArray(); - typename std::vector< ObjectIter >::const_iterator aEnd = m_aElements.end(); - for(typename std::vector< ObjectIter >::const_iterator aIter = m_aElements.begin(); aIter != aEnd;++aIter,++pStringArray) - *pStringArray = (*aIter)->first; + for(const auto& rIter : m_aElements) + { + *pStringArray = rIter->first; + ++pStringArray; + } return aNameList; } |