Kaydet (Commit) f9d1de6c authored tarafından Julien Nabet's avatar Julien Nabet

Use for range loops and lambda in dbfindex (dbaccess)

Change-Id: I72186af1eae37e31cafec695581336729d123d09
Reviewed-on: https://gerrit.libreoffice.org/44925Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarJulien Nabet <serval2412@yahoo.fr>
üst cba03991
...@@ -95,19 +95,6 @@ void ODbaseIndexDialog::dispose() ...@@ -95,19 +95,6 @@ void ODbaseIndexDialog::dispose()
ModalDialog::dispose(); ModalDialog::dispose();
} }
bool ODbaseIndexDialog::GetTable(const OUString& _rName, TableInfoList::iterator& _rPosition)
{
for ( _rPosition = m_aTableInfoList.begin();
_rPosition != m_aTableInfoList.end();
++_rPosition
)
{
if (_rPosition->aTableName == _rName)
return true;
}
return false;
}
void ODbaseIndexDialog::checkButtons() void ODbaseIndexDialog::checkButtons()
{ {
m_pAdd->Enable(0 != m_pLB_FreeIndexes->GetSelectedEntryCount()); m_pAdd->Enable(0 != m_pLB_FreeIndexes->GetSelectedEntryCount());
...@@ -162,8 +149,10 @@ OTableIndex ODbaseIndexDialog::RemoveTableIndex( const OUString& _rTableName, co ...@@ -162,8 +149,10 @@ OTableIndex ODbaseIndexDialog::RemoveTableIndex( const OUString& _rTableName, co
OTableIndex aReturn; OTableIndex aReturn;
// does the table exist ? // does the table exist ?
TableInfoList::iterator aTablePos; TableInfoList::iterator aTablePos = std::find_if(m_aTableInfoList.begin(), m_aTableInfoList.end(),
if (!GetTable(_rTableName, aTablePos)) [&] (const OTableInfo& arg) { return arg.aTableName == _rTableName; });
if (aTablePos == m_aTableInfoList.end())
return aReturn; return aReturn;
return implRemoveIndex(_rIndexName, aTablePos->aIndexList, *m_pLB_TableIndexes, true/*_bMustExist*/); return implRemoveIndex(_rIndexName, aTablePos->aIndexList, *m_pLB_TableIndexes, true/*_bMustExist*/);
...@@ -171,8 +160,10 @@ OTableIndex ODbaseIndexDialog::RemoveTableIndex( const OUString& _rTableName, co ...@@ -171,8 +160,10 @@ OTableIndex ODbaseIndexDialog::RemoveTableIndex( const OUString& _rTableName, co
void ODbaseIndexDialog::InsertTableIndex( const OUString& _rTableName, const OTableIndex& _rIndex) void ODbaseIndexDialog::InsertTableIndex( const OUString& _rTableName, const OTableIndex& _rIndex)
{ {
TableInfoList::iterator aTablePos; TableInfoList::iterator aTablePos = std::find_if(m_aTableInfoList.begin(), m_aTableInfoList.end(),
if (!GetTable(_rTableName, aTablePos)) [&] (const OTableInfo& arg) { return arg.aTableName == _rTableName; });
if (aTablePos == m_aTableInfoList.end())
return; return;
implInsertIndex(_rIndex, aTablePos->aIndexList, *m_pLB_TableIndexes); implInsertIndex(_rIndex, aTablePos->aIndexList, *m_pLB_TableIndexes);
...@@ -182,11 +173,8 @@ IMPL_LINK_NOARG( ODbaseIndexDialog, OKClickHdl, Button*, void ) ...@@ -182,11 +173,8 @@ IMPL_LINK_NOARG( ODbaseIndexDialog, OKClickHdl, Button*, void )
{ {
// let all tables write their INF file // let all tables write their INF file
for ( TableInfoList::const_iterator aLoop = m_aTableInfoList.begin(); for (auto const& tableInfo : m_aTableInfoList)
aLoop != m_aTableInfoList.end(); tableInfo.WriteInfFile(m_aDSN);
++aLoop
)
aLoop->WriteInfFile(m_aDSN);
EndDialog(); EndDialog();
} }
...@@ -241,19 +229,18 @@ IMPL_LINK_NOARG( ODbaseIndexDialog, OnListEntrySelected, ListBox&, void ) ...@@ -241,19 +229,18 @@ IMPL_LINK_NOARG( ODbaseIndexDialog, OnListEntrySelected, ListBox&, void )
IMPL_LINK( ODbaseIndexDialog, TableSelectHdl, ComboBox&, rComboBox, void ) IMPL_LINK( ODbaseIndexDialog, TableSelectHdl, ComboBox&, rComboBox, void )
{ {
// search the table // search the table
TableInfoList::iterator aTablePos; TableInfoList::iterator aTablePos = std::find_if(m_aTableInfoList.begin(), m_aTableInfoList.end(),
if (!GetTable(rComboBox.GetText(), aTablePos)) [&] (const OTableInfo& arg) { return arg.aTableName == rComboBox.GetText() ; });
if (aTablePos == m_aTableInfoList.end())
return; return;
// fill the listbox for the indexes // fill the listbox for the indexes
m_pLB_TableIndexes->Clear(); m_pLB_TableIndexes->Clear();
for ( TableIndexList::const_iterator aLoop = aTablePos->aIndexList.begin(); for (auto const& index : aTablePos->aIndexList)
aLoop != aTablePos->aIndexList.end(); m_pLB_TableIndexes->InsertEntry( index.GetIndexFileName() );
++aLoop
)
m_pLB_TableIndexes->InsertEntry( aLoop->GetIndexFileName() );
if ( aTablePos->aIndexList.size() ) if ( !aTablePos->aIndexList.empty() )
m_pLB_TableIndexes->SelectEntryPos(0); m_pLB_TableIndexes->SelectEntryPos(0);
checkButtons(); checkButtons();
...@@ -352,13 +339,10 @@ void ODbaseIndexDialog::Init() ...@@ -352,13 +339,10 @@ void ODbaseIndexDialog::Init()
} }
} }
for ( std::vector< OUString >::const_iterator aUsedIndex = aUsedIndexes.begin(); for (auto const& usedIndex : aUsedIndexes)
aUsedIndex != aUsedIndexes.end(); RemoveFreeIndex( usedIndex, false );
++aUsedIndex
)
RemoveFreeIndex( *aUsedIndex, false );
if (m_aTableInfoList.size()) if (!m_aTableInfoList.empty())
{ {
m_pPB_OK->Enable(); m_pPB_OK->Enable();
m_pIndexes->Enable(); m_pIndexes->Enable();
...@@ -370,37 +354,28 @@ void ODbaseIndexDialog::Init() ...@@ -370,37 +354,28 @@ void ODbaseIndexDialog::Init()
void ODbaseIndexDialog::SetCtrls() void ODbaseIndexDialog::SetCtrls()
{ {
// ComboBox tables // ComboBox tables
for ( TableInfoList::const_iterator aLoop = m_aTableInfoList.begin(); for (auto const& tableInfo : m_aTableInfoList)
aLoop != m_aTableInfoList.end(); m_pCB_Tables->InsertEntry( tableInfo.aTableName );
++aLoop
)
m_pCB_Tables->InsertEntry( aLoop->aTableName );
// put the first dataset into Edit // put the first dataset into Edit
if( m_aTableInfoList.size() ) if( !m_aTableInfoList.empty() )
{ {
const OTableInfo& rTabInfo = m_aTableInfoList.front(); const OTableInfo& rTabInfo = m_aTableInfoList.front();
m_pCB_Tables->SetText( rTabInfo.aTableName ); m_pCB_Tables->SetText( rTabInfo.aTableName );
// build ListBox of the table indices // build ListBox of the table indices
for ( TableIndexList::const_iterator aIndex = rTabInfo.aIndexList.begin(); for (auto const& index : rTabInfo.aIndexList)
aIndex != rTabInfo.aIndexList.end(); m_pLB_TableIndexes->InsertEntry( index.GetIndexFileName() );
++aIndex
)
m_pLB_TableIndexes->InsertEntry( aIndex->GetIndexFileName() );
if( rTabInfo.aIndexList.size() ) if( !rTabInfo.aIndexList.empty() )
m_pLB_TableIndexes->SelectEntryPos( 0 ); m_pLB_TableIndexes->SelectEntryPos( 0 );
} }
// ListBox of the free indices // ListBox of the free indices
for ( TableIndexList::const_iterator aFree = m_aFreeIndexList.begin(); for (auto const& freeIndex : m_aFreeIndexList)
aFree != m_aFreeIndexList.end(); m_pLB_FreeIndexes->InsertEntry( freeIndex.GetIndexFileName() );
++aFree
)
m_pLB_FreeIndexes->InsertEntry( aFree->GetIndexFileName() );
if( m_aFreeIndexList.size() ) if( !m_aFreeIndexList.empty() )
m_pLB_FreeIndexes->SelectEntryPos( 0 ); m_pLB_FreeIndexes->SelectEntryPos( 0 );
TableSelectHdl(*m_pCB_Tables); TableSelectHdl(*m_pCB_Tables);
...@@ -449,18 +424,16 @@ void OTableInfo::WriteInfFile( const OUString& rDSN ) const ...@@ -449,18 +424,16 @@ void OTableInfo::WriteInfFile( const OUString& rDSN ) const
// now add all saved indices // now add all saved indices
sal_uInt16 nPos = 0; sal_uInt16 nPos = 0;
for ( TableIndexList::const_iterator aIndex = aIndexList.begin(); for (auto const& index : aIndexList)
aIndex != aIndexList.end();
++aIndex, ++nPos
)
{ {
OStringBuffer aKeyName("NDX"); OStringBuffer aKeyName("NDX");
if( nPos > 0 ) // first index contains no number if( nPos > 0 ) // first index contains no number
aKeyName.append(static_cast<sal_Int32>(nPos)); aKeyName.append(static_cast<sal_Int32>(nPos));
aInfFile.WriteKey( aInfFile.WriteKey(
aKeyName.makeStringAndClear(), aKeyName.makeStringAndClear(),
OUStringToOString(aIndex->GetIndexFileName(), OUStringToOString(index.GetIndexFileName(),
osl_getThreadTextEncoding())); osl_getThreadTextEncoding()));
++nPos;
} }
aInfFile.Flush(); aInfFile.Flush();
......
...@@ -96,7 +96,6 @@ protected: ...@@ -96,7 +96,6 @@ protected:
void Init(); void Init();
void SetCtrls(); void SetCtrls();
bool GetTable(const OUString& rName, TableInfoList::iterator& _rPosition);
static OTableIndex implRemoveIndex(const OUString& _rName, TableIndexList& _rList, ListBox& _rDisplay, bool _bMustExist); static OTableIndex implRemoveIndex(const OUString& _rName, TableIndexList& _rList, ListBox& _rDisplay, bool _bMustExist);
static void implInsertIndex(const OTableIndex& _rIndex, TableIndexList& _rList, ListBox& _rDisplay); static void implInsertIndex(const OTableIndex& _rIndex, TableIndexList& _rList, ListBox& _rDisplay);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment