[Libreoffice-commits] core.git: sc/inc sc/source

Noel Grandin noel.grandin at collabora.co.uk
Tue Jan 17 06:50:14 UTC 2017


 sc/inc/dpsave.hxx                  |    9 +++----
 sc/source/core/data/dpobject.cxx   |    8 +++---
 sc/source/core/data/dpsave.cxx     |   47 ++++---------------------------------
 sc/source/filter/excel/xipivot.cxx |    2 -
 sc/source/filter/xml/xmldpimp.cxx  |   24 ++----------------
 sc/source/filter/xml/xmldpimp.hxx  |    7 ++---
 sc/source/ui/unoobj/dapiuno.cxx    |   23 +++++++-----------
 7 files changed, 30 insertions(+), 90 deletions(-)

New commits:
commit 998f635fb4caeaf3b9f010d6bb6da023569c5791
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Tue Jan 17 08:49:15 2017 +0200

    convert subtotalfuncs from manual array to std::vector
    
    Change-Id: I6af7e8c8d001c92edd364aa32224da1e4e1d1d9b

diff --git a/sc/inc/dpsave.hxx b/sc/inc/dpsave.hxx
index 8338e0e..db5b8ac 100644
--- a/sc/inc/dpsave.hxx
+++ b/sc/inc/dpsave.hxx
@@ -103,8 +103,7 @@ private:
     sal_uInt16 nShowEmptyMode; //! at level
     bool bRepeatItemLabels; //! at level
     bool bSubTotalDefault; //! at level
-    long nSubTotalCount;
-    sal_uInt16* pSubTotalFuncs; // GeneralFunction2
+    std::vector<sal_uInt16> maSubTotalFuncs; // GeneralFunction2
     css::sheet::DataPilotFieldReference* pReferenceValue;
     css::sheet::DataPilotFieldSortInfo* pSortInfo; // (level)
     css::sheet::DataPilotFieldAutoShowInfo* pAutoShowInfo; // (level)
@@ -146,12 +145,12 @@ public:
     void SetName( const OUString& rNew ); // used if the source dim was renamed (groups)
 
     void SetOrientation(sal_uInt16 nNew);
-    void SetSubTotals(long nCount, const sal_uInt16* pFuncs);
+    void SetSubTotals(std::vector<sal_uInt16> const & rFuncs);
     long GetSubTotalsCount() const
-        { return nSubTotalCount; }
+        { return maSubTotalFuncs.size(); }
 
     sal_uInt16 GetSubTotalFunc(long nIndex) const
-        { return pSubTotalFuncs[nIndex]; }
+        { return maSubTotalFuncs[nIndex]; }
 
     bool HasShowEmpty() const;
     void SetShowEmpty(bool bSet);
diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index ab220f1..26b4177 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -2698,16 +2698,16 @@ void ScDPObject::ConvertOrientation(
         {
             pDim->SetOrientation( nOrient );
 
-            sal_uInt16 nFuncArray[16];
-            sal_uInt16 nFuncCount = 0;
+            std::vector<sal_uInt16> nSubTotalFuncs;
+            nSubTotalFuncs.reserve(16);
             sal_uInt16 nMask = 1;
             for (sal_uInt16 nBit=0; nBit<16; nBit++)
             {
                 if ( nFuncs & (PivotFunc)nMask )
-                    nFuncArray[nFuncCount++] = sal::static_int_cast<sal_uInt16>(ScDataPilotConversion::FirstFunc( (PivotFunc)nMask ));
+                    nSubTotalFuncs.push_back( sal::static_int_cast<sal_uInt16>(ScDataPilotConversion::FirstFunc( (PivotFunc)nMask )) );
                 nMask *= 2;
             }
-            pDim->SetSubTotals( nFuncCount, nFuncArray );
+            pDim->SetSubTotals( nSubTotalFuncs );
 
             //  ShowEmpty was implicit in old tables,
             //  must be set for data layout dimension (not accessible in dialog)
diff --git a/sc/source/core/data/dpsave.cxx b/sc/source/core/data/dpsave.cxx
index 2e7102d..1a77c81 100644
--- a/sc/source/core/data/dpsave.cxx
+++ b/sc/source/core/data/dpsave.cxx
@@ -31,6 +31,7 @@
 #include <o3tl/make_unique.hxx>
 #include <comphelper/string.hxx>
 #include <comphelper/stl_types.hxx>
+#include <comphelper/sequence.hxx>
 
 #include <com/sun/star/sheet/GeneralFunction.hpp>
 #include <com/sun/star/sheet/GeneralFunction2.hpp>
@@ -200,8 +201,6 @@ ScDPSaveDimension::ScDPSaveDimension(const OUString& rName, bool bDataLayout) :
     nShowEmptyMode( SC_DPSAVEMODE_DONTKNOW ),
     bRepeatItemLabels( false ),
     bSubTotalDefault( true ),
-    nSubTotalCount( 0 ),
-    pSubTotalFuncs( nullptr ),
     pReferenceValue( nullptr ),
     pSortInfo( nullptr ),
     pAutoShowInfo( nullptr ),
@@ -221,16 +220,8 @@ ScDPSaveDimension::ScDPSaveDimension(const ScDPSaveDimension& r) :
     nShowEmptyMode( r.nShowEmptyMode ),
     bRepeatItemLabels( r.bRepeatItemLabels ),
     bSubTotalDefault( r.bSubTotalDefault ),
-    nSubTotalCount( r.nSubTotalCount ),
-    pSubTotalFuncs( nullptr )
+    maSubTotalFuncs( r.maSubTotalFuncs )
 {
-    if ( nSubTotalCount && r.pSubTotalFuncs )
-    {
-        pSubTotalFuncs = new sal_uInt16[nSubTotalCount];
-        for (long nSub=0; nSub<nSubTotalCount; nSub++)
-            pSubTotalFuncs[nSub] = r.pSubTotalFuncs[nSub];
-    }
-
     for (MemberList::const_iterator i=r.maMemberList.begin(); i != r.maMemberList.end() ; ++i)
     {
         const OUString& rName =  (*i)->GetName();
@@ -268,7 +259,6 @@ ScDPSaveDimension::~ScDPSaveDimension()
     delete pSortInfo;
     delete pAutoShowInfo;
     delete pLayoutInfo;
-    delete [] pSubTotalFuncs;
 }
 
 bool ScDPSaveDimension::operator== ( const ScDPSaveDimension& r ) const
@@ -282,17 +272,9 @@ bool ScDPSaveDimension::operator== ( const ScDPSaveDimension& r ) const
          nShowEmptyMode   != r.nShowEmptyMode   ||
          bRepeatItemLabels!= r.bRepeatItemLabels||
          bSubTotalDefault != r.bSubTotalDefault ||
-         nSubTotalCount   != r.nSubTotalCount    )
+         maSubTotalFuncs  != r.maSubTotalFuncs   )
         return false;
 
-    if ( nSubTotalCount && ( !pSubTotalFuncs || !r.pSubTotalFuncs ) ) // should not happen
-        return false;
-
-    long i;
-    for (i=0; i<nSubTotalCount; i++)
-        if ( pSubTotalFuncs[i] != r.pSubTotalFuncs[i] )
-            return false;
-
     if (maMemberHash.size() != r.maMemberHash.size() )
         return false;
 
@@ -370,20 +352,9 @@ void ScDPSaveDimension::SetOrientation(sal_uInt16 nNew)
     nOrientation = nNew;
 }
 
-void ScDPSaveDimension::SetSubTotals(long nCount, const sal_uInt16* pFuncs)
+void ScDPSaveDimension::SetSubTotals(std::vector<sal_uInt16> const & rFuncs)
 {
-    if (pSubTotalFuncs)
-        delete [] pSubTotalFuncs;
-    nSubTotalCount = nCount;
-    if ( nCount && pFuncs )
-    {
-        pSubTotalFuncs = new sal_uInt16[nCount];
-        for (long i=0; i<nCount; i++)
-            pSubTotalFuncs[i] = pFuncs[i];
-    }
-    else
-        pSubTotalFuncs = nullptr;
-
+    maSubTotalFuncs = rFuncs;
     bSubTotalDefault = false;
 }
 
