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.
This commit is contained in:
Kohei Yoshida 2011-02-28 18:14:22 -05:00
parent 633d352fb9
commit d444d877a1
11 changed files with 54 additions and 35 deletions

View file

@ -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<sal_Int32>& 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.
*

View file

@ -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<SCROW>& rEntries,
const std::vector<SCROW>& 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<SCROW>& GetNumEntries(
SCCOL nSourceDim, const ScDPTableDataCache* pCache,
const std::vector< SCROW >& rOriginal) const;
void MakeDateHelper( const ScDPNumGroupInfo& rInfo, sal_Int32 nPart );

View file

@ -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<bool> 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;

View file

@ -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 );

View file

@ -407,6 +407,11 @@ void ScDPCacheTable::filterTable(const vector<Criterion>& 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;

View file

@ -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<bool bUpdateData>
SCROW lcl_InsertValue( SCCOL nSourceDim, ScDPTableDataCache* pCache , std::vector< SCROW >& vIdx, const ScDPItemData & rData );
SCROW lcl_InsertValue(SCCOL nSourceDim, const ScDPTableDataCache* pCache, std::vector<SCROW>& vIdx, const ScDPItemData & rData);
template<>
SCROW lcl_InsertValue<false>( SCCOL nSourceDim, ScDPTableDataCache* pCache , std::vector< SCROW >& vIdx, const ScDPItemData & rData )
SCROW lcl_InsertValue<false>(SCCOL nSourceDim, const ScDPTableDataCache* pCache, std::vector<SCROW>& 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<true>( SCCOL nSourceDim, ScDPTableDataCache* pCache , std::vector< SCROW >& vIdx, const ScDPItemData & rData )
SCROW lcl_InsertValue<true>(SCCOL nSourceDim, const ScDPTableDataCache* pCache, std::vector<SCROW>& vIdx, const ScDPItemData & rData)
{
SCROW nItemId = lcl_InsertValue<false>( nSourceDim, pCache, vIdx, rData );
@ -142,13 +142,13 @@ namespace
}
template<bool bUpdateData>
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<bUpdateData>( nSourceDim, pCache, vIdx, ScDPItemData( rString, fValue, TRUE ) );
}
template<bool bUpdateData>
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<bUpdateData>( 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<SCROW>& rEntries, const std::vector<SCROW>& 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<SCROW>& ScDPNumGroupDimension::GetNumEntries(
SCCOL nSourceDim, const ScDPTableDataCache* pCache, const std::vector<SCROW>& 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; nDim<nCount; nDim++)
{
const ScDPDateGroupHelper* pDateHelper = NULL;

View file

@ -144,7 +144,7 @@ BOOL ScSheetDPData::IsDateDimension(long nDim)
}
else
{
return aCacheTable.getCache()->IsDateDimension( nDim);
return GetCacheTable().getCache()->IsDateDimension( nDim);
}
}

View file

@ -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 )

View file

@ -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];

View file

@ -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 ;

View file

@ -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<SCROW>& aMemberIds = aTmpDim.GetNumEntries(
static_cast<SCCOL>( 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] );