summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKohei Yoshida <kyoshida@novell.com>2011-01-12 23:46:09 -0500
committerKohei Yoshida <kyoshida@novell.com>2011-01-12 23:46:09 -0500
commit2bc1da2caa0caadf14921de58d0757ed82733bd0 (patch)
tree52aa3c377475efc6bd09af63c69881f563d81d33
parentCleaned up inconsistent coding styles. (diff)
downloadcore-2bc1da2caa0caadf14921de58d0757ed82733bd0.tar.gz
core-2bc1da2caa0caadf14921de58d0757ed82733bd0.zip
Moved the dp cache handling code from ScDocument to ScDPCollection.
Let's not bloat ScDocument any more than it currently is. We need to be making ScDocument smaller by moving stuff out, not adding stuff in. Plus, dp caches are relevant only when the document has data pilot tables, so it makes more sense to move it to ScDPCollection.
-rw-r--r--sc/inc/document.hxx7
-rw-r--r--sc/inc/dpobject.hxx8
-rw-r--r--sc/source/core/data/documen3.cxx100
-rw-r--r--sc/source/core/data/dpcachetable.cxx2
-rw-r--r--sc/source/core/data/dpobject.cxx103
-rw-r--r--sc/source/core/data/dpsdbtab.cxx6
-rw-r--r--sc/source/core/data/dpshttab.cxx6
7 files changed, 115 insertions, 117 deletions
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 11079b8313d4..2b893251e695 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -246,7 +246,6 @@ private:
ScRangeName* pRangeName;
ScDBCollection* pDBCollection;
ScDPCollection* pDPCollection;
- std::list<ScDPTableDataCache*> m_listDPObjectsCaches;
ScChartCollection* pChartCollection;
std::auto_ptr< ScTemporaryChartLock > apTemporaryChartLock;
ScPatternAttr* pSelectionAttr; // Attributes of a block
@@ -488,12 +487,6 @@ public:
SC_DLLPUBLIC ScDPCollection* GetDPCollection();
ScDPObject* GetDPAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab) const;
ScDPObject* GetDPAtBlock( const ScRange& rBlock ) const;
- SC_DLLPUBLIC ScDPTableDataCache* GetDPObjectCache( long nID );
- SC_DLLPUBLIC ScDPTableDataCache* GetUsedDPObjectCache ( ScRange rRange );
- SC_DLLPUBLIC long AddDPObjectCache( ScDPTableDataCache* pData );
- SC_DLLPUBLIC void RemoveDPObjectCache( long nID );
- SC_DLLPUBLIC void RemoveUnusedDPObjectCaches();
- SC_DLLPUBLIC long GetNewDPObjectCacheId ();
SC_DLLPUBLIC ScChartCollection* GetChartCollection() const;
diff --git a/sc/inc/dpobject.hxx b/sc/inc/dpobject.hxx
index 94fdae7535d0..208fce900df1 100644
--- a/sc/inc/dpobject.hxx
+++ b/sc/inc/dpobject.hxx
@@ -262,6 +262,7 @@ class ScDPCollection : public ScCollection
{
private:
ScDocument* pDoc;
+ std::list<ScDPTableDataCache*> m_listDPObjectsCaches;
public:
ScDPCollection(ScDocument* pDocument);
ScDPCollection(const ScDPCollection& r);
@@ -285,6 +286,13 @@ public:
SC_DLLPUBLIC bool InsertNewTable(ScDPObject* pDPObj);
bool HasDPTable(SCCOL nCol, SCROW nRow, SCTAB nTab) const;
+
+ ScDPTableDataCache* GetDPObjectCache( long nID );
+ ScDPTableDataCache* GetUsedDPObjectCache ( ScRange rRange );
+ long AddDPObjectCache( ScDPTableDataCache* pData );
+ void RemoveDPObjectCache( long nID );
+ void RemoveUnusedDPObjectCaches();
+ long GetNewDPObjectCacheId ();
};
diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx
index abe1c47a753e..4d642a894098 100644
--- a/sc/source/core/data/documen3.cxx
+++ b/sc/source/core/data/documen3.cxx
@@ -2031,104 +2031,4 @@ void ScDocument::DecSizeRecalcLevel( SCTAB nTab, bool bUpdateNoteCaptionPos )
pTab[nTab]->DecRecalcLevel( bUpdateNoteCaptionPos );
}
-ScDPTableDataCache* ScDocument::GetDPObjectCache( long nID )
-{
- for ( std::list<ScDPTableDataCache*>::iterator iter = m_listDPObjectsCaches.begin(); iter!=m_listDPObjectsCaches.end(); ++iter )
- { //
- if ( nID == (*iter)->GetId() )
- return *iter;
- }
- return NULL;
-}
-
-ScDPTableDataCache* ScDocument::GetUsedDPObjectCache ( ScRange rRange )
-{
- ScDPTableDataCache* pCache = NULL;
- USHORT nCount = GetDPCollection()->GetCount();
- for ( short i=nCount-1; i>=0 ; i--)
- {
- if ( const ScSheetSourceDesc* pUsedSheetDesc = (*pDPCollection)[i]->GetSheetDesc() )
- if ( rRange == pUsedSheetDesc->aSourceRange )
- {
- long nID = (*pDPCollection)[i]->GetCacheId();
- if ( nID >= 0 )
- pCache= GetDPObjectCache( nID );
- if ( pCache )
- return pCache;
- }
- }
- return pCache;
-}
-
-long ScDocument::AddDPObjectCache( ScDPTableDataCache* pData )
-{
- if ( pData->GetId() < 0 )
- { //create a id for it
- pData->SetId( GetNewDPObjectCacheId() );
- }
- m_listDPObjectsCaches.push_back( pData );
- return pData->GetId();
-}
-
-long ScDocument::GetNewDPObjectCacheId()
-{
- long nID = 0;
-
- bool bFound = false;
- std::list<ScDPTableDataCache*>::iterator iter;
- do {
- for ( iter = m_listDPObjectsCaches.begin(); iter!=m_listDPObjectsCaches.end(); ++iter )
- { //Get a new Id
- if ( nID == (*iter)->GetId() )
- {
- nID++;
- bFound = true;
- break;
- }
- }
- if ( iter == m_listDPObjectsCaches.end() )
- bFound = false;
- } while ( bFound );
-
- return nID;
-}
-
-void ScDocument::RemoveDPObjectCache( long nID )
-{
- for ( std::list<ScDPTableDataCache*>::iterator iter = m_listDPObjectsCaches.begin(); iter!=m_listDPObjectsCaches.end(); ++iter )
- {
- if ( nID == (*iter)->GetId() )
- {
- ScDPTableDataCache* pCache = *iter;
- m_listDPObjectsCaches.erase( iter );
- delete pCache;
- break;
- }
- }
-
-}
-
-void ScDocument::RemoveUnusedDPObjectCaches()
-{
- for ( std::list<ScDPTableDataCache*>::iterator iter = m_listDPObjectsCaches.begin(); iter!=m_listDPObjectsCaches.end(); ++iter )
- {
- long nID = (*iter)->GetId();
- USHORT nCount = GetDPCollection()->GetCount();
- USHORT i ;
- for ( i=0; i<nCount; i++)
- {
- if ( nID == (*pDPCollection)[i]->GetCacheId() )
- break;
- }
- if ( i == nCount )
- {
- ScDPTableDataCache* pCache = *iter;
- m_listDPObjectsCaches.erase( iter );
- delete pCache;
- continue;
- }
- }
-}
-
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/dpcachetable.cxx b/sc/source/core/data/dpcachetable.cxx
index f82fa832f13c..278696a2b13e 100644
--- a/sc/source/core/data/dpcachetable.cxx
+++ b/sc/source/core/data/dpcachetable.cxx
@@ -165,7 +165,7 @@ ScDPCacheTable::ScDPCacheTable( ScDocument* pDoc, long nId ) :
mpNoneCache( NULL )
{
if ( nId >= 0 )
- mpCache = pDoc->GetDPObjectCache( nId );
+ mpCache = pDoc->GetDPCollection()->GetDPObjectCache( nId );
else
{ //create a temp cache object
initNoneCache( NULL );
diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index 36bd0ec7633d..f126086df23a 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -2558,10 +2558,11 @@ ULONG ScDPObject::RefreshCache()
nErrId = pSheetDesc->CheckValidate( pDoc );
if ( nErrId == 0 )
{
+ ScDPCollection* pDPCollection = pDoc->GetDPCollection();
long nOldId = GetCacheId();
- long nNewId = pDoc->GetNewDPObjectCacheId();
+ long nNewId = pDPCollection->GetNewDPObjectCacheId();
if ( nOldId >= 0 )
- pDoc->RemoveDPObjectCache( nOldId );
+ pDPCollection->RemoveDPObjectCache( nOldId );
ScDPTableDataCache* pCache = NULL;
if ( pSheetDesc )
@@ -2579,7 +2580,6 @@ ULONG ScDPObject::RefreshCache()
nNewId = pCache->GetId();
bRefresh = TRUE;
- ScDPCollection* pDPCollection = pDoc->GetDPCollection();
USHORT nCount = pDPCollection->GetCount();
for (USHORT i=0; i<nCount; i++)
{ //set new cache id
@@ -2639,4 +2639,101 @@ bool ScDPCollection::HasDPTable(SCCOL nCol, SCROW nRow, SCTAB nTab) const
return pMergeAttr->HasDPTable();
}
+ScDPTableDataCache* ScDPCollection::GetDPObjectCache( long nID )
+{
+ for ( std::list<ScDPTableDataCache*>::iterator iter = m_listDPObjectsCaches.begin(); iter!=m_listDPObjectsCaches.end(); ++iter )
+ { //
+ if ( nID == (*iter)->GetId() )
+ return *iter;
+ }
+ return NULL;
+}
+
+ScDPTableDataCache* ScDPCollection::GetUsedDPObjectCache ( ScRange rRange )
+{
+ ScDPTableDataCache* pCache = NULL;
+ for ( short i=nCount-1; i>=0 ; i--)
+ {
+ if ( const ScSheetSourceDesc* pUsedSheetDesc = (*this)[i]->GetSheetDesc() )
+ if ( rRange == pUsedSheetDesc->aSourceRange )
+ {
+ long nID = (*this)[i]->GetCacheId();
+ if ( nID >= 0 )
+ pCache= GetDPObjectCache( nID );
+ if ( pCache )
+ return pCache;
+ }
+ }
+ return pCache;
+}
+
+long ScDPCollection::AddDPObjectCache( ScDPTableDataCache* pData )
+{
+ if ( pData->GetId() < 0 )
+ { //create a id for it
+ pData->SetId( GetNewDPObjectCacheId() );
+ }
+ m_listDPObjectsCaches.push_back( pData );
+ return pData->GetId();
+}
+
+void ScDPCollection::RemoveDPObjectCache( long nID )
+{
+ for ( std::list<ScDPTableDataCache*>::iterator iter = m_listDPObjectsCaches.begin(); iter!=m_listDPObjectsCaches.end(); ++iter )
+ {
+ if ( nID == (*iter)->GetId() )
+ {
+ ScDPTableDataCache* pCache = *iter;
+ m_listDPObjectsCaches.erase( iter );
+ delete pCache;
+ break;
+ }
+ }
+
+}
+
+void ScDPCollection::RemoveUnusedDPObjectCaches()
+{
+ for ( std::list<ScDPTableDataCache*>::iterator iter = m_listDPObjectsCaches.begin(); iter!=m_listDPObjectsCaches.end(); ++iter )
+ {
+ long nID = (*iter)->GetId();
+ USHORT i ;
+ for ( i=0; i<nCount; i++)
+ {
+ if ( nID == (*this)[i]->GetCacheId() )
+ break;
+ }
+ if ( i == nCount )
+ {
+ ScDPTableDataCache* pCache = *iter;
+ m_listDPObjectsCaches.erase( iter );
+ delete pCache;
+ continue;
+ }
+ }
+}
+
+long ScDPCollection::GetNewDPObjectCacheId()
+{
+ long nID = 0;
+
+ bool bFound = false;
+ std::list<ScDPTableDataCache*>::iterator iter;
+ do {
+ for ( iter = m_listDPObjectsCaches.begin(); iter!=m_listDPObjectsCaches.end(); ++iter )
+ { //Get a new Id
+ if ( nID == (*iter)->GetId() )
+ {
+ nID++;
+ bFound = true;
+ break;
+ }
+ }
+ if ( iter == m_listDPObjectsCaches.end() )
+ bFound = false;
+ } while ( bFound );
+
+ return nID;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/dpsdbtab.cxx b/sc/source/core/data/dpsdbtab.cxx
index 42807dba545f..a838a04dd333 100644
--- a/sc/source/core/data/dpsdbtab.cxx
+++ b/sc/source/core/data/dpsdbtab.cxx
@@ -90,7 +90,7 @@ using ::com::sun::star::uno::UNO_QUERY;
{
long nID = (*pDPCollection)[i]->GetCacheId();
if ( nID >= 0 )
- pCache= pDoc->GetDPObjectCache( nID );
+ pCache= pDPCollection->GetDPObjectCache( nID );
if ( pCache )
return pCache;
}
@@ -164,7 +164,7 @@ ScDPTableDataCache* ScImportSourceDesc::CreateCache( ScDocument* pDoc , long nID
SvNumberFormatter aFormat( pDoc->GetServiceManager(), ScGlobal::eLnge);
pCache->InitFromDataBase( xRowSet, *aFormat.GetNullDate() );
pCache->SetId( nID );
- pDoc->AddDPObjectCache( pCache );
+ pDoc->GetDPCollection()->AddDPObjectCache( pCache );
DBG_TRACE1("Create a cache id = %d \n", pCache->GetId() );
}
}
@@ -190,7 +190,7 @@ ScDPTableDataCache* ScImportSourceDesc::CreateCache( ScDocument* pDoc , long nID
ScDPTableDataCache* ScImportSourceDesc::GetCache( ScDocument* pDoc, long nID ) const
{
- ScDPTableDataCache* pCache = pDoc->GetDPObjectCache( nID );
+ ScDPTableDataCache* pCache = pDoc->GetDPCollection()->GetDPObjectCache( nID );
if ( NULL == pCache && pDoc )
pCache = GetExistDPObjectCache( pDoc);
if ( NULL == pCache )
diff --git a/sc/source/core/data/dpshttab.cxx b/sc/source/core/data/dpshttab.cxx
index 80b5fa2b4d3c..dddf25f34b51 100644
--- a/sc/source/core/data/dpshttab.cxx
+++ b/sc/source/core/data/dpshttab.cxx
@@ -248,7 +248,7 @@ ScDPTableDataCache* ScSheetSourceDesc::CreateCache( ScDocument* pDoc , long nID
pCache->InitFromDoc( pDoc, aSourceRange );
pCache->SetId( nID );
- pDoc->AddDPObjectCache( pCache );
+ pDoc->GetDPCollection()->AddDPObjectCache( pCache );
DBG_TRACE1("Create a cache id = %d \n", pCache->GetId() );
}
@@ -261,11 +261,11 @@ ScDPTableDataCache* ScSheetSourceDesc::CreateCache( ScDocument* pDoc , long nID
ScDPTableDataCache* ScSheetSourceDesc::GetExistDPObjectCache ( ScDocument* pDoc ) const
{
- return pDoc->GetUsedDPObjectCache( aSourceRange );
+ return pDoc->GetDPCollection()->GetUsedDPObjectCache( aSourceRange );
}
ScDPTableDataCache* ScSheetSourceDesc::GetCache( ScDocument* pDoc, long nID ) const
{
- ScDPTableDataCache* pCache = pDoc->GetDPObjectCache( nID );
+ ScDPTableDataCache* pCache = pDoc->GetDPCollection()->GetDPObjectCache( nID );
if ( NULL == pCache && pDoc )
pCache = GetExistDPObjectCache( pDoc );
if ( NULL == pCache )