new loplugin: useuniqueptr: svl..svtools

Change-Id: Ia4d5b37ee3cf67318e3cc01525e4b733af60d038
Reviewed-on: https://gerrit.libreoffice.org/33251
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin 2017-01-18 09:47:46 +02:00
parent d0cbdac23b
commit 352e036ada
14 changed files with 59 additions and 91 deletions

View file

@ -516,7 +516,8 @@ public:
class SVL_DLLPUBLIC SfxMultiRecordReader: public SfxSingleRecordReader
{
sal_uInt32 _nStartPos; // start position of this record
sal_uInt32* _pContentOfs; // offsets of the start positions
std::unique_ptr<sal_uInt32[]>
_pContentOfs; // offsets of the start positions
sal_uInt32 _nContentSize; // size of each record or table position
sal_uInt16 _nContentCount; // number of content items
sal_uInt16 _nContentNo; /* the index of the current content

View file

@ -20,15 +20,15 @@
#define INCLUDED_SVL_ISETHINT_HXX
#include <svl/svldllapi.h>
#include <svl/hint.hxx>
#include <memory>
class SfxItemSet;
class SVL_DLLPUBLIC SfxItemSetHint: public SfxHint
{
SfxItemSet* _pItemSet;
std::unique_ptr<SfxItemSet> _pItemSet;
public:
SfxItemSetHint( const SfxItemSet &rItemSet );

View file

@ -138,7 +138,8 @@ class OnDemandCalendarWrapper
{
css::uno::Reference< css::uno::XComponentContext > m_xContext;
css::lang::Locale aLocale;
mutable CalendarWrapper* pPtr;
mutable std::unique_ptr<CalendarWrapper>
pPtr;
mutable bool bValid;
bool bInitialized;
@ -150,7 +151,6 @@ public:
{}
~OnDemandCalendarWrapper()
{
delete pPtr;
}
void init(
@ -160,11 +160,7 @@ public:
{
m_xContext = rxContext;
changeLocale( rLocale );
if ( pPtr )
{
delete pPtr;
pPtr = nullptr;
}
pPtr.reset();
bInitialized = true;
}
@ -179,11 +175,11 @@ public:
if ( !bValid )
{
if ( !pPtr )
pPtr = new CalendarWrapper( m_xContext );
pPtr.reset(new CalendarWrapper( m_xContext ));
pPtr->loadDefaultCalendar( aLocale );
bValid = true;
}
return pPtr;
return pPtr.get();
}
};
@ -198,7 +194,8 @@ class OnDemandTransliterationWrapper
css::uno::Reference< css::uno::XComponentContext > m_xContext;
LanguageType eLanguage;
css::i18n::TransliterationModules nType;
mutable ::utl::TransliterationWrapper* pPtr;
mutable std::unique_ptr<::utl::TransliterationWrapper>
pPtr;
mutable bool bValid;
bool bInitialized;
@ -212,7 +209,6 @@ public:
{}
~OnDemandTransliterationWrapper()
{
delete pPtr;
}
bool isInitialized() const { return bInitialized; }
@ -225,11 +221,7 @@ public:
m_xContext = rxContext;
nType = css::i18n::TransliterationModules_IGNORE_CASE;
changeLocale( eLang );
if ( pPtr )
{
delete pPtr;
pPtr = nullptr;
}
pPtr.reset();
bInitialized = true;
}
@ -244,11 +236,11 @@ public:
if ( !bValid )
{
if ( !pPtr )
pPtr = new ::utl::TransliterationWrapper( m_xContext, nType );
pPtr.reset( new ::utl::TransliterationWrapper( m_xContext, nType ) );
pPtr->loadModuleIfNeeded( eLanguage );
bValid = true;
}
return pPtr;
return pPtr.get();
}
const ::utl::TransliterationWrapper* operator->() const { return get(); }
@ -264,7 +256,8 @@ public:
class OnDemandNativeNumberWrapper
{
css::uno::Reference< css::uno::XComponentContext > m_xContext;
mutable NativeNumberWrapper* pPtr;
mutable std::unique_ptr<NativeNumberWrapper>
pPtr;
bool bInitialized;
public:
@ -274,7 +267,6 @@ public:
{}
~OnDemandNativeNumberWrapper()
{
delete pPtr;
}
void init(
@ -282,19 +274,15 @@ public:
)
{
m_xContext = rxContext;
if ( pPtr )
{
delete pPtr;
pPtr = nullptr;
}
pPtr.reset();
bInitialized = true;
}
NativeNumberWrapper* get() const
{
if ( !pPtr )
pPtr = new NativeNumberWrapper( m_xContext );
return pPtr;
pPtr.reset(new NativeNumberWrapper( m_xContext ));
return pPtr.get();
}
};

View file

@ -62,7 +62,8 @@ private:
sal_uLong lEnd;
sal_uInt16 nId;
ResMgr *pMgr;
ResMgr *pFreeMgr;
std::unique_ptr<ResMgr>
pFreeMgr;
SVT_DLLPRIVATE static void GetClassString(sal_uLong lErrId, OUString &);
virtual bool CreateString( const ErrorInfo *, OUString &, sal_uInt16 &) const override;

View file

@ -419,10 +419,8 @@ private:
{
private:
DropTargetHelper& mrParent;
AcceptDropEvent* mpLastDragOverEvent;
private:
DropTargetHelper& mrParent;
std::unique_ptr<AcceptDropEvent> mpLastDragOverEvent;
// XEventListener
virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) throw(css::uno::RuntimeException, std::exception) override;

View file

@ -497,9 +497,9 @@ bool SfxMultiRecordReader::ReadHeader_Impl()
_nContentCount << " claimed, truncating");
_nContentCount = nMaxRecords;
}
_pContentOfs = new sal_uInt32[_nContentCount]{};
_pContentOfs.reset( new sal_uInt32[_nContentCount]{} );
#if defined(OSL_LITENDIAN)
_pStream->ReadBytes( _pContentOfs, sizeof(sal_uInt32)*_nContentCount );
_pStream->ReadBytes( _pContentOfs.get(), sizeof(sal_uInt32)*_nContentCount );
#else
// (loop without braces)
for ( sal_uInt16 n = 0; n < _nContentCount; ++n )
@ -541,7 +541,6 @@ SfxMultiRecordReader::SfxMultiRecordReader( SvStream *pStream, sal_uInt16 nTag )
SfxMultiRecordReader::~SfxMultiRecordReader()
{
delete[] _pContentOfs;
}
/**

View file

@ -347,7 +347,7 @@ class StylePoolImpl
private:
std::map< const SfxItemSet*, Node > maRoot;
// #i86923#
SfxItemSet* mpIgnorableItems;
std::unique_ptr<SfxItemSet> mpIgnorableItems;
public:
// #i86923#
explicit StylePoolImpl( SfxItemSet* pIgnorableItems )
@ -364,7 +364,6 @@ public:
~StylePoolImpl()
{
delete mpIgnorableItems;
}
std::shared_ptr<SfxItemSet> insertItemSet( const SfxItemSet& rSet );

View file

@ -32,7 +32,6 @@ SfxItemSetHint::SfxItemSetHint( const SfxItemSet &rItemSet )
SfxItemSetHint::~SfxItemSetHint()
{
delete _pItemSet;
}

View file

@ -223,7 +223,8 @@ typedef ::std::vector< SfxUndoListener* > UndoListeners;
struct SfxUndoManager_Data
{
::osl::Mutex aMutex;
SfxUndoArray* pUndoArray;
std::unique_ptr<SfxUndoArray>
pUndoArray;
SfxUndoArray* pActUndoArray;
SfxUndoArray* pFatherUndoArray;
@ -245,12 +246,11 @@ struct SfxUndoManager_Data
,mbDoing( false )
,mbClearUntilTopLevel( false )
{
pActUndoArray = pUndoArray;
pActUndoArray = pUndoArray.get();
}
~SfxUndoManager_Data()
{
delete pUndoArray;
}
// Copy assignment is forbidden and not implemented.
@ -600,7 +600,7 @@ void SfxUndoManager::ImplClearUndo( UndoManagerGuard& i_guard )
void SfxUndoManager::ImplClearRedo( UndoManagerGuard& i_guard, bool const i_currentLevel )
{
SfxUndoArray* pUndoArray = ( i_currentLevel == IUndoManager::CurrentLevel ) ? m_xData->pActUndoArray : m_xData->pUndoArray;
SfxUndoArray* pUndoArray = ( i_currentLevel == IUndoManager::CurrentLevel ) ? m_xData->pActUndoArray : m_xData->pUndoArray.get();
// clearance
while ( pUndoArray->aUndoActions.size() > pUndoArray->nCurUndoAction )
@ -643,7 +643,7 @@ bool SfxUndoManager::ImplAddUndoAction_NoNotify( SfxUndoAction *pAction, bool bT
ImplClearRedo( i_guard, IUndoManager::CurrentLevel );
// respect max number
if( m_xData->pActUndoArray == m_xData->pUndoArray )
if( m_xData->pActUndoArray == m_xData->pUndoArray.get() )
{
while(m_xData->pActUndoArray->aUndoActions.size() >= m_xData->pActUndoArray->nMaxUndoActions)
{
@ -684,7 +684,7 @@ void SfxUndoManager::AddUndoAction( SfxUndoAction *pAction, bool bTryMerge )
size_t SfxUndoManager::GetUndoActionCount( bool const i_currentLevel ) const
{
UndoManagerGuard aGuard( *m_xData );
const SfxUndoArray* pUndoArray = i_currentLevel ? m_xData->pActUndoArray : m_xData->pUndoArray;
const SfxUndoArray* pUndoArray = i_currentLevel ? m_xData->pActUndoArray : m_xData->pUndoArray.get();
return pUndoArray->nCurUndoAction;
}
@ -694,7 +694,7 @@ OUString SfxUndoManager::GetUndoActionComment( size_t nNo, bool const i_currentL
UndoManagerGuard aGuard( *m_xData );
OUString sComment;
const SfxUndoArray* pUndoArray = i_currentLevel ? m_xData->pActUndoArray : m_xData->pUndoArray;
const SfxUndoArray* pUndoArray = i_currentLevel ? m_xData->pActUndoArray : m_xData->pUndoArray.get();
assert(nNo < pUndoArray->nCurUndoAction);
if( nNo < pUndoArray->nCurUndoAction )
sComment = pUndoArray->aUndoActions[ pUndoArray->nCurUndoAction - 1 - nNo ].pAction->GetComment();
@ -833,7 +833,7 @@ size_t SfxUndoManager::GetRedoActionCount( bool const i_currentLevel ) const
size_t SfxUndoManager::ImplGetRedoActionCount_Lock( bool const i_currentLevel ) const
{
const SfxUndoArray* pUndoArray = i_currentLevel ? m_xData->pActUndoArray : m_xData->pUndoArray;
const SfxUndoArray* pUndoArray = i_currentLevel ? m_xData->pActUndoArray : m_xData->pUndoArray.get();
return pUndoArray->aUndoActions.size() - pUndoArray->nCurUndoAction;
}
@ -855,7 +855,7 @@ OUString SfxUndoManager::GetRedoActionComment( size_t nNo, bool const i_currentL
{
OUString sComment;
UndoManagerGuard aGuard( *m_xData );
const SfxUndoArray* pUndoArray = i_currentLevel ? m_xData->pActUndoArray : m_xData->pUndoArray;
const SfxUndoArray* pUndoArray = i_currentLevel ? m_xData->pActUndoArray : m_xData->pUndoArray.get();
if ( (pUndoArray->nCurUndoAction + nNo) < pUndoArray->aUndoActions.size() )
{
sComment = pUndoArray->aUndoActions[ pUndoArray->nCurUndoAction + nNo ].pAction->GetComment();
@ -1038,7 +1038,7 @@ bool SfxUndoManager::IsInListAction() const
bool SfxUndoManager::ImplIsInListAction_Lock() const
{
return ( m_xData->pActUndoArray != m_xData->pUndoArray );
return ( m_xData->pActUndoArray != m_xData->pUndoArray.get() );
}
@ -1048,7 +1048,7 @@ size_t SfxUndoManager::GetListActionDepth() const
size_t nDepth(0);
SfxUndoArray* pLookup( m_xData->pActUndoArray );
while ( pLookup != m_xData->pUndoArray )
while ( pLookup != m_xData->pUndoArray.get() )
{
pLookup = pLookup->pFatherUndoArray;
++nDepth;

View file

@ -286,7 +286,7 @@ const OUString* NameTranslationList::Translate( const OUString& rName ) const
class NameTranslator_Impl : public ::svt::IContentTitleTranslation
{
private:
NameTranslationList* mpActFolder;
std::unique_ptr<NameTranslationList> mpActFolder;
public:
explicit NameTranslator_Impl( const INetURLObject& rActualFolder );
virtual ~NameTranslator_Impl();
@ -1399,13 +1399,12 @@ void SvtFileView::StateChanged( StateChangedType nStateChange )
NameTranslator_Impl::NameTranslator_Impl( const INetURLObject& rActualFolder )
: mpActFolder( new NameTranslationList( rActualFolder ) )
{
mpActFolder = new NameTranslationList( rActualFolder );
}
NameTranslator_Impl::~NameTranslator_Impl()
{
delete mpActFolder;
}
void NameTranslator_Impl::SetActualFolder( const INetURLObject& rActualFolder )
@ -1414,12 +1413,11 @@ void NameTranslator_Impl::SetActualFolder( const INetURLObject& rActualFolder )
{
if (mpActFolder->GetHashedURL() != rActualFolder.GetMainURL(INetURLObject::DecodeMechanism::NONE))
{
delete mpActFolder;
mpActFolder = new NameTranslationList( rActualFolder );
mpActFolder.reset( new NameTranslationList( rActualFolder ) );
}
}
else
mpActFolder = new NameTranslationList( rActualFolder );
mpActFolder.reset( new NameTranslationList( rActualFolder ) );
}
bool NameTranslator_Impl::GetTranslation( const OUString& rOrg, OUString& rTrans ) const

View file

@ -445,7 +445,7 @@ void AssignmentPersistentData::ImplCommit()
/// the logical field names
std::vector<OUString> aLogicalFieldNames;
IAssigmentData* pConfigData;
std::unique_ptr<IAssigmentData> pConfigData;
AddressBookSourceDialogData( )
@ -474,7 +474,6 @@ void AssignmentPersistentData::ImplCommit()
~AddressBookSourceDialogData()
{
delete pConfigData;
}
// Copy assignment is forbidden and not implemented.
@ -1183,8 +1182,7 @@ void AssignmentPersistentData::ImplCommit()
sName = aFileNotation.get(OFileNotation::N_SYSTEM);
}
m_pDatasource->InsertEntry(sName);
delete m_pImpl->pConfigData;
m_pImpl->pConfigData = new AssignmentPersistentData();
m_pImpl->pConfigData.reset( new AssignmentPersistentData );
loadConfiguration();
resetTables();
// will reset the fields implicitly

View file

@ -150,14 +150,14 @@ SfxErrorHandler::SfxErrorHandler(sal_uInt16 nIdP, sal_uLong lStartP, sal_uLong l
RegisterDisplay(&aWndFunc);
if( ! pMgr )
{
pFreeMgr = pMgr = ResMgr::CreateResMgr("ofa", Application::GetSettings().GetUILanguageTag() );
pMgr = ResMgr::CreateResMgr("ofa", Application::GetSettings().GetUILanguageTag() );
pFreeMgr.reset(pMgr);
}
}
SfxErrorHandler::~SfxErrorHandler()
{
delete pFreeMgr;
}

View file

@ -228,10 +228,10 @@ struct EmbeddedObjectRef_Impl
uno::Reference <embed::XEmbeddedObject> mxObj;
EmbedEventListener_Impl* xListener;
OUString aPersistName;
OUString aMediaType;
OUString aPersistName;
OUString aMediaType;
comphelper::EmbeddedObjectContainer* pContainer;
Graphic* pGraphic;
std::unique_ptr<Graphic> pGraphic;
sal_Int64 nViewAspect;
bool bIsLocked:1;
bool bNeedUpdate:1;
@ -265,12 +265,11 @@ struct EmbeddedObjectRef_Impl
aDefaultSizeForChart_In_100TH_MM(r.aDefaultSizeForChart_In_100TH_MM)
{
if (r.pGraphic && !r.bNeedUpdate)
pGraphic = new Graphic(*r.pGraphic);
pGraphic.reset( new Graphic(*r.pGraphic) );
}
~EmbeddedObjectRef_Impl()
{
delete pGraphic;
}
};
@ -417,14 +416,14 @@ void EmbeddedObjectRef::GetReplacement( bool bUpdate )
{
if ( bUpdate )
{
DELETEZ( mpImpl->pGraphic );
mpImpl->pGraphic.reset();
(mpImpl->aMediaType).clear();
mpImpl->pGraphic = new Graphic;
mpImpl->pGraphic.reset( new Graphic );
mpImpl->mnGraphicVersion++;
}
else if ( !mpImpl->pGraphic )
{
mpImpl->pGraphic = new Graphic;
mpImpl->pGraphic.reset( new Graphic );
mpImpl->mnGraphicVersion++;
}
else
@ -458,7 +457,7 @@ const Graphic* EmbeddedObjectRef::GetGraphic() const
SAL_WARN("svtools.misc", "Something went wrong on getting the graphic: " << ex.Message);
}
return mpImpl->pGraphic;
return mpImpl->pGraphic.get();
}
Size EmbeddedObjectRef::GetSize( MapMode* pTargetMapMode ) const
@ -523,9 +522,7 @@ Size EmbeddedObjectRef::GetSize( MapMode* pTargetMapMode ) const
void EmbeddedObjectRef::SetGraphicStream( const uno::Reference< io::XInputStream >& xInGrStream,
const OUString& rMediaType )
{
if ( mpImpl->pGraphic )
delete mpImpl->pGraphic;
mpImpl->pGraphic = new Graphic();
mpImpl->pGraphic.reset( new Graphic );
mpImpl->aMediaType = rMediaType;
mpImpl->mnGraphicVersion++;
@ -552,9 +549,7 @@ void EmbeddedObjectRef::SetGraphicStream( const uno::Reference< io::XInputStream
void EmbeddedObjectRef::SetGraphic( const Graphic& rGraphic, const OUString& rMediaType )
{
if ( mpImpl->pGraphic )
delete mpImpl->pGraphic;
mpImpl->pGraphic = new Graphic( rGraphic );
mpImpl->pGraphic.reset( new Graphic( rGraphic ) );
mpImpl->aMediaType = rMediaType;
mpImpl->mnGraphicVersion++;
@ -837,7 +832,7 @@ void EmbeddedObjectRef::UpdateReplacement()
void EmbeddedObjectRef::UpdateReplacementOnDemand()
{
DELETEZ( mpImpl->pGraphic );
mpImpl->pGraphic.reset();
mpImpl->bNeedUpdate = true;
mpImpl->mnGraphicVersion++;

View file

@ -110,7 +110,6 @@ DropTargetHelper::DropTargetListener::DropTargetListener( DropTargetHelper& rDro
DropTargetHelper::DropTargetListener::~DropTargetListener()
{
delete mpLastDragOverEvent;
}
@ -156,11 +155,7 @@ void SAL_CALL DropTargetHelper::DropTargetListener::drop( const DropTargetDropEv
rDTDE.Context->dropComplete( DNDConstants::ACTION_NONE != nRet );
if( mpLastDragOverEvent )
{
delete mpLastDragOverEvent;
mpLastDragOverEvent = nullptr;
}
mpLastDragOverEvent.reset();
}
catch( const css::uno::Exception& )
{
@ -190,9 +185,7 @@ void SAL_CALL DropTargetHelper::DropTargetListener::dragOver( const DropTargetDr
try
{
delete mpLastDragOverEvent;
mpLastDragOverEvent = new AcceptDropEvent( rDTDE.DropAction & ~DNDConstants::ACTION_DEFAULT, Point( rDTDE.LocationX, rDTDE.LocationY ), rDTDE );
mpLastDragOverEvent.reset( new AcceptDropEvent( rDTDE.DropAction & ~DNDConstants::ACTION_DEFAULT, Point( rDTDE.LocationX, rDTDE.LocationY ), rDTDE ) );
mpLastDragOverEvent->mbDefault = ( ( rDTDE.DropAction & DNDConstants::ACTION_DEFAULT ) != 0 );
const sal_Int8 nRet = mrParent.AcceptDrop( *mpLastDragOverEvent );
@ -218,8 +211,7 @@ void SAL_CALL DropTargetHelper::DropTargetListener::dragExit( const DropTargetEv
{
mpLastDragOverEvent->mbLeaving = true;
mrParent.AcceptDrop( *mpLastDragOverEvent );
delete mpLastDragOverEvent;
mpLastDragOverEvent = nullptr;
mpLastDragOverEvent.reset();
}
mrParent.ImplEndDrag();