[Libreoffice-commits] core.git: sc/inc sc/source
Noel Grandin
noel.grandin at collabora.co.uk
Tue Jun 26 09:52:10 UTC 2018
sc/inc/global.hxx | 5 +-
sc/source/core/data/global2.cxx | 56 ++++++++---------------
sc/source/filter/xml/XMLConsolidationContext.cxx | 14 +----
sc/source/filter/xml/xmlexprt.cxx | 2
sc/source/ui/dbgui/consdlg.cxx | 15 +-----
sc/source/ui/docshell/docsh5.cxx | 22 ++++-----
sc/source/ui/unoobj/datauno.cxx | 26 ++++------
7 files changed, 53 insertions(+), 87 deletions(-)
New commits:
commit 364af18d7394c113dc8624c0c84de28c2747a927
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date: Fri Jun 22 13:17:26 2018 +0200
loplugin:useuniqueptr in ScConsolidateParam
Change-Id: I451315b844e759db3084220a1c889f47775189e3
Reviewed-on: https://gerrit.libreoffice.org/56331
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/sc/inc/global.hxx b/sc/inc/global.hxx
index bdef61bf5c39..4c658290cca8 100644
--- a/sc/inc/global.hxx
+++ b/sc/inc/global.hxx
@@ -34,6 +34,7 @@
// which confuses clang plugins.
#undef bool
#include <map>
+#include <memory>
class SfxItemSet;
class SfxViewShell;
@@ -887,7 +888,7 @@ struct ScConsolidateParam
SCTAB nTab;
ScSubTotalFunc eFunction;
sal_uInt16 nDataAreaCount; // number of data areas
- ScArea** ppDataAreas; // array of pointers into data areas
+ std::unique_ptr<ScArea[]> pDataAreas; // array of pointers into data areas
bool bByCol;
bool bByRow;
bool bReferenceData; // reference source data
@@ -900,7 +901,7 @@ struct ScConsolidateParam
bool operator== ( const ScConsolidateParam& r ) const;
void Clear (); // = ClearDataAreas()+Members
void ClearDataAreas ();
- void SetAreas ( ScArea* const* ppAreas, sal_uInt16 nCount );
+ void SetAreas ( std::unique_ptr<ScArea[]> pAreas, sal_uInt16 nCount );
};
extern SfxViewShell* pScActiveViewShell;
diff --git a/sc/source/core/data/global2.cxx b/sc/source/core/data/global2.cxx
index d75f64c1c57c..52b4b8aeb531 100644
--- a/sc/source/core/data/global2.cxx
+++ b/sc/source/core/data/global2.cxx
@@ -105,41 +105,23 @@ bool ScImportParam::operator==( const ScImportParam& rOther ) const
// struct ScConsolidateParam:
-ScConsolidateParam::ScConsolidateParam() :
- ppDataAreas( nullptr )
+ScConsolidateParam::ScConsolidateParam()
{
Clear();
}
-ScConsolidateParam::ScConsolidateParam( const ScConsolidateParam& r ) :
- nCol(r.nCol),nRow(r.nRow),nTab(r.nTab),
- eFunction(r.eFunction),nDataAreaCount(0),
- ppDataAreas( nullptr ),
- bByCol(r.bByCol),bByRow(r.bByRow),bReferenceData(r.bReferenceData)
+ScConsolidateParam::ScConsolidateParam( const ScConsolidateParam& r )
{
- if ( r.nDataAreaCount > 0 )
- {
- nDataAreaCount = r.nDataAreaCount;
- ppDataAreas = new ScArea*[nDataAreaCount];
- for ( sal_uInt16 i=0; i<nDataAreaCount; i++ )
- ppDataAreas[i] = new ScArea( *(r.ppDataAreas[i]) );
- }
+ operator=(r);
}
ScConsolidateParam::~ScConsolidateParam()
{
- ClearDataAreas();
}
void ScConsolidateParam::ClearDataAreas()
{
- if ( ppDataAreas )
- {
- for ( sal_uInt16 i=0; i<nDataAreaCount; i++ )
- delete ppDataAreas[i];
- delete [] ppDataAreas;
- ppDataAreas = nullptr;
- }
+ pDataAreas.reset();
nDataAreaCount = 0;
}
@@ -163,8 +145,16 @@ ScConsolidateParam& ScConsolidateParam::operator=( const ScConsolidateParam& r )
bByRow = r.bByRow;
bReferenceData = r.bReferenceData;
eFunction = r.eFunction;
- SetAreas( r.ppDataAreas, r.nDataAreaCount );
-
+ nDataAreaCount = r.nDataAreaCount;
+ if ( r.nDataAreaCount > 0 )
+ {
+ nDataAreaCount = r.nDataAreaCount;
+ pDataAreas.reset( new ScArea[nDataAreaCount] );
+ for ( sal_uInt16 i=0; i<nDataAreaCount; i++ )
+ pDataAreas[i] = r.pDataAreas[i];
+ }
+ else
+ pDataAreas.reset();
return *this;
}
@@ -180,27 +170,21 @@ bool ScConsolidateParam::operator==( const ScConsolidateParam& r ) const
&& (eFunction == r.eFunction);
if ( nDataAreaCount == 0 )
- bEqual = bEqual && (ppDataAreas == nullptr) && (r.ppDataAreas == nullptr);
+ bEqual = bEqual && (pDataAreas == nullptr) && (r.pDataAreas == nullptr);
else
- bEqual = bEqual && (ppDataAreas != nullptr) && (r.ppDataAreas != nullptr);
+ bEqual = bEqual && (pDataAreas != nullptr) && (r.pDataAreas != nullptr);
if ( bEqual && (nDataAreaCount > 0) )
for ( sal_uInt16 i=0; i<nDataAreaCount && bEqual; i++ )
- bEqual = *(ppDataAreas[i]) == *(r.ppDataAreas[i]);
+ bEqual = pDataAreas[i] == r.pDataAreas[i];
return bEqual;
}
-void ScConsolidateParam::SetAreas( ScArea* const* ppAreas, sal_uInt16 nCount )
+void ScConsolidateParam::SetAreas( std::unique_ptr<ScArea[]> pAreas, sal_uInt16 nCount )
{
- ClearDataAreas();
- if ( ppAreas && nCount > 0 )
- {
- ppDataAreas = new ScArea*[nCount];
- for ( sal_uInt16 i=0; i<nCount; i++ )
- ppDataAreas[i] = new ScArea( *(ppAreas[i]) );
- nDataAreaCount = nCount;
- }
+ pDataAreas = std::move(pAreas);
+ nDataAreaCount = nCount;
}
// struct ScSolveParam
diff --git a/sc/source/filter/xml/XMLConsolidationContext.cxx b/sc/source/filter/xml/XMLConsolidationContext.cxx
index f27b4b1508de..ba6525eabce3 100644
--- a/sc/source/filter/xml/XMLConsolidationContext.cxx
+++ b/sc/source/filter/xml/XMLConsolidationContext.cxx
@@ -84,27 +84,21 @@ void SAL_CALL ScXMLConsolidationContext::endFastElement( sal_Int32 /*nElement*/
pConsParam->eFunction = eFunction;
sal_uInt16 nCount = static_cast<sal_uInt16>(std::min( ScRangeStringConverter::GetTokenCount( sSourceList ), sal_Int32(0xFFFF) ));
- ScArea** ppAreas = nCount ? new ScArea*[ nCount ] : nullptr;
- if( ppAreas )
+ if( nCount )
{
+ std::unique_ptr<ScArea[]> ppAreas(new ScArea[ nCount ]);
sal_Int32 nOffset = 0;
sal_uInt16 nIndex;
for( nIndex = 0; nIndex < nCount; ++nIndex )
{
- ppAreas[ nIndex ] = new ScArea;
if ( !ScRangeStringConverter::GetAreaFromString(
- *ppAreas[ nIndex ], sSourceList, GetScImport().GetDocument(), ::formula::FormulaGrammar::CONV_OOO, nOffset ) )
+ ppAreas[ nIndex ], sSourceList, GetScImport().GetDocument(), ::formula::FormulaGrammar::CONV_OOO, nOffset ) )
{
//! handle error
}
}
- pConsParam->SetAreas( ppAreas, nCount );
-
- // array is copied in SetAreas
- for( nIndex = 0; nIndex < nCount; ++nIndex )
- delete ppAreas[nIndex];
- delete[] ppAreas;
+ pConsParam->SetAreas( std::move(ppAreas), nCount );
}
pConsParam->bByCol = pConsParam->bByRow = false;
diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx
index ec0833019240..6e5c2b49bbe7 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -4783,7 +4783,7 @@ void ScXMLExport::WriteConsolidation()
sStrData.clear();
for( sal_Int32 nIndex = 0; nIndex < pCons->nDataAreaCount; ++nIndex )
- ScRangeStringConverter::GetStringFromArea( sStrData, *pCons->ppDataAreas[ nIndex ], pDoc, FormulaGrammar::CONV_OOO, ' ', true );
+ ScRangeStringConverter::GetStringFromArea( sStrData, pCons->pDataAreas[ nIndex ], pDoc, FormulaGrammar::CONV_OOO, ' ', true );
AddAttribute( XML_NAMESPACE_TABLE, XML_SOURCE_CELL_RANGE_ADDRESSES, sStrData );
ScRangeStringConverter::GetStringFromAddress( sStrData, ScAddress( pCons->nCol, pCons->nRow, pCons->nTab ), pDoc, FormulaGrammar::CONV_OOO );
diff --git a/sc/source/ui/dbgui/consdlg.cxx b/sc/source/ui/dbgui/consdlg.cxx
index 7fadd6c22bd0..dc3338ddd5ab 100644
--- a/sc/source/ui/dbgui/consdlg.cxx
+++ b/sc/source/ui/dbgui/consdlg.cxx
@@ -184,7 +184,7 @@ void ScConsolidateDlg::Init()
const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
for ( i=0; i<theConsData.nDataAreaCount; i++ )
{
- const ScArea& rArea = *(theConsData.ppDataAreas[i] );
+ const ScArea& rArea = theConsData.pDataAreas[i];
if ( rArea.nTab < pDoc->GetTableCount() )
{
aStr = ScRange( rArea.nColStart, rArea.nRowStart, rArea.nTab,
@@ -381,15 +381,12 @@ IMPL_LINK_NOARG(ScConsolidateDlg, OkHdl, Button*, void)
if ( ScRangeUtil::IsAbsPos( aDestPosStr, pDoc, nTab, nullptr, &aDestAddress, eConv ) )
{
ScConsolidateParam theOutParam( theConsData );
- ScArea** ppDataAreas = new ScArea*[nDataAreaCount];
- ScArea* pArea;
+ std::unique_ptr<ScArea[]> pDataAreas(new ScArea[nDataAreaCount]);
for ( sal_Int32 i=0; i<nDataAreaCount; ++i )
{
- pArea = new ScArea;
ScRangeUtil::MakeArea( pLbConsAreas->GetEntry( i ),
- *pArea, pDoc, nTab, eConv );
- ppDataAreas[i] = pArea;
+ pDataAreas[i], pDoc, nTab, eConv );
}
theOutParam.nCol = aDestAddress.Col();
@@ -399,11 +396,7 @@ IMPL_LINK_NOARG(ScConsolidateDlg, OkHdl, Button*, void)
theOutParam.bByCol = pBtnByCol->IsChecked();
theOutParam.bByRow = pBtnByRow->IsChecked();
theOutParam.bReferenceData = pBtnRefs->IsChecked();
- theOutParam.SetAreas( ppDataAreas, nDataAreaCount );
-
- for ( sal_Int32 i=0; i<nDataAreaCount; ++i )
- delete ppDataAreas[i];
- delete [] ppDataAreas;
+ theOutParam.SetAreas( std::move(pDataAreas), nDataAreaCount );
ScConsolidateItem aOutItem( nWhichCons, &theOutParam );
diff --git a/sc/source/ui/docshell/docsh5.cxx b/sc/source/ui/docshell/docsh5.cxx
index 2b43c4de1dfe..feb168a74a07 100644
--- a/sc/source/ui/docshell/docsh5.cxx
+++ b/sc/source/ui/docshell/docsh5.cxx
@@ -511,13 +511,13 @@ void ScDocShell::DoConsolidate( const ScConsolidateParam& rParam, bool bRecord )
bool bErr = false;
for (nPos=0; nPos<rParam.nDataAreaCount; nPos++)
{
- ScArea* pArea = rParam.ppDataAreas[nPos];
- nColSize = std::max( nColSize, SCCOL( pArea->nColEnd - pArea->nColStart + 1 ) );
- nRowSize = std::max( nRowSize, SCROW( pArea->nRowEnd - pArea->nRowStart + 1 ) );
+ ScArea const & rArea = rParam.pDataAreas[nPos];
+ nColSize = std::max( nColSize, SCCOL( rArea.nColEnd - rArea.nColStart + 1 ) );
+ nRowSize = std::max( nRowSize, SCROW( rArea.nRowEnd - rArea.nRowStart + 1 ) );
// test if source data were moved
if (rParam.bReferenceData)
- if (pArea->nTab == rParam.nTab && pArea->nRowEnd >= rParam.nRow)
+ if (rArea.nTab == rParam.nTab && rArea.nRowEnd >= rParam.nRow)
bErr = true;
}
@@ -546,17 +546,17 @@ void ScDocShell::DoConsolidate( const ScConsolidateParam& rParam, bool bRecord )
if ( rParam.bByCol || rParam.bByRow )
for (nPos=0; nPos<rParam.nDataAreaCount; nPos++)
{
- ScArea* pArea = rParam.ppDataAreas[nPos];
- aData.AddFields( &m_aDocument, pArea->nTab, pArea->nColStart, pArea->nRowStart,
- pArea->nColEnd, pArea->nRowEnd );
+ ScArea const & rArea = rParam.pDataAreas[nPos];
+ aData.AddFields( &m_aDocument, rArea.nTab, rArea.nColStart, rArea.nRowStart,
+ rArea.nColEnd, rArea.nRowEnd );
}
aData.DoneFields();
for (nPos=0; nPos<rParam.nDataAreaCount; nPos++)
{
- ScArea* pArea = rParam.ppDataAreas[nPos];
- aData.AddData( &m_aDocument, pArea->nTab, pArea->nColStart, pArea->nRowStart,
- pArea->nColEnd, pArea->nRowEnd );
- aData.AddName( lcl_GetAreaName(&m_aDocument,pArea) );
+ ScArea const & rArea = rParam.pDataAreas[nPos];
+ aData.AddData( &m_aDocument, rArea.nTab, rArea.nColStart, rArea.nRowStart,
+ rArea.nColEnd, rArea.nRowEnd );
+ aData.AddName( lcl_GetAreaName(&m_aDocument, &rArea) );
}
aData.GetSize( nColSize, nRowSize );
diff --git a/sc/source/ui/unoobj/datauno.cxx b/sc/source/ui/unoobj/datauno.cxx
index d67d0595521e..8bbc68bbdb83 100644
--- a/sc/source/ui/unoobj/datauno.cxx
+++ b/sc/source/ui/unoobj/datauno.cxx
@@ -843,22 +843,19 @@ uno::Sequence<table::CellRangeAddress> SAL_CALL ScConsolidationDescriptor::getSo
{
SolarMutexGuard aGuard;
sal_uInt16 nCount = aParam.nDataAreaCount;
- if (!aParam.ppDataAreas)
+ if (!aParam.pDataAreas)
nCount = 0;
table::CellRangeAddress aRange;
uno::Sequence<table::CellRangeAddress> aSeq(nCount);
table::CellRangeAddress* pAry = aSeq.getArray();
for (sal_uInt16 i=0; i<nCount; i++)
{
- ScArea* pArea = aParam.ppDataAreas[i];
- if (pArea)
- {
- aRange.Sheet = pArea->nTab;
- aRange.StartColumn = pArea->nColStart;
- aRange.StartRow = pArea->nRowStart;
- aRange.EndColumn = pArea->nColEnd;
- aRange.EndRow = pArea->nRowEnd;
- }
+ ScArea const & rArea = aParam.pDataAreas[i];
+ aRange.Sheet = rArea.nTab;
+ aRange.StartColumn = rArea.nColStart;
+ aRange.StartRow = rArea.nRowStart;
+ aRange.EndColumn = rArea.nColEnd;
+ aRange.EndRow = rArea.nRowEnd;
pAry[i] = aRange;
}
return aSeq;
@@ -872,17 +869,14 @@ void SAL_CALL ScConsolidationDescriptor::setSources(
if (nCount)
{
const table::CellRangeAddress* pAry = aSources.getConstArray();
- std::unique_ptr<ScArea*[]> pNew(new ScArea*[nCount]);
+ std::unique_ptr<ScArea[]> pNew(new ScArea[nCount]);
sal_uInt16 i;
for (i=0; i<nCount; i++)
- pNew[i] = new ScArea( pAry[i].Sheet,
+ pNew[i] = ScArea( pAry[i].Sheet,
static_cast<SCCOL>(pAry[i].StartColumn), pAry[i].StartRow,
static_cast<SCCOL>(pAry[i].EndColumn), pAry[i].EndRow );
- aParam.SetAreas( pNew.get(), nCount ); // copy everything
-
- for (i=0; i<nCount; i++)
- delete pNew[i];
+ aParam.SetAreas( std::move(pNew), nCount ); // copy everything
}
else
aParam.ClearDataAreas();
More information about the Libreoffice-commits
mailing list