diff options
author | Kohei Yoshida <kyoshida@novell.com> | 2011-01-13 01:44:03 -0500 |
---|---|---|
committer | Kohei Yoshida <kyoshida@novell.com> | 2011-01-13 01:44:03 -0500 |
commit | bf9499781bc5d9d8ccb08681a25a9ec4312c8f82 (patch) | |
tree | dd7d81b8fb903c33fa7a143452a7d02fd37a6ab4 /sc | |
parent | eaa9f3425196260798e750a5564522dfa2b4c863 (diff) |
ScDPCollection is no longer derived from ScCollection.
ScCollection is another redundant data structure that could easily
be replaced with boost::ptr_vector or any of its siblings.
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/dpobject.hxx | 31 | ||||
-rw-r--r-- | sc/source/core/data/dpobject.cxx | 163 | ||||
-rw-r--r-- | sc/source/core/data/dpsdbtab.cxx | 11 | ||||
-rw-r--r-- | sc/source/filter/excel/xepivot.cxx | 2 | ||||
-rw-r--r-- | sc/source/filter/xml/XMLExportDataPilot.cxx | 4 | ||||
-rw-r--r-- | sc/source/ui/docshell/docsh.cxx | 4 | ||||
-rw-r--r-- | sc/source/ui/unoobj/dapiuno.cxx | 24 | ||||
-rw-r--r-- | sc/source/ui/view/dbfunc3.cxx | 4 |
8 files changed, 142 insertions, 101 deletions
diff --git a/sc/inc/dpobject.hxx b/sc/inc/dpobject.hxx index 3538f966362e..307052373317 100644 --- a/sc/inc/dpobject.hxx +++ b/sc/inc/dpobject.hxx @@ -38,6 +38,7 @@ #include <com/sun/star/sheet/XDimensionsSupplier.hpp> #include <boost/ptr_container/ptr_list.hpp> +#include <boost/ptr_container/ptr_vector.hpp> #include <boost/shared_ptr.hpp> //------------------------------------------------------------------ @@ -259,36 +260,48 @@ public: // ============================================================================ -class ScDPCollection : public ScCollection +class ScDPCollection { private: ScDocument* pDoc; typedef ::boost::ptr_list<ScDPTableDataCache> DataCachesType; - DataCachesType maDPDataCaches; + typedef ::boost::ptr_vector<ScDPObject> TablesType; + TablesType maTables; + DataCachesType maDPDataCaches; public: ScDPCollection(ScDocument* pDocument); ScDPCollection(const ScDPCollection& r); - virtual ~ScDPCollection(); + ~ScDPCollection(); - virtual ScDataObject* Clone() const; + SC_DLLPUBLIC size_t GetCount() const; + SC_DLLPUBLIC ScDPObject* operator[](size_t nIndex); + SC_DLLPUBLIC const ScDPObject* operator[](size_t nIndex) const; - ScDPObject* operator[](USHORT nIndex) const {return (ScDPObject*)At(nIndex);} - ScDPObject* GetByName(const String& rName) const; + const ScDPObject* GetByName(const String& rName) const; void DeleteOnTab( SCTAB nTab ); void UpdateReference( UpdateRefMode eUpdateRefMode, const ScRange& r, SCsCOL nDx, SCsROW nDy, SCsTAB nDz ); - BOOL RefsEqual( const ScDPCollection& r ) const; + bool RefsEqual( const ScDPCollection& r ) const; void WriteRefsTo( ScDPCollection& r ) const; - String CreateNewName( USHORT nMin = 1 ) const; + /** + * Create a new name that's not yet used by any existing data pilot + * objects. All data pilot names are 'DataPilot' + <num>, and the nMin + * specifies the minimum number allowed. + * + * @param nMin minimum number allowed. + * + * @return new name for data pilot object. + */ + String CreateNewName( USHORT nMin = 1 ) const; void FreeTable(ScDPObject* pDPObj); SC_DLLPUBLIC bool InsertNewTable(ScDPObject* pDPObj); - bool HasDPTable(SCCOL nCol, SCROW nRow, SCTAB nTab) const; + bool HasDPTable(SCCOL nCol, SCROW nRow, SCTAB nTab) const; ScDPTableDataCache* GetDPObjectCache( long nID ); ScDPTableDataCache* GetUsedDPObjectCache ( const ScRange& rRange ); diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx index 0ab5caaa38ff..fab675e01755 100644 --- a/sc/source/core/data/dpobject.cxx +++ b/sc/source/core/data/dpobject.cxx @@ -2418,7 +2418,6 @@ ScDPCollection::ScDPCollection(ScDocument* pDocument) : } ScDPCollection::ScDPCollection(const ScDPCollection& r) : - ScCollection(r), pDoc(r.pDoc), maDPDataCaches(r.maDPDataCaches) { @@ -2428,94 +2427,109 @@ ScDPCollection::~ScDPCollection() { } -ScDataObject* ScDPCollection::Clone() const -{ - return new ScDPCollection(*this); -} - void ScDPCollection::DeleteOnTab( SCTAB nTab ) { - USHORT nPos = 0; - while ( nPos < nCount ) + TablesType::iterator itr = maTables.begin(), itrEnd = maTables.end(); + while (itr != itrEnd) { - // look for output positions on the deleted sheet - if ( static_cast<const ScDPObject*>(At(nPos))->GetOutRange().aStart.Tab() == nTab ) - AtFree(nPos); + const ScDPObject& rObj = *itr; + if (rObj.GetOutRange().aStart.Tab() == nTab) + // returns the next position after the erased element. + itr = maTables.erase(itr); else - ++nPos; + ++itr; } } void ScDPCollection::UpdateReference( UpdateRefMode eUpdateRefMode, const ScRange& r, SCsCOL nDx, SCsROW nDy, SCsTAB nDz ) { - for (USHORT i=0; i<nCount; i++) - ((ScDPObject*)At(i))->UpdateReference( eUpdateRefMode, r, nDx, nDy, nDz ); + TablesType::iterator itr = maTables.begin(), itrEnd = maTables.end(); + for (; itr != itrEnd; ++itr) + itr->UpdateReference(eUpdateRefMode, r, nDx, nDy, nDz); } -BOOL ScDPCollection::RefsEqual( const ScDPCollection& r ) const +bool ScDPCollection::RefsEqual( const ScDPCollection& r ) const { - if ( nCount != r.nCount ) - return FALSE; + if (maTables.size() != r.maTables.size()) + return false; - for (USHORT i=0; i<nCount; i++) - if ( ! ((const ScDPObject*)At(i))->RefsEqual( *((const ScDPObject*)r.At(i)) ) ) - return FALSE; + TablesType::const_iterator itr = maTables.begin(), itr2 = r.maTables.begin(), itrEnd = maTables.end(); + for (; itr != itrEnd; ++itr, ++itr2) + if (!itr->RefsEqual(*itr2)) + return false; - return TRUE; // all equal + return true; } void ScDPCollection::WriteRefsTo( ScDPCollection& r ) const { - if ( nCount == r.nCount ) + if ( maTables.size() == r.maTables.size() ) { //! assert equal names? - for (USHORT i=0; i<nCount; i++) - ((const ScDPObject*)At(i))->WriteRefsTo( *((ScDPObject*)r.At(i)) ); + TablesType::const_iterator itr = maTables.begin(), itrEnd = maTables.end(); + TablesType::iterator itr2 = r.maTables.begin(); + for (; itr != itrEnd; ++itr, ++itr2) + itr->WriteRefsTo(*itr2); } else { // #i8180# If data pilot tables were deleted with their sheet, // this collection contains extra entries that must be restored. // Matching objects are found by their names. - - DBG_ASSERT( nCount >= r.nCount, "WriteRefsTo: missing entries in document" ); - for (USHORT nSourcePos=0; nSourcePos<nCount; nSourcePos++) + size_t nSrcSize = maTables.size(); + size_t nDestSize = r.maTables.size(); + DBG_ASSERT( nSrcSize >= nDestSize, "WriteRefsTo: missing entries in document" ); + for (size_t nSrcPos = 0; nSrcPos < nSrcSize; ++nSrcPos) { - const ScDPObject* pSourceObj = static_cast<const ScDPObject*>(At(nSourcePos)); - String aName = pSourceObj->GetName(); + const ScDPObject& rSrcObj = maTables[nSrcPos]; + String aName = rSrcObj.GetName(); bool bFound = false; - for (USHORT nDestPos=0; nDestPos<r.nCount && !bFound; nDestPos++) + for (size_t nDestPos = 0; nDestPos < nDestSize && !bFound; ++nDestPos) { - ScDPObject* pDestObj = static_cast<ScDPObject*>(r.At(nDestPos)); - if ( pDestObj->GetName() == aName ) + ScDPObject& rDestObj = r.maTables[nDestPos]; + if (rDestObj.GetName() == aName) { - pSourceObj->WriteRefsTo( *pDestObj ); // found object, copy refs + rSrcObj.WriteRefsTo(rDestObj); // found object, copy refs bFound = true; } } - if ( !bFound ) + + if (!bFound) { // none found, re-insert deleted object (see ScUndoDataPilot::Undo) - ScDPObject* pDestObj = new ScDPObject( *pSourceObj ); - pDestObj->SetAlive(TRUE); - if ( !r.InsertNewTable(pDestObj) ) - { - DBG_ERROR("cannot insert DPObject"); - DELETEZ( pDestObj ); - } + ScDPObject* pDestObj = new ScDPObject(rSrcObj); + pDestObj->SetAlive(true); + r.InsertNewTable(pDestObj); } } - DBG_ASSERT( nCount == r.nCount, "WriteRefsTo: couldn't restore all entries" ); + DBG_ASSERT( maTables.size() == r.maTables.size(), "WriteRefsTo: couldn't restore all entries" ); } } -ScDPObject* ScDPCollection::GetByName(const String& rName) const +size_t ScDPCollection::GetCount() const +{ + return maTables.size(); +} + +ScDPObject* ScDPCollection::operator [](size_t nIndex) +{ + return &maTables[nIndex]; +} + +const ScDPObject* ScDPCollection::operator [](size_t nIndex) const +{ + return &maTables[nIndex]; +} + +const ScDPObject* ScDPCollection::GetByName(const String& rName) const { - for (USHORT i=0; i<nCount; i++) - if (static_cast<const ScDPObject*>(pItems[i])->GetName() == rName) - return static_cast<ScDPObject*>(pItems[i]); + TablesType::const_iterator itr = maTables.begin(), itrEnd = maTables.end(); + for (; itr != itrEnd; ++itr) + if (itr->GetName() == rName) + return &(*itr); + return NULL; } @@ -2524,14 +2538,21 @@ String ScDPCollection::CreateNewName( USHORT nMin ) const String aBase = String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("DataPilot")); //! from Resource? - for (USHORT nAdd=0; nAdd<=nCount; nAdd++) // nCount+1 tries + size_t n = maTables.size(); + for (size_t nAdd = 0; nAdd <= n; ++nAdd) // nCount+1 tries { String aNewName = aBase; aNewName += String::CreateFromInt32( nMin + nAdd ); - BOOL bFound = FALSE; - for (USHORT i=0; i<nCount && !bFound; i++) - if (((const ScDPObject*)pItems[i])->GetName() == aNewName) - bFound = TRUE; + bool bFound = false; + TablesType::const_iterator itr = maTables.begin(), itrEnd = maTables.end(); + for (; itr != itrEnd; ++itr) + { + if (itr->GetName() == aNewName) + { + bFound = true; + break; + } + } if (!bFound) return aNewName; // found unused Name } @@ -2581,8 +2602,8 @@ ULONG ScDPObject::RefreshCache() nNewId = pCache->GetId(); bRefresh = TRUE; - USHORT nCount = pDPCollection->GetCount(); - for (USHORT i=0; i<nCount; i++) + size_t nCount = pDPCollection->GetCount(); + for (size_t i=0; i<nCount; ++i) { //set new cache id if ( (*pDPCollection)[i]->GetCacheId() == nOldId ) { @@ -2595,6 +2616,7 @@ ULONG ScDPObject::RefreshCache() } return nErrId; } + void ScDPObject::SetCacheId( long nCacheId ) { if ( GetCacheId() != nCacheId ) @@ -2613,20 +2635,27 @@ void ScDPCollection::FreeTable(ScDPObject* pDPObj) const ScAddress& s = rOutRange.aStart; const ScAddress& e = rOutRange.aEnd; pDoc->RemoveFlagsTab(s.Col(), s.Row(), e.Col(), e.Row(), s.Tab(), SC_MF_DP_TABLE); - Free(pDPObj); + TablesType::iterator itr = maTables.begin(), itrEnd = maTables.end(); + for (; itr != itrEnd; ++itr) + { + ScDPObject* p = &(*itr); + if (p == pDPObj) + { + maTables.erase(itr); + break; + } + } } bool ScDPCollection::InsertNewTable(ScDPObject* pDPObj) { - bool bSuccess = Insert(pDPObj); - if (bSuccess) - { - const ScRange& rOutRange = pDPObj->GetOutRange(); - const ScAddress& s = rOutRange.aStart; - const ScAddress& e = rOutRange.aEnd; - pDoc->ApplyFlagsTab(s.Col(), s.Row(), e.Col(), e.Row(), s.Tab(), SC_MF_DP_TABLE); - } - return bSuccess; + const ScRange& rOutRange = pDPObj->GetOutRange(); + const ScAddress& s = rOutRange.aStart; + const ScAddress& e = rOutRange.aEnd; + pDoc->ApplyFlagsTab(s.Col(), s.Row(), e.Col(), e.Row(), s.Tab(), SC_MF_DP_TABLE); + + maTables.push_back(pDPObj); + return true; } bool ScDPCollection::HasDPTable(SCCOL nCol, SCROW nRow, SCTAB nTab) const @@ -2654,13 +2683,13 @@ ScDPTableDataCache* ScDPCollection::GetDPObjectCache( long nID ) ScDPTableDataCache* ScDPCollection::GetUsedDPObjectCache ( const ScRange& rRange ) { ScDPTableDataCache* pCache = NULL; - for ( short i=nCount-1; i>=0 ; i--) + for (size_t i=maTables.size(); i > 0 ; --i) { - if ( const ScSheetSourceDesc* pUsedSheetDesc = (*this)[i]->GetSheetDesc() ) + if ( const ScSheetSourceDesc* pUsedSheetDesc = maTables[i-1].GetSheetDesc() ) if ( rRange == pUsedSheetDesc->aSourceRange ) { - long nID = (*this)[i]->GetCacheId(); - if ( nID >= 0 ) + long nID = maTables[i-1].GetCacheId(); + if ( nID >= 0 ) pCache= GetDPObjectCache( nID ); if ( pCache ) return pCache; diff --git a/sc/source/core/data/dpsdbtab.cxx b/sc/source/core/data/dpsdbtab.cxx index a838a04dd333..22aad27efcc9 100644 --- a/sc/source/core/data/dpsdbtab.cxx +++ b/sc/source/core/data/dpsdbtab.cxx @@ -81,15 +81,14 @@ using ::com::sun::star::uno::UNO_QUERY; { ScDPTableDataCache* pCache = NULL; ScDPCollection* pDPCollection= pDoc->GetDPCollection(); - USHORT nCount = pDPCollection->GetCount(); - - for ( short i=nCount-1; i>=0 ; i--) + size_t nCount = pDPCollection->GetCount(); + for (size_t i = nCount; i > 0; --i) { - if ( const ScImportSourceDesc* pUsedDesc = (*pDPCollection)[i]->GetImportSourceDesc() ) + if ( const ScImportSourceDesc* pUsedDesc = (*pDPCollection)[i-1]->GetImportSourceDesc() ) if ( *this == *pUsedDesc ) { - long nID = (*pDPCollection)[i]->GetCacheId(); - if ( nID >= 0 ) + long nID = (*pDPCollection)[i-1]->GetCacheId(); + if ( nID >= 0 ) pCache= pDPCollection->GetDPObjectCache( nID ); if ( pCache ) return pCache; diff --git a/sc/source/filter/excel/xepivot.cxx b/sc/source/filter/excel/xepivot.cxx index 6b8adb4f4490..59cb019b9a16 100644 --- a/sc/source/filter/excel/xepivot.cxx +++ b/sc/source/filter/excel/xepivot.cxx @@ -1849,7 +1849,7 @@ XclExpPivotTableManager::XclExpPivotTableManager( const XclExpRoot& rRoot ) : void XclExpPivotTableManager::CreatePivotTables() { if( ScDPCollection* pDPColl = GetDoc().GetDPCollection() ) - for( USHORT nDPObj = 0, nCount = pDPColl->GetCount(); nDPObj < nCount; ++nDPObj ) + for( size_t nDPObj = 0, nCount = pDPColl->GetCount(); nDPObj < nCount; ++nDPObj ) if( ScDPObject* pDPObj = (*pDPColl)[ nDPObj ] ) if( const XclExpPivotCache* pPCache = CreatePivotCache( *pDPObj ) ) maPTableList.AppendNewRecord( new XclExpPivotTable( GetRoot(), *pDPObj, *pPCache ) ); diff --git a/sc/source/filter/xml/XMLExportDataPilot.cxx b/sc/source/filter/xml/XMLExportDataPilot.cxx index 7a54dae623a5..2fe7957cb1b8 100644 --- a/sc/source/filter/xml/XMLExportDataPilot.cxx +++ b/sc/source/filter/xml/XMLExportDataPilot.cxx @@ -755,12 +755,12 @@ void ScXMLExportDataPilot::WriteDataPilots(const uno::Reference <sheet::XSpreads ScDPCollection* pDPs = pDoc->GetDPCollection(); if (pDPs) { - sal_Int16 nDPCount = pDPs->GetCount(); + size_t nDPCount = pDPs->GetCount(); if (nDPCount > 0) { SvXMLElementExport aElemDPs(rExport, XML_NAMESPACE_TABLE, XML_DATA_PILOT_TABLES, sal_True, sal_True); rExport.CheckAttrList(); - for (sal_Int16 i = 0; i < nDPCount; ++i) + for (size_t i = 0; i < nDPCount; ++i) { ScDPSaveData* pDPSave = (*pDPs)[i]->GetSaveData(); if (pDPSave) diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx index 06a809541319..a824e79edf71 100644 --- a/sc/source/ui/docshell/docsh.cxx +++ b/sc/source/ui/docshell/docsh.cxx @@ -378,8 +378,8 @@ void ScDocShell::AfterXMLLoading(sal_Bool bRet) ScDPCollection* pDPCollection = aDocument.GetDPCollection(); if ( pDPCollection ) { - USHORT nDPCount = pDPCollection->GetCount(); - for (USHORT nDP=0; nDP<nDPCount; nDP++) + size_t nDPCount = pDPCollection->GetCount(); + for (size_t nDP=0; nDP<nDPCount; ++nDP) { ScDPObject* pDPObj = (*pDPCollection)[nDP]; if ( !pDPObj->GetName().Len() ) diff --git a/sc/source/ui/unoobj/dapiuno.cxx b/sc/source/ui/unoobj/dapiuno.cxx index fae3c9bfa941..5584d5f9c64f 100644 --- a/sc/source/ui/unoobj/dapiuno.cxx +++ b/sc/source/ui/unoobj/dapiuno.cxx @@ -265,8 +265,8 @@ ScDPObject* lcl_GetDPObject( ScDocShell* pDocShell, SCTAB nTab, const String& rN ScDPCollection* pColl = pDoc->GetDPCollection(); if ( pColl ) { - USHORT nCount = pColl->GetCount(); - for (USHORT i=0; i<nCount; i++) + size_t nCount = pColl->GetCount(); + for (size_t i=0; i<nCount; ++i) { ScDPObject* pDPObj = (*pColl)[i]; if ( pDPObj->GetOutRange().aStart.Tab() == nTab && @@ -347,8 +347,8 @@ ScDataPilotTableObj* ScDataPilotTablesObj::GetObjectByIndex_Impl( sal_Int32 nInd // api only handles sheet data at this time //! allow all data sources!!! sal_Int32 nFound = 0; - USHORT nCount = pColl->GetCount(); - for (USHORT i=0; i<nCount; i++) + size_t nCount = pColl->GetCount(); + for (size_t i=0; i<nCount; ++i) { ScDPObject* pDPObj = (*pColl)[i]; if ( pDPObj->GetOutRange().aStart.Tab() == nTab ) @@ -499,8 +499,8 @@ sal_Int32 SAL_CALL ScDataPilotTablesObj::getCount() throw(RuntimeException) //! allow all data sources!!! USHORT nFound = 0; - USHORT nCount = pColl->GetCount(); - for (USHORT i=0; i<nCount; i++) + size_t nCount = pColl->GetCount(); + for (size_t i=0; i<nCount; ++i) { ScDPObject* pDPObj = (*pColl)[i]; if ( pDPObj->GetOutRange().aStart.Tab() == nTab ) @@ -562,9 +562,9 @@ Sequence<OUString> SAL_CALL ScDataPilotTablesObj::getElementNames() //! allow all data sources!!! USHORT nFound = 0; - USHORT nCount = pColl->GetCount(); - USHORT i; - for (i=0; i<nCount; i++) + size_t nCount = pColl->GetCount(); + size_t i; + for (i=0; i<nCount; ++i) { ScDPObject* pDPObj = (*pColl)[i]; if ( pDPObj->GetOutRange().aStart.Tab() == nTab ) @@ -574,7 +574,7 @@ Sequence<OUString> SAL_CALL ScDataPilotTablesObj::getElementNames() USHORT nPos = 0; Sequence<OUString> aSeq(nFound); OUString* pAry = aSeq.getArray(); - for (i=0; i<nCount; i++) + for (i=0; i<nCount; ++i) { ScDPObject* pDPObj = (*pColl)[i]; if ( pDPObj->GetOutRange().aStart.Tab() == nTab ) @@ -598,8 +598,8 @@ sal_Bool SAL_CALL ScDataPilotTablesObj::hasByName( const OUString& aName ) if ( pColl ) { String aNamStr(aName); - USHORT nCount = pColl->GetCount(); - for (USHORT i=0; i<nCount; i++) + size_t nCount = pColl->GetCount(); + for (size_t i=0; i<nCount; ++i) { // api only handles sheet data at this time //! allow all data sources!!! diff --git a/sc/source/ui/view/dbfunc3.cxx b/sc/source/ui/view/dbfunc3.cxx index 3db93dee0d96..55ac3d55ef7c 100644 --- a/sc/source/ui/view/dbfunc3.cxx +++ b/sc/source/ui/view/dbfunc3.cxx @@ -708,8 +708,8 @@ ULONG RefreshDPObject( ScDPObject *pDPObj, ScDocument *pDoc, ScDocShell *pDocSh, { //Refresh all dpobjects ScDPCollection* pDPCollection = pDoc->GetDPCollection(); - USHORT nCount = pDPCollection->GetCount(); - for (USHORT i=0; i<nCount; i++) + size_t nCount = pDPCollection->GetCount(); + for (size_t i=0; i<nCount; ++i) { if ( (*pDPCollection)[i]->GetCacheId() == pDPObj->GetCacheId() ) { |