@@ -627,13 +598,7 @@ void ScDPSaveDimension::WriteToSource( const uno::Reference<uno::XInterface>& xD
             {
                 if ( !bSubTotalDefault )
                 {
-                    if ( !pSubTotalFuncs )
-                        nSubTotalCount = 0;
-
-                    uno::Sequence<sal_Int16> aSeq(nSubTotalCount);
-                    sal_Int16* pArray = aSeq.getArray();
-                    for (long i=0; i<nSubTotalCount; i++)
-                        pArray[i] = static_cast<sal_Int16>(pSubTotalFuncs[i]);
+                    uno::Sequence<sal_Int16> aSeq(comphelper::containerToSequence<sal_Int16>(maSubTotalFuncs));
                     xLevProp->setPropertyValue( SC_UNO_DP_SUBTOTAL2, uno::Any(aSeq) );
                 }
                 if ( nShowEmptyMode != SC_DPSAVEMODE_DONTKNOW )
diff --git a/sc/source/filter/excel/xipivot.cxx b/sc/source/filter/excel/xipivot.cxx
index 4e40fa2..9888e08 100644
--- a/sc/source/filter/excel/xipivot.cxx
+++ b/sc/source/filter/excel/xipivot.cxx
@@ -1092,7 +1092,7 @@ ScDPSaveDimension* XclImpPTField::ConvertRCPField( ScDPSaveData& rSaveData ) con
     XclPTSubtotalVec aSubtotalVec;
     maFieldInfo.GetSubtotals( aSubtotalVec );
     if( !aSubtotalVec.empty() )
-        rSaveDim.SetSubTotals( static_cast< long >( aSubtotalVec.size() ), &aSubtotalVec[ 0 ] );
+        rSaveDim.SetSubTotals( aSubtotalVec );
 
     // sorting
     DataPilotFieldSortInfo aSortInfo;
diff --git a/sc/source/filter/xml/xmldpimp.cxx b/sc/source/filter/xml/xmldpimp.cxx
index cc39b95..fda3597 100644
--- a/sc/source/filter/xml/xmldpimp.cxx
+++ b/sc/source/filter/xml/xmldpimp.cxx
@@ -1435,9 +1435,7 @@ ScXMLDataPilotSubTotalsContext::ScXMLDataPilotSubTotalsContext( ScXMLImport& rIm
                                       const css::uno::Reference<css::xml::sax::XAttributeList>& /* xAttrList */,
                                       ScXMLDataPilotFieldContext* pTempDataPilotField) :
     ScXMLImportContext( rImport, nPrfx, rLName ),
-    pDataPilotField(pTempDataPilotField),
-    nFunctionCount(0),
-    pFunctions(nullptr)
+    pDataPilotField(pTempDataPilotField)
 {
 
     // has no attributes
@@ -1445,7 +1443,6 @@ ScXMLDataPilotSubTotalsContext::ScXMLDataPilotSubTotalsContext( ScXMLImport& rIm
 
 ScXMLDataPilotSubTotalsContext::~ScXMLDataPilotSubTotalsContext()
 {
-    delete[] pFunctions;
 }
 
 SvXMLImportContext *ScXMLDataPilotSubTotalsContext::CreateChildContext( sal_uInt16 nPrefix,
@@ -1470,29 +1467,14 @@ SvXMLImportContext *ScXMLDataPilotSubTotalsContext::CreateChildContext( sal_uInt
 
 void ScXMLDataPilotSubTotalsContext::EndElement()
 {
-    pDataPilotField->SetSubTotals(pFunctions, nFunctionCount);
+    pDataPilotField->SetSubTotals(maFunctions);
     if (!maDisplayName.isEmpty())
         pDataPilotField->SetSubTotalName(maDisplayName);
 }
 
 void ScXMLDataPilotSubTotalsContext::AddFunction(sal_Int16 nFunction)
 {
-    if (nFunctionCount)
-    {
-        ++nFunctionCount;
-        sal_uInt16* pTemp = new sal_uInt16[nFunctionCount];
-        for (sal_Int16 i = 0; i < nFunctionCount - 1; ++i)
-            pTemp[i] = pFunctions[i];
-        pTemp[nFunctionCount - 1] = nFunction;
-        delete[] pFunctions;
-        pFunctions = pTemp;
-    }
-    else
-    {
-        nFunctionCount = 1;
-        pFunctions = new sal_uInt16[nFunctionCount];
-        pFunctions[0] = nFunction;
-    }
+    maFunctions.push_back(nFunction);
 }
 
 void ScXMLDataPilotSubTotalsContext::SetDisplayName(const OUString& rName)
diff --git a/sc/source/filter/xml/xmldpimp.hxx b/sc/source/filter/xml/xmldpimp.hxx
index d67e730..6749b1d 100644
--- a/sc/source/filter/xml/xmldpimp.hxx
+++ b/sc/source/filter/xml/xmldpimp.hxx
@@ -318,7 +318,7 @@ public:
 
     void SetShowEmpty(const bool bValue) { if (xDim) xDim->SetShowEmpty(bValue); }
     void SetRepeatItemLabels(const bool bSet) { if (xDim) xDim->SetRepeatItemLabels(bSet); }
-    void SetSubTotals(const sal_uInt16* pFunctions, const sal_Int16 nCount) { if (xDim) xDim->SetSubTotals(nCount, pFunctions); }
+    void SetSubTotals(std::vector<sal_uInt16> const & rFunctions) { if (xDim) xDim->SetSubTotals(rFunctions); }
     void AddMember(ScDPSaveMember* pMember);
     void SetSubTotalName(const OUString& rName);
     void SetFieldReference(const css::sheet::DataPilotFieldReference& aRef) { if (xDim) xDim->SetReferenceValue(&aRef); }
@@ -413,9 +413,8 @@ class ScXMLDataPilotSubTotalsContext : public ScXMLImportContext
 {
     ScXMLDataPilotFieldContext* pDataPilotField;
 
-    sal_Int16   nFunctionCount;
-    sal_uInt16* pFunctions;
-    OUString    maDisplayName;
+    std::vector<sal_uInt16>      maFunctions;
+    OUString                     maDisplayName;
 
 public:
     ScXMLDataPilotSubTotalsContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
diff --git a/sc/source/ui/unoobj/dapiuno.cxx b/sc/source/ui/unoobj/dapiuno.cxx
index 8166bb5..9d2af2a 100644
--- a/sc/source/ui/unoobj/dapiuno.cxx
+++ b/sc/source/ui/unoobj/dapiuno.cxx
@@ -2173,13 +2173,12 @@ void ScDataPilotFieldObj::setFunction(sal_Int16 eNewFunc)
         if( pDim->GetOrientation() != DataPilotFieldOrientation_DATA )
         {
             // for non-data fields, property Function is the subtotals
-            if ( eNewFunc == GeneralFunction2::NONE )
-                pDim->SetSubTotals( 0, nullptr );
-            else
+            std::vector<sal_uInt16> nSubTotalFuncs;
+            if ( eNewFunc != GeneralFunction2::NONE )
             {
-                sal_uInt16 nFunc = sal::static_int_cast<sal_uInt16>( eNewFunc );
-                pDim->SetSubTotals( 1, &nFunc );
+                nSubTotalFuncs.push_back( sal::static_int_cast<sal_uInt16>( eNewFunc ) );
             }
+            pDim->SetSubTotals( nSubTotalFuncs );
         }
         else
             pDim->SetFunction( sal::static_int_cast<sal_uInt16>( eNewFunc ) );
@@ -2220,13 +2219,12 @@ void ScDataPilotFieldObj::setSubtotals( const Sequence< sal_Int16 >& rSubtotals
             if( nCount == 1 )
             {
                 // count 1: all values are allowed (including NONE and AUTO)
-                if( rSubtotals[ 0 ] == GeneralFunction2::NONE )
-                    pDim->SetSubTotals( 0, nullptr );
-                else
+                std::vector<sal_uInt16> nTmpFuncs;
+                if( rSubtotals[ 0 ] != GeneralFunction2::NONE )
                 {
-                    sal_uInt16 nFunc = sal::static_int_cast<sal_uInt16>( rSubtotals[ 0 ] );
-                    pDim->SetSubTotals( 1, &nFunc );
+                    nTmpFuncs.push_back( sal::static_int_cast<sal_uInt16>( rSubtotals[ 0 ] ) );
                 }
+                pDim->SetSubTotals( nTmpFuncs );
             }
             else if( nCount > 1 )
             {
@@ -2244,10 +2242,7 @@ void ScDataPilotFieldObj::setSubtotals( const Sequence< sal_Int16 >& rSubtotals
                     }
                 }
                 // set values from vector to ScDPSaveDimension
-                if ( aSubt.empty() )
-                    pDim->SetSubTotals( 0, nullptr );
-                else
-                    pDim->SetSubTotals( static_cast< long >( aSubt.size() ), &aSubt.front() );
+                pDim->SetSubTotals( aSubt );
             }
         }
         SetDPObject( pDPObj );


More information about the Libreoffice-commits mailing list