svtools/inc/svtools/treelist.hxx | 107 +++++------------- svtools/source/contnr/svlbox.cxx | 24 ++-- svtools/source/contnr/treelist.cxx | 219 +++++++++++++++++++++++++++---------- 3 files changed, 205 insertions(+), 145 deletions(-)
New commits: commit 1f48c56387fa95bc52e88512f82bc5b5436d7c4c Author: Kohei Yoshida <[email protected]> Date: Thu Sep 27 09:32:19 2012 -0400 Use more STL iterators instead of First(), Next() and last() (sic). Change-Id: If5f7b749539979e95548b93b840412f18fcb68d7 diff --git a/svtools/inc/svtools/treelist.hxx b/svtools/inc/svtools/treelist.hxx index 98e5675..d5ba003 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 bc95659..d3e0c03 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 72f24a1..cb12059 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); } } commit fb7053ca7cf439372cfd5abb7ab788cbd416c219 Author: Kohei Yoshida <[email protected]> Date: Thu Sep 27 00:45:21 2012 -0400 Correct prefix for integer type. Change-Id: I57668a3a288b4ffc4f0adf6614cdd7e50d21fdf8 diff --git a/svtools/inc/svtools/treelist.hxx b/svtools/inc/svtools/treelist.hxx index ed1761f..98e5675 100644 --- a/svtools/inc/svtools/treelist.hxx +++ b/svtools/inc/svtools/treelist.hxx @@ -67,7 +67,7 @@ class SVT_DLLPUBLIC SvTreeEntryList { private: std::vector<SvListEntry*> maEntryList; - size_t maCurrent; + size_t mnCurrent; public: SvTreeEntryList(); diff --git a/svtools/source/contnr/treelist.cxx b/svtools/source/contnr/treelist.cxx index d832f47..72f24a1 100644 --- a/svtools/source/contnr/treelist.cxx +++ b/svtools/source/contnr/treelist.cxx @@ -31,7 +31,7 @@ DBG_NAME(SvListEntry); -SvTreeEntryList::SvTreeEntryList() { maCurrent = 0; }; +SvTreeEntryList::SvTreeEntryList() : mnCurrent(0) {} void SvTreeEntryList::push_back( SvListEntry* pItem ) { @@ -116,13 +116,13 @@ const SvListEntry* SvTreeEntryList::operator[](size_t i) const SvListEntry* SvTreeEntryList::First() { - maCurrent = 0; - return ( maCurrent < maEntryList.size() ) ? maEntryList[ 0 ] : NULL; + mnCurrent = 0; + return ( mnCurrent < maEntryList.size() ) ? maEntryList[ 0 ] : NULL; } SvListEntry* SvTreeEntryList::Next() { - return ( maCurrent+1 < maEntryList.size() ) ? maEntryList[ ++maCurrent ] : NULL; + return ( mnCurrent+1 < maEntryList.size() ) ? maEntryList[ ++mnCurrent ] : NULL; } SvListEntry* SvTreeEntryList::last() @@ -143,7 +143,7 @@ void SvTreeEntryList::DestroyAll() SvTreeEntryList::SvTreeEntryList(const SvTreeEntryList& rList) { maEntryList.clear(); - maCurrent = 0; + mnCurrent = 0; for ( size_t i = 0, n = rList.size(); i < n; ++i ) maEntryList.push_back(const_cast<SvListEntry*>(rList[i])); } commit f930a02c4b6bfd19da7ae18264eca066117541db Author: Kohei Yoshida <[email protected]> Date: Thu Sep 27 00:43:47 2012 -0400 Let's use std::vector directly. Change-Id: Ie725c554d0ec8b3b505212d47c76b70e6ecdddd5 diff --git a/svtools/inc/svtools/treelist.hxx b/svtools/inc/svtools/treelist.hxx index b43110a..ed1761f 100644 --- a/svtools/inc/svtools/treelist.hxx +++ b/svtools/inc/svtools/treelist.hxx @@ -63,15 +63,11 @@ class SvListEntry; -//============================================================================= - -typedef ::std::vector< SvListEntry* > SvTreeEntryList_impl; - class SVT_DLLPUBLIC SvTreeEntryList { private: - SvTreeEntryList_impl maEntryList; - size_t maCurrent; + std::vector<SvListEntry*> maEntryList; + size_t maCurrent; public: SvTreeEntryList(); diff --git a/svtools/source/contnr/treelist.cxx b/svtools/source/contnr/treelist.cxx index 0d80879..d832f47 100644 --- a/svtools/source/contnr/treelist.cxx +++ b/svtools/source/contnr/treelist.cxx @@ -52,7 +52,7 @@ void SvTreeEntryList::insert( SvListEntry* pItem, size_t i ) void SvTreeEntryList::remove( SvListEntry* pItem ) { - for (SvTreeEntryList_impl::iterator it = maEntryList.begin(); it != maEntryList.end(); ++it) + for (std::vector<SvListEntry*>::iterator it = maEntryList.begin(); it != maEntryList.end(); ++it) { if ( *it == pItem ) { commit ae99d0ce6081d54373b06c618c64567fa03ba028 Author: Kohei Yoshida <[email protected]> Date: Thu Sep 27 00:41:47 2012 -0400 const correctness. Change-Id: I7303a31d415d23c50d6b7b8a6b071c260cb00bb0 diff --git a/svtools/inc/svtools/treelist.hxx b/svtools/inc/svtools/treelist.hxx index 6c1fc0a..b43110a 100644 --- a/svtools/inc/svtools/treelist.hxx +++ b/svtools/inc/svtools/treelist.hxx @@ -75,7 +75,7 @@ private: public: SvTreeEntryList(); - SvTreeEntryList(SvTreeEntryList& rList); + SvTreeEntryList(const SvTreeEntryList& rList); void DestroyAll(); void push_back(SvListEntry* pItem); @@ -85,12 +85,13 @@ public: void replace(SvListEntry* pNew, SvListEntry* pOld); void clear(); - bool empty(); + bool empty() const; - size_t size(); - size_t GetPos(SvListEntry* pItem); + size_t size() const; + size_t GetPos(const SvListEntry* pItem) const; SvListEntry* operator[](size_t i); + const SvListEntry* operator[](size_t i) const; SvListEntry* First(); SvListEntry* Next(); SvListEntry* last(); diff --git a/svtools/source/contnr/treelist.cxx b/svtools/source/contnr/treelist.cxx index 78fb0b6..0d80879 100644 --- a/svtools/source/contnr/treelist.cxx +++ b/svtools/source/contnr/treelist.cxx @@ -84,17 +84,17 @@ void SvTreeEntryList::clear() maEntryList.clear(); } -bool SvTreeEntryList::empty() +bool SvTreeEntryList::empty() const { return maEntryList.empty(); } -size_t SvTreeEntryList::size() +size_t SvTreeEntryList::size() const { return maEntryList.size(); } -size_t SvTreeEntryList::GetPos( SvListEntry* pItem ) +size_t SvTreeEntryList::GetPos(const SvListEntry* pItem) const { for ( size_t i = 0, n = maEntryList.size(); i < n; ++i ) { if ( maEntryList[ i ] == pItem ) { @@ -104,9 +104,14 @@ size_t SvTreeEntryList::GetPos( SvListEntry* pItem ) return (size_t)~0; } -SvListEntry* SvTreeEntryList::operator[]( size_t i ) +SvListEntry* SvTreeEntryList::operator[](size_t i) { - return i < maEntryList.size() ? maEntryList[ i ] : NULL; + return i < maEntryList.size() ? maEntryList[i] : NULL; +} + +const SvListEntry* SvTreeEntryList::operator[](size_t i) const +{ + return i < maEntryList.size() ? maEntryList[i] : NULL; } SvListEntry* SvTreeEntryList::First() @@ -135,13 +140,12 @@ void SvTreeEntryList::DestroyAll() } } -SvTreeEntryList::SvTreeEntryList(SvTreeEntryList& rList) +SvTreeEntryList::SvTreeEntryList(const SvTreeEntryList& rList) { maEntryList.clear(); maCurrent = 0; - for ( size_t i = 0, n = rList.size(); i < n; ++i ) { - maEntryList.push_back( rList[ i ] ); - } + for ( size_t i = 0, n = rList.size(); i < n; ++i ) + maEntryList.push_back(const_cast<SvListEntry*>(rList[i])); } SvListEntry::SvListEntry() commit ccc779769153ce61f658776f6c2847eb4242e3bd Author: Kohei Yoshida <[email protected]> Date: Thu Sep 27 00:33:21 2012 -0400 Hide method definitions of SvTreeEntryList. Change-Id: Id110a12bc462d4da0b000d7c441da34f861c8892 diff --git a/svtools/inc/svtools/treelist.hxx b/svtools/inc/svtools/treelist.hxx index 0875052..6c1fc0a 100644 --- a/svtools/inc/svtools/treelist.hxx +++ b/svtools/inc/svtools/treelist.hxx @@ -74,74 +74,26 @@ private: size_t maCurrent; public: - SvTreeEntryList() { maCurrent = 0; }; - SvTreeEntryList( SvTreeEntryList& rList ); - - void DestroyAll(); - void push_back( SvListEntry* pItem ) - { maEntryList.push_back( pItem ); } - void insert( SvListEntry* pItem, size_t i ) - { - if ( i < maEntryList.size() ) { - maEntryList.insert( maEntryList.begin() + i, pItem ); - } else { - maEntryList.push_back( pItem ); - } - } - void remove( SvListEntry* pItem ) - { - for ( SvTreeEntryList_impl::iterator it = maEntryList.begin(); - it != maEntryList.end(); - ++it - ) { - if ( *it == pItem ) { - maEntryList.erase( it ); - break; - } - } - } - void remove( size_t i ) - { - if ( i < maEntryList.size() ) { - maEntryList.erase( maEntryList.begin() + i ); - } - } - void replace( SvListEntry* pNew, SvListEntry* pOld ) - { - for ( size_t i = 0, n = maEntryList.size(); i < n; ++i ) { - if ( maEntryList[ i ] == pOld ) { - maEntryList[ i ] = pNew; - break; - } - } - } - void clear() { maEntryList.clear(); } - - bool empty() { return maEntryList.empty(); } - - size_t size() { return maEntryList.size(); } - size_t GetPos( SvListEntry* pItem ) - { - for ( size_t i = 0, n = maEntryList.size(); i < n; ++i ) { - if ( maEntryList[ i ] == pItem ) { - return i; - } - } - return (size_t)~0; - } - - SvListEntry* operator[]( size_t i ) - { return i < maEntryList.size() ? maEntryList[ i ] : NULL; } - SvListEntry* First() - { - maCurrent = 0; - return ( maCurrent < maEntryList.size() ) ? maEntryList[ 0 ] : NULL; - } - SvListEntry* Next() - { - return ( maCurrent+1 < maEntryList.size() ) ? maEntryList[ ++maCurrent ] : NULL; - } - SvListEntry* last() { return maEntryList.empty() ? NULL : maEntryList.back(); } + SvTreeEntryList(); + SvTreeEntryList(SvTreeEntryList& rList); + + void DestroyAll(); + void push_back(SvListEntry* pItem); + void insert(SvListEntry* pItem, size_t i); + void remove(SvListEntry* pItem); + void remove(size_t i); + void replace(SvListEntry* pNew, SvListEntry* pOld); + void clear(); + + bool empty(); + + size_t size(); + size_t GetPos(SvListEntry* pItem); + + SvListEntry* operator[](size_t i); + SvListEntry* First(); + SvListEntry* Next(); + SvListEntry* last(); }; //============================================================================= diff --git a/svtools/source/contnr/treelist.cxx b/svtools/source/contnr/treelist.cxx index 42bb3e4..78fb0b6 100644 --- a/svtools/source/contnr/treelist.cxx +++ b/svtools/source/contnr/treelist.cxx @@ -30,6 +30,120 @@ DBG_NAME(SvListEntry); + +SvTreeEntryList::SvTreeEntryList() { maCurrent = 0; }; + +void SvTreeEntryList::push_back( SvListEntry* pItem ) +{ + maEntryList.push_back( pItem ); +} + +void SvTreeEntryList::insert( SvListEntry* pItem, size_t i ) +{ + if ( i < maEntryList.size() ) + { + maEntryList.insert( maEntryList.begin() + i, pItem ); + } + else + { + maEntryList.push_back( pItem ); + } +} + +void SvTreeEntryList::remove( SvListEntry* pItem ) +{ + for (SvTreeEntryList_impl::iterator it = maEntryList.begin(); it != maEntryList.end(); ++it) + { + if ( *it == pItem ) + { + maEntryList.erase( it ); + break; + } + } +} + +void SvTreeEntryList::remove( size_t i ) +{ + if ( i < maEntryList.size() ) { + maEntryList.erase( maEntryList.begin() + i ); + } +} + +void SvTreeEntryList::replace( SvListEntry* pNew, SvListEntry* pOld ) +{ + for ( size_t i = 0, n = maEntryList.size(); i < n; ++i ) { + if ( maEntryList[ i ] == pOld ) { + maEntryList[ i ] = pNew; + break; + } + } +} + +void SvTreeEntryList::clear() +{ + maEntryList.clear(); +} + +bool SvTreeEntryList::empty() +{ + return maEntryList.empty(); +} + +size_t SvTreeEntryList::size() +{ + return maEntryList.size(); +} + +size_t SvTreeEntryList::GetPos( SvListEntry* pItem ) +{ + for ( size_t i = 0, n = maEntryList.size(); i < n; ++i ) { + if ( maEntryList[ i ] == pItem ) { + return i; + } + } + return (size_t)~0; +} + +SvListEntry* SvTreeEntryList::operator[]( size_t i ) +{ + return i < maEntryList.size() ? maEntryList[ i ] : NULL; +} + +SvListEntry* SvTreeEntryList::First() +{ + maCurrent = 0; + return ( maCurrent < maEntryList.size() ) ? maEntryList[ 0 ] : NULL; +} + +SvListEntry* SvTreeEntryList::Next() +{ + return ( maCurrent+1 < maEntryList.size() ) ? maEntryList[ ++maCurrent ] : NULL; +} + +SvListEntry* SvTreeEntryList::last() +{ + return maEntryList.empty() ? NULL : maEntryList.back(); +} + +void SvTreeEntryList::DestroyAll() +{ + SvListEntry* pPtr = (SvListEntry*)First(); + while( pPtr ) + { + delete pPtr; + pPtr = (SvListEntry*)Next(); + } +} + +SvTreeEntryList::SvTreeEntryList(SvTreeEntryList& rList) +{ + maEntryList.clear(); + maCurrent = 0; + for ( size_t i = 0, n = rList.size(); i < n; ++i ) { + maEntryList.push_back( rList[ i ] ); + } +} + SvListEntry::SvListEntry() { DBG_CTOR(SvListEntry,0); @@ -115,29 +229,6 @@ SvViewData::~SvViewData() #endif } -//============================================================================= -// SvTreeEntryList -//============================================================================= - -void SvTreeEntryList::DestroyAll() -{ - SvListEntry* pPtr = (SvListEntry*)First(); - while( pPtr ) - { - delete pPtr; - pPtr = (SvListEntry*)Next(); - } -} - -SvTreeEntryList::SvTreeEntryList(SvTreeEntryList& rList) -{ - maEntryList.clear(); - maCurrent = 0; - for ( size_t i = 0, n = rList.size(); i < n; ++i ) { - maEntryList.push_back( rList[ i ] ); - } -} - /************************************************************************* |* |* SvTreeList:: _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
