diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-07-12 18:58:17 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-07-13 08:30:26 +0200 |
commit | 647e11dc2fcbf0c8f7e39f4260d2b89057267e36 (patch) | |
tree | b90e69042d1b95c59c3d4e5918d64ed3b2bbad3e /sc/source/ui | |
parent | sd: Use std::unique_ptr<> as SdUndoGroup owns SdUndoActions (diff) | |
download | core-647e11dc2fcbf0c8f7e39f4260d2b89057267e36.tar.gz core-647e11dc2fcbf0c8f7e39f4260d2b89057267e36.zip |
loplugin:useuniqueptr in sc
Change-Id: I004e1f0292c8a40515880546574255ab835dbdbe
Reviewed-on: https://gerrit.libreoffice.org/39875
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sc/source/ui')
-rw-r--r-- | sc/source/ui/dbgui/asciiopt.cxx | 102 | ||||
-rw-r--r-- | sc/source/ui/docshell/pagedata.cxx | 27 | ||||
-rw-r--r-- | sc/source/ui/inc/asciiopt.hxx | 11 | ||||
-rw-r--r-- | sc/source/ui/inc/pagedata.hxx | 23 | ||||
-rw-r--r-- | sc/source/ui/inc/prevloc.hxx | 10 | ||||
-rw-r--r-- | sc/source/ui/inc/undoblk.hxx | 15 | ||||
-rw-r--r-- | sc/source/ui/undo/undoblk.cxx | 7 | ||||
-rw-r--r-- | sc/source/ui/view/gridwin4.cxx | 4 | ||||
-rw-r--r-- | sc/source/ui/view/output.cxx | 2 | ||||
-rw-r--r-- | sc/source/ui/view/prevloc.cxx | 8 |
10 files changed, 68 insertions, 141 deletions
diff --git a/sc/source/ui/dbgui/asciiopt.cxx b/sc/source/ui/dbgui/asciiopt.cxx index acccdfb55bb3..b104af3b7979 100644 --- a/sc/source/ui/dbgui/asciiopt.cxx +++ b/sc/source/ui/dbgui/asciiopt.cxx @@ -36,10 +36,7 @@ ScAsciiOptions::ScAsciiOptions() : eCharSet ( osl_getThreadTextEncoding() ), eLang ( LANGUAGE_SYSTEM ), bCharSetSystem ( false ), - nStartRow ( 1 ), - nInfoCount ( 0 ), - pColStart ( nullptr ), - pColFormat ( nullptr ) + nStartRow ( 1 ) { } @@ -54,78 +51,41 @@ ScAsciiOptions::ScAsciiOptions(const ScAsciiOptions& rOpt) : eLang ( rOpt.eLang ), bCharSetSystem ( rOpt.bCharSetSystem ), nStartRow ( rOpt.nStartRow ), - nInfoCount ( rOpt.nInfoCount ) + mvColStart ( rOpt.mvColStart ), + mvColFormat ( rOpt.mvColFormat ) { - if (nInfoCount) - { - pColStart = new sal_Int32[nInfoCount]; - pColFormat = new sal_uInt8[nInfoCount]; - for (sal_uInt16 i=0; i<nInfoCount; i++) - { - pColStart[i] = rOpt.pColStart[i]; - pColFormat[i] = rOpt.pColFormat[i]; - } - } - else - { - pColStart = nullptr; - pColFormat = nullptr; - } } ScAsciiOptions::~ScAsciiOptions() { - delete[] pColStart; - delete[] pColFormat; } void ScAsciiOptions::SetColInfo( sal_uInt16 nCount, const sal_Int32* pStart, const sal_uInt8* pFormat ) { - delete[] pColStart; - delete[] pColFormat; - - nInfoCount = nCount; - - if (nInfoCount) + mvColStart.resize(nCount); + mvColFormat.resize(nCount); + for (sal_uInt16 i=0; i<nCount; i++) { - pColStart = new sal_Int32[nInfoCount]; - pColFormat = new sal_uInt8[nInfoCount]; - for (sal_uInt16 i=0; i<nInfoCount; i++) - { - pColStart[i] = pStart[i]; - pColFormat[i] = pFormat[i]; - } - } - else - { - pColStart = nullptr; - pColFormat = nullptr; + mvColStart[i] = pStart[i]; + mvColFormat[i] = pFormat[i]; } } void ScAsciiOptions::SetColumnInfo( const ScCsvExpDataVec& rDataVec ) { - delete[] pColStart; - pColStart = nullptr; - delete[] pColFormat; - pColFormat = nullptr; - - nInfoCount = static_cast< sal_uInt16 >( rDataVec.size() ); - if( nInfoCount ) + sal_uInt16 nInfoCount = static_cast< sal_uInt16 >( rDataVec.size() ); + mvColStart.resize(nInfoCount); + mvColFormat.resize(nInfoCount); + for( sal_uInt16 nIx = 0; nIx < nInfoCount; ++nIx ) { - pColStart = new sal_Int32[ nInfoCount ]; - pColFormat = new sal_uInt8[ nInfoCount ]; - for( sal_uInt16 nIx = 0; nIx < nInfoCount; ++nIx ) - { - pColStart[ nIx ] = rDataVec[ nIx ].mnIndex; - pColFormat[ nIx ] = rDataVec[ nIx ].mnType; - } + mvColStart[ nIx ] = rDataVec[ nIx ].mnIndex; + mvColFormat[ nIx ] = rDataVec[ nIx ].mnType; } } ScAsciiOptions& ScAsciiOptions::operator=( const ScAsciiOptions& rCpy ) { - SetColInfo( rCpy.nInfoCount, rCpy.pColStart, rCpy.pColFormat ); + SetColInfo( rCpy.mvColStart.size(), rCpy.mvColStart.data(), rCpy.mvColFormat.data() ); bFixedLen = rCpy.bFixedLen; aFieldSeps = rCpy.aFieldSeps; @@ -203,27 +163,16 @@ void ScAsciiOptions::ReadFromString( const OUString& rString ) // Token 4: Column info. if ( nPos >= 0 ) { - delete[] pColStart; - delete[] pColFormat; - const OUString aToken = rString.getToken(0, ',', nPos); sal_Int32 nSub = comphelper::string::getTokenCount(aToken, '/'); - nInfoCount = nSub / 2; - if (nInfoCount) - { - pColStart = new sal_Int32[nInfoCount]; - pColFormat = new sal_uInt8[nInfoCount]; - sal_Int32 nP = 0; - for (sal_Int32 nInfo=0; nInfo<nInfoCount; ++nInfo) - { - pColStart[nInfo] = aToken.getToken(0, '/', nP).toInt32(); - pColFormat[nInfo] = static_cast<sal_uInt8>(aToken.getToken(0, '/', nP).toInt32()); - } - } - else + sal_Int32 nInfoCount = nSub / 2; + mvColStart.resize(nInfoCount); + mvColFormat.resize(nInfoCount); + sal_Int32 nP = 0; + for (sal_Int32 nInfo=0; nInfo<nInfoCount; ++nInfo) { - pColStart = nullptr; - pColFormat = nullptr; + mvColStart[nInfo] = aToken.getToken(0, '/', nP).toInt32(); + mvColFormat[nInfo] = static_cast<sal_uInt8>(aToken.getToken(0, '/', nP).toInt32()); } } @@ -289,14 +238,13 @@ OUString ScAsciiOptions::WriteToString() const aOutStr += "," + OUString::number(nStartRow) + ","; // Column info. - OSL_ENSURE( !nInfoCount || (pColStart && pColFormat), "NULL pointer in ScAsciiOptions column info" ); - for (sal_uInt16 nInfo=0; nInfo<nInfoCount; nInfo++) + for (size_t nInfo=0; nInfo<mvColStart.size(); nInfo++) { if (nInfo) aOutStr += "/"; - aOutStr += OUString::number(pColStart[nInfo]) + + aOutStr += OUString::number(mvColStart[nInfo]) + "/" + - OUString::number(pColFormat[nInfo]); + OUString::number(mvColFormat[nInfo]); } // #i112025# the options string is used in macros and linked sheets, diff --git a/sc/source/ui/docshell/pagedata.cxx b/sc/source/ui/docshell/pagedata.cxx index 143c1e50119f..94ce9277776c 100644 --- a/sc/source/ui/docshell/pagedata.cxx +++ b/sc/source/ui/docshell/pagedata.cxx @@ -25,43 +25,24 @@ ScPrintRangeData::ScPrintRangeData() { - nPagesX = nPagesY = 0; - pPageEndX = nullptr; - pPageEndY = nullptr; bTopDown = bAutomatic = true; nFirstPage = 1; } ScPrintRangeData::~ScPrintRangeData() { - delete[] pPageEndX; - delete[] pPageEndY; } void ScPrintRangeData::SetPagesX( size_t nCount, const SCCOL* pData ) { - delete[] pPageEndX; - if ( nCount ) - { - pPageEndX = new SCCOL[nCount]; - memcpy( pPageEndX, pData, nCount * sizeof(SCCOL) ); - } - else - pPageEndX = nullptr; - nPagesX = nCount; + mvPageEndX.resize( nCount ); + memcpy( mvPageEndX.data(), pData, nCount * sizeof(SCCOL) ); } void ScPrintRangeData::SetPagesY( size_t nCount, const SCROW* pData ) { - delete[] pPageEndY; - if ( nCount ) - { - pPageEndY = new SCROW[nCount]; - memcpy( pPageEndY, pData, nCount * sizeof(SCROW) ); - } - else - pPageEndY = nullptr; - nPagesY = nCount; + mvPageEndY.resize(nCount); + memcpy( mvPageEndY.data(), pData, nCount * sizeof(SCROW) ); } ScPageBreakData::ScPageBreakData(size_t nMax) diff --git a/sc/source/ui/inc/asciiopt.hxx b/sc/source/ui/inc/asciiopt.hxx index 551b5f277990..61308a9fe7d2 100644 --- a/sc/source/ui/inc/asciiopt.hxx +++ b/sc/source/ui/inc/asciiopt.hxx @@ -38,9 +38,8 @@ private: LanguageType eLang; bool bCharSetSystem; long nStartRow; - sal_uInt16 nInfoCount; - sal_Int32* pColStart; //! TODO replace with vector - sal_uInt8* pColFormat; //! TODO replace with vector + std::vector<sal_Int32> mvColStart; + std::vector<sal_uInt8> mvColFormat; public: ScAsciiOptions(); @@ -61,9 +60,9 @@ public: bool IsDetectSpecialNumber() const { return bDetectSpecialNumber; } sal_Unicode GetTextSep() const { return cTextSep; } bool IsFixedLen() const { return bFixedLen; } - sal_uInt16 GetInfoCount() const { return nInfoCount; } - const sal_Int32* GetColStart() const { return pColStart; } - const sal_uInt8* GetColFormat() const { return pColFormat; } + sal_uInt16 GetInfoCount() const { return mvColStart.size(); } + const sal_Int32* GetColStart() const { return mvColStart.data(); } + const sal_uInt8* GetColFormat() const { return mvColFormat.data(); } long GetStartRow() const { return nStartRow; } LanguageType GetLanguage() const { return eLang; } diff --git a/sc/source/ui/inc/pagedata.hxx b/sc/source/ui/inc/pagedata.hxx index 7dce22202e32..ffca7fe86cd2 100644 --- a/sc/source/ui/inc/pagedata.hxx +++ b/sc/source/ui/inc/pagedata.hxx @@ -20,25 +20,26 @@ #ifndef INCLUDED_SC_SOURCE_UI_INC_PAGEDATA_HXX #define INCLUDED_SC_SOURCE_UI_INC_PAGEDATA_HXX -#include <memory> #include "global.hxx" #include "address.hxx" +#include <memory> +#include <vector> class ScPrintRangeData { private: ScRange aPrintRange; - size_t nPagesX; - SCCOL* pPageEndX; - size_t nPagesY; - SCROW* pPageEndY; + std::vector<SCCOL> + mvPageEndX; + std::vector<SCROW> + mvPageEndY; long nFirstPage; bool bTopDown; bool bAutomatic; public: - ScPrintRangeData(); - ~ScPrintRangeData(); + ScPrintRangeData(); + ~ScPrintRangeData(); void SetPrintRange( const ScRange& rNew ) { aPrintRange = rNew; } const ScRange& GetPrintRange() const { return aPrintRange; } @@ -46,10 +47,10 @@ public: void SetPagesX( size_t nCount, const SCCOL* pEnd ); void SetPagesY( size_t nCount, const SCROW* pEnd ); - size_t GetPagesX() const { return nPagesX; } - const SCCOL* GetPageEndX() const { return pPageEndX; } - size_t GetPagesY() const { return nPagesY; } - const SCROW* GetPageEndY() const { return pPageEndY; } + size_t GetPagesX() const { return mvPageEndX.size(); } + const SCCOL* GetPageEndX() const { return mvPageEndX.data(); } + size_t GetPagesY() const { return mvPageEndY.size(); } + const SCROW* GetPageEndY() const { return mvPageEndY.data(); } void SetFirstPage( long nNew ) { nFirstPage = nNew; } long GetFirstPage() const { return nFirstPage; } diff --git a/sc/source/ui/inc/prevloc.hxx b/sc/source/ui/inc/prevloc.hxx index 419deb6e003c..a6ffc80489c8 100644 --- a/sc/source/ui/inc/prevloc.hxx +++ b/sc/source/ui/inc/prevloc.hxx @@ -65,8 +65,10 @@ class ScPreviewTableInfo SCTAB nTab; SCCOL nCols; SCROW nRows; - ScPreviewColRowInfo* pColInfo; - ScPreviewColRowInfo* pRowInfo; + std::unique_ptr<ScPreviewColRowInfo[]> + pColInfo; + std::unique_ptr<ScPreviewColRowInfo[]> + pRowInfo; public: ScPreviewTableInfo(); @@ -75,8 +77,8 @@ public: SCTAB GetTab() const { return nTab; } SCCOL GetCols() const { return nCols; } SCROW GetRows() const { return nRows; } - const ScPreviewColRowInfo* GetColInfo() const { return pColInfo; } - const ScPreviewColRowInfo* GetRowInfo() const { return pRowInfo; } + const ScPreviewColRowInfo* GetColInfo() const { return pColInfo.get(); } + const ScPreviewColRowInfo* GetRowInfo() const { return pRowInfo.get(); } void SetTab( SCTAB nNewTab ); void SetColInfo( SCCOL nCount, ScPreviewColRowInfo* pNewInfo ); diff --git a/sc/source/ui/inc/undoblk.hxx b/sc/source/ui/inc/undoblk.hxx index 1dd470ff264f..9b89e55a2fde 100644 --- a/sc/source/ui/inc/undoblk.hxx +++ b/sc/source/ui/inc/undoblk.hxx @@ -60,12 +60,15 @@ public: private: ScRange aEffRange; SCTAB nCount; - SCTAB* pTabs; - SCTAB* pScenarios; + std::unique_ptr<SCTAB[]> + pTabs; + std::unique_ptr<SCTAB[]> + pScenarios; sal_uLong nEndChangeAction; InsCellCmd eCmd; bool bPartOfPaste; - SfxUndoAction* pPasteUndo; + std::unique_ptr<SfxUndoAction> + pPasteUndo; void DoChange ( const bool bUndo ); void SetChangeTrack(); @@ -89,8 +92,10 @@ public: private: ScRange aEffRange; SCTAB nCount; - SCTAB* pTabs; - SCTAB* pScenarios; + std::unique_ptr<SCTAB[]> + pTabs; + std::unique_ptr<SCTAB[]> + pScenarios; sal_uLong nStartChangeAction; sal_uLong nEndChangeAction; DelCellCmd eCmd; diff --git a/sc/source/ui/undo/undoblk.cxx b/sc/source/ui/undo/undoblk.cxx index 5d4444dd06b3..4696623ead07 100644 --- a/sc/source/ui/undo/undoblk.cxx +++ b/sc/source/ui/undo/undoblk.cxx @@ -96,9 +96,6 @@ ScUndoInsertCells::ScUndoInsertCells( ScDocShell* pNewDocShell, ScUndoInsertCells::~ScUndoInsertCells() { - delete pPasteUndo; - delete []pTabs; - delete []pScenarios; } OUString ScUndoInsertCells::GetComment() const @@ -121,7 +118,7 @@ bool ScUndoInsertCells::Merge( SfxUndoAction* pNextAction ) // Store paste action if this is part of paste with inserting cells. // A list action isn't used because Repeat wouldn't work (insert wrong cells). - pPasteUndo = pWrappedAction; + pPasteUndo.reset( pWrappedAction ); pWrapper->ForgetWrappedUndo(); // pWrapper is deleted by UndoManager return true; } @@ -352,8 +349,6 @@ ScUndoDeleteCells::ScUndoDeleteCells( ScDocShell* pNewDocShell, ScUndoDeleteCells::~ScUndoDeleteCells() { - delete []pTabs; - delete []pScenarios; } OUString ScUndoDeleteCells::GetComment() const diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx index 5fea40a60d51..68a1ec5fb461 100644 --- a/sc/source/ui/view/gridwin4.cxx +++ b/sc/source/ui/view/gridwin4.cxx @@ -1532,8 +1532,8 @@ void ScGridWindow::DrawButtons(SCCOL nX1, SCCOL nX2, const ScTableInfo& rTabInfo ScDBData* pDBData = nullptr; std::unique_ptr<ScQueryParam> pQueryParam; - RowInfo* pRowInfo = rTabInfo.mpRowInfo; - sal_uInt16 nArrCount = rTabInfo.mnArrCount; + RowInfo* pRowInfo = rTabInfo.mpRowInfo.get(); + sal_uInt16 nArrCount = rTabInfo.mnArrCount; bool bLayoutRTL = pDoc->IsLayoutRTL( nTab ); diff --git a/sc/source/ui/view/output.cxx b/sc/source/ui/view/output.cxx index 8c656ca45bb7..900d880ccee7 100644 --- a/sc/source/ui/view/output.cxx +++ b/sc/source/ui/view/output.cxx @@ -150,7 +150,7 @@ ScOutputData::ScOutputData( OutputDevice* pNewDev, ScOutputType eNewType, mpRefDevice( pNewDev ), // default is output device pFmtDevice( pNewDev ), // default is output device mrTabInfo( rTabInfo ), - pRowInfo( rTabInfo.mpRowInfo ), + pRowInfo( rTabInfo.mpRowInfo.get() ), nArrCount( rTabInfo.mnArrCount ), mpDoc( pNewDoc ), nTab( nNewTab ), diff --git a/sc/source/ui/view/prevloc.cxx b/sc/source/ui/view/prevloc.cxx index 4c9f6ed18450..f929a4e24e58 100644 --- a/sc/source/ui/view/prevloc.cxx +++ b/sc/source/ui/view/prevloc.cxx @@ -67,8 +67,6 @@ ScPreviewTableInfo::ScPreviewTableInfo() : ScPreviewTableInfo::~ScPreviewTableInfo() { - delete[] pColInfo; - delete[] pRowInfo; } void ScPreviewTableInfo::SetTab( SCTAB nNewTab ) @@ -78,15 +76,13 @@ void ScPreviewTableInfo::SetTab( SCTAB nNewTab ) void ScPreviewTableInfo::SetColInfo( SCCOL nCount, ScPreviewColRowInfo* pNewInfo ) { - delete[] pColInfo; - pColInfo = pNewInfo; + pColInfo.reset(pNewInfo); nCols = nCount; } void ScPreviewTableInfo::SetRowInfo( SCROW nCount, ScPreviewColRowInfo* pNewInfo ) { - delete[] pRowInfo; - pRowInfo = pNewInfo; + pRowInfo.reset(pNewInfo); nRows = nCount; } |