summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2019-01-15 09:09:22 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2019-01-16 11:05:47 +0100
commitd08425c14b29bbac9f33c234f89b451388cd1d7c (patch)
treefa441dcaa912692c2e10f6189337446147400bfd
parent4c9caae6c8ab608688a68be2c81bde2dd40315b7 (diff)
use unique_ptr in sc
Change-Id: If64b50919002f1f7376602f6e9cfb24e2184263b Reviewed-on: https://gerrit.libreoffice.org/66417 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--sc/source/filter/excel/tokstack.cxx15
-rw-r--r--sc/source/ui/docshell/dbdocfun.cxx6
-rw-r--r--sc/source/ui/docshell/docfunc.cxx14
-rw-r--r--sc/source/ui/docshell/docsh3.cxx12
-rw-r--r--sc/source/ui/unoobj/cellsuno.cxx65
-rw-r--r--sc/source/ui/view/formatsh.cxx6
-rw-r--r--sc/source/ui/view/preview.cxx7
-rw-r--r--sc/source/ui/view/viewfun3.cxx18
8 files changed, 66 insertions, 77 deletions
diff --git a/sc/source/filter/excel/tokstack.cxx b/sc/source/filter/excel/tokstack.cxx
index a2991daf4692..f734e3168a18 100644
--- a/sc/source/filter/excel/tokstack.cxx
+++ b/sc/source/filter/excel/tokstack.cxx
@@ -125,14 +125,11 @@ bool TokenPool::GrowElement()
if (!nElementNew)
return false;
- sal_uInt16* pElementNew = new (::std::nothrow) sal_uInt16[ nElementNew ];
- E_TYPE* pTypeNew = new (::std::nothrow) E_TYPE[ nElementNew ];
- sal_uInt16* pSizeNew = new (::std::nothrow) sal_uInt16[ nElementNew ];
+ std::unique_ptr<sal_uInt16[]> pElementNew(new (::std::nothrow) sal_uInt16[ nElementNew ]);
+ std::unique_ptr<E_TYPE[]> pTypeNew(new (::std::nothrow) E_TYPE[ nElementNew ]);
+ std::unique_ptr<sal_uInt16[]> pSizeNew(new (::std::nothrow) sal_uInt16[ nElementNew ]);
if (!pElementNew || !pTypeNew || !pSizeNew)
{
- delete [] pElementNew;
- delete [] pTypeNew;
- delete [] pSizeNew;
return false;
}
@@ -145,9 +142,9 @@ bool TokenPool::GrowElement()
nElement = nElementNew;
- pElement.reset( pElementNew );
- pType.reset( pTypeNew );
- pSize.reset( pSizeNew );
+ pElement = std::move( pElementNew );
+ pType = std::move( pTypeNew );
+ pSize = std::move( pSizeNew );
return true;
}
diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx
index 8a7896a71024..a3c1474766bf 100644
--- a/sc/source/ui/docshell/dbdocfun.cxx
+++ b/sc/source/ui/docshell/dbdocfun.cxx
@@ -782,7 +782,7 @@ bool ScDBDocFunc::Query( SCTAB nTab, const ScQueryParam& rQueryParam,
rDoc.BeginDrawUndo();
}
- ScDocument* pAttribDoc = nullptr;
+ std::unique_ptr<ScDocument> pAttribDoc;
ScRange aAttribRange;
if (pDestData) // delete destination range
{
@@ -798,7 +798,7 @@ bool ScDBDocFunc::Query( SCTAB nTab, const ScQueryParam& rQueryParam,
// also for filled-in formulas
aAttribRange.aEnd.SetCol( aAttribRange.aEnd.Col() + nFormulaCols );
- pAttribDoc = new ScDocument( SCDOCMODE_UNDO );
+ pAttribDoc.reset(new ScDocument( SCDOCMODE_UNDO ));
pAttribDoc->InitUndo( &rDoc, nDestTab, nDestTab, false, true );
rDoc.CopyToDocument(aAttribRange, InsertDeleteFlags::ATTRIB, false, *pAttribDoc);
}
@@ -882,8 +882,6 @@ bool ScDBDocFunc::Query( SCTAB nTab, const ScQueryParam& rQueryParam,
nDestTab, *pStyle );
}
}
-
- delete pAttribDoc;
}
}
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index 8f8d642190e5..a3255535443f 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -2457,7 +2457,7 @@ bool ScDocFunc::DeleteCells( const ScRange& rRange, const ScMarkData* pTabMark,
WaitObject aWait( ScDocShell::GetActiveDialogParent() ); // important because of TrackFormulas in UpdateReference
ScDocumentUniquePtr pUndoDoc;
- ScDocument* pRefUndoDoc = nullptr;
+ std::unique_ptr<ScDocument> pRefUndoDoc;
std::unique_ptr<ScRefUndoData> pUndoData;
if ( bRecord )
{
@@ -2480,7 +2480,7 @@ bool ScDocFunc::DeleteCells( const ScRange& rRange, const ScMarkData* pTabMark,
InsertDeleteFlags::ALL | InsertDeleteFlags::NOCAPTIONS, false, *pUndoDoc );
}
- pRefUndoDoc = new ScDocument( SCDOCMODE_UNDO );
+ pRefUndoDoc.reset(new ScDocument( SCDOCMODE_UNDO ));
pRefUndoDoc->InitUndo( &rDoc, 0, nTabCount-1 );
pUndoData.reset(new ScRefUndoData( &rDoc ));
@@ -2501,22 +2501,22 @@ bool ScDocFunc::DeleteCells( const ScRange& rRange, const ScMarkData* pTabMark,
switch (eCmd)
{
case DelCellCmd::CellsUp:
- rDoc.DeleteRow( nStartCol, 0, nEndCol, MAXTAB, nStartRow, static_cast<SCSIZE>(nEndRow-nStartRow+1), pRefUndoDoc, nullptr, &aFullMark );
+ rDoc.DeleteRow( nStartCol, 0, nEndCol, MAXTAB, nStartRow, static_cast<SCSIZE>(nEndRow-nStartRow+1), pRefUndoDoc.get(), nullptr, &aFullMark );
nPaintEndRow = MAXROW;
break;
case DelCellCmd::Rows:
- rDoc.DeleteRow( 0, 0, MAXCOL, MAXTAB, nStartRow, static_cast<SCSIZE>(nEndRow-nStartRow+1), pRefUndoDoc, &bUndoOutline, &aFullMark );
+ rDoc.DeleteRow( 0, 0, MAXCOL, MAXTAB, nStartRow, static_cast<SCSIZE>(nEndRow-nStartRow+1), pRefUndoDoc.get(), &bUndoOutline, &aFullMark );
nPaintStartCol = 0;
nPaintEndCol = MAXCOL;
nPaintEndRow = MAXROW;
nPaintFlags |= PaintPartFlags::Left;
break;
case DelCellCmd::CellsLeft:
- rDoc.DeleteCol( nStartRow, 0, nEndRow, MAXTAB, nStartCol, static_cast<SCSIZE>(nEndCol-nStartCol+1), pRefUndoDoc, nullptr, &aFullMark );
+ rDoc.DeleteCol( nStartRow, 0, nEndRow, MAXTAB, nStartCol, static_cast<SCSIZE>(nEndCol-nStartCol+1), pRefUndoDoc.get(), nullptr, &aFullMark );
nPaintEndCol = MAXCOL;
break;
case DelCellCmd::Cols:
- rDoc.DeleteCol( 0, 0, MAXROW, MAXTAB, nStartCol, static_cast<SCSIZE>(nEndCol-nStartCol+1), pRefUndoDoc, &bUndoOutline, &aFullMark );
+ rDoc.DeleteCol( 0, 0, MAXROW, MAXTAB, nStartCol, static_cast<SCSIZE>(nEndCol-nStartCol+1), pRefUndoDoc.get(), &bUndoOutline, &aFullMark );
nPaintStartRow = 0;
nPaintEndRow = MAXROW;
nPaintEndCol = MAXCOL;
@@ -2544,7 +2544,7 @@ bool ScDocFunc::DeleteCells( const ScRange& rRange, const ScMarkData* pTabMark,
// copy with bColRowFlags=false (#54194#)
pRefUndoDoc->CopyToDocument(0,0,0,MAXCOL,MAXROW,MAXTAB,InsertDeleteFlags::FORMULA,false,*pUndoDoc,nullptr,false);
- delete pRefUndoDoc;
+ pRefUndoDoc.reset();
std::unique_ptr<SCTAB[]> pTabs( new SCTAB[nSelCount]);
std::unique_ptr<SCTAB[]> pScenarios( new SCTAB[nSelCount]);
diff --git a/sc/source/ui/docshell/docsh3.cxx b/sc/source/ui/docshell/docsh3.cxx
index c57c0ecb52b8..c817db247664 100644
--- a/sc/source/ui/docshell/docsh3.cxx
+++ b/sc/source/ui/docshell/docsh3.cxx
@@ -1176,17 +1176,17 @@ bool ScDocShell::MergeSharedDocument( ScDocShell* pSharedDocShell )
// merge own changes into shared document
sal_uLong nActStartShared = pSharedAction->GetActionNumber();
sal_uLong nActEndShared = pSharedTrack->GetActionMax();
- ScDocument* pTmpDoc = new ScDocument;
+ std::unique_ptr<ScDocument> pTmpDoc(new ScDocument);
for ( sal_Int32 nIndex = 0; nIndex < m_aDocument.GetTableCount(); ++nIndex )
{
OUString sTabName;
pTmpDoc->CreateValidTabName( sTabName );
pTmpDoc->InsertTab( SC_TAB_APPEND, sTabName );
}
- m_aDocument.GetChangeTrack()->Clone( pTmpDoc );
+ m_aDocument.GetChangeTrack()->Clone( pTmpDoc.get() );
ScChangeActionMergeMap aOwnInverseMergeMap;
pSharedDocShell->MergeDocument( *pTmpDoc, true, true, 0, &aOwnInverseMergeMap, true );
- delete pTmpDoc;
+ pTmpDoc.reset();
sal_uLong nActStartOwn = nActEndShared + 1;
sal_uLong nActEndOwn = pSharedTrack->GetActionMax();
@@ -1224,14 +1224,14 @@ bool ScDocShell::MergeSharedDocument( ScDocShell* pSharedDocShell )
pSharedTrack->Undo( nActStartOwn, nActEndOwn );
// clone change track for merging into own document
- pTmpDoc = new ScDocument;
+ pTmpDoc.reset(new ScDocument);
for ( sal_Int32 nIndex = 0; nIndex < m_aDocument.GetTableCount(); ++nIndex )
{
OUString sTabName;
pTmpDoc->CreateValidTabName( sTabName );
pTmpDoc->InsertTab( SC_TAB_APPEND, sTabName );
}
- pThisTrack->Clone( pTmpDoc );
+ pThisTrack->Clone( pTmpDoc.get() );
// undo own changes since last save in own document
sal_uLong nStartShared = pThisAction->GetActionNumber();
@@ -1276,7 +1276,7 @@ bool ScDocShell::MergeSharedDocument( ScDocShell* pSharedDocShell )
sal_uLong nStartOwn = nEndShared + 1;
ScChangeActionMergeMap aOwnMergeMap;
MergeDocument( *pTmpDoc, true, true, nEndShared - nStartShared + 1, &aOwnMergeMap );
- delete pTmpDoc;
+ pTmpDoc.reset();
sal_uLong nEndOwn = pThisTrack->GetActionMax();
// resolve conflicts for shared content actions and own actions
diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx
index 998e4c968d58..faf6c2b2b96e 100644
--- a/sc/source/ui/unoobj/cellsuno.cxx
+++ b/sc/source/ui/unoobj/cellsuno.cxx
@@ -5599,49 +5599,44 @@ uno::Reference<sheet::XSheetFilterDescriptor> SAL_CALL ScCellRangeObj::createFil
uno::Reference<sheet::XCellRangeAddressable> xAddr( xObject, uno::UNO_QUERY );
ScDocShell* pDocSh = GetDocShell();
- if ( pDocSh && xAddr.is() )
+ if ( !pDocSh || !xAddr.is() )
{
- //! check if xObject is in the same document
+ OSL_FAIL("no document or no area");
+ return nullptr;
+ }
- ScFilterDescriptor* pNew = new ScFilterDescriptor(pDocSh); //! instead from object?
+ //! check if xObject is in the same document
- ScQueryParam aParam = pNew->GetParam();
- aParam.bHasHeader = true;
+ std::unique_ptr<ScFilterDescriptor> pNew(new ScFilterDescriptor(pDocSh)); //! instead from object?
- table::CellRangeAddress aDataAddress(xAddr->getRangeAddress());
- aParam.nCol1 = static_cast<SCCOL>(aDataAddress.StartColumn);
- aParam.nRow1 = static_cast<SCROW>(aDataAddress.StartRow);
- aParam.nCol2 = static_cast<SCCOL>(aDataAddress.EndColumn);
- aParam.nRow2 = static_cast<SCROW>(aDataAddress.EndRow);
- aParam.nTab = aDataAddress.Sheet;
+ ScQueryParam aParam = pNew->GetParam();
+ aParam.bHasHeader = true;
- ScDocument& rDoc = pDocSh->GetDocument();
- if (rDoc.CreateQueryParam(aRange, aParam))
- {
- // FilterDescriptor contains the counted fields inside the area
- SCCOLROW nFieldStart = aParam.bByRow ?
- static_cast<SCCOLROW>(aDataAddress.StartColumn) :
- static_cast<SCCOLROW>(aDataAddress.StartRow);
- SCSIZE nCount = aParam.GetEntryCount();
- for (SCSIZE i=0; i<nCount; i++)
- {
- ScQueryEntry& rEntry = aParam.GetEntry(i);
- if (rEntry.bDoQuery && rEntry.nField >= nFieldStart)
- rEntry.nField -= nFieldStart;
- }
+ table::CellRangeAddress aDataAddress(xAddr->getRangeAddress());
+ aParam.nCol1 = static_cast<SCCOL>(aDataAddress.StartColumn);
+ aParam.nRow1 = static_cast<SCROW>(aDataAddress.StartRow);
+ aParam.nCol2 = static_cast<SCCOL>(aDataAddress.EndColumn);
+ aParam.nRow2 = static_cast<SCROW>(aDataAddress.EndRow);
+ aParam.nTab = aDataAddress.Sheet;
- pNew->SetParam( aParam );
- return pNew;
- }
- else
- {
- delete pNew;
- return nullptr;
- }
+ ScDocument& rDoc = pDocSh->GetDocument();
+ if (!rDoc.CreateQueryParam(aRange, aParam))
+ return nullptr;
+
+ // FilterDescriptor contains the counted fields inside the area
+ SCCOLROW nFieldStart = aParam.bByRow ?
+ static_cast<SCCOLROW>(aDataAddress.StartColumn) :
+ static_cast<SCCOLROW>(aDataAddress.StartRow);
+ SCSIZE nCount = aParam.GetEntryCount();
+ for (SCSIZE i=0; i<nCount; i++)
+ {
+ ScQueryEntry& rEntry = aParam.GetEntry(i);
+ if (rEntry.bDoQuery && rEntry.nField >= nFieldStart)
+ rEntry.nField -= nFieldStart;
}
- OSL_FAIL("no document or no area");
- return nullptr;
+ pNew->SetParam( aParam );
+ return pNew.release();
}
// XSubTotalSource
diff --git a/sc/source/ui/view/formatsh.cxx b/sc/source/ui/view/formatsh.cxx
index e3c560a4661e..43cd5be206e9 100644
--- a/sc/source/ui/view/formatsh.cxx
+++ b/sc/source/ui/view/formatsh.cxx
@@ -1400,7 +1400,7 @@ void ScFormatShell::ExecuteTextAttr( SfxRequest& rReq )
const ScPatternAttr* pAttrs = pTabViewShell->GetSelectionPattern();
const SfxItemSet* pSet = rReq.GetArgs();
sal_uInt16 nSlot = rReq.GetSlot();
- SfxAllItemSet* pNewSet = nullptr;
+ std::unique_ptr<SfxAllItemSet> pNewSet;
pTabViewShell->HideListBox(); // Autofilter-DropDown-Listbox
@@ -1412,7 +1412,7 @@ void ScFormatShell::ExecuteTextAttr( SfxRequest& rReq )
||(nSlot == SID_ULINE_VAL_DOUBLE)
||(nSlot == SID_ULINE_VAL_DOTTED) )
{
- pNewSet = new SfxAllItemSet( GetPool() );
+ pNewSet.reset(new SfxAllItemSet( GetPool() ));
switch ( nSlot )
{
@@ -1631,7 +1631,7 @@ void ScFormatShell::ExecuteTextAttr( SfxRequest& rReq )
if( pNewSet )
{
rReq.Done( *pNewSet );
- delete pNewSet;
+ pNewSet.reset();
}
else
{
diff --git a/sc/source/ui/view/preview.cxx b/sc/source/ui/view/preview.cxx
index 320b07d9ebd2..5fa5774b39ca 100644
--- a/sc/source/ui/view/preview.cxx
+++ b/sc/source/ui/view/preview.cxx
@@ -1309,12 +1309,12 @@ void ScPreview::MouseMove( const MouseEvent& rMEvt )
{
ScPrintOptions aOptions = SC_MOD()->GetPrintOptions();
- ScPrintFunc* pPrintFunc;
+ std::unique_ptr<ScPrintFunc> pPrintFunc;
if (bStateValid)
- pPrintFunc = new ScPrintFunc( this, pDocShell, aState, &aOptions );
+ pPrintFunc.reset(new ScPrintFunc( this, pDocShell, aState, &aOptions ));
else
- pPrintFunc = new ScPrintFunc( this, pDocShell, nTab, nFirstAttr[nTab], nTotalPages, nullptr, &aOptions );
+ pPrintFunc.reset(new ScPrintFunc( this, pDocShell, nTab, nFirstAttr[nTab], nTotalPages, nullptr, &aOptions ));
nLeftMargin = static_cast<long>( pPrintFunc->GetLeftMargin() * HMM_PER_TWIPS - aOffset.X() );
nRightMargin = static_cast<long>( pPrintFunc->GetRightMargin() * HMM_PER_TWIPS );
@@ -1332,7 +1332,6 @@ void ScPreview::MouseMove( const MouseEvent& rMEvt )
nHeaderHeight = static_cast<long>( nTopMargin + pPrintFunc->GetHeader().nHeight * HMM_PER_TWIPS );
nFooterHeight = static_cast<long>( nBottomMargin - pPrintFunc->GetFooter().nHeight * HMM_PER_TWIPS );
}
- delete pPrintFunc;
}
Point aPixPt( rMEvt.GetPosPixel() );
diff --git a/sc/source/ui/view/viewfun3.cxx b/sc/source/ui/view/viewfun3.cxx
index 4ea5b443d034..719b3d555991 100644
--- a/sc/source/ui/view/viewfun3.cxx
+++ b/sc/source/ui/view/viewfun3.cxx
@@ -1237,7 +1237,7 @@ bool ScViewFunc::PasteFromClip( InsertDeleteFlags nFlags, ScDocument* pClipDoc,
bool bRowInfo = ( nStartCol==0 && nEndCol==MAXCOL );
ScDocumentUniquePtr pUndoDoc;
- ScDocument* pRefUndoDoc = nullptr;
+ std::unique_ptr<ScDocument> pRefUndoDoc;
std::unique_ptr<ScRefUndoData> pUndoData;
if ( bRecord )
@@ -1252,7 +1252,7 @@ bool ScViewFunc::PasteFromClip( InsertDeleteFlags nFlags, ScDocument* pClipDoc,
if ( bCutMode )
{
- pRefUndoDoc = new ScDocument( SCDOCMODE_UNDO );
+ pRefUndoDoc.reset(new ScDocument( SCDOCMODE_UNDO ));
pRefUndoDoc->InitUndo( pDoc, 0, nTabCount-1 );
pUndoData.reset(new ScRefUndoData( pDoc ));
@@ -1301,23 +1301,23 @@ bool ScViewFunc::PasteFromClip( InsertDeleteFlags nFlags, ScDocument* pClipDoc,
{
// copy normally (original range)
pDoc->CopyFromClip( aUserRange, aFilteredMark, nNoObjFlags,
- pRefUndoDoc, pClipDoc, true, false, bIncludeFiltered,
+ pRefUndoDoc.get(), pClipDoc, true, false, bIncludeFiltered,
bSkipEmpty, (bMarkIsFiltered ? &aRangeList : nullptr) );
// adapt refs manually in case of transpose
if ( bTranspose && bCutMode && (nFlags & InsertDeleteFlags::CONTENTS) )
- pDoc->UpdateTranspose( aUserRange.aStart, pOrigClipDoc, aFilteredMark, pRefUndoDoc );
+ pDoc->UpdateTranspose( aUserRange.aStart, pOrigClipDoc, aFilteredMark, pRefUndoDoc.get() );
}
else if (!bTranspose)
{
// copy with bAsLink=TRUE
- pDoc->CopyFromClip( aUserRange, aFilteredMark, nNoObjFlags, pRefUndoDoc, pClipDoc,
+ pDoc->CopyFromClip( aUserRange, aFilteredMark, nNoObjFlags, pRefUndoDoc.get(), pClipDoc,
true, true, bIncludeFiltered, bSkipEmpty );
}
else
{
// copy all content (TransClipDoc contains only formula)
- pDoc->CopyFromClip( aUserRange, aFilteredMark, nContFlags, pRefUndoDoc, pClipDoc );
+ pDoc->CopyFromClip( aUserRange, aFilteredMark, nContFlags, pRefUndoDoc.get(), pClipDoc );
}
// skipped rows and merged cells don't mix
@@ -1350,7 +1350,7 @@ bool ScViewFunc::PasteFromClip( InsertDeleteFlags nFlags, ScDocument* pClipDoc,
// Paste the drawing objects after the row heights have been updated.
- pDoc->CopyFromClip( aUserRange, aFilteredMark, InsertDeleteFlags::OBJECTS, pRefUndoDoc, pClipDoc,
+ pDoc->CopyFromClip( aUserRange, aFilteredMark, InsertDeleteFlags::OBJECTS, pRefUndoDoc.get(), pClipDoc,
true, false, bIncludeFiltered );
}
@@ -1384,7 +1384,7 @@ bool ScViewFunc::PasteFromClip( InsertDeleteFlags nFlags, ScDocument* pClipDoc,
SCTAB nTabCount = pDoc->GetTableCount();
pRedoDoc->AddUndoTab( 0, nTabCount-1 );
- pDoc->CopyUpdated( pRefUndoDoc, pRedoDoc.get() );
+ pDoc->CopyUpdated( pRefUndoDoc.get(), pRedoDoc.get() );
// move old refs to Undo-Doc
@@ -1393,7 +1393,7 @@ bool ScViewFunc::PasteFromClip( InsertDeleteFlags nFlags, ScDocument* pClipDoc,
pRefUndoDoc->DeleteArea( nStartCol, nStartRow, nEndCol, nEndRow, aFilteredMark, InsertDeleteFlags::ALL );
pRefUndoDoc->CopyToDocument( 0,0,0, MAXCOL,MAXROW,nTabCount-1,
InsertDeleteFlags::FORMULA, false, *pUndoDoc );
- delete pRefUndoDoc;
+ pRefUndoDoc.reset();
}
// DeleteUnchanged for pUndoData is in ScUndoPaste ctor,