diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-07-10 13:57:53 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-07-11 16:01:28 +0200 |
commit | 673347af7d37f6789855c17732c9980d91ec6240 (patch) | |
tree | 4447a73900c50db2f949755eca64a91ac2d9a385 | |
parent | 0bc97adb82f14d6ec22f868422cbfe000afec402 (diff) |
loplugin:useuniqueptr in scaddins..svx
Change-Id: I309f98f6b820103a926e9fe94d67d0aff6eb6476
Reviewed-on: https://gerrit.libreoffice.org/39754
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | include/svtools/unoevent.hxx | 8 | ||||
-rw-r--r-- | include/svx/xpool.hxx | 5 | ||||
-rw-r--r-- | scaddins/source/analysis/analysis.cxx | 3 | ||||
-rw-r--r-- | scaddins/source/analysis/analysis.hxx | 4 | ||||
-rw-r--r-- | sd/source/filter/eppt/grouptable.hxx | 13 | ||||
-rw-r--r-- | sd/source/filter/eppt/pptx-grouptable.cxx | 43 | ||||
-rw-r--r-- | sfx2/source/explorer/nochaos.cxx | 10 | ||||
-rw-r--r-- | svtools/source/uno/unoevent.cxx | 21 | ||||
-rw-r--r-- | svx/inc/xpolyimp.hxx | 4 | ||||
-rw-r--r-- | svx/source/dialog/svxruler.cxx | 18 | ||||
-rw-r--r-- | svx/source/svdraw/svdattr.cxx | 2 | ||||
-rw-r--r-- | svx/source/xoutdev/_xpoly.cxx | 21 | ||||
-rw-r--r-- | svx/source/xoutdev/xpool.cxx | 4 |
13 files changed, 61 insertions, 95 deletions
diff --git a/include/svtools/unoevent.hxx b/include/svtools/unoevent.hxx index 50044da03279..3d8b0936dfde 100644 --- a/include/svtools/unoevent.hxx +++ b/include/svtools/unoevent.hxx @@ -24,6 +24,8 @@ #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/uno/XInterface.hpp> #include <cppuhelper/implbase.hxx> +#include <vector> +#include <memory> class SvxMacroTableDtor; class SvxMacroItem; @@ -202,13 +204,15 @@ protected: class SVT_DLLPUBLIC SvDetachedEventDescriptor : public SvBaseEventDescriptor { // the macros; aMacros[i] is the value for aSupportedMacroItemIDs[i] - SvxMacro** aMacros; + std::vector<std::unique_ptr<SvxMacro>> aMacros; const OUString sImplName; public: - SvDetachedEventDescriptor(const SvEventDescription* pSupportedMacroItems); + SvDetachedEventDescriptor(const SvEventDescription* pSupportedMacroItems); + SvDetachedEventDescriptor& operator=( SvDetachedEventDescriptor const & ) = delete; // MSVC2015 workaround + SvDetachedEventDescriptor( SvDetachedEventDescriptor const & ) = delete; // MSVC2015 workaround virtual ~SvDetachedEventDescriptor() override; diff --git a/include/svx/xpool.hxx b/include/svx/xpool.hxx index 5e6dd21efab3..6d3122153330 100644 --- a/include/svx/xpool.hxx +++ b/include/svx/xpool.hxx @@ -23,6 +23,7 @@ #include <svl/itempool.hxx> #include <svx/xdef.hxx> #include <svx/svxdllapi.h> +#include <memory> /************************************************************************* |* @@ -33,8 +34,8 @@ class SVX_DLLPUBLIC XOutdevItemPool : public SfxItemPool { protected: - std::vector<SfxPoolItem*>* mpLocalPoolDefaults; - SfxItemInfo* mpLocalItemInfos; + std::vector<SfxPoolItem*>* mpLocalPoolDefaults; + std::unique_ptr<SfxItemInfo[]> mpLocalItemInfos; public: XOutdevItemPool( SfxItemPool* pMaster, bool bLoadRefCounts = true); diff --git a/scaddins/source/analysis/analysis.cxx b/scaddins/source/analysis/analysis.cxx index 344d5aa0f54a..14a9b6b89481 100644 --- a/scaddins/source/analysis/analysis.cxx +++ b/scaddins/source/analysis/analysis.cxx @@ -112,7 +112,6 @@ AnalysisAddIn::~AnalysisAddIn() { delete pResMgr; delete pCDL; - delete[] pFactDoubles; delete pFD; delete[] pDefLocales; } @@ -136,7 +135,7 @@ double AnalysisAddIn::FactDouble( sal_Int32 nNum ) if( !pFactDoubles ) { - pFactDoubles = new double[ MAXFACTDOUBLE + 1 ]; + pFactDoubles.reset( new double[ MAXFACTDOUBLE + 1 ] ); pFactDoubles[ 0 ] = 1.0; // by default diff --git a/scaddins/source/analysis/analysis.hxx b/scaddins/source/analysis/analysis.hxx index 97c671820045..c38c65759148 100644 --- a/scaddins/source/analysis/analysis.hxx +++ b/scaddins/source/analysis/analysis.hxx @@ -35,6 +35,8 @@ #include "analysisdefs.hxx" #include "analysishelper.hxx" +#include <memory> + namespace sca { namespace analysis { class ConvertDataList; } } @@ -55,7 +57,7 @@ private: css::lang::Locale aFuncLoc; css::lang::Locale* pDefLocales; sca::analysis::FuncDataList* pFD; - double* pFactDoubles; + std::unique_ptr<double[]> pFactDoubles; sca::analysis::ConvertDataList* pCDL; ResMgr* pResMgr; diff --git a/sd/source/filter/eppt/grouptable.hxx b/sd/source/filter/eppt/grouptable.hxx index dd672c240f61..09139fcf1888 100644 --- a/sd/source/filter/eppt/grouptable.hxx +++ b/sd/source/filter/eppt/grouptable.hxx @@ -21,6 +21,8 @@ #define INCLUDED_SD_SOURCE_FILTER_EPPT_GROUPTABLE_HXX #include <com/sun/star/container/XIndexAccess.hpp> +#include <memory> +#include <vector> struct GroupEntry { @@ -47,19 +49,16 @@ class GroupTable protected: sal_uInt32 mnIndex; - sal_uInt32 mnCurrentGroupEntry; - sal_uInt32 mnMaxGroupEntry; sal_uInt32 mnGroupsClosed; - GroupEntry** mpGroupEntry; - - void ImplResizeGroupTable( sal_uInt32 nEntrys ); + std::vector<std::unique_ptr<GroupEntry>> + mvGroupEntry; public: sal_uInt32 GetCurrentGroupIndex() const { return mnIndex; }; - sal_Int32 GetCurrentGroupLevel() const { return mnCurrentGroupEntry - 1; }; + sal_Int32 GetCurrentGroupLevel() const { return mvGroupEntry.size() - 1; }; css::uno::Reference< css::container::XIndexAccess > & - GetCurrentGroupAccess() const { return mpGroupEntry[ mnCurrentGroupEntry - 1 ]->mXIndexAccess; }; + GetCurrentGroupAccess() const { return mvGroupEntry.back()->mXIndexAccess; }; sal_uInt32 GetGroupsClosed(); void ResetGroupTable( sal_uInt32 nCount ); void ClearGroupTable(); diff --git a/sd/source/filter/eppt/pptx-grouptable.cxx b/sd/source/filter/eppt/pptx-grouptable.cxx index 712de6ac694f..98105a7e6fb6 100644 --- a/sd/source/filter/eppt/pptx-grouptable.cxx +++ b/sd/source/filter/eppt/pptx-grouptable.cxx @@ -23,31 +23,13 @@ using ::com::sun::star::container::XIndexAccess; GroupTable::GroupTable() : mnIndex(0) - , mnCurrentGroupEntry(0) - , mnMaxGroupEntry(0) , mnGroupsClosed(0) - , mpGroupEntry(nullptr) { - ImplResizeGroupTable( 32 ); + mvGroupEntry.reserve(32); } GroupTable::~GroupTable() { - for ( sal_uInt32 i = 0; i < mnCurrentGroupEntry; delete mpGroupEntry[ i++ ] ) ; - delete[] mpGroupEntry; -} - -void GroupTable::ImplResizeGroupTable( sal_uInt32 nEntrys ) -{ - if ( nEntrys > mnMaxGroupEntry ) - { - mnMaxGroupEntry = nEntrys; - GroupEntry** pTemp = new GroupEntry*[ nEntrys ]; - for ( sal_uInt32 i = 0; i < mnCurrentGroupEntry; i++ ) - pTemp[ i ] = mpGroupEntry[ i ]; - delete[] mpGroupEntry; - mpGroupEntry = pTemp; - } } bool GroupTable::EnterGroup( css::uno::Reference< css::container::XIndexAccess >& rXIndexAccessRef ) @@ -55,16 +37,12 @@ bool GroupTable::EnterGroup( css::uno::Reference< css::container::XIndexAccess > bool bRet = false; if ( rXIndexAccessRef.is() ) { - GroupEntry* pNewGroup = new GroupEntry( rXIndexAccessRef ); + std::unique_ptr<GroupEntry> pNewGroup( new GroupEntry( rXIndexAccessRef ) ); if ( pNewGroup->mnCount ) { - if ( mnMaxGroupEntry == mnCurrentGroupEntry ) - ImplResizeGroupTable( mnMaxGroupEntry + 8 ); - mpGroupEntry[ mnCurrentGroupEntry++ ] = pNewGroup; + mvGroupEntry.push_back( std::move(pNewGroup) ); bRet = true; } - else - delete pNewGroup; } return bRet; } @@ -78,28 +56,27 @@ sal_uInt32 GroupTable::GetGroupsClosed() void GroupTable::ClearGroupTable() { - for ( sal_uInt32 i = 0; i < mnCurrentGroupEntry; i++, delete mpGroupEntry[ i ] ) ; - mnCurrentGroupEntry = 0; + mvGroupEntry.clear(); } void GroupTable::ResetGroupTable( sal_uInt32 nCount ) { ClearGroupTable(); - mpGroupEntry[ mnCurrentGroupEntry++ ] = new GroupEntry( nCount ); + mvGroupEntry.push_back( std::unique_ptr<GroupEntry>(new GroupEntry( nCount )) ); } bool GroupTable::GetNextGroupEntry() { - while ( mnCurrentGroupEntry ) + while ( !mvGroupEntry.empty() ) { - mnIndex = mpGroupEntry[ mnCurrentGroupEntry - 1 ]->mnCurrentPos++; + mnIndex = mvGroupEntry.back()->mnCurrentPos++; - if ( mpGroupEntry[ mnCurrentGroupEntry - 1 ]->mnCount > mnIndex ) + if ( mvGroupEntry.back()->mnCount > mnIndex ) return true; - delete ( mpGroupEntry[ --mnCurrentGroupEntry ] ); + mvGroupEntry.pop_back(); - if ( mnCurrentGroupEntry ) + if ( !mvGroupEntry.empty() ) mnGroupsClosed++; } return false; diff --git a/sfx2/source/explorer/nochaos.cxx b/sfx2/source/explorer/nochaos.cxx index 3023b3bd9f28..a499764c1d87 100644 --- a/sfx2/source/explorer/nochaos.cxx +++ b/sfx2/source/explorer/nochaos.cxx @@ -22,8 +22,9 @@ #include <svl/itempool.hxx> #include <svl/poolitem.hxx> #include <svl/stritem.hxx> -#include <nochaos.hxx> #include <sfx2/sfxuno.hxx> +#include <nochaos.hxx> +#include <memory> #define WID_CHAOS_START 500 @@ -37,7 +38,7 @@ class CntStaticPoolDefaults_Impl { static const sal_uInt32 m_nItems = 1; std::vector<SfxPoolItem*>* m_pDefaults; - SfxItemInfo* m_pItemInfos; + std::unique_ptr<SfxItemInfo[]> m_pItemInfos; private: inline void Insert( SfxPoolItem* pItem ); @@ -49,7 +50,7 @@ public: CntStaticPoolDefaults_Impl& operator=(const CntStaticPoolDefaults_Impl&) = delete; std::vector<SfxPoolItem*>* GetDefaults() const { return m_pDefaults; } - const SfxItemInfo* GetItemInfos() const { return m_pItemInfos; } + const SfxItemInfo* GetItemInfos() const { return m_pItemInfos.get(); } }; @@ -174,7 +175,6 @@ CntStaticPoolDefaults_Impl::~CntStaticPoolDefaults_Impl() delete (*m_pDefaults)[ n ]; delete m_pDefaults; - delete [] m_pItemInfos; } @@ -182,7 +182,7 @@ CntStaticPoolDefaults_Impl::CntStaticPoolDefaults_Impl() : m_pDefaults( new std::vector<SfxPoolItem*>( m_nItems, nullptr ) ), m_pItemInfos( new SfxItemInfo [ m_nItems ] ) { - memset( m_pItemInfos, 0, sizeof( SfxItemInfo ) * m_nItems ); + memset( m_pItemInfos.get(), 0, sizeof( SfxItemInfo ) * m_nItems ); Insert( new SfxStringItem( WID_CHAOS_START, OUString() ) ); } diff --git a/svtools/source/uno/unoevent.cxx b/svtools/source/uno/unoevent.cxx index 6a6688574501..04e335a146a1 100644 --- a/svtools/source/uno/unoevent.cxx +++ b/svtools/source/uno/unoevent.cxx @@ -390,26 +390,11 @@ SvDetachedEventDescriptor::SvDetachedEventDescriptor( SvBaseEventDescriptor(pSupportedMacroItems), sImplName("SvDetachedEventDescriptor") { - // allocate aMacros - aMacros = new SvxMacro*[mnMacroItems]; - - // ... and initialize - for(sal_Int16 i = 0; i < mnMacroItems; i++) - { - aMacros[i] = nullptr; - } + aMacros.resize(mnMacroItems); } SvDetachedEventDescriptor::~SvDetachedEventDescriptor() { - // delete contents of aMacros - for(sal_Int16 i = 0; i < mnMacroItems; i++) - { - if (nullptr != aMacros[i]) - delete aMacros[i]; - } - - delete [] aMacros; } sal_Int16 SvDetachedEventDescriptor::getIndex(const sal_uInt16 nID) const @@ -438,8 +423,8 @@ void SvDetachedEventDescriptor::replaceByName( if (-1 == nIndex) throw IllegalArgumentException(); - aMacros[nIndex] = new SvxMacro(rMacro.GetMacName(), rMacro.GetLibName(), - rMacro.GetScriptType() ); + aMacros[nIndex].reset( new SvxMacro(rMacro.GetMacName(), rMacro.GetLibName(), + rMacro.GetScriptType() ) ); } diff --git a/svx/inc/xpolyimp.hxx b/svx/inc/xpolyimp.hxx index 35ead6c9a87a..02c9b08e1bef 100644 --- a/svx/inc/xpolyimp.hxx +++ b/svx/inc/xpolyimp.hxx @@ -21,6 +21,7 @@ #define INCLUDED_SVX_INC_XPOLYIMP_HXX #include <svx/xpoly.hxx> +#include <memory> #include <vector> class Point; @@ -29,7 +30,8 @@ class ImpXPolygon { public: Point* pPointAry; - PolyFlags* pFlagAry; + std::unique_ptr<PolyFlags[]> + pFlagAry; Point* pOldPointAry; bool bDeleteOldPoints; sal_uInt16 nSize; diff --git a/svx/source/dialog/svxruler.cxx b/svx/source/dialog/svxruler.cxx index 6c17a9c448c1..5beb625cb0a4 100644 --- a/svx/source/dialog/svxruler.cxx +++ b/svx/source/dialog/svxruler.cxx @@ -39,6 +39,7 @@ #include <svx/svdtrans.hxx> #include "rlrcitem.hxx" +#include <memory> #ifndef RULER_TAB_RTL #define RULER_TAB_RTL ((sal_uInt16)0x0010) @@ -115,8 +116,8 @@ void RulerDebugWindow::AddDebugText(const sal_Char* pDescription, const OUSt #endif struct SvxRuler_Impl { - sal_uInt16 *pPercBuf; - sal_uInt16 *pBlockBuf; + std::unique_ptr<sal_uInt16[]> pPercBuf; + std::unique_ptr<sal_uInt16[]> pBlockBuf; sal_uInt16 nPercSize; long nTotalDist; long lOldWinPos; @@ -152,7 +153,7 @@ struct SvxRuler_Impl { ~SvxRuler_Impl() { nPercSize = 0; nTotalDist = 0; - delete[] pPercBuf; delete[] pBlockBuf; pPercBuf = nullptr; + pPercBuf = nullptr; delete pTextRTLItem; } void SetPercSize(sal_uInt16 nSize); @@ -183,14 +184,13 @@ void SvxRuler_Impl::SetPercSize(sal_uInt16 nSize) { if(nSize > nPercSize) { - delete[] pPercBuf; - delete[] pBlockBuf; - pPercBuf = new sal_uInt16[nPercSize = nSize]; - pBlockBuf = new sal_uInt16[nPercSize = nSize]; + nPercSize = nSize; + pPercBuf.reset( new sal_uInt16[nPercSize] ); + pBlockBuf.reset( new sal_uInt16[nPercSize] ); } size_t nSize2 = sizeof(sal_uInt16) * nPercSize; - memset(pPercBuf, 0, nSize2); - memset(pBlockBuf, 0, nSize2); + memset(pPercBuf.get(), 0, nSize2); + memset(pBlockBuf.get(), 0, nSize2); } // Constructor of the ruler diff --git a/svx/source/svdraw/svdattr.cxx b/svx/source/svdraw/svdattr.cxx index ebac16e576af..46ae6858ec01 100644 --- a/svx/source/svdraw/svdattr.cxx +++ b/svx/source/svdraw/svdattr.cxx @@ -339,7 +339,7 @@ SdrItemPool::SdrItemPool( // it's my own creation level, set Defaults and ItemInfos SetDefaults(mpLocalPoolDefaults); - SetItemInfos(mpLocalItemInfos); + SetItemInfos(mpLocalItemInfos.get()); } // copy ctor, so that static defaults are cloned diff --git a/svx/source/xoutdev/_xpoly.cxx b/svx/source/xoutdev/_xpoly.cxx index 39d8cfc6aa14..f8d6b12f48f7 100644 --- a/svx/source/xoutdev/_xpoly.cxx +++ b/svx/source/xoutdev/_xpoly.cxx @@ -62,13 +62,12 @@ ImpXPolygon::ImpXPolygon( const ImpXPolygon& rImpXPoly ) // copy nPoints = rImpXPoly.nPoints; memcpy( pPointAry, rImpXPoly.pPointAry, nSize*sizeof( Point ) ); - memcpy( pFlagAry, rImpXPoly.pFlagAry, nSize ); + memcpy( pFlagAry.get(), rImpXPoly.pFlagAry.get(), nSize ); } ImpXPolygon::~ImpXPolygon() { delete[] reinterpret_cast<char*>(pPointAry); - delete[] pFlagAry; if ( bDeleteOldPoints ) { delete[] reinterpret_cast<char*>(pOldPointAry); @@ -80,8 +79,8 @@ bool ImpXPolygon::operator==(const ImpXPolygon& rImpXPoly) const { return nPoints==rImpXPoly.nPoints && (nPoints==0 || - (memcmp(pPointAry,rImpXPoly.pPointAry,nPoints*sizeof(Point))==0 && - memcmp(pFlagAry,rImpXPoly.pFlagAry,nPoints)==0)); + (memcmp(pPointAry, rImpXPoly.pPointAry, nPoints*sizeof(Point))==0 && + memcmp(pFlagAry.get(), rImpXPoly.pFlagAry.get(), nPoints)==0)); } /** Change polygon size @@ -97,7 +96,7 @@ void ImpXPolygon::Resize( sal_uInt16 nNewSize, bool bDeletePoints ) if( nNewSize == nSize ) return; - PolyFlags* pOldFlagAry = pFlagAry; + PolyFlags* pOldFlagAry = pFlagAry.get(); sal_uInt16 nOldSize = nSize; CheckPointDelete(); @@ -116,8 +115,8 @@ void ImpXPolygon::Resize( sal_uInt16 nNewSize, bool bDeletePoints ) memset( pPointAry, 0, nSize*sizeof( Point ) ); // create flag array - pFlagAry = new PolyFlags[ nSize ]; - memset( pFlagAry, 0, nSize ); + pFlagAry.reset( new PolyFlags[ nSize ] ); + memset( pFlagAry.get(), 0, nSize ); // copy if needed if( nOldSize ) @@ -125,12 +124,12 @@ void ImpXPolygon::Resize( sal_uInt16 nNewSize, bool bDeletePoints ) if( nOldSize < nSize ) { memcpy( pPointAry, pOldPointAry, nOldSize*sizeof( Point ) ); - memcpy( pFlagAry, pOldFlagAry, nOldSize ); + memcpy( pFlagAry.get(), pOldFlagAry, nOldSize ); } else { memcpy( pPointAry, pOldPointAry, nSize*sizeof( Point ) ); - memcpy( pFlagAry, pOldFlagAry, nSize ); + memcpy( pFlagAry.get(), pOldFlagAry, nSize ); // adjust number of valid points if( nPoints > nSize ) @@ -383,7 +382,7 @@ void XPolygon::Insert( sal_uInt16 nPos, const XPolygon& rXPoly ) rXPoly.pImpXPolygon->pPointAry, nPoints*sizeof( Point ) ); memcpy( &(pImpXPolygon->pFlagAry[nPos]), - rXPoly.pImpXPolygon->pFlagAry, + rXPoly.pImpXPolygon->pFlagAry.get(), nPoints ); } @@ -835,7 +834,7 @@ basegfx::B2DPolygon XPolygon::getB2DPolygon() const // #i74631# use tools Polygon class for conversion to not have the code doubled // here. This needs one more conversion but avoids different convertors in // the long run - const tools::Polygon aSource(GetPointCount(), pImpXPolygon->pPointAry, pImpXPolygon->pFlagAry); + const tools::Polygon aSource(GetPointCount(), pImpXPolygon->pPointAry, pImpXPolygon->pFlagAry.get()); return aSource.getB2DPolygon(); } diff --git a/svx/source/xoutdev/xpool.cxx b/svx/source/xoutdev/xpool.cxx index 0146afe75120..367e07aaf18d 100644 --- a/svx/source/xoutdev/xpool.cxx +++ b/svx/source/xoutdev/xpool.cxx @@ -161,7 +161,7 @@ XOutdevItemPool::XOutdevItemPool(SfxItemPool* _pMaster, bool bLoadRefCounts) if(XATTR_START == GetFirstWhich() && XATTR_END == GetLastWhich()) { SetDefaults(mpLocalPoolDefaults); - SetItemInfos(mpLocalItemInfos); + SetItemInfos(mpLocalItemInfos.get()); } } @@ -183,8 +183,6 @@ XOutdevItemPool::~XOutdevItemPool() Delete(); // release and delete static pool default items ReleaseDefaults(true); - - delete[] mpLocalItemInfos; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |