[Libreoffice-commits] .: Branch 'libreoffice-3-4' - sc/inc sc/source
Kohei Yoshida
kohei at kemper.freedesktop.org
Fri Apr 29 16:40:23 PDT 2011
sc/inc/dptablecache.hxx | 35 ++++++++++++++++++-----
sc/source/core/data/dptablecache.cxx | 52 ++++++++++++++++++++---------------
2 files changed, 59 insertions(+), 28 deletions(-)
New commits:
commit ba633e08bf8cca703576eec2bd6df9c31a263cf3
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Fri Apr 29 19:38:19 2011 -0400
A bit of cleanups & annotation of data members.
I'm trying to understand what ScDPCache does exactly.
diff --git a/sc/inc/dptablecache.hxx b/sc/inc/dptablecache.hxx
index e1ad6ab..9de18bf 100644
--- a/sc/inc/dptablecache.hxx
+++ b/sc/inc/dptablecache.hxx
@@ -58,12 +58,33 @@ private:
ScDocument* mpDoc;
long mnColumnCount;
- DataGridType maTableDataValues; // Data Pilot Table's index - value map
- RowGridType maSourceData; // Data Pilot Table's source data
- RowGridType maGlobalOrder; // Sorted members index
- mutable RowGridType maIndexOrder; // Index the sorted numbers
- DataListType maLabelNames; // Source label data
- std::vector<bool> mbEmptyRow; //If empty row?
+ /**
+ * This container stores only the unique instances of item data in each
+ * column. Duplicates are not allowed.
+ */
+ DataGridType maTableDataValues;
+
+ /**
+ * This container stores indices within maTableDataValues pointing to the
+ * data. The order of data are exactly as they appear in the original
+ * data source.
+ */
+ RowGridType maSourceData;
+
+ /**
+ * This container stores indices within maTableDataValues. The order of
+ * indices in each column represents ascending order of the actual data.
+ */
+ RowGridType maGlobalOrder;
+
+ /**
+ * This container stores the ranks of each unique data represented by
+ * their index.
+ */
+ mutable RowGridType maIndexOrder;
+
+ DataListType maLabelNames; // Stores dimension names.
+ std::vector<bool> mbEmptyRow; // Keeps track of empty rows.
mutable ScDPItemDataPool maAdditionalData;
@@ -108,7 +129,7 @@ public:
private:
SCROW GetOrder( long nDim, SCROW nIndex ) const;
void AddLabel( ScDPItemData* pData);
- bool AddData( long nDim, ScDPItemData* itemData );
+ bool AddData(long nDim, ScDPItemData* pData);
};
#endif
diff --git a/sc/source/core/data/dptablecache.cxx b/sc/source/core/data/dptablecache.cxx
index 3aff118..da412db 100644
--- a/sc/source/core/data/dptablecache.cxx
+++ b/sc/source/core/data/dptablecache.cxx
@@ -48,6 +48,8 @@
#include <com/sun/star/sdbc/XResultSetMetaData.hpp>
#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
+#include <memory>
+
const double D_TIMEFACTOR = 86400.0;
using namespace ::com::sun::star;
@@ -57,26 +59,37 @@ using ::com::sun::star::uno::Reference;
using ::com::sun::star::uno::UNO_QUERY;
using ::com::sun::star::uno::UNO_QUERY_THROW;
using ::std::vector;
+using ::std::auto_ptr;
namespace {
-bool lcl_isDate( sal_uLong nNumType )
+bool isDate( sal_uLong nNumType )
{
return ((nNumType & NUMBERFORMAT_DATE) != 0) ? 1 : 0;
}
-bool lcl_Search( const ScDPCache::DataListType& list, const ::std::vector<SCROW>& rOrder, const ScDPItemData& item, SCROW& rIndex)
+/**
+ * Search for an item in the data array. If it's in the array, return its
+ * index to the caller.
+ *
+ * @param rArray dimension array
+ * @param rOrder global order (what's this?)
+ * @param item item to search for
+ * @param rIndex the index of the found item in the global order.
+ *
+ * @return true if the item is found, or false otherwise.
+ */
+bool hasItemInDimension(const ScDPCache::DataListType& rArray, const ::std::vector<SCROW>& rOrder, const ScDPItemData& item, SCROW& rIndex)
{
- rIndex = list.size();
+ rIndex = rArray.size();
bool bFound = false;
SCROW nLo = 0;
- SCROW nHi = list.size() - 1;
- SCROW nIndex;
+ SCROW nHi = rArray.size() - 1;
long nCompare;
while (nLo <= nHi)
{
- nIndex = (nLo + nHi) / 2;
- nCompare = ScDPItemData::Compare( list[rOrder[nIndex]], item );
+ SCROW nIndex = (nLo + nHi) / 2;
+ nCompare = ScDPItemData::Compare( rArray[rOrder[nIndex]], item );
if (nCompare < 0)
nLo = nIndex + 1;
else
@@ -173,7 +186,7 @@ ScDPItemData* lcl_GetItemValue(
ScDPItemData::ScDPItemData(const String& rS, double fV, bool bHV, const sal_uLong nNumFormatP, bool bData) :
nNumFormat( nNumFormatP ), aString(rS), fValue(fV),
- mbFlag( (MK_VAL*!!bHV) | (MK_DATA*!!bData) | (MK_ERR*!!false) | (MK_DATE*!!lcl_isDate( nNumFormat ) ) )
+ mbFlag( (MK_VAL*!!bHV) | (MK_DATA*!!bData) | (MK_ERR*!!false) | (MK_DATE*!!isDate( nNumFormat ) ) )
{
}
@@ -203,7 +216,7 @@ ScDPItemData::ScDPItemData(ScDocument* pDoc, SCROW nRow, sal_uInt16 nCol, sal_uI
fValue = fVal;
mbFlag |= MK_VAL|MK_DATA;
nNumFormat = pDoc->GetNumberFormat( ScAddress( nCol, nRow, nDocTab ) );
- lcl_isDate( nFormat ) ? ( mbFlag |= MK_DATE ) : (mbFlag &= ~MK_DATE);
+ isDate( nFormat ) ? ( mbFlag |= MK_DATE ) : (mbFlag &= ~MK_DATE);
}
else if ( pDoc->HasData( nCol,nRow, nDocTab ) )
SetString ( aDocStr );
@@ -787,23 +800,23 @@ bool ScDPCache::IsEmptyMember( SCROW nRow, sal_uInt16 nColumn ) const
return !GetItemDataById( nColumn, GetItemDataId( nColumn, nRow, false ) )->IsHasData();
}
-bool ScDPCache::AddData(long nDim, ScDPItemData* pitemData)
+bool ScDPCache::AddData(long nDim, ScDPItemData* pData)
{
DBG_ASSERT( IsValid(), " IsValid() == false " );
DBG_ASSERT( nDim < mnColumnCount && nDim >=0 , "dimension out of bound" );
- SCROW nIndex = 0;
-
- bool bInserted = false;
- pitemData->SetDate( lcl_isDate( GetNumType( pitemData->nNumFormat ) ) );
+ // Wrap this instance with scoped pointer to ensure proper deletion.
+ auto_ptr<ScDPItemData> p(pData);
+ pData->SetDate(isDate(GetNumType(pData->nNumFormat)));
- if ( !lcl_Search( maTableDataValues[nDim], maGlobalOrder[nDim], *pitemData, nIndex ) )
+ SCROW nIndex = 0;
+ if (!hasItemInDimension(maTableDataValues[nDim], maGlobalOrder[nDim], *pData, nIndex))
{
- maTableDataValues[nDim].push_back( pitemData );
+ // This item doesn't exist in the dimension array yet.
+ maTableDataValues[nDim].push_back(p);
maGlobalOrder[nDim].insert( maGlobalOrder[nDim].begin()+nIndex, maTableDataValues[nDim].size()-1 );
DBG_ASSERT( (size_t) maGlobalOrder[nDim][nIndex] == maTableDataValues[nDim].size()-1 ,"ScDPTableDataCache::AddData ");
maSourceData[nDim].push_back( maTableDataValues[nDim].size()-1 );
- bInserted = true;
}
else
maSourceData[nDim].push_back( maGlobalOrder[nDim][nIndex] );
@@ -813,12 +826,9 @@ bool ScDPCache::AddData(long nDim, ScDPItemData* pitemData)
while ( mbEmptyRow.size() <= nCurRow )
mbEmptyRow.push_back( true );
- if ( pitemData->IsHasData() )
+ if ( pData->IsHasData() )
mbEmptyRow[ nCurRow ] = false;
- if ( !bInserted )
- delete pitemData;
-
return true;
}
More information about the Libreoffice-commits
mailing list