diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2012-09-27 09:32:19 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2012-09-27 13:45:20 -0400 |
commit | 1f48c56387fa95bc52e88512f82bc5b5436d7c4c (patch) | |
tree | 8e9f914035a7ea0d447dac73d0ae61a2707e0bee | |
parent | Correct prefix for integer type. (diff) | |
download | core-1f48c56387fa95bc52e88512f82bc5b5436d7c4c.tar.gz core-1f48c56387fa95bc52e88512f82bc5b5436d7c4c.zip |
Use more STL iterators instead of First(), Next() and last() (sic).
Change-Id: If5f7b749539979e95548b93b840412f18fcb68d7
-rw-r--r-- | svtools/inc/svtools/treelist.hxx | 20 | ||||
-rw-r--r-- | svtools/source/contnr/svlbox.cxx | 24 | ||||
-rw-r--r-- | svtools/source/contnr/treelist.cxx | 108 |
3 files changed, 84 insertions, 68 deletions
diff --git a/svtools/inc/svtools/treelist.hxx b/svtools/inc/svtools/treelist.hxx index 98e56758e03a..d5ba0035269d 100644 --- a/svtools/inc/svtools/treelist.hxx +++ b/svtools/inc/svtools/treelist.hxx @@ -66,10 +66,13 @@ class SvListEntry; class SVT_DLLPUBLIC SvTreeEntryList { private: - std::vector<SvListEntry*> maEntryList; - size_t mnCurrent; + typedef std::vector<SvListEntry*> ListType; + ListType maEntryList; public: + typedef ListType::const_iterator const_iterator; + typedef ListType::iterator iterator; + SvTreeEntryList(); SvTreeEntryList(const SvTreeEntryList& rList); @@ -88,9 +91,14 @@ public: SvListEntry* operator[](size_t i); const SvListEntry* operator[](size_t i) const; - SvListEntry* First(); - SvListEntry* Next(); - SvListEntry* last(); + + const_iterator begin() const; + const_iterator end() const; + + iterator begin(); + iterator end(); + SvListEntry* front(); + SvListEntry* back(); }; //============================================================================= @@ -321,7 +329,7 @@ public: sal_Bool HasParent( SvListEntry* pEntry ) const { return (sal_Bool)(pEntry->pParent!=pRootItem); } - sal_Bool IsChild( SvListEntry* pParent, SvListEntry* pChild ) const; + bool IsChild(const SvListEntry* pParent, const SvListEntry* pChild) const; SvListEntry* GetEntry( SvListEntry* pParent, sal_uLong nPos ) const; SvListEntry* GetEntry( sal_uLong nRootPos ) const; SvListEntry* GetEntryAtAbsPos( sal_uLong nAbsPos ) const; diff --git a/svtools/source/contnr/svlbox.cxx b/svtools/source/contnr/svlbox.cxx index bc956597c31a..d3e0c031919c 100644 --- a/svtools/source/contnr/svlbox.cxx +++ b/svtools/source/contnr/svlbox.cxx @@ -827,9 +827,10 @@ sal_Bool SvLBox::CopySelection( SvLBox* pSource, SvLBoxEntry* pTarget ) pSourceEntry = pSource->NextSelected( pSourceEntry ); } - pSourceEntry = (SvLBoxEntry*)aList.First(); - while ( pSourceEntry ) + SvTreeEntryList::iterator it = aList.begin(), itEnd = aList.end(); + for (; it != itEnd; ++it) { + pSourceEntry = static_cast<SvLBoxEntry*>(*it); SvLBoxEntry* pNewParent = 0; sal_uLong nInsertionPos = ULONG_MAX; sal_Bool bOk=NotifyCopying(pTarget,pSourceEntry,pNewParent,nInsertionPos); @@ -855,8 +856,6 @@ sal_Bool SvLBox::CopySelection( SvLBox* pSource, SvLBoxEntry* pTarget ) if( bOk == (sal_Bool)2 ) // HACK: make visible moved entry? MakeVisible( pSourceEntry ); - - pSourceEntry = (SvLBoxEntry*)aList.Next(); } pModel->SetCloneLink( aCloneLink ); return bSuccess; @@ -888,9 +887,11 @@ sal_Bool SvLBox::MoveSelectionCopyFallbackPossible( SvLBox* pSource, SvLBoxEntry pSourceEntry = pSource->NextSelected( pSourceEntry ); } - pSourceEntry = (SvLBoxEntry*)aList.First(); - while ( pSourceEntry ) + SvTreeEntryList::iterator it = aList.begin(), itEnd = aList.end(); + for (; it != itEnd; ++it) { + pSourceEntry = static_cast<SvLBoxEntry*>(*it); + SvLBoxEntry* pNewParent = 0; sal_uLong nInsertionPos = ULONG_MAX; sal_Bool bOk = NotifyMoving(pTarget,pSourceEntry,pNewParent,nInsertionPos); @@ -926,8 +927,6 @@ sal_Bool SvLBox::MoveSelectionCopyFallbackPossible( SvLBox* pSource, SvLBoxEntry if( bOk == (sal_Bool)2 ) // HACK: make moved entry visible? MakeVisible( pSourceEntry ); - - pSourceEntry = (SvLBoxEntry*)aList.Next(); } pModel->SetCloneLink( aCloneLink ); return bSuccess; @@ -948,11 +947,12 @@ void SvLBox::RemoveSelection() SelectChildren( pEntry, sal_False ); pEntry = NextSelected( pEntry ); } - pEntry = (SvLBoxEntry*)aList.First(); - while ( pEntry ) + + SvTreeEntryList::iterator it = aList.begin(), itEnd = aList.end(); + for (; it != itEnd; ++it) { - pModel->Remove( pEntry ); - pEntry = (SvLBoxEntry*)aList.Next(); + pEntry = static_cast<SvLBoxEntry*>(*it); + pModel->Remove(pEntry); } } diff --git a/svtools/source/contnr/treelist.cxx b/svtools/source/contnr/treelist.cxx index 72f24a10b336..cb12059a1c61 100644 --- a/svtools/source/contnr/treelist.cxx +++ b/svtools/source/contnr/treelist.cxx @@ -31,7 +31,7 @@ DBG_NAME(SvListEntry); -SvTreeEntryList::SvTreeEntryList() : mnCurrent(0) {} +SvTreeEntryList::SvTreeEntryList() {} void SvTreeEntryList::push_back( SvListEntry* pItem ) { @@ -114,36 +114,46 @@ const SvListEntry* SvTreeEntryList::operator[](size_t i) const return i < maEntryList.size() ? maEntryList[i] : NULL; } -SvListEntry* SvTreeEntryList::First() +SvTreeEntryList::const_iterator SvTreeEntryList::begin() const { - mnCurrent = 0; - return ( mnCurrent < maEntryList.size() ) ? maEntryList[ 0 ] : NULL; + return maEntryList.begin(); } -SvListEntry* SvTreeEntryList::Next() +SvTreeEntryList::const_iterator SvTreeEntryList::end() const { - return ( mnCurrent+1 < maEntryList.size() ) ? maEntryList[ ++mnCurrent ] : NULL; + return maEntryList.end(); } -SvListEntry* SvTreeEntryList::last() +SvTreeEntryList::iterator SvTreeEntryList::begin() { - return maEntryList.empty() ? NULL : maEntryList.back(); + return maEntryList.begin(); +} + +SvTreeEntryList::iterator SvTreeEntryList::end() +{ + return maEntryList.end(); +} + +SvListEntry* SvTreeEntryList::front() +{ + return maEntryList.front(); +} + +SvListEntry* SvTreeEntryList::back() +{ + return maEntryList.back(); } void SvTreeEntryList::DestroyAll() { - SvListEntry* pPtr = (SvListEntry*)First(); - while( pPtr ) - { - delete pPtr; - pPtr = (SvListEntry*)Next(); - } + ListType::const_iterator it = maEntryList.begin(), itEnd = maEntryList.end(); + for (; it != itEnd; ++it) + delete *it; } SvTreeEntryList::SvTreeEntryList(const SvTreeEntryList& rList) { maEntryList.clear(); - mnCurrent = 0; for ( size_t i = 0, n = rList.size(); i < n; ++i ) maEntryList.push_back(const_cast<SvListEntry*>(rList[i])); } @@ -193,14 +203,14 @@ void SvListEntry::SetListPositions() { if( pChildren ) { - SvListEntry *pEntry = (SvListEntry*)pChildren->First(); - sal_uLong nCur = 0; - while ( pEntry ) + SvTreeEntryList::iterator it = pChildren->begin(), itEnd = pChildren->end(); + sal_uLong nCur = 0; + for (; it != itEnd; ++it) { + SvListEntry* pEntry = *it; pEntry->nListPos &= 0x80000000; pEntry->nListPos |= nCur; - nCur++; - pEntry = (SvListEntry*)pChildren->Next(); + ++nCur; } } nListPos &= (~0x80000000); @@ -349,12 +359,7 @@ void SvTreeList::Clear() SvTreeEntryList* pRootList = pRootItem->pChildren; if ( pRootList ) { - SvListEntry* pEntry = (SvListEntry*)(pRootList->First()); - while( pEntry ) - { - delete pEntry; - pEntry = (SvListEntry*)(pRootList->Next()); - } + pRootList->DestroyAll(); delete pRootItem->pChildren; pRootItem->pChildren = 0; } @@ -369,25 +374,27 @@ void SvTreeList::Clear() |* *************************************************************************/ -sal_Bool SvTreeList::IsChild( SvListEntry* pParent, SvListEntry* pChild ) const +bool SvTreeList::IsChild(const SvListEntry* pParent, const SvListEntry* pChild) const { if ( !pParent ) pParent = pRootItem; - sal_Bool bIsChild = sal_False; + bool bIsChild = false; SvTreeEntryList* pList = pParent->pChildren; if ( !pList ) - return sal_False; - SvListEntry* pActualChild = (SvListEntry*)(pList->First()); - while( !bIsChild && pActualChild ) + return false; + + SvTreeEntryList::const_iterator it = pList->begin(), itEnd = pList->end(); + while (!bIsChild && it != itEnd) { + const SvListEntry* pActualChild = *it; if ( pActualChild == pChild ) - bIsChild = sal_True; + bIsChild = true; else { if ( pActualChild->pChildren ) bIsChild = IsChild( pActualChild, pChild ); - pActualChild = (SvListEntry*)(pList->Next()); + ++it; } } return bIsChild; @@ -578,9 +585,10 @@ SvTreeEntryList* SvTreeList::CloneChildren( SvTreeEntryList* pChildren, { DBG_ASSERT(!pChildren->empty(),"Children?"); SvTreeEntryList* pClonedChildren = new SvTreeEntryList; - SvListEntry* pChild = (SvListEntry*)pChildren->First(); - while ( pChild ) + SvTreeEntryList::iterator it = pChildren->begin(), itEnd = pChildren->end(); + while (it != itEnd) { + SvListEntry* pChild = *it; SvListEntry* pNewChild = CloneEntry( pChild ); nCloneCount++; pNewChild->pParent = pNewParent; @@ -592,7 +600,7 @@ SvTreeEntryList* SvTreeList::CloneChildren( SvTreeEntryList* pChildren, } pClonedChildren->push_back( pNewChild ); - pChild = (SvListEntry*)pChildren->Next(); + ++it; } return pClonedChildren; } @@ -765,12 +773,12 @@ SvListEntry* SvTreeList::Prev( SvListEntry* pActEntry, sal_uInt16* pDepth ) cons if ( nActualPos > 0 ) { - pActEntry = (SvListEntry*)(*pActualList)[ nActualPos - 1 ]; + pActEntry = (*pActualList)[nActualPos-1]; while( pActEntry->pChildren ) { pActualList = pActEntry->pChildren; nDepth++; - pActEntry = (SvListEntry*)(pActualList->last()); + pActEntry = pActualList->back(); } if ( bWithDepth ) *pDepth = nDepth; @@ -805,7 +813,7 @@ SvListEntry* SvTreeList::Last() const SvListEntry* pEntry = 0; while( pActList ) { - pEntry = (SvListEntry*)(pActList->last()); + pEntry = pActList->back(); pActList = pEntry->pChildren; // if ( pActList->Count() == 0 ) // pActList = 0; @@ -965,7 +973,7 @@ SvListEntry* SvTreeList::PrevVisible(const SvListView* pView, SvListEntry* pActE { pActualList = pActEntry->pChildren; nDepth++; - pActEntry = (SvListEntry*)(pActualList->last()); + pActEntry = pActualList->back(); } if ( bWithDepth ) *pActDepth = nDepth; @@ -1124,7 +1132,7 @@ SvListEntry* SvTreeList::LastSibling( SvListEntry* pEntry ) const SvListEntry* pSib = 0; SvTreeEntryList* pSibs = pEntry->pParent->pChildren; if ( pSibs ) - pSib = (SvListEntry*)(pSibs->last()); + pSib = pSibs->back(); return pSib; } @@ -1715,16 +1723,16 @@ void SvListView::ActionInsertedTree( SvListEntry* pEntry ) void SvListView::RemoveViewData( SvListEntry* pParent ) { SvTreeEntryList* pChildren = pParent->pChildren; - if( pChildren ) + if (!pChildren) + return; + + SvTreeEntryList::iterator it = pChildren->begin(), itEnd = pChildren->end(); + for (; it != itEnd; ++it) { - SvListEntry* pCur = (SvListEntry*)pChildren->First(); - while( pCur ) - { - maDataTable.erase(pCur); - if( pCur->HasChildren()) - RemoveViewData( pCur ); - pCur = (SvListEntry*)pChildren->Next(); - } + SvListEntry* pCur = *it; + maDataTable.erase(pCur); + if (pCur->HasChildren()) + RemoveViewData(pCur); } } |