[Libreoffice-commits] .: Branch 'libreoffice-4-0' - 4 commits - sc/inc sc/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Jan 4 06:47:26 PST 2013


 sc/inc/dpglobal.hxx              |    2 
 sc/inc/dptabres.hxx              |   87 +++++-----
 sc/inc/dptabsrc.hxx              |   14 -
 sc/source/core/data/dptabres.cxx |  200 +++++++++++-------------
 sc/source/core/data/dptabsrc.cxx |  325 ++++++++++++++++++++-------------------
 5 files changed, 319 insertions(+), 309 deletions(-)

New commits:
commit 744c4a4f4eb2555d3a0c1aba9fa74209a8f1942d
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Fri Jan 4 02:31:26 2013 -0500

    Remove the last use of SC_DP_MAX_FIELDS.
    
    Now the pivot table core no longer uses static array for result data
    storage.
    
    Change-Id: I70a44011e2c12a1739c0507b1723c21a4808758c

diff --git a/sc/inc/dpglobal.hxx b/sc/inc/dpglobal.hxx
index 4096a57..fe94b32 100644
--- a/sc/inc/dpglobal.hxx
+++ b/sc/inc/dpglobal.hxx
@@ -20,8 +20,6 @@
 #ifndef _SC_DPGLOBAL_HXX
 #define _SC_DPGLOBAL_HXX
 
-#define SC_DP_MAX_FIELDS  256
-
 #define     PIVOT_MAXFUNC           11
 #define     PIVOT_FUNC_NONE         0x0000
 #define     PIVOT_FUNC_SUM          0x0001
diff --git a/sc/inc/dptabsrc.hxx b/sc/inc/dptabsrc.hxx
index 11888dd..1aefebc 100644
--- a/sc/inc/dptabsrc.hxx
+++ b/sc/inc/dptabsrc.hxx
@@ -98,14 +98,12 @@ private:
     ScDPTableData*          pData;              // data source (ScDPObject manages its life time)
     ScDPDimensions*         pDimensions;        // api objects
                                                 // settings:
-    long                    nColDims[SC_DP_MAX_FIELDS];
-    long                    nRowDims[SC_DP_MAX_FIELDS];
-    long                    nDataDims[SC_DP_MAX_FIELDS];
-    long                    nPageDims[SC_DP_MAX_FIELDS];
-    long                    nColDimCount;
-    long                    nRowDimCount;
-    long                    nDataDimCount;
-    long                    nPageDimCount;
+
+    std::vector<long> maColDims;
+    std::vector<long> maRowDims;
+    std::vector<long> maDataDims;
+    std::vector<long> maPageDims;
+
     bool                    bColumnGrand;
     bool                    bRowGrand;
     bool                    bIgnoreEmptyRows;
diff --git a/sc/source/core/data/dptabsrc.cxx b/sc/source/core/data/dptabsrc.cxx
index 60f493f..56aa2c7 100644
--- a/sc/source/core/data/dptabsrc.cxx
+++ b/sc/source/core/data/dptabsrc.cxx
@@ -109,10 +109,6 @@ static void lcl_SetBoolInAny( uno::Any& rAny, sal_Bool bValue )
 ScDPSource::ScDPSource( ScDPTableData* pD ) :
     pData( pD ),
     pDimensions( NULL ),
-    nColDimCount( 0 ),
-    nRowDimCount( 0 ),
-    nDataDimCount( 0 ),
-    nPageDimCount( 0 ),
     bColumnGrand( true ),       // default is true
     bRowGrand( true ),
     bIgnoreEmptyRows( false ),
@@ -152,33 +148,32 @@ const ::rtl::OUString* ScDPSource::GetGrandTotalName() const
 
 sal_uInt16 ScDPSource::GetOrientation(long nColumn)
 {
-    long i;
-    for (i=0; i<nColDimCount; i++)
-        if (nColDims[i] == nColumn)
-            return sheet::DataPilotFieldOrientation_COLUMN;
-    for (i=0; i<nRowDimCount; i++)
-        if (nRowDims[i] == nColumn)
-            return sheet::DataPilotFieldOrientation_ROW;
-    for (i=0; i<nDataDimCount; i++)
-        if (nDataDims[i] == nColumn)
-            return sheet::DataPilotFieldOrientation_DATA;
-    for (i=0; i<nPageDimCount; i++)
-        if (nPageDims[i] == nColumn)
-            return sheet::DataPilotFieldOrientation_PAGE;
+    if (std::find(maColDims.begin(), maColDims.end(), nColumn) != maColDims.end())
+        return sheet::DataPilotFieldOrientation_COLUMN;
+
+    if (std::find(maRowDims.begin(), maRowDims.end(), nColumn) != maRowDims.end())
+        return sheet::DataPilotFieldOrientation_ROW;
+
+    if (std::find(maDataDims.begin(), maDataDims.end(), nColumn) != maDataDims.end())
+        return sheet::DataPilotFieldOrientation_DATA;
+
+    if (std::find(maPageDims.begin(), maPageDims.end(), nColumn) != maPageDims.end())
+        return sheet::DataPilotFieldOrientation_PAGE;
+
     return sheet::DataPilotFieldOrientation_HIDDEN;
 }
 
 long ScDPSource::GetDataDimensionCount()
 {
-    return nDataDimCount;
+    return maDataDims.size();
 }
 
 ScDPDimension* ScDPSource::GetDataDimension(long nIndex)
 {
-    if (nIndex < 0 || nIndex >= nDataDimCount)
+    if (nIndex < 0 || static_cast<size_t>(nIndex) >= maDataDims.size())
         return NULL;
 
-    long nDimIndex = nDataDims[nIndex];
+    long nDimIndex = maDataDims[nIndex];
     return GetDimensionsObject()->getByIndex(nDimIndex);
 }
 
@@ -193,92 +188,107 @@ rtl::OUString ScDPSource::GetDataDimName(long nIndex)
 
 long ScDPSource::GetPosition(long nColumn)
 {
-    long i;
-    for (i=0; i<nColDimCount; i++)
-        if (nColDims[i] == nColumn)
-            return i;
-    for (i=0; i<nRowDimCount; i++)
-        if (nRowDims[i] == nColumn)
-            return i;
-    for (i=0; i<nDataDimCount; i++)
-        if (nDataDims[i] == nColumn)
-            return i;
-    for (i=0; i<nPageDimCount; i++)
-        if (nPageDims[i] == nColumn)
-            return i;
+    std::vector<long>::const_iterator it, itBeg = maColDims.begin(), itEnd = maColDims.end();
+    it = std::find(itBeg, itEnd, nColumn);
+    if (it != itEnd)
+        return std::distance(itBeg, it);
+
+    itBeg = maRowDims.begin();
+    itEnd = maRowDims.end();
+    it = std::find(itBeg, itEnd, nColumn);
+    if (it != itEnd)
+        return std::distance(itBeg, it);
+
+    itBeg = maDataDims.begin();
+    itEnd = maDataDims.end();
+    it = std::find(itBeg, itEnd, nColumn);
+    if (it != itEnd)
+        return std::distance(itBeg, it);
+
+    itBeg = maPageDims.begin();
+    itEnd = maPageDims.end();
+    it = std::find(itBeg, itEnd, nColumn);
+    if (it != itEnd)
+        return std::distance(itBeg, it);
+
     return 0;
 }
 
-static sal_Bool lcl_TestSubTotal( sal_Bool& rAllowed, long nColumn, long* pArray, long nCount, ScDPSource* pSource )
+namespace {
+
+bool testSubTotal( bool& rAllowed, long nColumn, const std::vector<long>& rDims, ScDPSource* pSource )
 {
-    for (long i=0; i<nCount; i++)
-        if (pArray[i] == nColumn)
+    rAllowed = true;
+    std::vector<long>::const_iterator it = rDims.begin(), itEnd = rDims.end();
+    for (; it != itEnd; ++it)
+    {
+        if (*it != nColumn)
+            continue;
+
+        if ( pSource->IsDataLayoutDimension(nColumn) )
         {
             //  no subtotals for data layout dim, no matter where
-            if ( pSource->IsDataLayoutDimension(nColumn) )
-                rAllowed = false;
-            else
-            {
-                //  no subtotals if no other dim but data layout follows
-                long nNextIndex = i+1;
-                if ( nNextIndex < nCount && pSource->IsDataLayoutDimension(pArray[nNextIndex]) )
-                    ++nNextIndex;
-                if ( nNextIndex >= nCount )
-                    rAllowed = false;
-            }
-
-            return sal_True;    // found
+            rAllowed = false;
+            return true;
         }
+
+        //  no subtotals if no other dim but data layout follows
+        ++it;
+        if (it != itEnd && pSource->IsDataLayoutDimension(*it))
+            ++it;
+        if (it == itEnd)
+            rAllowed = false;
+
+        return true;    // found
+    }
+
     return false;
 }
 
+void removeDim( long nRemove, std::vector<long>& rDims )
+{
+    std::vector<long>::iterator it = std::find(rDims.begin(), rDims.end(), nRemove);
+    if (it != rDims.end())
+        rDims.erase(it);
+}
+
+}
+
 sal_Bool ScDPSource::SubTotalAllowed(long nColumn)
 {
     //! cache this at ScDPResultData
-    sal_Bool bAllowed = sal_True;
-    if ( lcl_TestSubTotal( bAllowed, nColumn, nColDims, nColDimCount, this ) )
+    bool bAllowed = true;
+    if ( testSubTotal(bAllowed, nColumn, maColDims, this) )
         return bAllowed;
-    if ( lcl_TestSubTotal( bAllowed, nColumn, nRowDims, nRowDimCount, this ) )
+    if ( testSubTotal(bAllowed, nColumn, maRowDims, this) )
         return bAllowed;
     return bAllowed;
 }
 
