summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArkadiy Illarionov <qarkai@gmail.com>2019-02-24 17:09:03 +0300
committerNoel Grandin <noel.grandin@collabora.co.uk>2019-02-25 08:06:57 +0100
commit435b64ecb6289a5ebfb8474f81dac032aaccfa4c (patch)
treeb105af973d612852dded93c5ed07ca4600ecd332
parent970ca8de0be4c4cd9485170f3c56a34b4069eec2 (diff)
Simplify containers iterations in dbaccess
Use range-based loop or replace with STL functions Change-Id: I01b4d97fa77ef8daf88e8e006b9523a6b71786cf Reviewed-on: https://gerrit.libreoffice.org/68286 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--dbaccess/source/core/api/KeySet.cxx8
-rw-r--r--dbaccess/source/core/api/RowSet.cxx32
-rw-r--r--dbaccess/source/core/api/RowSetCache.cxx108
-rw-r--r--dbaccess/source/core/dataaccess/ModelImpl.cxx13
-rw-r--r--dbaccess/source/core/dataaccess/bookmarkcontainer.cxx15
-rw-r--r--dbaccess/source/core/dataaccess/datasource.cxx2
-rw-r--r--dbaccess/source/core/misc/DatabaseDataProvider.cxx4
-rw-r--r--dbaccess/source/filter/xml/xmlTableFilterList.cxx5
-rw-r--r--dbaccess/source/filter/xml/xmlfilter.cxx3
-rw-r--r--dbaccess/source/ui/browser/genericcontroller.cxx31
-rw-r--r--dbaccess/source/ui/dlg/DbAdminImpl.cxx2
-rw-r--r--dbaccess/source/ui/dlg/dbfindex.cxx31
-rw-r--r--dbaccess/source/ui/dlg/generalpage.cxx8
-rw-r--r--dbaccess/source/ui/dlg/indexdialog.cxx18
-rw-r--r--dbaccess/source/ui/dlg/indexfieldscontrol.cxx9
-rw-r--r--dbaccess/source/ui/misc/indexcollection.cxx36
-rw-r--r--dbaccess/source/ui/querydesign/JAccess.cxx4
-rw-r--r--dbaccess/source/ui/querydesign/JoinTableView.cxx7
-rw-r--r--dbaccess/source/ui/querydesign/QueryTableView.cxx12
-rw-r--r--dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx14
-rw-r--r--dbaccess/source/ui/tabledesign/TEditControl.cxx9
-rw-r--r--dbaccess/source/ui/tabledesign/TableController.cxx56
-rw-r--r--dbaccess/source/ui/tabledesign/TableUndo.cxx10
23 files changed, 160 insertions, 277 deletions
diff --git a/dbaccess/source/core/api/KeySet.cxx b/dbaccess/source/core/api/KeySet.cxx
index e10d51f50326..f057b3de14e6 100644
--- a/dbaccess/source/core/api/KeySet.cxx
+++ b/dbaccess/source/core/api/KeySet.cxx
@@ -1080,8 +1080,8 @@ bool OKeySet::absolute_checked( sal_Int32 row, bool /* i_bFetchRow */ )
if(!m_bRowCountFinal)
bFetchedRow = fillAllRows();
- for(;row < 0 && m_aKeyIter != m_aKeyMap.begin();++row)
- --m_aKeyIter;
+ row = std::min(std::abs(row), static_cast<sal_Int32>(std::distance(m_aKeyMap.begin(), m_aKeyIter)));
+ m_aKeyIter = std::prev(m_aKeyIter, row);
}
else
{
@@ -1116,9 +1116,7 @@ bool OKeySet::absolute_checked( sal_Int32 row, bool /* i_bFetchRow */ )
}
else
{
- m_aKeyIter = m_aKeyMap.begin();
- for(;row > 0 && m_aKeyIter != m_aKeyMap.end();--row)
- ++m_aKeyIter;
+ m_aKeyIter = std::next(m_aKeyMap.begin(), row);
}
}
if ( !bFetchedRow )
diff --git a/dbaccess/source/core/api/RowSet.cxx b/dbaccess/source/core/api/RowSet.cxx
index 671f9d3abeea..5cff9d646dfb 100644
--- a/dbaccess/source/core/api/RowSet.cxx
+++ b/dbaccess/source/core/api/RowSet.cxx
@@ -103,24 +103,18 @@ com_sun_star_comp_dba_ORowSet_get_implementation(css::uno::XComponentContext* co
#define NOTIFY_LISTENERS_CHECK(_rListeners,T,method) \
std::vector< Reference< XInterface > > aListenerSeq = _rListeners.getElements(); \
\
- auto it = aListenerSeq.rbegin(); \
- const auto itEnd = aListenerSeq.rend(); \
- \
_rGuard.clear(); \
- bool bCheck = true; \
- for ( ; it != itEnd; ) \
- { \
- try \
- { \
- bCheck = static_cast< T* >( it->get() )->method(aEvt); \
- if (!bCheck) \
- break; \
- } \
- catch( RuntimeException& ) \
- { \
- } \
- ++it; \
- } \
+ bool bCheck = std::all_of(aListenerSeq.rbegin(), aListenerSeq.rend(), \
+ [&aEvt](Reference<XInterface>& rxItem) { \
+ try \
+ { \
+ return static_cast<bool>(static_cast<T*>(rxItem.get())->method(aEvt)); \
+ } \
+ catch( RuntimeException& ) \
+ { \
+ return true; \
+ } \
+ }); \
_rGuard.reset();
@@ -913,7 +907,7 @@ void SAL_CALL ORowSet::insertRow()
if ( !aBookmarks.empty() )
{
- RowsChangeEvent aUpEvt(*this,RowChangeAction::UPDATE,aBookmarks.size(),Sequence<Any>(&(*aBookmarks.begin()),aBookmarks.size()));
+ RowsChangeEvent aUpEvt(*this,RowChangeAction::UPDATE,aBookmarks.size(),comphelper::containerToSequence(aBookmarks));
notifyAllListenersRowChanged(aGuard,aUpEvt);
}
@@ -952,7 +946,7 @@ void SAL_CALL ORowSet::updateRow( )
std::vector< Any > aBookmarks;
m_pCache->updateRow(m_aCurrentRow.operator ->(),aBookmarks);
if ( !aBookmarks.empty() )
- aEvt.Bookmarks = Sequence<Any>(&(*aBookmarks.begin()),aBookmarks.size());
+ aEvt.Bookmarks = comphelper::containerToSequence(aBookmarks);
aEvt.Rows += aBookmarks.size();
m_aBookmark = m_pCache->getBookmark();
m_aCurrentRow = m_pCache->m_aMatrixIter;
diff --git a/dbaccess/source/core/api/RowSetCache.cxx b/dbaccess/source/core/api/RowSetCache.cxx
index e7f5b66a6171..7eaca7c70a6b 100644
--- a/dbaccess/source/core/api/RowSetCache.cxx
+++ b/dbaccess/source/core/api/RowSetCache.cxx
@@ -385,17 +385,15 @@ void ORowSetCache::setFetchSize(sal_Int32 _nSize)
std::vector<sal_Int32> aPositions;
std::map<sal_Int32,bool> aCacheIterToChange;
// first get the positions where they stand now
- ORowSetCacheMap::iterator aCacheIter = m_aCacheIterators.begin();
- ORowSetCacheMap::const_iterator aCacheEnd = m_aCacheIterators.end();
- for(;aCacheIter != aCacheEnd;++aCacheIter)
+ for(const auto& [rIndex, rHelper] : m_aCacheIterators)
{
- aCacheIterToChange[aCacheIter->first] = false;
- if ( !aCacheIter->second.pRowSet->isInsertRow()
- /*&& aCacheIter->second.aIterator != m_pMatrix->end()*/ && !m_bModified )
+ aCacheIterToChange[rIndex] = false;
+ if ( !rHelper.pRowSet->isInsertRow()
+ /*&& rHelper.aIterator != m_pMatrix->end()*/ && !m_bModified )
{
- ptrdiff_t nDist = aCacheIter->second.aIterator - m_pMatrix->begin();
+ ptrdiff_t nDist = rHelper.aIterator - m_pMatrix->begin();
aPositions.push_back(nDist);
- aCacheIterToChange[aCacheIter->first] = true;
+ aCacheIterToChange[rIndex] = true;
}
}
sal_Int32 nKeyPos = m_aMatrixIter - m_pMatrix->begin();
@@ -409,12 +407,10 @@ void ORowSetCache::setFetchSize(sal_Int32 _nSize)
// now adjust their positions because a resize invalidates all iterators
std::vector<sal_Int32>::const_iterator aIter = aPositions.begin();
- std::map<sal_Int32,bool>::const_iterator aPosChangeIter = aCacheIterToChange.begin();
- for( aCacheIter = m_aCacheIterators.begin();
- aPosChangeIter != aCacheIterToChange.end();
- ++aPosChangeIter,++aCacheIter)
+ ORowSetCacheMap::iterator aCacheIter = m_aCacheIterators.begin();
+ for(const auto& rPosChange : aCacheIterToChange)
{
- if ( aPosChangeIter->second )
+ if ( rPosChange.second )
{
CHECK_MATRIX_POS(*aIter);
if ( *aIter < _nSize )
@@ -422,6 +418,7 @@ void ORowSetCache::setFetchSize(sal_Int32 _nSize)
else
aCacheIter->second.aIterator = m_pMatrix->end();
}
+ ++aCacheIter;
}
}
if(!m_nPosition)
@@ -912,26 +909,24 @@ void ORowSetCache::moveWindow()
{
// now correct the iterator in our iterator vector
// rotateCacheIterator(aEnd-m_pMatrix->begin()); //can't be used because they decrement and here we need to increment
- ORowSetCacheMap::iterator aCacheIter = m_aCacheIterators.begin();
- const ORowSetCacheMap::const_iterator aCacheEnd = m_aCacheIterators.end();
- for(;aCacheIter != aCacheEnd;++aCacheIter)
+ for(auto& rCacheIter : m_aCacheIterators)
{
- if ( !aCacheIter->second.pRowSet->isInsertRow()
- && aCacheIter->second.aIterator != m_pMatrix->end() )
+ if ( !rCacheIter.second.pRowSet->isInsertRow()
+ && rCacheIter.second.aIterator != m_pMatrix->end() )
{
- const ptrdiff_t nDist = aCacheIter->second.aIterator - m_pMatrix->begin();
+ const ptrdiff_t nDist = rCacheIter.second.aIterator - m_pMatrix->begin();
if ( nDist >= nOverlapSize )
{
// That's from outside the overlap area; invalidate iterator.
- aCacheIter->second.aIterator = m_pMatrix->end();
+ rCacheIter.second.aIterator = m_pMatrix->end();
}
else
{
// Inside overlap area: move to correct position
CHECK_MATRIX_POS( (nDist + nStartPosOffset) );
- aCacheIter->second.aIterator += nStartPosOffset;
- OSL_ENSURE(aCacheIter->second.aIterator >= m_pMatrix->begin()
- && aCacheIter->second.aIterator < m_pMatrix->end(),"Iterator out of area!");
+ rCacheIter.second.aIterator += nStartPosOffset;
+ OSL_ENSURE(rCacheIter.second.aIterator >= m_pMatrix->begin()
+ && rCacheIter.second.aIterator < m_pMatrix->end(),"Iterator out of area!");
}
}
}
@@ -1315,12 +1310,10 @@ void ORowSetCache::resetInsertRow(bool _bClearInsertRow)
void ORowSetCache::cancelRowModification()
{
// clear the insertrow references -> implies that the current row of the rowset changes as well
- ORowSetCacheMap::iterator aCacheIter = m_aCacheIterators.begin();
- ORowSetCacheMap::const_iterator aCacheEnd = m_aCacheIterators.end();
- for(;aCacheIter != aCacheEnd;++aCacheIter)
+ for(auto& rCacheIter : m_aCacheIterators)
{
- if ( aCacheIter->second.pRowSet->isInsertRow() && aCacheIter->second.aIterator == m_aInsertRow )
- aCacheIter->second.aIterator = m_pMatrix->end();
+ if ( rCacheIter.second.pRowSet->isInsertRow() && rCacheIter.second.aIterator == m_aInsertRow )
+ rCacheIter.second.aIterator = m_pMatrix->end();
}
resetInsertRow(false);
}
@@ -1451,24 +1444,22 @@ void ORowSetCache::rotateCacheIterator(ORowSetMatrix::difference_type _nDist)
if(_nDist)
{
// now correct the iterator in our iterator vector
- ORowSetCacheMap::iterator aCacheIter = m_aCacheIterators.begin();
- ORowSetCacheMap::const_iterator aCacheEnd = m_aCacheIterators.end();
- for(;aCacheIter != aCacheEnd;++aCacheIter)
+ for(auto& rCacheIter : m_aCacheIterators)
{
- if ( !aCacheIter->second.pRowSet->isInsertRow()
- && aCacheIter->second.aIterator != m_pMatrix->end())
+ if ( !rCacheIter.second.pRowSet->isInsertRow()
+ && rCacheIter.second.aIterator != m_pMatrix->end())
{
- ptrdiff_t nDist = aCacheIter->second.aIterator - m_pMatrix->begin();
+ ptrdiff_t nDist = rCacheIter.second.aIterator - m_pMatrix->begin();
if(nDist < _nDist)
{
- aCacheIter->second.aIterator = m_pMatrix->end();
+ rCacheIter.second.aIterator = m_pMatrix->end();
}
else
{
- OSL_ENSURE((aCacheIter->second.aIterator - m_pMatrix->begin()) >= _nDist,"Invalid Dist value!");
- aCacheIter->second.aIterator -= _nDist;
- OSL_ENSURE(aCacheIter->second.aIterator >= m_pMatrix->begin()
- && aCacheIter->second.aIterator < m_pMatrix->end(),"Iterator out of area!");
+ OSL_ENSURE((rCacheIter.second.aIterator - m_pMatrix->begin()) >= _nDist,"Invalid Dist value!");
+ rCacheIter.second.aIterator -= _nDist;
+ OSL_ENSURE(rCacheIter.second.aIterator >= m_pMatrix->begin()
+ && rCacheIter.second.aIterator < m_pMatrix->end(),"Iterator out of area!");
}
}
}
@@ -1481,12 +1472,11 @@ void ORowSetCache::rotateAllCacheIterators()
return;
// now correct the iterator in our iterator vector
- auto aCacheEnd = m_aCacheIterators.end();
- for (auto aCacheIter = m_aCacheIterators.begin(); aCacheIter != aCacheEnd; ++aCacheIter)
+ for (auto& rCacheIter : m_aCacheIterators)
{
- if (!aCacheIter->second.pRowSet->isInsertRow())
+ if (!rCacheIter.second.pRowSet->isInsertRow())
{
- aCacheIter->second.aIterator = m_pMatrix->end();
+ rCacheIter.second.aIterator = m_pMatrix->end();
}
}
}
@@ -1499,10 +1489,8 @@ void ORowSetCache::setUpdateIterator(const ORowSetMatrix::iterator& _rOriginalRo
(*(*m_aInsertRow)) = *(*_rOriginalRow);
// we don't unbound the bookmark column
- ORowSetValueVector::Vector::iterator aIter = (*m_aInsertRow)->get().begin();
- ORowSetValueVector::Vector::const_iterator aEnd = (*m_aInsertRow)->get().end();
- for(;aIter != aEnd;++aIter)
- aIter->setModified(false);
+ for(auto& rItem : (*m_aInsertRow)->get())
+ rItem.setModified(false);
}
void ORowSetCache::checkPositionFlags()
@@ -1655,25 +1643,18 @@ TORowSetOldRowHelperRef ORowSetCache::registerOldRow()
void ORowSetCache::deregisterOldRow(const TORowSetOldRowHelperRef& _rRow)
{
- TOldRowSetRows::const_iterator aOldRowEnd = m_aOldRows.end();
- for (TOldRowSetRows::iterator aOldRowIter = m_aOldRows.begin(); aOldRowIter != aOldRowEnd; ++aOldRowIter)
- {
- if ( aOldRowIter->get() == _rRow.get() )
- {
- m_aOldRows.erase(aOldRowIter);
- break;
- }
-
- }
+ TOldRowSetRows::iterator aOldRowIter = std::find_if(m_aOldRows.begin(), m_aOldRows.end(),
+ [&_rRow](const TORowSetOldRowHelperRef& rxOldRow) { return rxOldRow.get() == _rRow.get(); });
+ if (aOldRowIter != m_aOldRows.end())
+ m_aOldRows.erase(aOldRowIter);
}
bool ORowSetCache::reFillMatrix(sal_Int32 _nNewStartPos, sal_Int32 _nNewEndPos)
{
- const TOldRowSetRows::const_iterator aOldRowEnd = m_aOldRows.end();
- for (TOldRowSetRows::const_iterator aOldRowIter = m_aOldRows.begin(); aOldRowIter != aOldRowEnd; ++aOldRowIter)
+ for (const auto& rxOldRow : m_aOldRows)
{
- if ( aOldRowIter->is() && (*aOldRowIter)->getRow().is() )
- (*aOldRowIter)->setRow(new ORowSetValueVector( *((*aOldRowIter)->getRow()) ) );
+ if ( rxOldRow.is() && rxOldRow->getRow().is() )
+ rxOldRow->setRow(new ORowSetValueVector( *(rxOldRow->getRow()) ) );
}
sal_Int32 nNewSt = _nNewStartPos;
bool bRet = fillMatrix(nNewSt,_nNewEndPos);
@@ -1692,10 +1673,9 @@ bool ORowSetCache::fill(ORowSetMatrix::iterator& _aIter, const ORowSetMatrix::co
*_aIter = new ORowSetValueVector(nColumnCount);
else
{
- const TOldRowSetRows::const_iterator aOldRowEnd = m_aOldRows.end();
- for (TOldRowSetRows::const_iterator aOldRowIter = m_aOldRows.begin(); aOldRowIter != aOldRowEnd; ++aOldRowIter)
+ for (const auto& rxOldRow : m_aOldRows)
{
- if ( (*aOldRowIter)->getRow() == *_aIter )
+ if ( rxOldRow->getRow() == *_aIter )
*_aIter = new ORowSetValueVector(nColumnCount);
}
}
diff --git a/dbaccess/source/core/dataaccess/ModelImpl.cxx b/dbaccess/source/core/dataaccess/ModelImpl.cxx
index cfa8998244bd..00463902b340 100644
--- a/dbaccess/source/core/dataaccess/ModelImpl.cxx
+++ b/dbaccess/source/core/dataaccess/ModelImpl.cxx
@@ -344,15 +344,10 @@ void SAL_CALL DocumentStorageAccess::disposing( const css::lang::EventObject& So
if ( m_bDisposingSubStorages )
return;
- for ( NamedStorages::const_iterator find = m_aExposedStorages.begin();
- find != m_aExposedStorages.end();
- ++find
- )
- if ( find->second == Source.Source )
- {
- m_aExposedStorages.erase( find );
- break;
- }
+ auto find = std::find_if(m_aExposedStorages.begin(), m_aExposedStorages.end(),
+ [&Source](const NamedStorages::value_type& rEntry) { return rEntry.second == Source.Source; });
+ if (find != m_aExposedStorages.end())
+ m_aExposedStorages.erase( find );
}
// ODatabaseModelImpl
diff --git a/dbaccess/source/core/dataaccess/bookmarkcontainer.cxx b/dbaccess/source/core/dataaccess/bookmarkcontainer.cxx
index 47d08357a5a7..8964117b1c9a 100644
--- a/dbaccess/source/core/dataaccess/bookmarkcontainer.cxx
+++ b/dbaccess/source/core/dataaccess/bookmarkcontainer.cxx
@@ -264,17 +264,12 @@ void OBookmarkContainer::implRemove(const OUString& _rName)
// look for the name in the index access vector
MapString2String::const_iterator aMapPos = m_aBookmarks.end();
- for ( MapIteratorVector::iterator aSearch = m_aBookmarksIndexed.begin();
- aSearch != m_aBookmarksIndexed.end();
- ++aSearch
- )
+ auto aSearch = std::find_if(m_aBookmarksIndexed.begin(), m_aBookmarksIndexed.end(),
+ [&_rName](const MapString2String::iterator& rIter) { return rIter->first == _rName; });
+ if (aSearch != m_aBookmarksIndexed.end())
{
- if ((*aSearch)->first == _rName)
- {
- aMapPos = *aSearch;
- m_aBookmarksIndexed.erase(aSearch);
- break;
- }
+ aMapPos = *aSearch;
+ m_aBookmarksIndexed.erase(aSearch);
}
if (m_aBookmarks.end() == aMapPos)
diff --git a/dbaccess/source/core/dataaccess/datasource.cxx b/dbaccess/source/core/dataaccess/datasource.cxx
index 9d80a1bf3a56..6dd3a3fbd1e8 100644
--- a/dbaccess/source/core/dataaccess/datasource.cxx
+++ b/dbaccess/source/core/dataaccess/datasource.cxx
@@ -439,7 +439,7 @@ namespace
}
}
if ( !aRet.empty() )
- return Sequence< PropertyValue >(&(*aRet.begin()),aRet.size());
+ return comphelper::containerToSequence(aRet);
}
return Sequence< PropertyValue >();
}
diff --git a/dbaccess/source/core/misc/DatabaseDataProvider.cxx b/dbaccess/source/core/misc/DatabaseDataProvider.cxx
index b3d151c73cfd..9d84fdb5bbb2 100644
--- a/dbaccess/source/core/misc/DatabaseDataProvider.cxx
+++ b/dbaccess/source/core/misc/DatabaseDataProvider.cxx
@@ -802,7 +802,7 @@ void DatabaseDataProvider::impl_fillInternalDataProvider_throw(bool _bHasCategor
}
uno::Reference< chart::XChartDataArray> xData(m_xInternal,uno::UNO_QUERY);
- xData->setRowDescriptions(uno::Sequence< OUString >(&(*aRowLabels.begin()),aRowLabels.size()));
+ xData->setRowDescriptions(comphelper::containerToSequence(aRowLabels));
const size_t nOffset = bFirstColumnIsCategory ? 1 : 0;
uno::Sequence< OUString > aColumnDescriptions( aColumns.size() - nOffset );
@@ -820,7 +820,7 @@ void DatabaseDataProvider::impl_fillInternalDataProvider_throw(bool _bHasCategor
for(sal_Int32 i= 0;pDataIter != pDataEnd; ++pDataIter,++i )
{
if ( !aDataValues[i].empty() )
- *pDataIter = uno::Sequence< double >(&(*(aDataValues[i]).begin()),(aDataValues[i]).size());
+ *pDataIter = comphelper::containerToSequence(aDataValues[i]);
}
xData->setData(aData);
}
diff --git a/dbaccess/source/filter/xml/xmlTableFilterList.cxx b/dbaccess/source/filter/xml/xmlTableFilterList.cxx
index e09a9482506a..34c823e1cc1f 100644
--- a/dbaccess/source/filter/xml/xmlTableFilterList.cxx
+++ b/dbaccess/source/filter/xml/xmlTableFilterList.cxx
@@ -27,6 +27,7 @@
#include <stringconstants.hxx>
#include <strings.hxx>
#include <com/sun/star/beans/XPropertySet.hpp>
+#include <comphelper/sequence.hxx>
#include <xmloff/xmlimp.hxx>
#include "xmlfilter.hxx"
@@ -82,9 +83,9 @@ void OXMLTableFilterList::EndElement()
if ( xDataSource.is() )
{
if ( !m_aPatterns.empty() )
- xDataSource->setPropertyValue(PROPERTY_TABLEFILTER,makeAny(Sequence< OUString>(&(*m_aPatterns.begin()),m_aPatterns.size())));
+ xDataSource->setPropertyValue(PROPERTY_TABLEFILTER,makeAny(comphelper::containerToSequence(m_aPatterns)));
if ( !m_aTypes.empty() )
- xDataSource->setPropertyValue(PROPERTY_TABLETYPEFILTER,makeAny(Sequence< OUString>(&(*m_aTypes.begin()),m_aTypes.size())));
+ xDataSource->setPropertyValue(PROPERTY_TABLETYPEFILTER,makeAny(comphelper::containerToSequence(m_aTypes)));
}
}
diff --git a/dbaccess/source/filter/xml/xmlfilter.cxx b/dbaccess/source/filter/xml/xmlfilter.cxx
index a0fabc0d02d8..a674fce529d6 100644
--- a/dbaccess/source/filter/xml/xmlfilter.cxx
+++ b/dbaccess/source/filter/xml/xmlfilter.cxx
@@ -59,6 +59,7 @@
#include <tools/diagnose_ex.h>
#include <osl/diagnose.h>
#include <comphelper/processfactory.hxx>
+#include <comphelper/sequence.hxx>
#include <comphelper/types.hxx>
#include <comphelper/namedvaluecollection.hxx>
#include <cppuhelper/exc_hlp.hxx>
@@ -941,7 +942,7 @@ void ODBFilter::setPropertyInfo()
Sequence<PropertyValue> aInfo;
if ( !m_aInfoSequence.empty() )
- aInfo = Sequence<PropertyValue>(&(*m_aInfoSequence.begin()),m_aInfoSequence.size());
+ aInfo = comphelper::containerToSequence(m_aInfoSequence);
aDataSourceSettings.merge( ::comphelper::NamedValueCollection( aInfo ), true );
aDataSourceSettings >>= aInfo;
diff --git a/dbaccess/source/ui/browser/genericcontroller.cxx b/dbaccess/source/ui/browser/genericcontroller.cxx
index 3e75a0285b39..c5560d8e9512 100644
--- a/dbaccess/source/ui/browser/genericcontroller.cxx
+++ b/dbaccess/source/ui/browser/genericcontroller.cxx
@@ -671,25 +671,20 @@ void OGenericUnoController::addStatusListener(const Reference< XStatusListener >
void OGenericUnoController::removeStatusListener(const Reference< XStatusListener > & aListener, const URL& _rURL)
{
- Dispatch::iterator iterSearch = m_arrStatusListener.begin();
-
- bool bRemoveForAll = _rURL.Complete.isEmpty();
- while ( iterSearch != m_arrStatusListener.end() )
+ if (_rURL.Complete.isEmpty())
{
- DispatchTarget& rCurrent = *iterSearch;
- if ( (rCurrent.xListener == aListener)
- && ( bRemoveForAll
- || (rCurrent.aURL.Complete == _rURL.Complete)
- )
- )
- {
- iterSearch = m_arrStatusListener.erase(iterSearch);
- if (!bRemoveForAll)
- // remove the listener only for the given URL, so we can exit the loop after deletion
- break;
- }
- else
- ++iterSearch;
+ m_arrStatusListener.erase(std::remove_if(m_arrStatusListener.begin(), m_arrStatusListener.end(),
+ [&aListener](const DispatchTarget& rCurrent) { return rCurrent.xListener == aListener; }),
+ m_arrStatusListener.end());
+ }
+ else
+ {
+ // remove the listener only for the given URL
+ Dispatch::iterator iterSearch = std::find_if(m_arrStatusListener.begin(), m_arrStatusListener.end(),
+ [&aListener, &_rURL](const DispatchTarget& rCurrent) {
+ return (rCurrent.xListener == aListener) && (rCurrent.aURL.Complete == _rURL.Complete); });
+ if (iterSearch != m_arrStatusListener.end())
+ m_arrStatusListener.erase(iterSearch);
}
OSL_PRECOND( !m_aSupportedFeatures.empty(), "OGenericUnoController::removeStatusListener: shouldn't this be filled at construction time?" );
diff --git a/dbaccess/source/ui/dlg/DbAdminImpl.cxx b/dbaccess/source/ui/dlg/DbAdminImpl.cxx
index b5f514cf41d0..d80dbbd344b6 100644
--- a/dbaccess/source/ui/dlg/DbAdminImpl.cxx
+++ b/dbaccess/source/ui/dlg/DbAdminImpl.cxx
@@ -306,7 +306,7 @@ bool ODbDataSourceAdministrationHelper::getCurrentSettings(Sequence< PropertyVal
}
if ( !aReturn.empty() )
- _rDriverParam = Sequence< PropertyValue >(&(*aReturn.begin()), aReturn.size());
+ _rDriverParam = comphelper::containerToSequence(aReturn);
// append all the other stuff (charset etc.)
fillDatasourceInfo(*m_pItemSetHelper->getOutputSet(), _rDriverParam);
diff --git a/dbaccess/source/ui/dlg/dbfindex.cxx b/dbaccess/source/ui/dlg/dbfindex.cxx
index a6c202a2026f..f5016d239428 100644
--- a/dbaccess/source/ui/dlg/dbfindex.cxx
+++ b/dbaccess/source/ui/dlg/dbfindex.cxx
@@ -89,29 +89,22 @@ OTableIndex ODbaseIndexDialog::implRemoveIndex(const OUString& _rName, TableInde
{
OTableIndex aReturn;
- sal_Int32 nPos = 0;
-
- TableIndexList::iterator aSearch;
- for ( aSearch = _rList.begin();
- aSearch != _rList.end();
- ++aSearch, ++nPos
- )
+ TableIndexList::iterator aSearch = std::find_if(_rList.begin(), _rList.end(),
+ [&_rName](const OTableIndex& rIndex) { return rIndex.GetIndexFileName() == _rName; });
+ if (aSearch != _rList.end())
{
- if ( aSearch->GetIndexFileName() == _rName )
- {
- aReturn = *aSearch;
+ sal_Int32 nPos = static_cast<sal_Int32>(std::distance(_rList.begin(), aSearch));
- _rList.erase(aSearch);
- _rDisplay.remove_text(_rName);
+ aReturn = *aSearch;
- // adjust selection if necessary
- if (static_cast<sal_uInt32>(nPos) == _rList.size())
- _rDisplay.select(static_cast<sal_uInt16>(nPos)-1);
- else
- _rDisplay.select(static_cast<sal_uInt16>(nPos));
+ _rList.erase(aSearch);
+ _rDisplay.remove_text(_rName);
- break;
- }
+ // adjust selection if necessary
+ if (static_cast<sal_uInt32>(nPos) == _rList.size())
+ _rDisplay.select(static_cast<sal_uInt16>(nPos)-1);
+ else
+ _rDisplay.select(static_cast<sal_uInt16>(nPos));
}
OSL_ENSURE(!_bMustExist || (aSearch != _rList.end()), "ODbaseIndexDialog::implRemoveIndex : did not find the index!");
diff --git a/dbaccess/source/ui/dlg/generalpage.cxx b/dbaccess/source/ui/dlg/generalpage.cxx
index c66241ce22e3..d9da7d5bc7ab 100644
--- a/dbaccess/source/ui/dlg/generalpage.cxx
+++ b/dbaccess/source/ui/dlg/generalpage.cxx
@@ -138,12 +138,8 @@ namespace dbaui
}
}
std::sort( aDisplayedTypes.begin(), aDisplayedTypes.end(), DisplayedTypeLess() );
- DisplayedTypes::const_iterator aDisplayEnd = aDisplayedTypes.end();
- for ( DisplayedTypes::const_iterator loop = aDisplayedTypes.begin();
- loop != aDisplayEnd;
- ++loop
- )
- insertDatasourceTypeEntryData( loop->eType, loop->sDisplayName );
+ for ( const auto& rDisplayedType : aDisplayedTypes )
+ insertDatasourceTypeEntryData( rDisplayedType.eType, rDisplayedType.sDisplayName );
}
}
}
diff --git a/dbaccess/source/ui/dlg/indexdialog.cxx b/dbaccess/source/ui/dlg/indexdialog.cxx
index 3969557e061c..446737e41e1f 100644
--- a/dbaccess/source/ui/dlg/indexdialog.cxx
+++ b/dbaccess/source/ui/dlg/indexdialog.cxx
@@ -57,25 +57,9 @@ namespace dbaui
&& (_rLHS.bSortAscending == _rRHS.bSortAscending);
}
- static bool operator !=(const OIndexField& _rLHS, const OIndexField& _rRHS)
- {
- return !(_rLHS == _rRHS);
- }
-
static bool operator ==(const IndexFields& _rLHS, const IndexFields& _rRHS)
{
- if (_rLHS.size() != _rRHS.size())
- return false;
-
- IndexFields::const_iterator aRight = _rRHS.begin();
- for (auto const& left : _rLHS)
- {
- if (left != *aRight)
- return false;
- ++aRight;
- }
-
- return true;
+ return std::equal(_rLHS.begin(), _rLHS.end(), _rRHS.begin(), _rRHS.end());
}
static bool operator !=(const IndexFields& _rLHS, const IndexFields& _rRHS)
diff --git a/dbaccess/source/ui/dlg/indexfieldscontrol.cxx b/dbaccess/source/ui/dlg/indexfieldscontrol.cxx
index 3b0d83ed2403..27beb4654d78 100644
--- a/dbaccess/source/ui/dlg/indexfieldscontrol.cxx
+++ b/dbaccess/source/ui/dlg/indexfieldscontrol.cxx
@@ -166,13 +166,8 @@ static constexpr auto BROWSER_STANDARD_FLAGS = BrowserMode::COLUMNSELECTION | Br
{
// do not just copy the array, we may have empty field names (which should not be copied)
_rFields.resize(m_aFields.size());
- IndexFields::iterator aDest = _rFields.begin();
- for (auto const& source : m_aFields)
- if (!source.sFieldName.isEmpty())
- {
- *aDest = source;
- ++aDest;
- }
+ IndexFields::iterator aDest = std::copy_if(m_aFields.begin(), m_aFields.end(), _rFields.begin(),
+ [](const OIndexField& source) { return !source.sFieldName.isEmpty(); });
_rFields.resize(aDest - _rFields.begin());
}
diff --git a/dbaccess/source/ui/misc/indexcollection.cxx b/dbaccess/source/ui/misc/indexcollection.cxx
index 1ae2d2696cd3..280ec5c2cd95 100644
--- a/dbaccess/source/ui/misc/indexcollection.cxx
+++ b/dbaccess/source/ui/misc/indexcollection.cxx
@@ -68,49 +68,29 @@ namespace dbaui
Indexes::const_iterator OIndexCollection::find(const OUString& _rName) const
{
// loop'n'compare
- Indexes::const_iterator aSearch = m_aIndexes.begin();
- Indexes::const_iterator aEnd = m_aIndexes.end();
- for (; aSearch != aEnd; ++aSearch)
- if (aSearch->sName == _rName)
- break;
-
- return aSearch;
+ return std::find_if(m_aIndexes.cbegin(), m_aIndexes.cend(),
+ [&_rName](const OIndex& rIndex) { return rIndex.sName == _rName; });
}
Indexes::iterator OIndexCollection::find(const OUString& _rName)
{
// loop'n'compare
- Indexes::iterator aSearch = m_aIndexes.begin();
- Indexes::const_iterator aEnd = m_aIndexes.end();
- for (; aSearch != aEnd; ++aSearch)
- if (aSearch->sName == _rName)
- break;
-
- return aSearch;
+ return std::find_if(m_aIndexes.begin(), m_aIndexes.end(),
+ [&_rName](const OIndex& rIndex) { return rIndex.sName == _rName; });
}
Indexes::const_iterator OIndexCollection::findOriginal(const OUString& _rName) const
{
// loop'n'compare
- Indexes::const_iterator aSearch = m_aIndexes.begin();
- Indexes::const_iterator aEnd = m_aIndexes.end();
- for (; aSearch != aEnd; ++aSearch)
- if (aSearch->getOriginalName() == _rName)
- break;
-
- return aSearch;
+ return std::find_if(m_aIndexes.cbegin(), m_aIndexes.cend(),
+ [&_rName](const OIndex& rIndex) { return rIndex.getOriginalName() == _rName; });
}
Indexes::iterator OIndexCollection::findOriginal(const OUString& _rName)
{
// loop'n'compare
- Indexes::iterator aSearch = m_aIndexes.begin();
- Indexes::const_iterator aEnd = m_aIndexes.end();
- for (; aSearch != aEnd; ++aSearch)
- if (aSearch->getOriginalName() == _rName)
- break;
-
- return aSearch;
+ return std::find_if(m_aIndexes.begin(), m_aIndexes.end(),
+ [&_rName](const OIndex& rIndex) { return rIndex.getOriginalName() == _rName; });
}
void OIndexCollection::commitNewIndex(const Indexes::iterator& _rPos)
diff --git a/dbaccess/source/ui/querydesign/JAccess.cxx b/dbaccess/source/ui/querydesign/JAccess.cxx
index 796749e494a9..781592bbe016 100644
--- a/dbaccess/source/ui/querydesign/JAccess.cxx
+++ b/dbaccess/source/ui/querydesign/JAccess.cxx
@@ -68,9 +68,7 @@ namespace dbaui
sal_Int32 nTableWindowCount = m_pTableView->GetTabWinCount();
if( i < nTableWindowCount )
{
- OJoinTableView::OTableWindowMap::const_iterator aIter = m_pTableView->GetTabWinMap().begin();
- for (sal_Int32 j=i; j; ++aIter,--j)
- ;
+ OJoinTableView::OTableWindowMap::const_iterator aIter = std::next(m_pTableView->GetTabWinMap().begin(), i);
aRet = aIter->second->GetAccessible();
}
else if( size_t(i - nTableWindowCount) < m_pTableView->getTableConnections().size() )
diff --git a/dbaccess/source/ui/querydesign/JoinTableView.cxx b/dbaccess/source/ui/querydesign/JoinTableView.cxx
index 54f595e79d47..12521c4f6243 100644
--- a/dbaccess/source/ui/querydesign/JoinTableView.cxx
+++ b/dbaccess/source/ui/querydesign/JoinTableView.cxx
@@ -1251,11 +1251,8 @@ bool OJoinTableView::PreNotify(NotifyEvent& rNEvt)
bool bForward = !pKeyEvent->GetKeyCode().IsShift();
// is there an active tab win ?
- OTableWindowMap::const_iterator aIter = m_aTableMap.begin();
- OTableWindowMap::const_iterator aEnd = m_aTableMap.end();
- for(;aIter != aEnd;++aIter)
- if (aIter->second && aIter->second->HasChildPathFocus())
- break;
+ OTableWindowMap::const_iterator aIter = std::find_if(m_aTableMap.begin(), m_aTableMap.end(),
+ [](const OTableWindowMap::value_type& rEntry) { return rEntry.second && rEntry.second->HasChildPathFocus(); });
OTableWindow* pNextWin = nullptr;
OTableConnection* pNextConn = nullptr;
diff --git a/dbaccess/source/ui/querydesign/QueryTableView.cxx b/dbaccess/source/ui/querydesign/QueryTableView.cxx
index 9f5c8a1520b9..79ebb89fc69d 100644
--- a/dbaccess/source/ui/querydesign/QueryTableView.cxx
+++ b/dbaccess/source/ui/querydesign/QueryTableView.cxx
@@ -738,14 +738,10 @@ void OQueryTableView::HideTabWin( OQueryTableWindow* pTabWin, OQueryTabWinUndoAc
getDesignView()->SaveTabWinUIConfig(pTabWin);
// (I need to go via the parent, as only the parent knows the position of the scrollbars)
// and then out of the TabWins list and hide
- OTableWindowMap::const_iterator aIter = rTabWins.begin();
- OTableWindowMap::const_iterator aEnd = rTabWins.end();
- for ( ;aIter != aEnd ; ++aIter )
- if ( aIter->second == pTabWin )
- {
- rTabWins.erase( aIter );
- break;
- }
+ OTableWindowMap::const_iterator aIter = std::find_if(rTabWins.begin(), rTabWins.end(),
+ [&pTabWin](const OTableWindowMap::value_type& rEntry) { return rEntry.second == pTabWin; });
+ if (aIter != rTabWins.end())
+ rTabWins.erase( aIter );
pTabWin->Hide(); // do not destroy it, as it is still in the undo list!!
diff --git a/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx b/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx
index 766b1dcd2523..e83516797a6d 100644
--- a/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx
+++ b/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx
@@ -1425,16 +1425,12 @@ void OSelectionBrowseBox::DeleteFields(const OUString& rAliasName)
if (bWasEditing)
DeactivateCell();
- OTableFields::const_reverse_iterator aIter = getFields().rbegin();
- OTableFieldDescRef pEntry;
- for(sal_uInt16 nPos=sal::static_int_cast< sal_uInt16 >(getFields().size());aIter != getFields().rend();++aIter,--nPos)
+ auto aIter = std::find_if(getFields().rbegin(), getFields().rend(),
+ [&rAliasName](const OTableFieldDescRef pEntry) { return pEntry->GetAlias() == rAliasName; });
+ if (aIter != getFields().rend())
{
- pEntry = *aIter;
- if ( pEntry->GetAlias() == rAliasName )
- {
- RemoveField( GetColumnId( nPos ) );
- break;
- }
+ sal_uInt16 nPos = sal::static_int_cast<sal_uInt16>(std::distance(aIter, getFields().rend()));
+ RemoveField( GetColumnId( nPos ) );
}
if (bWasEditing)
diff --git a/dbaccess/source/ui/tabledesign/TEditControl.cxx b/dbaccess/source/ui/tabledesign/TEditControl.cxx
index 594778dd6d35..97e78c6b7103 100644
--- a/dbaccess/source/ui/tabledesign/TEditControl.cxx
+++ b/dbaccess/source/ui/tabledesign/TEditControl.cxx
@@ -1432,12 +1432,9 @@ IMPL_LINK_NOARG( OTableEditorCtrl, DelayedPaste, void*, void )
if (!IsInsertNewAllowed(nPastePosition))
{ // Insertion is not allowed, only appending, so test if there are full cells after the PastePosition
- sal_Int32 nFreeFromPos; // from here on there are only empty rows
- std::vector< std::shared_ptr<OTableRow> >::const_reverse_iterator aIter = m_pRowList->rbegin();
- for(nFreeFromPos = m_pRowList->size();
- aIter != m_pRowList->rend() && (!(*aIter) || !(*aIter)->GetActFieldDescr() || (*aIter)->GetActFieldDescr()->GetName().isEmpty());
- --nFreeFromPos, ++aIter)
- ;
+ auto aIter = std::find_if(m_pRowList->rbegin(), m_pRowList->rend(), [](const std::shared_ptr<OTableRow>& rxRow) {
+ return rxRow && rxRow->GetActFieldDescr() && !rxRow->GetActFieldDescr()->GetName().isEmpty(); });
+ auto nFreeFromPos = static_cast<sal_Int32>(std::distance(aIter, m_pRowList->rend())); // from here on there are only empty rows
if (nPastePosition < nFreeFromPos) // if at least one PastePosition is full, go right to the end
nPastePosition = nFreeFromPos;
}
diff --git a/dbaccess/source/ui/tabledesign/TableController.cxx b/dbaccess/source/ui/tabledesign/TableController.cxx
index 67662eea07c0..b5c3aab719b9 100644
--- a/dbaccess/source/ui/tabledesign/TableController.cxx
+++ b/dbaccess/source/ui/tabledesign/TableController.cxx
@@ -900,18 +900,18 @@ bool OTableController::checkColumns(bool _bNew)
{
bFoundPKey |= (*aIter)->IsPrimaryKey();
// first check for duplicate names
- std::vector< std::shared_ptr<OTableRow> >::const_iterator aIter2 = aIter+1;
- for(;aIter2 != aEnd;++aIter2)
+ bool bDuplicateNameFound = std::any_of(aIter+1, aEnd,
+ [&bCase, &pFieldDesc](const std::shared_ptr<OTableRow>& rxRow) {
+ OFieldDescription* pCompareDesc = rxRow->GetActFieldDescr();
+ return pCompareDesc && bCase(pCompareDesc->GetName(),pFieldDesc->GetName());
+ });
+ if (bDuplicateNameFound)
{
- OFieldDescription* pCompareDesc = (*aIter2)->GetActFieldDescr();
- if (pCompareDesc && bCase(pCompareDesc->GetName(),pFieldDesc->GetName()))
- {
- OUString strMessage = DBA_RES(STR_TABLEDESIGN_DUPLICATE_NAME);
- strMessage = strMessage.replaceFirst("$column$", pFieldDesc->GetName());
- OSQLWarningBox aWarning(getFrameWeld(), strMessage);
- aWarning.run();
- return false;
- }
+ OUString strMessage = DBA_RES(STR_TABLEDESIGN_DUPLICATE_NAME);
+ strMessage = strMessage.replaceFirst("$column$", pFieldDesc->GetName());
+ OSQLWarningBox aWarning(getFrameWeld(), strMessage);
+ aWarning.run();
+ return false;
}
}
}
@@ -1202,12 +1202,11 @@ void OTableController::alterColumns()
}
// third append the new columns
- aIter = m_vRowList.begin();
- for(;aIter != aEnd;++aIter)
+ for(const auto& rxRow : m_vRowList)
{
- OSL_ENSURE(*aIter,"OTableRow is null!");
- OFieldDescription* pField = (*aIter)->GetActFieldDescr();
- if ( !pField || (*aIter)->IsReadOnly() || aColumns.find(pField->GetName()) != aColumns.end() )
+ OSL_ENSURE(rxRow,"OTableRow is null!");
+ OFieldDescription* pField = rxRow->GetActFieldDescr();
+ if ( !pField || rxRow->IsReadOnly() || aColumns.find(pField->GetName()) != aColumns.end() )
continue;
Reference<XPropertySet> xColumn;
@@ -1239,11 +1238,10 @@ void OTableController::alterColumns()
bool bNeedAppendKey = false;
if ( xKeyColumns.is() )
{
- aIter = m_vRowList.begin();
- for(;aIter != aEnd;++aIter)
+ for(const auto& rxRow : m_vRowList)
{
- OSL_ENSURE(*aIter,"OTableRow is null!");
- OFieldDescription* pField = (*aIter)->GetActFieldDescr();
+ OSL_ENSURE(rxRow,"OTableRow is null!");
+ OFieldDescription* pField = rxRow->GetActFieldDescr();
if ( !pField )
continue;
@@ -1439,16 +1437,16 @@ OUString OTableController::createUniqueName(const OUString& _rName)
::comphelper::UStringMixEqual bCase(!xMetaData.is() || xMetaData->supportsMixedCaseQuotedIdentifiers());
- std::vector< std::shared_ptr<OTableRow> >::const_iterator aIter = m_vRowList.begin();
- std::vector< std::shared_ptr<OTableRow> >::const_iterator aEnd = m_vRowList.end();
- for(sal_Int32 i=0;aIter != aEnd;++aIter)
+ auto lHasName = [&bCase, &sName](const std::shared_ptr<OTableRow>& rxRow) {
+ OFieldDescription* pFieldDesc = rxRow->GetActFieldDescr();
+ return pFieldDesc && !pFieldDesc->GetName().isEmpty() && bCase(sName, pFieldDesc->GetName());
+ };
+
+ sal_Int32 i = 0;
+ while(std::any_of(m_vRowList.begin(), m_vRowList.end(), lHasName))
{
- OFieldDescription* pFieldDesc = (*aIter)->GetActFieldDescr();
- if (pFieldDesc && !pFieldDesc->GetName().isEmpty() && bCase(sName,pFieldDesc->GetName()))
- { // found a second name of _rName so we need another
- sName = _rName + OUString::number(++i);
- aIter = m_vRowList.begin(); // and retry
- }
+ // found a second name of _rName so we need another
+ sName = _rName + OUString::number(++i);
}
return sName;
}
diff --git a/dbaccess/source/ui/tabledesign/TableUndo.cxx b/dbaccess/source/ui/tabledesign/TableUndo.cxx
index 42f586b8608b..61f0e02cfc03 100644
--- a/dbaccess/source/ui/tabledesign/TableUndo.cxx
+++ b/dbaccess/source/ui/tabledesign/TableUndo.cxx
@@ -235,10 +235,7 @@ void OTableEditorInsUndoAct::Undo()
{
// delete lines again
std::vector< std::shared_ptr<OTableRow> >* pOriginalRows = pTabEdCtrl->GetRowList();
- for( long i=m_nInsPos+m_vInsertedRows.size()-1; i>(m_nInsPos-1); i-- )
- {
- pOriginalRows->erase(pOriginalRows->begin()+i);
- }
+ pOriginalRows->erase(pOriginalRows->begin() + m_nInsPos, pOriginalRows->begin() + m_nInsPos + m_vInsertedRows.size());
pTabEdCtrl->RowRemoved( m_nInsPos, m_vInsertedRows.size() );
pTabEdCtrl->InvalidateHandleColumn();
@@ -282,10 +279,7 @@ void OTableEditorInsNewUndoAct::Undo()
// delete inserted lines
std::vector< std::shared_ptr<OTableRow> >* pOriginalRows = pTabEdCtrl->GetRowList();
- for( long i=m_nInsPos+m_nInsRows-1; i>(m_nInsPos-1); i-- )
- {
- pOriginalRows->erase(pOriginalRows->begin()+i);
- }
+ pOriginalRows->erase(pOriginalRows->begin() + m_nInsPos, pOriginalRows->begin() + m_nInsPos + m_nInsRows);
pTabEdCtrl->RowRemoved( m_nInsPos, m_nInsRows );
pTabEdCtrl->InvalidateHandleColumn();