On Tue, Jun 7, 2011 at 8:19 PM, Rafael Dominguez <venccsra...@gmail.com>wrote:
> > >> Also haven't pushed >> 0002-Replace-List-with-std-vector-XclExpUserBView.calc.patch because I >> am not sure about >> >> --- cut --- >> XclExpUserBViewList::XclExpUserBViewList( const ScChangeTrack& >> rChangeTrack ) >> + : aViews(rChangeTrack.GetUserCollection().GetCount()) >> [...] >> - List::Insert( new XclExpUserBView( pStrData->GetString(), >> aGUID ), LIST_APPEND ); >> + aViews.push_back( new XclExpUserBView( pStrData->GetString(), >> aGUID ) ); >> --- cut --- >> >> Why do you initialize the vector with NULL pointers? >> >> IMHO, all the pointers will stay NULL because you later use .push_back(). >> >> For example, rChangeTrack has the collection: A B C D and GetCount() >> returns 4. >> If you initialize the vector, you will end with the vector: 0 0 0 0 A B C >> D >> >> Or did I miss something? >> >> > Nope, heres a patch fixing those issues > > Forgot to remove the initializing the vector changed it for reserve. Tripled checked so it should be fine now
From 04f5c37f2816c5e6bbdf2cd58e0619cb52277cc7 Mon Sep 17 00:00:00 2001 From: Rafael Dominguez <venccsra...@gmail.com> Date: Tue, 7 Jun 2011 20:29:41 -0430 Subject: [PATCH] Replace List with std::vector<XclExpUserBView*>. --- sc/source/filter/excel/excdoc.cxx | 10 ++++++---- sc/source/filter/inc/XclExpChangeTrack.hxx | 18 +++++++++++++----- sc/source/filter/xcl97/XclExpChangeTrack.cxx | 17 ++++++++++++----- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/sc/source/filter/excel/excdoc.cxx b/sc/source/filter/excel/excdoc.cxx index 180d57d..8dbc680 100644 --- a/sc/source/filter/excel/excdoc.cxx +++ b/sc/source/filter/excel/excdoc.cxx @@ -530,9 +530,10 @@ void ExcTable::FillAsTable( SCTAB nCodeNameIdx ) // change tracking if( rR.pUserBViewList ) { - for( const XclExpUserBView* pBView = rR.pUserBViewList->First(); pBView; pBView = rR.pUserBViewList->Next() ) + XclExpUserBViewList::const_iterator iter; + for ( iter = rR.pUserBViewList->begin(); iter != rR.pUserBViewList->end(); ++iter) { - Add( new XclExpUsersViewBegin( pBView->GetGUID(), nExcTab ) ); + Add( new XclExpUsersViewBegin( (*iter)->GetGUID(), nExcTab ) ); Add( new XclExpUsersViewEnd ); } } @@ -619,9 +620,10 @@ void ExcTable::FillAsXmlTable( SCTAB nCodeNameIdx ) // change tracking if( rR.pUserBViewList ) { - for( const XclExpUserBView* pBView = rR.pUserBViewList->First(); pBView; pBView = rR.pUserBViewList->Next() ) + XclExpUserBViewList::const_iterator iter; + for ( iter = rR.pUserBViewList->begin(); iter != rR.pUserBViewList->end(); ++iter ) { - Add( new XclExpUsersViewBegin( pBView->GetGUID(), nExcTab ) ); + Add( new XclExpUsersViewBegin( (*iter)->GetGUID(), nExcTab ) ); Add( new XclExpUsersViewEnd ); } } diff --git a/sc/source/filter/inc/XclExpChangeTrack.hxx b/sc/source/filter/inc/XclExpChangeTrack.hxx index ef98f77..2c71432 100644 --- a/sc/source/filter/inc/XclExpChangeTrack.hxx +++ b/sc/source/filter/inc/XclExpChangeTrack.hxx @@ -64,18 +64,26 @@ public: //___________________________________________________________________ // XclExpUserBViewList - list of UserBView records -class XclExpUserBViewList : public ExcEmptyRec, private List +class XclExpUserBViewList : public ExcEmptyRec { private: - inline XclExpUserBView* _First() { return (XclExpUserBView*) List::First(); } - inline XclExpUserBView* _Next() { return (XclExpUserBView*) List::Next(); } + std::vector<XclExpUserBView*> aViews; public: + + typedef std::vector<XclExpUserBView*>::iterator iterator; + typedef std::vector<XclExpUserBView*>::const_iterator const_iterator; + XclExpUserBViewList( const ScChangeTrack& rChangeTrack ); virtual ~XclExpUserBViewList(); - inline const XclExpUserBView* First() { return (const XclExpUserBView*) List::First(); } - inline const XclExpUserBView* Next() { return (const XclExpUserBView*) List::Next(); } + inline iterator begin () { return aViews.begin(); } + + inline iterator end () { return aViews.end(); } + + inline const_iterator begin () const { return aViews.begin(); } + + inline const_iterator end () const { return aViews.end(); } virtual void Save( XclExpStream& rStrm ); }; diff --git a/sc/source/filter/xcl97/XclExpChangeTrack.cxx b/sc/source/filter/xcl97/XclExpChangeTrack.cxx index cd78aba..f96c8a1 100644 --- a/sc/source/filter/xcl97/XclExpChangeTrack.cxx +++ b/sc/source/filter/xcl97/XclExpChangeTrack.cxx @@ -150,26 +150,33 @@ XclExpUserBViewList::XclExpUserBViewList( const ScChangeTrack& rChangeTrack ) { sal_uInt8 aGUID[ 16 ]; sal_Bool bValidGUID = false; + XclExpUserBView *pView = NULL; const ScStrCollection& rStrColl = rChangeTrack.GetUserCollection(); + aViews.reserve(rChangeTrack.GetUserCollection().GetCount()); for( sal_uInt16 nIndex = 0; nIndex < rStrColl.GetCount(); nIndex++ ) { const StrData* pStrData = (const StrData*) rStrColl.At( nIndex ); lcl_GenerateGUID( aGUID, bValidGUID ); if( pStrData ) - List::Insert( new XclExpUserBView( pStrData->GetString(), aGUID ), LIST_APPEND ); + { + pView = new XclExpUserBView( pStrData->GetString(), aGUID ); + + if (pView) + aViews.push_back( pView ); + } } } XclExpUserBViewList::~XclExpUserBViewList() { - for( XclExpUserBView* pRec = _First(); pRec; pRec = _Next() ) - delete pRec; + for( iterator iter = aViews.begin(); iter != aViews.end(); ++iter ) + delete *iter; } void XclExpUserBViewList::Save( XclExpStream& rStrm ) { - for( XclExpUserBView* pRec = _First(); pRec; pRec = _Next() ) - pRec->Save( rStrm ); + for( iterator iter = aViews.begin(); iter != aViews.end(); ++iter ) + (*iter)->Save( rStrm ); } //___________________________________________________________________ -- 1.7.3.4
_______________________________________________ LibreOffice mailing list LibreOffice@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice