From d444d877a1023dec34859f9cf59039e81a638c4f Mon Sep 17 00:00:00 2001 From: Kohei Yoshida Date: Mon, 28 Feb 2011 18:14:22 -0500 Subject: [PATCH] Make sure nobody modifies the table cache outside of ScDPCacheTable. Use const to ensure that nobody modifies the content of the table cache outside of ScDPCacheTable. --- sc/inc/dpcachetable.hxx | 5 ++++- sc/inc/dpgroup.hxx | 10 ++++++---- sc/inc/dptablecache.hxx | 8 ++++---- sc/inc/dptabsrc.hxx | 2 +- sc/source/core/data/dpcachetable.cxx | 14 +++++++++++++- sc/source/core/data/dpgroup.cxx | 29 ++++++++++++++-------------- sc/source/core/data/dpshttab.cxx | 2 +- sc/source/core/data/dptabdat.cxx | 6 +++--- sc/source/core/data/dptablecache.cxx | 8 ++++---- sc/source/core/data/dptabsrc.cxx | 2 +- sc/source/filter/excel/xepivot.cxx | 3 ++- 11 files changed, 54 insertions(+), 35 deletions(-) diff --git a/sc/inc/dpcachetable.hxx b/sc/inc/dpcachetable.hxx index 06eecef19763..eb0a7565e496 100644 --- a/sc/inc/dpcachetable.hxx +++ b/sc/inc/dpcachetable.hxx @@ -134,7 +134,7 @@ public: sal_Int32 getRowSize() const; sal_Int32 getColSize() const; - ScDPTableDataCache* getCache() const; + const ScDPTableDataCache* getCache() const; /** Fill the internal table from the cell range provided. This function assumes that the first row is the column header. */ @@ -173,6 +173,7 @@ public: ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > >& rTabData, const ::boost::unordered_set& rRepeatIfEmptyDims); + SCROW getOrder(long nDim, SCROW nIndex) const; void clear(); bool empty() const; @@ -180,6 +181,8 @@ private: ScDPCacheTable(); ScDPCacheTable(const ScDPCacheTable&); + ScDPTableDataCache* getCache(); + /** * Check if a given row meets all specified criteria. * diff --git a/sc/inc/dpgroup.hxx b/sc/inc/dpgroup.hxx index 223425b5e23f..82e82af3dd12 100644 --- a/sc/inc/dpgroup.hxx +++ b/sc/inc/dpgroup.hxx @@ -74,8 +74,9 @@ public: sal_Int32 GetDatePart() const { return nDatePart; } const ScDPNumGroupInfo& GetNumInfo() const { return aNumInfo; } - void FillColumnEntries( SCCOL nSourceDim, ScDPTableDataCache* pCahe , std::vector< SCROW >& rEntries, - const std::vector< SCROW >& rOriginal ) const; + void FillColumnEntries( + SCCOL nSourceDim, const ScDPTableDataCache* pCahe , std::vector& rEntries, + const std::vector& rOriginal) const; }; // -------------------------------------------------------------------- @@ -164,8 +165,9 @@ public: const ScDPDateGroupHelper* GetDateHelper() const { return pDateHelper; } - const std::vector< SCROW >& GetNumEntries( SCCOL nSourceDim, ScDPTableDataCache* pCache, - const std::vector< SCROW >& rOriginal ) const; + const std::vector& GetNumEntries( + SCCOL nSourceDim, const ScDPTableDataCache* pCache, + const std::vector< SCROW >& rOriginal) const; void MakeDateHelper( const ScDPNumGroupInfo& rInfo, sal_Int32 nPart ); diff --git a/sc/inc/dptablecache.hxx b/sc/inc/dptablecache.hxx index 89efce644dad..7b52211c6dda 100644 --- a/sc/inc/dptablecache.hxx +++ b/sc/inc/dptablecache.hxx @@ -58,19 +58,19 @@ private: DataGridType maTableDataValues; // Data Pilot Table's index - value map RowGridType maSourceData; // Data Pilot Table's source data RowGridType maGlobalOrder; // Sorted members index - RowGridType maIndexOrder; // Index the sorted numbers + mutable RowGridType maIndexOrder; // Index the sorted numbers DataListType maLabelNames; // Source label data std::vector mbEmptyRow; //If empty row? mutable ScDPItemDataPool maAdditionalData; public: - SCROW GetOrder( long nDim, SCROW nIndex ); + SCROW GetOrder( long nDim, SCROW nIndex ) const; SCROW GetIdByItemData( long nDim, String sItemData ) const; SCROW GetIdByItemData( long nDim, const ScDPItemData& rData ) const; - SCROW GetAdditionalItemID ( String sItemData ); - SCROW GetAdditionalItemID( const ScDPItemData& rData ); + SCROW GetAdditionalItemID ( String sItemData ) const; + SCROW GetAdditionalItemID( const ScDPItemData& rData ) const; SCCOL GetDimensionIndex( String sName) const; const ScDPItemData* GetSortedItemData( SCCOL nDim, SCROW nOrder ) const; diff --git a/sc/inc/dptabsrc.hxx b/sc/inc/dptabsrc.hxx index 870980fb0a25..1c3fb4ad2229 100644 --- a/sc/inc/dptabsrc.hxx +++ b/sc/inc/dptabsrc.hxx @@ -174,7 +174,7 @@ public: long GetDataDimensionCount(); ScDPDimension* GetDataDimension(long nIndex); String GetDataDimName(long nIndex); - ScDPTableDataCache* GetCache(); + const ScDPTableDataCache* GetCache(); const ScDPItemData* GetItemDataById( long nDim, long nId ); long GetDataLayoutDim(){ return pData->GetColumnCount(); } SCROW GetMemberId( long nDim, const ScDPItemData& rData ); diff --git a/sc/source/core/data/dpcachetable.cxx b/sc/source/core/data/dpcachetable.cxx index 79df2db91b63..83728d45f94a 100644 --- a/sc/source/core/data/dpcachetable.cxx +++ b/sc/source/core/data/dpcachetable.cxx @@ -407,6 +407,11 @@ void ScDPCacheTable::filterTable(const vector& rCriteria, Sequence< S rTabData[i] = tableData[i]; } +SCROW ScDPCacheTable::getOrder(long nDim, SCROW nIndex) const +{ + return getCache()->GetOrder(nDim, nIndex); +} + void ScDPCacheTable::clear() { maFieldEntries.clear(); @@ -447,7 +452,14 @@ void ScDPCacheTable::initNoneCache( ScDocument* pDoc ) mpNoneCache = new ScDPTableDataCache( pDoc ); } -ScDPTableDataCache* ScDPCacheTable::getCache() const +const ScDPTableDataCache* ScDPCacheTable::getCache() const +{ + if ( mpCache ) + return mpCache; + return mpNoneCache; +} + +ScDPTableDataCache* ScDPCacheTable::getCache() { if ( mpCache ) return mpCache; diff --git a/sc/source/core/data/dpgroup.cxx b/sc/source/core/data/dpgroup.cxx index 24bae3add031..456422b46133 100644 --- a/sc/source/core/data/dpgroup.cxx +++ b/sc/source/core/data/dpgroup.cxx @@ -80,7 +80,7 @@ const sal_Int32 SC_DP_DATE_LAST = 10000; // ============================================================================ namespace { - BOOL lcl_Search( SCCOL nSourceDim, ScDPTableDataCache* pCache , const std::vector< SCROW >& vIdx, SCROW nNew , SCROW& rIndex) + BOOL lcl_Search( SCCOL nSourceDim, const ScDPTableDataCache* pCache , const std::vector< SCROW >& vIdx, SCROW nNew , SCROW& rIndex) { rIndex = vIdx.size(); BOOL bFound = FALSE; @@ -112,7 +112,7 @@ namespace return bFound; } - void lcl_Insert( SCCOL nSourceDim, ScDPTableDataCache* pCache , std::vector< SCROW >& vIdx, SCROW nNew ) + void lcl_Insert( SCCOL nSourceDim, const ScDPTableDataCache* pCache , std::vector< SCROW >& vIdx, SCROW nNew ) { SCROW nIndex = 0; if ( !lcl_Search( nSourceDim, pCache, vIdx, nNew ,nIndex ) ) @@ -120,18 +120,18 @@ namespace } template - SCROW lcl_InsertValue( SCCOL nSourceDim, ScDPTableDataCache* pCache , std::vector< SCROW >& vIdx, const ScDPItemData & rData ); + SCROW lcl_InsertValue(SCCOL nSourceDim, const ScDPTableDataCache* pCache, std::vector& vIdx, const ScDPItemData & rData); template<> - SCROW lcl_InsertValue( SCCOL nSourceDim, ScDPTableDataCache* pCache , std::vector< SCROW >& vIdx, const ScDPItemData & rData ) + SCROW lcl_InsertValue(SCCOL nSourceDim, const ScDPTableDataCache* pCache, std::vector& vIdx, const ScDPItemData & rData) { - SCROW nNewID = pCache->GetAdditionalItemID( rData ); - lcl_Insert( nSourceDim, pCache, vIdx, nNewID ); + SCROW nNewID = pCache->GetAdditionalItemID(rData); + lcl_Insert(nSourceDim, pCache, vIdx, nNewID); return nNewID; } template<> - SCROW lcl_InsertValue( SCCOL nSourceDim, ScDPTableDataCache* pCache , std::vector< SCROW >& vIdx, const ScDPItemData & rData ) + SCROW lcl_InsertValue(SCCOL nSourceDim, const ScDPTableDataCache* pCache, std::vector& vIdx, const ScDPItemData & rData) { SCROW nItemId = lcl_InsertValue( nSourceDim, pCache, vIdx, rData ); @@ -142,13 +142,13 @@ namespace } template - void lcl_InsertValue ( SCCOL nSourceDim, ScDPTableDataCache* pCache , std::vector< SCROW >& vIdx, const String& rString, const double& fValue ) + void lcl_InsertValue ( SCCOL nSourceDim, const ScDPTableDataCache* pCache, std::vector< SCROW >& vIdx, const String& rString, const double& fValue ) { lcl_InsertValue( nSourceDim, pCache, vIdx, ScDPItemData( rString, fValue, TRUE ) ); } template - void lcl_InsertValue ( SCCOL nSourceDim, ScDPTableDataCache* pCache , std::vector< SCROW >& vIdx, const String& rString, const double& fValue, sal_Int32 nDatePart ) + void lcl_InsertValue ( SCCOL nSourceDim, const ScDPTableDataCache* pCache, std::vector< SCROW >& vIdx, const String& rString, const double& fValue, sal_Int32 nDatePart ) { lcl_InsertValue( nSourceDim, pCache, vIdx, ScDPItemData( nDatePart, rString, fValue, ScDPItemData::MK_DATA|ScDPItemData::MK_VAL|ScDPItemData::MK_DATEPART ) ); } @@ -600,7 +600,8 @@ String lcl_GetSpecialDateName( double fValue, bool bFirst, SvNumberFormatter* pF return aBuffer.makeStringAndClear(); } -void ScDPDateGroupHelper::FillColumnEntries( SCCOL nSourceDim, ScDPTableDataCache* pCache, std::vector< SCROW >& rEntries, const std::vector< SCROW >& rOriginal ) const +void ScDPDateGroupHelper::FillColumnEntries( + SCCOL nSourceDim, const ScDPTableDataCache* pCache, std::vector& rEntries, const std::vector& rOriginal) const { // auto min/max is only used for "Years" part, but the loop is always needed double fSourceMin = 0.0; @@ -900,8 +901,8 @@ void ScDPNumGroupDimension::MakeDateHelper( const ScDPNumGroupInfo& rInfo, sal_I aGroupInfo.Enable = sal_True; //! or query both? } -const std::vector< SCROW >& ScDPNumGroupDimension::GetNumEntries( SCCOL nSourceDim, ScDPTableDataCache* pCache, - const std::vector< SCROW >& rOriginal ) const +const std::vector& ScDPNumGroupDimension::GetNumEntries( + SCCOL nSourceDim, const ScDPTableDataCache* pCache, const std::vector& rOriginal) const { if ( maMemberEntries.empty() ) { @@ -1095,7 +1096,7 @@ const std::vector< SCROW >& ScDPGroupTableData::GetColumnEntries( long nColumn { // dimension number is unchanged for numerical groups const std::vector< SCROW >& rOriginal = pSourceData->GetColumnEntries( nColumn ); - return pNumGroups[nColumn].GetNumEntries( (SCCOL)nColumn, GetCacheTable().getCache(), rOriginal ); + return pNumGroups[nColumn].GetNumEntries( (SCCOL)nColumn, GetCacheTable().getCache(), rOriginal ); } return pSourceData->GetColumnEntries( nColumn ); @@ -1337,7 +1338,7 @@ void ScDPGroupTableData::FillGroupValues( /*ScDPItemData* pItemData*/ SCROW* pIt { long nGroupedColumns = aGroups.size(); - ScDPTableDataCache* pCache = GetCacheTable().getCache(); + const ScDPTableDataCache* pCache = GetCacheTable().getCache(); for (long nDim=0; nDimIsDateDimension( nDim); + return GetCacheTable().getCache()->IsDateDimension( nDim); } } diff --git a/sc/source/core/data/dptabdat.cxx b/sc/source/core/data/dptabdat.cxx index 7a5fdd9aa1e9..1742bb30276c 100644 --- a/sc/source/core/data/dptabdat.cxx +++ b/sc/source/core/data/dptabdat.cxx @@ -301,13 +301,13 @@ long ScDPTableData::GetSourceDim( long nDim ) } - long ScDPTableData::Compare( long nDim, long nDataId1, long nDataId2) +long ScDPTableData::Compare( long nDim, long nDataId1, long nDataId2) { if ( getIsDataLayoutDimension(nDim) ) return 0; - long n1 = GetCacheTable().getCache()->GetOrder( nDim, nDataId1); - long n2 = GetCacheTable().getCache()->GetOrder( nDim, nDataId2); + long n1 = GetCacheTable().getOrder(nDim, nDataId1); + long n2 = GetCacheTable().getOrder(nDim, nDataId2); if ( n1 > n2 ) return 1; else if ( n1 == n2 ) diff --git a/sc/source/core/data/dptablecache.cxx b/sc/source/core/data/dptablecache.cxx index ca82b09e3d2d..c7466903482f 100644 --- a/sc/source/core/data/dptablecache.cxx +++ b/sc/source/core/data/dptablecache.cxx @@ -996,19 +996,19 @@ SCROW ScDPTableDataCache::GetIdByItemData( long nDim, const ScDPItemData& rData return GetRowCount() + maAdditionalData.getDataId(rData); } -SCROW ScDPTableDataCache::GetAdditionalItemID ( String sItemData ) +SCROW ScDPTableDataCache::GetAdditionalItemID ( String sItemData ) const { ScDPItemData rData ( sItemData ); return GetAdditionalItemID( rData ); } -SCROW ScDPTableDataCache::GetAdditionalItemID( const ScDPItemData& rData ) +SCROW ScDPTableDataCache::GetAdditionalItemID( const ScDPItemData& rData ) const { return GetRowCount() + maAdditionalData.insertData( rData ); } -SCROW ScDPTableDataCache::GetOrder(long nDim, SCROW nIndex) +SCROW ScDPTableDataCache::GetOrder(long nDim, SCROW nIndex) const { DBG_ASSERT( IsValid(), " IsValid() == false " ); DBG_ASSERT( nDim >=0 && nDim < mnColumnCount, "ScDPTableDataCache::GetOrder : out of bound" ); @@ -1016,7 +1016,7 @@ SCROW ScDPTableDataCache::GetOrder(long nDim, SCROW nIndex) if ( maIndexOrder[nDim].size() != maGlobalOrder[nDim].size() ) { //not inited SCROW i = 0; - maIndexOrder[nDim].resize( maGlobalOrder[nDim].size(), 0 ); + maIndexOrder[nDim].resize(maGlobalOrder[nDim].size(), 0); for ( size_t n = 0 ; n< maGlobalOrder[nDim].size(); n++ ) { i = maGlobalOrder[nDim][n]; diff --git a/sc/source/core/data/dptabsrc.cxx b/sc/source/core/data/dptabsrc.cxx index 93be2233c71f..2f2c523163db 100644 --- a/sc/source/core/data/dptabsrc.cxx +++ b/sc/source/core/data/dptabsrc.cxx @@ -2796,7 +2796,7 @@ uno::Any SAL_CALL ScDPMember::getPropertyValue( const rtl::OUString& aPropertyNa SC_IMPL_DUMMY_PROPERTY_LISTENER( ScDPMember ) -ScDPTableDataCache* ScDPSource::GetCache() +const ScDPTableDataCache* ScDPSource::GetCache() { DBG_ASSERT( GetData() , "empty ScDPTableData pointer"); return ( GetData()!=NULL) ? GetData()->GetCacheTable().getCache() : NULL ; diff --git a/sc/source/filter/excel/xepivot.cxx b/sc/source/filter/excel/xepivot.cxx index 855ce0e75528..55ac0e151c04 100644 --- a/sc/source/filter/excel/xepivot.cxx +++ b/sc/source/filter/excel/xepivot.cxx @@ -544,7 +544,8 @@ void XclExpPCField::InsertNumDateGroupItems( const ScDPObject& rDPObj, const ScD ScDPNumGroupDimension aTmpDim( rNumInfo ); if( nDatePart != 0 ) aTmpDim.MakeDateHelper( rNumInfo, nDatePart ); - const std::vector< SCROW > aMemberIds = aTmpDim.GetNumEntries( static_cast< SCCOL >( GetBaseFieldIndex() ), aDPData.GetCacheTable().getCache(), aOrignial ); + const std::vector& aMemberIds = aTmpDim.GetNumEntries( + static_cast( GetBaseFieldIndex() ), aDPData.GetCacheTable().getCache(), aOrignial); for ( size_t nIdx = 0 ; nIdx < aMemberIds.size(); nIdx++ ) { const ScDPItemData* pData = aDPData.GetMemberById( static_cast< long >( GetBaseFieldIndex() ) , aMemberIds[ nIdx] );