-static void lcl_RemoveDim( long nRemove, long* pDims, long& rCount )
-{
-    for (long i=0; i<rCount; i++)
-        if ( pDims[i] == nRemove )
-        {
-            for (long j=i; j+1<rCount; j++)
-                pDims[j] = pDims[j+1];
-            --rCount;
-            return;
-        }
-}
-
 void ScDPSource::SetOrientation(long nColumn, sal_uInt16 nNew)
 {
     //! change to no-op if new orientation is equal to old?
 
     // remove from old list
-    lcl_RemoveDim( nColumn, nColDims, nColDimCount );
-    lcl_RemoveDim( nColumn, nRowDims, nRowDimCount );
-    lcl_RemoveDim( nColumn, nDataDims, nDataDimCount );
-    lcl_RemoveDim( nColumn, nPageDims, nPageDimCount );
+    removeDim(nColumn, maColDims);
+    removeDim(nColumn, maRowDims);
+    removeDim(nColumn, maDataDims);
+    removeDim(nColumn, maPageDims);
 
     // add to new list
     switch (nNew)
     {
         case sheet::DataPilotFieldOrientation_COLUMN:
-            nColDims[nColDimCount++] = nColumn;
+            maColDims.push_back(nColumn);
             break;
         case sheet::DataPilotFieldOrientation_ROW:
-            nRowDims[nRowDimCount++] = nColumn;
+            maRowDims.push_back(nColumn);
             break;
         case sheet::DataPilotFieldOrientation_DATA:
-            nDataDims[nDataDimCount++] = nColumn;
+            maDataDims.push_back(nColumn);
             break;
         case sheet::DataPilotFieldOrientation_PAGE:
-            nPageDims[nPageDimCount++] = nColumn;
+            maPageDims.push_back(nColumn);
             break;
             // DataPilot Migration - Cache&&Performance
         case sheet::DataPilotFieldOrientation_HIDDEN:
@@ -514,8 +524,10 @@ void ScDPSource::disposeData()
     }
     SetDupCount( 0 );
 
-    //! Test ????
-    nColDimCount = nRowDimCount = nDataDimCount = nPageDimCount = 0;
+    maColDims.clear();
+    maRowDims.clear();
+    maDataDims.clear();
+    maPageDims.clear();
 
     pData->DisposeData();   // cached entries etc.
     bPageFiltered = false;
@@ -596,12 +608,11 @@ static long lcl_GetIndexFromName( const rtl::OUString rName, const uno::Sequence
 
 void ScDPSource::FillCalcInfo(bool bIsRow, ScDPTableData::CalcInfo& rInfo, bool &rHasAutoShow)
 {
-    long* nDims = bIsRow ? nRowDims : nColDims;
-    long nDimCount = bIsRow ? nRowDimCount : nColDimCount;
-
-    for (long i = 0; i < nDimCount; ++i)
+    const std::vector<long>& rDims = bIsRow ? maRowDims : maColDims;
+    std::vector<long>::const_iterator it = rDims.begin(), itEnd = rDims.end();
+    for (; it != itEnd; ++it)
     {
-        ScDPDimension* pDim = GetDimensionsObject()->getByIndex( nDims[i] );
+        ScDPDimension* pDim = GetDimensionsObject()->getByIndex(*it);
         long nHierarchy = pDim->getUsedHierarchy();
         if ( nHierarchy >= pDim->GetHierarchiesObject()->getCount() )
             nHierarchy = 0;
@@ -609,7 +620,7 @@ void ScDPSource::FillCalcInfo(bool bIsRow, ScDPTableData::CalcInfo& rInfo, bool
         long nCount = pLevels->getCount();
 
         //! Test
-        if ( pDim->getIsDataLayoutDimension() && nDataDimCount < 2 )
+        if (pDim->getIsDataLayoutDimension() && maDataDims.size() < 2)
             nCount = 0;
         //! Test
 
@@ -622,17 +633,17 @@ void ScDPSource::FillCalcInfo(bool bIsRow, ScDPTableData::CalcInfo& rInfo, bool
             pLevel->SetEnableLayout( bIsRow );
 
             if ( pLevel->GetAutoShow().IsEnabled )
-                rHasAutoShow = sal_True;
+                rHasAutoShow = true;
 
             if (bIsRow)
             {
-                rInfo.aRowLevelDims.push_back(nDims[i]);
+                rInfo.aRowLevelDims.push_back(*it);
                 rInfo.aRowDims.push_back(pDim);
                 rInfo.aRowLevels.push_back(pLevel);
             }
             else
             {
-                rInfo.aColLevelDims.push_back(nDims[i]);
+                rInfo.aColLevelDims.push_back(*it);
                 rInfo.aColDims.push_back(pDim);
                 rInfo.aColLevels.push_back(pLevel);
             }
@@ -642,29 +653,34 @@ void ScDPSource::FillCalcInfo(bool bIsRow, ScDPTableData::CalcInfo& rInfo, bool
     }
 }
 
-void ScDPSource::GetCategoryDimensionIndices(boost::unordered_set<sal_Int32>& rCatDims)
+namespace {
+
+class CategoryDimInserter : std::unary_function<long, void>
 {
-    boost::unordered_set<sal_Int32> aCatDims;
-    for (long i = 0; i < nColDimCount; ++i)
-    {
-        sal_Int32 nDim = static_cast<sal_Int32>(nColDims[i]);
-        if (!IsDataLayoutDimension(nDim))
-            aCatDims.insert(nDim);
-    }
+    ScDPSource& mrSource;
+    boost::unordered_set<sal_Int32>& mrCatDims;
+public:
+    CategoryDimInserter(ScDPSource& rSource, boost::unordered_set<sal_Int32>& rCatDims) :
+        mrSource(rSource),
+        mrCatDims(rCatDims) {}
 
-    for (long i = 0; i < nRowDimCount; ++i)
+    void operator() (long nDim)
     {
-        sal_Int32 nDim = static_cast<sal_Int32>(nRowDims[i]);
-        if (!IsDataLayoutDimension(nDim))
-            aCatDims.insert(nDim);
+        if (!mrSource.IsDataLayoutDimension(nDim))
+            mrCatDims.insert(nDim);
     }
+};
 
-    for (long i = 0; i < nPageDimCount; ++i)
-    {
-        sal_Int32 nDim = static_cast<sal_Int32>(nPageDims[i]);
-        if (!IsDataLayoutDimension(nDim))
-            aCatDims.insert(nDim);
-    }
+}
+
+void ScDPSource::GetCategoryDimensionIndices(boost::unordered_set<sal_Int32>& rCatDims)
+{
+    boost::unordered_set<sal_Int32> aCatDims;
+
+    CategoryDimInserter aInserter(*this, aCatDims);
+    std::for_each(maColDims.begin(), maColDims.end(), aInserter);
+    std::for_each(maRowDims.begin(), maRowDims.end(), aInserter);
+    std::for_each(maPageDims.begin(), maPageDims.end(), aInserter);
 
     rCatDims.swap(aCatDims);
 }
@@ -688,9 +704,10 @@ void ScDPSource::FilterCacheByPageDimensions()
 
     // filter table by page dimensions.
     vector<ScDPFilteredCache::Criterion> aCriteria;
-    for (long i = 0; i < nPageDimCount; ++i)
+    vector<long>::const_iterator it = maPageDims.begin(), itEnd = maPageDims.end();
+    for (; it != itEnd; ++it)
     {
-        ScDPDimension* pDim = GetDimensionsObject()->getByIndex(nPageDims[i]);
+        ScDPDimension* pDim = GetDimensionsObject()->getByIndex(*it);
         long nField = pDim->GetDimension();
 
         ScDPMembers* pMems = pDim->GetHierarchiesObject()->getByIndex(0)->
@@ -699,7 +716,7 @@ void ScDPSource::FilterCacheByPageDimensions()
         long nMemCount = pMems->getCount();
         ScDPFilteredCache::Criterion aFilter;
         aFilter.mnFieldIndex = static_cast<sal_Int32>(nField);
-        aFilter.mpFilter.reset(new ScDPFilteredCache::GroupFilter(/*rSharedString*/));
+        aFilter.mpFilter.reset(new ScDPFilteredCache::GroupFilter);
         ScDPFilteredCache::GroupFilter* pGrpFilter =
             static_cast<ScDPFilteredCache::GroupFilter*>(aFilter.mpFilter.get());
         for (long j = 0; j < nMemCount; ++j)
@@ -740,7 +757,7 @@ void ScDPSource::CreateRes_Impl()
         return;
 
     sal_uInt16 nDataOrient = GetDataLayoutOrientation();
-    if ( nDataDimCount > 1 && ( nDataOrient != sheet::DataPilotFieldOrientation_COLUMN &&
+    if (maDataDims.size() > 1 && ( nDataOrient != sheet::DataPilotFieldOrientation_COLUMN &&
                                 nDataOrient != sheet::DataPilotFieldOrientation_ROW ) )
     {
         //  if more than one data dimension, data layout orientation must be set
@@ -752,14 +769,9 @@ void ScDPSource::CreateRes_Impl()
     // eDataFunctions into a structure and use vector instead of static
     // or pointer arrays.
     vector<rtl::OUString> aDataNames;
-    sheet::DataPilotFieldReference* pDataRefValues = NULL;
+    vector<sheet::DataPilotFieldReference> aDataRefValues;
     vector<ScSubTotalFunc> aDataFunctions;
     vector<sal_uInt16> aDataRefOrient;
-    if (nDataDimCount)
-    {
-        aDataNames.resize(nDataDimCount);
-        pDataRefValues = new sheet::DataPilotFieldReference[nDataDimCount];
-    }
 
     ScDPTableData::CalcInfo aInfo;
 
@@ -771,11 +783,11 @@ void ScDPSource::CreateRes_Impl()
     // Go through all data dimensions (i.e. fields) and build their meta data
     // so that they can be passed on to ScDPResultData instance later.
     // TODO: aggregate all of data dimension info into a structure.
-    long i;
-    for (i=0; i<nDataDimCount; i++)
+    vector<long>::const_iterator it = maDataDims.begin(), itEnd = maDataDims.end();
+    for (; it != itEnd; ++it)
     {
         // Get function for each data field.
-        long nDimIndex = nDataDims[i];
+        long nDimIndex = *it;
         ScDPDimension* pDim = GetDimensionsObject()->getByIndex(nDimIndex);
         sheet::GeneralFunction eUser = (sheet::GeneralFunction)pDim->getFunction();
         if (eUser == sheet::GeneralFunction_AUTO)
@@ -788,16 +800,16 @@ void ScDPSource::CreateRes_Impl()
         aDataFunctions.push_back(ScDataUnoConversion::GeneralToSubTotal(eUser));
 
         // Get reference field/item information.
-        pDataRefValues[i] = pDim->GetReferenceValue();
+        aDataRefValues.push_back(pDim->GetReferenceValue());
         sal_uInt16 nDataRefOrient = sheet::DataPilotFieldOrientation_HIDDEN;    // default if not used
-        sal_Int32 eRefType = pDataRefValues[i].ReferenceType;
+        sal_Int32 eRefType = aDataRefValues.back().ReferenceType;
         if ( eRefType == sheet::DataPilotFieldReferenceType::ITEM_DIFFERENCE ||
              eRefType == sheet::DataPilotFieldReferenceType::ITEM_PERCENTAGE ||
              eRefType == sheet::DataPilotFieldReferenceType::ITEM_PERCENTAGE_DIFFERENCE ||
              eRefType == sheet::DataPilotFieldReferenceType::RUNNING_TOTAL )
         {
-            long nColumn = lcl_GetIndexFromName( pDataRefValues[i].ReferenceField,
-                                    GetDimensionsObject()->getElementNames() );
+            long nColumn = lcl_GetIndexFromName(
+                aDataRefValues.back().ReferenceField, GetDimensionsObject()->getElementNames());
             if ( nColumn >= 0 )
             {
                 nDataRefOrient = GetOrientation(nColumn);
@@ -810,18 +822,18 @@ void ScDPSource::CreateRes_Impl()
 
         aDataRefOrient.push_back(nDataRefOrient);
 
-        aDataNames[i] = pDim->getName();
+        aDataNames.push_back(pDim->getName());
 
         //! modify user visible strings as in ScDPResultData::GetMeasureString instead!
 
-        aDataNames[i] = ScDPUtil::getSourceDimensionName(aDataNames[i]);
+        aDataNames.back() = ScDPUtil::getSourceDimensionName(aDataNames.back());
 
         //! if the name is overridden by user, a flag must be set
         //! so the user defined name replaces the function string and field name.
 
         //! the complete name (function and field) must be stored at the dimension
 
-        long nSource = ((ScDPDimension*)pDim)->GetSourceDim();
+        long nSource = pDim->GetSourceDim();
         if (nSource >= 0)
             aInfo.aDataSrcCols.push_back(nSource);
         else
@@ -829,12 +841,19 @@ void ScDPSource::CreateRes_Impl()
     }
 
     pResData = new ScDPResultData( this );
-    pResData->SetMeasureData(nDataDimCount, &aDataFunctions[0], pDataRefValues, &aDataRefOrient[0], aDataNames);
+    const ScSubTotalFunc* pDataFunctions = NULL;
+    const sheet::DataPilotFieldReference* pDataRefValues = NULL;
+    const sal_uInt16* pDataRefOrient = NULL;
+    if (!maDataDims.empty())
+    {
+        pDataFunctions = &aDataFunctions[0];
+        pDataRefValues = &aDataRefValues[0];
+        pDataRefOrient = &aDataRefOrient[0];
+    }
+    pResData->SetMeasureData(maDataDims.size(), pDataFunctions, pDataRefValues, pDataRefOrient, aDataNames);
     pResData->SetDataLayoutOrientation(nDataOrient);
     pResData->SetLateInit( bLateInit );
 
-    delete[] pDataRefValues;
-
     bool bHasAutoShow = false;
 
     ScDPInitState aInitState;
@@ -843,18 +862,18 @@ void ScDPSource::CreateRes_Impl()
     // (both in column and row fields). aInitState is filled with the page
     // field selections, they are kept across the data iterator loop.
 
-    for (i=0; i<nPageDimCount; i++)
+    for (it = maPageDims.begin(), itEnd = maPageDims.end(); it != itEnd; ++it)
     {
-        ScDPDimension* pDim = GetDimensionsObject()->getByIndex( nPageDims[i] );
+        ScDPDimension* pDim = GetDimensionsObject()->getByIndex(*it);
         if ( pDim->HasSelectedPage() )
-            aInitState.AddMember( nPageDims[i], GetMemberId( nPageDims[i],  pDim->GetSelectedData() ) );
+            aInitState.AddMember(*it, GetMemberId(*it, pDim->GetSelectedData()));
     }
 
     // Show grand total columns only when the option is set *and* there is at
     // least one column field.  Same for the grand total rows.
     sal_uInt16 nDataLayoutOrient = GetDataLayoutOrientation();
-    long nColDimCount2 = nColDimCount - (nDataLayoutOrient == sheet::DataPilotFieldOrientation_COLUMN ? 1 : 0);
-    long nRowDimCount2 = nRowDimCount - (nDataLayoutOrient == sheet::DataPilotFieldOrientation_ROW ? 1 : 0);
+    long nColDimCount2 = maColDims.size() - (nDataLayoutOrient == sheet::DataPilotFieldOrientation_COLUMN ? 1 : 0);
+    long nRowDimCount2 = maRowDims.size() - (nDataLayoutOrient == sheet::DataPilotFieldOrientation_ROW ? 1 : 0);
     bool bShowColGrand = bColumnGrand && nColDimCount2 > 0;
     bool bShowRowGrand = bRowGrand && nRowDimCount2 > 0;
     pColResRoot = new ScDPResultMember(pResData, bShowColGrand);
@@ -879,9 +898,9 @@ void ScDPSource::CreateRes_Impl()
     pRowResRoot->SetHasElements();
 
     // initialize members object also for all page dimensions (needed for numeric groups)
-    for (i=0; i<nPageDimCount; i++)
+    for (it = maPageDims.begin(), itEnd = maPageDims.end(); it != itEnd; ++it)
     {
-        ScDPDimension* pDim = GetDimensionsObject()->getByIndex( nPageDims[i] );
+        ScDPDimension* pDim = GetDimensionsObject()->getByIndex(*it);
         long nHierarchy = pDim->getUsedHierarchy();
         if ( nHierarchy >= pDim->GetHierarchiesObject()->getCount() )
             nHierarchy = 0;
@@ -909,9 +928,9 @@ void ScDPSource::CreateRes_Impl()
 
     FilterCacheByPageDimensions();
 
-    aInfo.aPageDims.reserve(nPageDimCount);
-    for (i = 0; i < nPageDimCount; ++i)
-        aInfo.aPageDims.push_back(nPageDims[i]);
+    aInfo.aPageDims.reserve(maPageDims.size());
+    for (it = maPageDims.begin(), itEnd = maPageDims.end(); it != itEnd; ++it)
+        aInfo.aPageDims.push_back(*it);
 
     aInfo.pInitState = &aInitState;
     aInfo.pColRoot   = pColResRoot;
@@ -963,25 +982,20 @@ void ScDPSource::FillLevelList( sal_uInt16 nOrientation, std::vector<ScDPLevel*>
 {
     rList.clear();
 
-    long nDimCount = 0;
-    long* pDimIndex = NULL;
+    std::vector<long>* pDimIndex = NULL;
     switch (nOrientation)
     {
         case sheet::DataPilotFieldOrientation_COLUMN:
-            pDimIndex = nColDims;
-            nDimCount = nColDimCount;
+            pDimIndex = &maColDims;
             break;
         case sheet::DataPilotFieldOrientation_ROW:
-            pDimIndex = nRowDims;
-            nDimCount = nRowDimCount;
+            pDimIndex = &maRowDims;
             break;
         case sheet::DataPilotFieldOrientation_DATA:
-            pDimIndex = nDataDims;
-            nDimCount = nDataDimCount;
+            pDimIndex = &maDataDims;
             break;
         case sheet::DataPilotFieldOrientation_PAGE:
-            pDimIndex = nPageDims;
-            nDimCount = nPageDimCount;
+            pDimIndex = &maPageDims;
             break;
         default:
             OSL_FAIL( "ScDPSource::FillLevelList: unexpected orientation" );
@@ -994,9 +1008,10 @@ void ScDPSource::FillLevelList( sal_uInt16 nOrientation, std::vector<ScDPLevel*>
     }
 
     ScDPDimensions* pDims = GetDimensionsObject();
-    for (long nDim=0; nDim<nDimCount; nDim++)
+    std::vector<long>::const_iterator it = pDimIndex->begin(), itEnd = pDimIndex->end();
+    for (; it != itEnd; ++it)
     {
-        ScDPDimension* pDim = pDims->getByIndex(pDimIndex[nDim]);
+        ScDPDimension* pDim = pDims->getByIndex(*it);
         OSL_ENSURE( pDim->getOrientation() == nOrientation, "orientations are wrong" );
 
         ScDPHierarchies* pHiers = pDim->GetHierarchiesObject();
@@ -1147,11 +1162,11 @@ uno::Any SAL_CALL ScDPSource::getPropertyValue( const rtl::OUString& aPropertyNa
     else if ( aPropertyName.equalsAscii( SC_UNO_DP_DATADESC ) )             // read-only
         aRet <<= getDataDescription();
     else if ( aPropertyName.equalsAscii( SC_UNO_DP_ROWFIELDCOUNT ) )        // read-only
-        aRet <<= static_cast<sal_Int32>(nRowDimCount);
+        aRet <<= static_cast<sal_Int32>(maRowDims.size());
     else if ( aPropertyName.equalsAscii( SC_UNO_DP_COLUMNFIELDCOUNT ) )     // read-only
-        aRet <<= static_cast<sal_Int32>(nColDimCount);
+        aRet <<= static_cast<sal_Int32>(maColDims.size());
     else if ( aPropertyName.equalsAscii( SC_UNO_DP_DATAFIELDCOUNT ) )       // read-only
-        aRet <<= static_cast<sal_Int32>(nDataDimCount);
+        aRet <<= static_cast<sal_Int32>(maDataDims.size());
     else if (aPropertyName.equalsAscii(SC_UNO_DP_GRANDTOTAL_NAME))
     {
         if (mpGrandTotalName.get())
commit 5f1fbdd60d754365e0909aaf6d16db40fd4f278a
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Fri Jan 4 00:23:02 2013 -0500

    More on removing use of SC_DP_MAX_FIELDS.
    
    This time it's in ScDPSource::CreateRes_Impl().
    
    Change-Id: Ie2657045aeb8770c083daa34dc1a7e60c9921b65

diff --git a/sc/source/core/data/dptabsrc.cxx b/sc/source/core/data/dptabsrc.cxx
index b2d9895..60f493f 100644
--- a/sc/source/core/data/dptabsrc.cxx
+++ b/sc/source/core/data/dptabsrc.cxx
@@ -753,8 +753,8 @@ void ScDPSource::CreateRes_Impl()
     // or pointer arrays.
     vector<rtl::OUString> aDataNames;
     sheet::DataPilotFieldReference* pDataRefValues = NULL;
-    ScSubTotalFunc eDataFunctions[SC_DP_MAX_FIELDS];
-    sal_uInt16 nDataRefOrient[SC_DP_MAX_FIELDS];
+    vector<ScSubTotalFunc> aDataFunctions;
+    vector<sal_uInt16> aDataRefOrient;
     if (nDataDimCount)
     {
         aDataNames.resize(nDataDimCount);
@@ -785,11 +785,11 @@ void ScDPSource::CreateRes_Impl()
         }
 
         // Map UNO's enum to internal enum ScSubTotalFunc.
-        eDataFunctions[i] = ScDataUnoConversion::GeneralToSubTotal( eUser );
+        aDataFunctions.push_back(ScDataUnoConversion::GeneralToSubTotal(eUser));
 
         // Get reference field/item information.
         pDataRefValues[i] = pDim->GetReferenceValue();
-        nDataRefOrient[i] = sheet::DataPilotFieldOrientation_HIDDEN;    // default if not used
+        sal_uInt16 nDataRefOrient = sheet::DataPilotFieldOrientation_HIDDEN;    // default if not used
         sal_Int32 eRefType = pDataRefValues[i].ReferenceType;
         if ( eRefType == sheet::DataPilotFieldReferenceType::ITEM_DIFFERENCE ||
              eRefType == sheet::DataPilotFieldReferenceType::ITEM_PERCENTAGE ||
@@ -800,7 +800,7 @@ void ScDPSource::CreateRes_Impl()
                                     GetDimensionsObject()->getElementNames() );
             if ( nColumn >= 0 )
             {
-                nDataRefOrient[i] = GetOrientation( nColumn );
+                nDataRefOrient = GetOrientation(nColumn);
                 //  need fully initialized results to find reference values
                 //  (both in column or row dimensions), so updated values or
                 //  differences to 0 can be displayed even for empty results.
@@ -808,6 +808,8 @@ void ScDPSource::CreateRes_Impl()
             }
         }
 
+        aDataRefOrient.push_back(nDataRefOrient);
+
         aDataNames[i] = pDim->getName();
 
         //! modify user visible strings as in ScDPResultData::GetMeasureString instead!
@@ -827,7 +829,7 @@ void ScDPSource::CreateRes_Impl()
     }
 
     pResData = new ScDPResultData( this );
-    pResData->SetMeasureData( nDataDimCount, eDataFunctions, pDataRefValues, nDataRefOrient, aDataNames );
+    pResData->SetMeasureData(nDataDimCount, &aDataFunctions[0], pDataRefValues, &aDataRefOrient[0], aDataNames);
     pResData->SetDataLayoutOrientation(nDataOrient);
     pResData->SetLateInit( bLateInit );
 
commit f7e0056b796fcd7cd105f489ed58e64c74a29ade
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Thu Jan 3 23:59:15 2013 -0500

    Remove SC_DP_MAX_FIELDS from ScDPRunningTotalState too.
    
    Change-Id: I60bf45fd5148692adafb050189247f211293a3d1

diff --git a/sc/inc/dptabres.hxx b/sc/inc/dptabres.hxx
index 97cb230..edef1b3 100644
--- a/sc/inc/dptabres.hxx
+++ b/sc/inc/dptabres.hxx
@@ -96,41 +96,43 @@ struct ScDPSubTotalState
     {}
 };
 
-//
-//  indexes when calculating running totals
-//  Col/RowVisible: simple counts from 0 - without sort order applied - visible index
-//                  (only used for running total / relative index)
-//  Col/RowIndexes: with sort order applied - member index
-//                  (used otherwise - so other members' children can be accessed)
-//
-
+/**
+ * indexes when calculating running totals
+ *
+ * Col/RowVisible: simple counts from 0 - without sort order applied
+ * - visible index (only used for running total / relative index)
+ *
+ * Col/RowSorted: with sort order applied - member index (used otherwise -
+ * so other members' children can be accessed).
+ */
 class ScDPRunningTotalState
 {
-    ScDPResultMember*   pColResRoot;
-    ScDPResultMember*   pRowResRoot;
-    long*               pColVisible;
-    long*               pColIndexes;
-    long*               pRowVisible;
-    long*               pRowIndexes;
-    long                nColIndexPos;
-    long                nRowIndexPos;
-
 public:
-            ScDPRunningTotalState( ScDPResultMember* pColRoot, ScDPResultMember* pRowRoot );
-            ~ScDPRunningTotalState();
+    typedef std::vector<long> IndexArray; /// array of long integers terminated by -1.
+
+    ScDPRunningTotalState( ScDPResultMember* pColRoot, ScDPResultMember* pRowRoot );
 
     ScDPResultMember*   GetColResRoot() const   { return pColResRoot; }
     ScDPResultMember*   GetRowResRoot() const   { return pRowResRoot; }
 
-    const long*         GetColVisible() const   { return pColVisible; }
-    const long*         GetColIndexes() const   { return pColIndexes; }
-    const long*         GetRowVisible() const   { return pRowVisible; }
-    const long*         GetRowIndexes() const   { return pRowIndexes; }
+    const IndexArray& GetColVisible() const;
+    const IndexArray& GetColSorted() const;
+    const IndexArray& GetRowVisible() const;
+    const IndexArray& GetRowSorted() const;
 
     void    AddColIndex( long nVisible, long nSorted );
     void    AddRowIndex( long nVisible, long nSorted );
     void    RemoveColIndex();
     void    RemoveRowIndex();
+
+private:
+    ScDPResultMember*   pColResRoot;
+    ScDPResultMember*   pRowResRoot;
+
+    mutable IndexArray maColVisible;
+    mutable IndexArray maColSorted;
+    mutable IndexArray maRowVisible;
+    mutable IndexArray maRowSorted;
 };
 
 struct ScDPRelativePos
diff --git a/sc/source/core/data/dptabres.cxx b/sc/source/core/data/dptabres.cxx
index 12a84de..eb200db 100644
--- a/sc/source/core/data/dptabres.cxx
+++ b/sc/source/core/data/dptabres.cxx
@@ -273,72 +273,82 @@ static void lcl_Indent( ScDocument* pDoc, SCROW nStartRow, const ScAddress& rPos
 // -----------------------------------------------------------------------
 
 ScDPRunningTotalState::ScDPRunningTotalState( ScDPResultMember* pColRoot, ScDPResultMember* pRowRoot ) :
-    pColResRoot( pColRoot ),
-    pRowResRoot( pRowRoot ),
-    nColIndexPos( 0 ),
-    nRowIndexPos( 0 )
+    pColResRoot(pColRoot), pRowResRoot(pRowRoot)
 {
-    pColVisible = new long[SC_DP_MAX_FIELDS+1];
-    pColIndexes = new long[SC_DP_MAX_FIELDS+1];
-    pRowVisible = new long[SC_DP_MAX_FIELDS+1];
-    pRowIndexes = new long[SC_DP_MAX_FIELDS+1];
-    pColIndexes[0] = -1;
-    pRowIndexes[0] = -1;
+    // These arrays should never be empty as the terminating value must be present at all times.
+    maColVisible.push_back(-1);
+    maColSorted.push_back(-1);
+    maRowVisible.push_back(-1);
+    maRowSorted.push_back(-1);
 }
 
-ScDPRunningTotalState::~ScDPRunningTotalState()
+const ScDPRunningTotalState::IndexArray& ScDPRunningTotalState::GetColVisible() const
 {
-    delete[] pColVisible;
-    delete[] pColIndexes;
-    delete[] pRowVisible;
-    delete[] pRowIndexes;
+    return maColVisible;
+}
+
+const ScDPRunningTotalState::IndexArray& ScDPRunningTotalState::GetColSorted() const
+{
+    return maColSorted;
+}
+
+const ScDPRunningTotalState::IndexArray& ScDPRunningTotalState::GetRowVisible() const
+{
+    return maRowVisible;
+}
+
+const ScDPRunningTotalState::IndexArray& ScDPRunningTotalState::GetRowSorted() const
+{
+    return maRowSorted;
 }
 
 void ScDPRunningTotalState::AddColIndex( long nVisible, long nSorted )
 {
-    OSL_ENSURE( nColIndexPos < SC_DP_MAX_FIELDS, "too many column indexes" );
-    if ( nColIndexPos < SC_DP_MAX_FIELDS )
-    {
-        pColVisible[nColIndexPos] = nVisible;
-        pColIndexes[nColIndexPos] = nSorted;
-        pColVisible[nColIndexPos+1] = -1;
-        pColIndexes[nColIndexPos+1] = -1;
-        ++nColIndexPos;
-    }
+    maColVisible.back() = nVisible;
+    maColVisible.push_back(-1);
+
+    maColSorted.back() = nSorted;
+    maColSorted.push_back(-1);
 }
 
 void ScDPRunningTotalState::AddRowIndex( long nVisible, long nSorted )
 {
-    OSL_ENSURE( nRowIndexPos < SC_DP_MAX_FIELDS, "too many row indexes" );
-    if ( nRowIndexPos < SC_DP_MAX_FIELDS )
-    {
-        pRowVisible[nRowIndexPos] = nVisible;
-        pRowIndexes[nRowIndexPos] = nSorted;
-        pRowVisible[nRowIndexPos+1] = -1;
-        pRowIndexes[nRowIndexPos+1] = -1;
-        ++nRowIndexPos;
-    }
+    maRowVisible.back() = nVisible;
+    maRowVisible.push_back(-1);
+
+    maRowSorted.back() = nSorted;
+    maRowSorted.push_back(-1);
 }
 
 void ScDPRunningTotalState::RemoveColIndex()
 {
-    OSL_ENSURE( nColIndexPos > 0, "RemoveColIndex without index" );
-    if ( nColIndexPos > 0 )
+    OSL_ENSURE(!maColVisible.empty() && !maColSorted.empty(), "ScDPRunningTotalState::RemoveColIndex: array is already empty!");
+    if (maColVisible.size() >= 2)
+    {
+        maColVisible.pop_back();
+        maColVisible.back() = -1;
+    }
+
+    if (maColSorted.size() >= 2)
     {
-        --nColIndexPos;
-        pColVisible[nColIndexPos] = -1;
-        pColIndexes[nColIndexPos] = -1;
+        maColSorted.pop_back();
+        maColSorted.back() = -1;
     }
 }
 
 void ScDPRunningTotalState::RemoveRowIndex()
 {
-    OSL_ENSURE( nRowIndexPos > 0, "RemoveRowIndex without index" );
-    if ( nRowIndexPos > 0 )
+    OSL_ENSURE(!maRowVisible.empty() && !maRowSorted.empty(), "ScDPRunningTotalState::RemoveRowIndex: array is already empty!");
+    if (maRowVisible.size() >= 2)
+    {
+        maRowVisible.pop_back();
+        maRowVisible.back() = -1;
+    }
+
+    if (maRowSorted.size() >= 2)
     {
-        --nRowIndexPos;
-        pRowVisible[nRowIndexPos] = -1;
-        pRowIndexes[nRowIndexPos] = -1;
+        maRowSorted.pop_back();
+        maRowSorted.back() = -1;
     }
 }
 
@@ -2256,10 +2266,10 @@ void ScDPDataMember::UpdateRunningTotals( const ScDPResultMember* pRefMember,
                             long nRelativeDir = bRelative ?
                                 ( ( aReferenceValue.ReferenceItemType == sheet::DataPilotFieldReferenceItemType::PREVIOUS ) ? -1 : 1 ) : 0;
 
-                            const long* pColVisible = rRunning.GetColVisible();
-                            const long* pColIndexes = rRunning.GetColIndexes();
-                            const long* pRowVisible = rRunning.GetRowVisible();
-                            const long* pRowIndexes = rRunning.GetRowIndexes();
+                            const ScDPRunningTotalState::IndexArray& rColVisible = rRunning.GetColVisible();
+                            const ScDPRunningTotalState::IndexArray& rColSorted = rRunning.GetColSorted();
+                            const ScDPRunningTotalState::IndexArray& rRowVisible = rRunning.GetRowVisible();
+                            const ScDPRunningTotalState::IndexArray& rRowSorted = rRunning.GetRowSorted();
 
                             String aRefFieldName = aReferenceValue.ReferenceField;
 
@@ -2281,7 +2291,7 @@ void ScDPDataMember::UpdateRunningTotals( const ScDPResultMember* pRefMember,
                                 pSelectDim = rRunning.GetRowResRoot()->GetChildDimension();
                                 while ( pSelectDim && pSelectDim->GetName() != aRefFieldName )
                                 {
-                                    long nIndex = pRowIndexes[nRowPos];
+                                    long nIndex = rRowSorted[nRowPos];
                                     if ( nIndex >= 0 && nIndex < pSelectDim->GetMemberCount() )
                                         pSelectDim = pSelectDim->GetMember(nIndex)->GetChildDimension();
                                     else
@@ -2289,7 +2299,7 @@ void ScDPDataMember::UpdateRunningTotals( const ScDPResultMember* pRefMember,
                                     ++nRowPos;
                                 }
                                 // child dimension of innermost member?
-                                if ( pSelectDim && pRowIndexes[nRowPos] < 0 )
+                                if ( pSelectDim && rRowSorted[nRowPos] < 0 )
                                     pSelectDim = NULL;
                             }
 
@@ -2298,7 +2308,7 @@ void ScDPDataMember::UpdateRunningTotals( const ScDPResultMember* pRefMember,
                                 pSelectDim = rRunning.GetColResRoot()->GetChildDimension();
                                 while ( pSelectDim && pSelectDim->GetName() != aRefFieldName )
                                 {
-                                    long nIndex = pColIndexes[nColPos];
+                                    long nIndex = rColSorted[nColPos];
                                     if ( nIndex >= 0 && nIndex < pSelectDim->GetMemberCount() )
                                         pSelectDim = pSelectDim->GetMember(nIndex)->GetChildDimension();
                                     else
@@ -2306,7 +2316,7 @@ void ScDPDataMember::UpdateRunningTotals( const ScDPResultMember* pRefMember,
                                     ++nColPos;
                                 }
                                 // child dimension of innermost member?
-                                if ( pSelectDim && pColIndexes[nColPos] < 0 )
+                                if ( pSelectDim && rColSorted[nColPos] < 0 )
                                     pSelectDim = NULL;
                             }
 
@@ -2318,7 +2328,7 @@ void ScDPDataMember::UpdateRunningTotals( const ScDPResultMember* pRefMember,
                                 //  don't show or sum up the value. Otherwise, for following members,
                                 //  the running totals of details and subtotals wouldn't match.
 
-                                long nMyIndex = bRefDimInCol ? pColIndexes[nColPos] : pRowIndexes[nRowPos];
+                                long nMyIndex = bRefDimInCol ? rColSorted[nColPos] : rRowSorted[nRowPos];
                                 if ( nMyIndex >= 0 && nMyIndex < pSelectDim->GetMemberCount() )
                                 {
                                     const ScDPResultMember* pMyRefMember = pSelectDim->GetMember(nMyIndex);
@@ -2372,9 +2382,11 @@ void ScDPDataMember::UpdateRunningTotals( const ScDPResultMember* pRefMember,
                                                                         nColPos, rRunning );
                                     else
                                     {
-                                        long nSkip = nRowPos + 1;   // including the reference dimension
-                                        pSelectMember = pSelectDim->GetRowReferenceMember( NULL, NULL,
-                                                                        pRowIndexes+nSkip, pColIndexes );
+                                        const long* pRowSorted = &rRowSorted[0];
+                                        const long* pColSorted = &rColSorted[0];
+                                        pRowSorted += nRowPos + 1; // including the reference dimension
+                                        pSelectMember = pSelectDim->GetRowReferenceMember(
+                                            NULL, NULL, pRowSorted, pColSorted);
                                     }
 
                                     if ( pSelectMember )
@@ -2422,16 +2434,18 @@ void ScDPDataMember::UpdateRunningTotals( const ScDPResultMember* pRefMember,
                                     ScDPDataMember* pSelectMember;
                                     if ( bRefDimInCol )
                                     {
-                                        aRefItemPos.nBasePos = pColVisible[nColPos];    // without sort order applied
+                                        aRefItemPos.nBasePos = rColVisible[nColPos];    // without sort order applied
                                         pSelectMember = ScDPResultDimension::GetColReferenceMember( pRefPos, pRefName,
                                                                         nColPos, rRunning );
                                     }
                                     else
                                     {
-                                        aRefItemPos.nBasePos = pRowVisible[nRowPos];    // without sort order applied
-                                        long nSkip = nRowPos + 1;   // including the reference dimension
-                                        pSelectMember = pSelectDim->GetRowReferenceMember( pRefPos, pRefName,
-                                                                        pRowIndexes+nSkip, pColIndexes );
+                                        aRefItemPos.nBasePos = rRowVisible[nRowPos];    // without sort order applied
+                                        const long* pRowSorted = &rRowSorted[0];
+                                        const long* pColSorted = &rColSorted[0];
+                                        pRowSorted += nRowPos + 1; // including the reference dimension
+                                        pSelectMember = pSelectDim->GetRowReferenceMember(
+                                            pRefPos, pRefName, pRowSorted, pColSorted);
                                     }
 
                                     // difference or perc.difference is empty for the reference item itself
@@ -3266,8 +3280,8 @@ ScDPDataMember* ScDPResultDimension::GetColReferenceMember( const ScDPRelativePo
 {
     OSL_ENSURE( pRelativePos == NULL || pName == NULL, "can't use position and name" );
 
-    const long* pColIndexes = rRunning.GetColIndexes();
-    const long* pRowIndexes = rRunning.GetRowIndexes();
+    const long* pColIndexes = &rRunning.GetColSorted()[0];
+    const long* pRowIndexes = &rRunning.GetRowSorted()[0];
 
     // get own row member using all indexes
 
commit 55847a413430e1aaa2c9ec51e7836d4fed4ff03f
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Thu Jan 3 21:31:44 2013 -0500

    Remove hard-coded upper field limit from ScDPInitState.
    
    This was going to cause trouble sooner or later....
    
    Change-Id: I5eea2ba7b1cc4e358a0192b4863d79596549bad9

diff --git a/sc/inc/dptabres.hxx b/sc/inc/dptabres.hxx
index 81c3c01..97cb230 100644
--- a/sc/inc/dptabres.hxx
+++ b/sc/inc/dptabres.hxx
@@ -51,35 +51,36 @@ class ScDPResultVisibilityData;
 
 struct ScDPValueData;
 class ScDPItemData;
-//
-//  Member names that are being processed for InitFrom/LateInitFrom
-//  (needed for initialization of grouped items)
-//
 
+/**
+ * Member names that are being processed for InitFrom/LateInitFrom (needed
+ * for initialization of grouped items).
+ */
 class ScDPInitState
 {
-    long*           pIndex;     // array
-    SCROW*     pData; // array
-    long            nCount;
-
 public:
-            ScDPInitState();
-            ~ScDPInitState();
+    struct Member
+    {
+        long mnSrcIndex;
+        SCROW mnNameIndex;
+
+        Member(long nSrcIndex, SCROW nNameIndex);
+    };
+
+    void AddMember(long nSourceIndex, SCROW nMember);
+    void RemoveMember();
 
-    void    AddMember( long nSourceIndex,SCROW nMember);
-    void    RemoveMember();
+    const std::vector<Member>& GetMembers() const { return maMembers; }
 
-    long                GetCount() const    { return nCount; }
-    const long*         GetSource() const   { return pIndex; }
-    const SCROW* GetNameIds() const    { return pData; }
+private:
+    std::vector<Member> maMembers;
 };
 
 typedef ::std::vector<sal_Int32> ScMemberSortOrder;
 
-//
-//  selected subtotal information, passed down the dimensions
-//
-
+/**
+ * Select subtotal information, passed down the dimensions.
+ */
 struct ScDPSubTotalState
 {
     ScSubTotalFunc eColForce;
diff --git a/sc/source/core/data/dptabres.cxx b/sc/source/core/data/dptabres.cxx
index 01c256d..12a84de 100644
--- a/sc/source/core/data/dptabres.cxx
+++ b/sc/source/core/data/dptabres.cxx
@@ -222,41 +222,21 @@ sal_Bool ScDPColMembersOrder::operator()( sal_Int32 nIndex1, sal_Int32 nIndex2 )
     return lcl_IsLess( pDataMember1, pDataMember2, nMeasure, bAscending );
 }
 
-// -----------------------------------------------------------------------
-
-ScDPInitState::ScDPInitState() :
-    nCount( 0 )
-{
-    pIndex = new long[SC_DP_MAX_FIELDS];
-    pData = new SCROW[SC_DP_MAX_FIELDS];
-}
-
-ScDPInitState::~ScDPInitState()
-{
-    delete[] pIndex;
-    delete[] pData;
-}
+ScDPInitState::Member::Member(long nSrcIndex, SCROW nNameIndex) :
+    mnSrcIndex(nSrcIndex), mnNameIndex(nNameIndex) {}
 
 void ScDPInitState::AddMember( long nSourceIndex, SCROW nMember )
 {
-    OSL_ENSURE( nCount < SC_DP_MAX_FIELDS, "too many InitState members" );
-    if ( nCount < SC_DP_MAX_FIELDS )
-    {
-        pIndex[nCount] = nSourceIndex;
-        pData[nCount] = nMember;
-        ++nCount;
-    }
+    maMembers.push_back(Member(nSourceIndex, nMember));
 }
 
 void ScDPInitState::RemoveMember()
 {
-    OSL_ENSURE( nCount > 0, "RemoveColIndex without index" );
-    if ( nCount > 0 )
-        --nCount;
+    OSL_ENSURE(!maMembers.empty(), "ScDPInitState::RemoveMember: Attempt to remmove member while empty.");
+    if (!maMembers.empty())
+        maMembers.pop_back();
 }
 
-// -----------------------------------------------------------------------
-
 static void lcl_DumpRow( const String& rType, const String& rName, const ScDPAggData* pAggData,
                     ScDocument* pDoc, ScAddress& rPos )
 {
@@ -2649,16 +2629,15 @@ sal_Bool ScDPGroupCompare::TestIncluded( const ScDPMember& rMember )
         //! get array of groups (or indexes) before loop?
         ScDPItemData aMemberData;
         rMember.FillItemData( aMemberData );
-        long nInitCount = rInitState.GetCount();
-        const long* pInitSource = rInitState.GetSource();
-        const SCROW* pInitNames = rInitState.GetNameIds();
 
-        for (long nInitPos=0; nInitPos<nInitCount && bInclude; nInitPos++)
+        const std::vector<ScDPInitState::Member>& rMemStates = rInitState.GetMembers();
+        std::vector<ScDPInitState::Member>::const_iterator it = rMemStates.begin(), itEnd = rMemStates.end();
+        for (; it != itEnd && bInclude; ++it)
         {
-            if ( pResultData->GetGroupBase( pInitSource[nInitPos] ) == nDimSource )
+            if (pResultData->GetGroupBase(it->mnSrcIndex) == nDimSource)
             {
-                bInclude = pResultData->IsInGroup( pInitNames[nInitPos], pInitSource[nInitPos],
-                                                    aMemberData, nDimSource );
+                bInclude = pResultData->IsInGroup(
+                    it->mnNameIndex, it->mnSrcIndex, aMemberData, nDimSource);
             }
         }
     }
@@ -2670,17 +2649,18 @@ sal_Bool ScDPGroupCompare::TestIncluded( const ScDPMember& rMember )
         //! get array of groups (or indexes) before loop?
         ScDPItemData aMemberData;
         rMember.FillItemData( aMemberData );
-        long nInitCount = rInitState.GetCount();
-        const long* pInitSource = rInitState.GetSource();
-       /*const ScDPItemData* pInitNames = rInitState.GetNames();*/
-        const SCROW* pInitNames = rInitState.GetNameIds();
-        for (long nInitPos=0; nInitPos<nInitCount && bInclude; nInitPos++)
-            if ( pResultData->GetGroupBase( pInitSource[nInitPos] ) == nGroupBase )
+        const std::vector<ScDPInitState::Member>& rMemStates = rInitState.GetMembers();
+        std::vector<ScDPInitState::Member>::const_iterator it = rMemStates.begin(), itEnd = rMemStates.end();
+        for (; it != itEnd && bInclude; ++it)
+        {
+            if (pResultData->GetGroupBase(it->mnSrcIndex) == nGroupBase)
             {
                 // same base (hierarchy between the two groups is irrelevant)
-                bInclude = pResultData->HasCommonElement( pInitNames[nInitPos], pInitSource[nInitPos],
-                                                        aMemberData, nDimSource );
+                bInclude = pResultData->HasCommonElement(
+                    it->mnNameIndex, it->mnSrcIndex, aMemberData, nDimSource);
             }
+
+        }
     }
 
     return bInclude;


More information about the Libreoffice-commits mailing list