Kaydet (Commit) e57a0369 authored tarafından Noel Grandin's avatar Noel Grandin

loplugin:useuniqueptr in tools,stoc,unotools

Change-Id: Ia72b65577143623cedc7a40bc34f7fb897add097
Reviewed-on: https://gerrit.libreoffice.org/47726Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst cb5d79b5
...@@ -112,6 +112,11 @@ void UseUniquePtr::CheckForUnconditionalDelete(const CXXDestructorDecl* destruct ...@@ -112,6 +112,11 @@ void UseUniquePtr::CheckForUnconditionalDelete(const CXXDestructorDecl* destruct
// @TODO it's sharing pointers with another class // @TODO it's sharing pointers with another class
if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/sc/inc/formulacell.hxx")) if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/sc/inc/formulacell.hxx"))
continue; continue;
// some weird stuff going on here around struct Entity
if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/sax/"))
continue;
if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/include/sax/"))
continue;
report( report(
DiagnosticsEngine::Warning, DiagnosticsEngine::Warning,
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <tools/stream.hxx> #include <tools/stream.hxx>
#include <sal/types.h> #include <sal/types.h>
#include <vector> #include <vector>
#include <memory>
class INetMIMEMessage; class INetMIMEMessage;
class SvStream; class SvStream;
...@@ -36,7 +37,8 @@ class TOOLS_DLLPUBLIC INetMIMEMessageStream ...@@ -36,7 +37,8 @@ class TOOLS_DLLPUBLIC INetMIMEMessageStream
sal_Char *pRead; sal_Char *pRead;
sal_Char *pWrite; sal_Char *pWrite;
SvStream *pMsgStrm; std::unique_ptr<SvStream>
pMsgStrm;
SvMemoryStream maMsgBuffer; SvMemoryStream maMsgBuffer;
sal_Char *pMsgRead; sal_Char *pMsgRead;
sal_Char *pMsgWrite; sal_Char *pMsgWrite;
...@@ -44,7 +46,7 @@ class TOOLS_DLLPUBLIC INetMIMEMessageStream ...@@ -44,7 +46,7 @@ class TOOLS_DLLPUBLIC INetMIMEMessageStream
bool done; bool done;
sal_uInt32 nChildIndex; sal_uInt32 nChildIndex;
INetMIMEMessageStream *pChildStrm; std::unique_ptr<INetMIMEMessageStream> pChildStrm;
INetMIMEMessageStream (const INetMIMEMessageStream& rStrm) = delete; INetMIMEMessageStream (const INetMIMEMessageStream& rStrm) = delete;
INetMIMEMessageStream& operator= (const INetMIMEMessageStream& rStrm) = delete; INetMIMEMessageStream& operator= (const INetMIMEMessageStream& rStrm) = delete;
......
...@@ -26,14 +26,13 @@ ...@@ -26,14 +26,13 @@
#include <vector> #include <vector>
#include <set> #include <set>
typedef ::std::vector< Range* > ImpSelList;
#define SFX_ENDOFSELECTION SAL_MAX_INT32 #define SFX_ENDOFSELECTION SAL_MAX_INT32
class SAL_WARN_UNUSED TOOLS_DLLPUBLIC MultiSelection class SAL_WARN_UNUSED TOOLS_DLLPUBLIC MultiSelection
{ {
private: private:
ImpSelList aSels; // array of SV-selections std::vector< Range >
aSels; // array of SV-selections
Range aTotRange; // total range of indexes Range aTotRange; // total range of indexes
sal_Int32 nCurSubSel; // index in aSels of current selected index sal_Int32 nCurSubSel; // index in aSels of current selected index
sal_Int32 nCurIndex; // current selected entry sal_Int32 nCurIndex; // current selected entry
...@@ -72,7 +71,7 @@ public: ...@@ -72,7 +71,7 @@ public:
sal_Int32 NextSelected(); sal_Int32 NextSelected();
sal_Int32 GetRangeCount() const { return aSels.size(); } sal_Int32 GetRangeCount() const { return aSels.size(); }
const Range& GetRange( sal_Int32 nRange ) const { return *aSels[nRange]; } const Range& GetRange( sal_Int32 nRange ) const { return aSels[nRange]; }
}; };
class SAL_WARN_UNUSED TOOLS_DLLPUBLIC StringRangeEnumerator class SAL_WARN_UNUSED TOOLS_DLLPUBLIC StringRangeEnumerator
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <vcl/errcode.hxx> #include <vcl/errcode.hxx>
#include <rtl/string.hxx> #include <rtl/string.hxx>
#include <o3tl/typed_flags_set.hxx> #include <o3tl/typed_flags_set.hxx>
#include <memory>
class StreamData; class StreamData;
...@@ -143,7 +144,8 @@ private: ...@@ -143,7 +144,8 @@ private:
sal_uInt64 m_nActPos; sal_uInt64 m_nActPos;
// buffer management // buffer management
sal_uInt8* m_pRWBuf; ///< Points to read/write buffer std::unique_ptr<sal_uInt8>
m_pRWBuf; ///< Points to read/write buffer
sal_uInt8* m_pBufPos; ///< m_pRWBuf + m_nBufActualPos sal_uInt8* m_pBufPos; ///< m_pRWBuf + m_nBufActualPos
sal_uInt16 m_nBufSize; ///< Allocated size of buffer sal_uInt16 m_nBufSize; ///< Allocated size of buffer
sal_uInt16 m_nBufActualLen; ///< Length of used segment of puffer sal_uInt16 m_nBufActualLen; ///< Length of used segment of puffer
...@@ -582,7 +584,8 @@ TOOLS_DLLPUBLIC bool checkSeek(SvStream &rSt, sal_uInt64 nOffset) SAL_WARN_UNUSE ...@@ -582,7 +584,8 @@ TOOLS_DLLPUBLIC bool checkSeek(SvStream &rSt, sal_uInt64 nOffset) SAL_WARN_UNUSE
class TOOLS_DLLPUBLIC SvFileStream : public SvStream class TOOLS_DLLPUBLIC SvFileStream : public SvStream
{ {
private: private:
StreamData* pInstanceData; std::unique_ptr<StreamData>
pInstanceData;
OUString aFilename; OUString aFilename;
#if defined(_WIN32) #if defined(_WIN32)
sal_uInt16 nLockCounter; sal_uInt16 nLockCounter;
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <unotools/collatorwrapper.hxx> #include <unotools/collatorwrapper.hxx>
#include <i18nlangtag/lang.h> #include <i18nlangtag/lang.h>
#include <i18nlangtag/languagetag.hxx> #include <i18nlangtag/languagetag.hxx>
#include <memory>
/** /**
A wrapper of I18N wrappers. Using this is more expensive than using some A wrapper of I18N wrappers. Using this is more expensive than using some
...@@ -50,9 +51,9 @@ private: ...@@ -50,9 +51,9 @@ private:
LanguageTag maLanguageTag; LanguageTag maLanguageTag;
css::uno::Reference< css::uno::XComponentContext > m_xContext; css::uno::Reference< css::uno::XComponentContext > m_xContext;
LocaleDataWrapper* pLocaleData; std::unique_ptr<LocaleDataWrapper> pLocaleData;
CollatorWrapper* pCollator; std::unique_ptr<CollatorWrapper> pCollator;
CollatorWrapper* pCaseCollator; std::unique_ptr<CollatorWrapper> pCaseCollator;
void ImplNewLocaleData() const; void ImplNewLocaleData() const;
void ImplNewCollator( bool bCaseSensitive ) const; void ImplNewCollator( bool bCaseSensitive ) const;
...@@ -65,21 +66,21 @@ public: ...@@ -65,21 +66,21 @@ public:
{ {
if ( !pLocaleData ) if ( !pLocaleData )
ImplNewLocaleData(); ImplNewLocaleData();
return pLocaleData; return pLocaleData.get();
} }
/// case insensitive collator, simple IGNORE_CASE /// case insensitive collator, simple IGNORE_CASE
const CollatorWrapper* getCollator() const const CollatorWrapper* getCollator() const
{ {
if ( !pCollator ) if ( !pCollator )
ImplNewCollator( false ); ImplNewCollator( false );
return pCollator; return pCollator.get();
} }
/// case sensitive collator /// case sensitive collator
const CollatorWrapper* getCaseCollator() const const CollatorWrapper* getCaseCollator() const
{ {
if ( !pCaseCollator ) if ( !pCaseCollator )
ImplNewCollator( true ); ImplNewCollator( true );
return pCaseCollator; return pCaseCollator.get();
} }
}; };
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <unotools/unotoolsdllapi.h> #include <unotools/unotoolsdllapi.h>
#include <tools/stream.hxx> #include <tools/stream.hxx>
#include <memory>
namespace utl namespace utl
{ {
...@@ -45,7 +46,8 @@ namespace utl ...@@ -45,7 +46,8 @@ namespace utl
class UNOTOOLS_DLLPUBLIC TempFile class UNOTOOLS_DLLPUBLIC TempFile
{ {
OUString aName; OUString aName;
SvStream* pStream; std::unique_ptr<SvStream>
pStream;
bool bIsDirectory; bool bIsDirectory;
bool bKillingFileEnabled; bool bKillingFileEnabled;
......
...@@ -197,7 +197,7 @@ class InterfaceIdlClassImpl ...@@ -197,7 +197,7 @@ class InterfaceIdlClassImpl
css::uno::Sequence< css::uno::Reference< css::reflection::XIdlClass > > _xSuperClasses; css::uno::Sequence< css::uno::Reference< css::reflection::XIdlClass > > _xSuperClasses;
MemberInit * _pSortedMemberInit; // first methods, then attributes std::unique_ptr<MemberInit[]> _pSortedMemberInit; // first methods, then attributes
OUString2Field _aName2Field; OUString2Field _aName2Field;
OUString2Method _aName2Method; OUString2Method _aName2Method;
sal_Int32 _nMethods; sal_Int32 _nMethods;
......
...@@ -327,9 +327,9 @@ class IdlInterfaceMethodImpl ...@@ -327,9 +327,9 @@ class IdlInterfaceMethodImpl
: public IdlMemberImpl : public IdlMemberImpl
, public XIdlMethod , public XIdlMethod
{ {
Sequence< Reference< XIdlClass > > * _pExceptionTypes; std::unique_ptr<Sequence< Reference< XIdlClass > >> _pExceptionTypes;
Sequence< Reference< XIdlClass > > * _pParamTypes; std::unique_ptr<Sequence< Reference< XIdlClass > >> _pParamTypes;
Sequence< ParamInfo > * _pParamInfos; std::unique_ptr<Sequence< ParamInfo >> _pParamInfos;
public: public:
typelib_InterfaceMethodTypeDescription * getMethodTypeDescr() const typelib_InterfaceMethodTypeDescription * getMethodTypeDescr() const
...@@ -338,11 +338,7 @@ public: ...@@ -338,11 +338,7 @@ public:
IdlInterfaceMethodImpl( IdlReflectionServiceImpl * pReflection, const OUString & rName, IdlInterfaceMethodImpl( IdlReflectionServiceImpl * pReflection, const OUString & rName,
typelib_TypeDescription * pTypeDescr, typelib_TypeDescription * pDeclTypeDescr ) typelib_TypeDescription * pTypeDescr, typelib_TypeDescription * pDeclTypeDescr )
: IdlMemberImpl( pReflection, rName, pTypeDescr, pDeclTypeDescr ) : IdlMemberImpl( pReflection, rName, pTypeDescr, pDeclTypeDescr )
, _pExceptionTypes( nullptr )
, _pParamTypes( nullptr )
, _pParamInfos( nullptr )
{} {}
virtual ~IdlInterfaceMethodImpl() override;
// XInterface // XInterface
virtual Any SAL_CALL queryInterface( const Type & rType ) override; virtual Any SAL_CALL queryInterface( const Type & rType ) override;
...@@ -365,13 +361,6 @@ public: ...@@ -365,13 +361,6 @@ public:
virtual Any SAL_CALL invoke( const Any & rObj, Sequence< Any > & rArgs ) override; virtual Any SAL_CALL invoke( const Any & rObj, Sequence< Any > & rArgs ) override;
}; };
IdlInterfaceMethodImpl::~IdlInterfaceMethodImpl()
{
delete _pParamInfos;
delete _pParamTypes;
delete _pExceptionTypes;
}
// XInterface // XInterface
Any IdlInterfaceMethodImpl::queryInterface( const Type & rType ) Any IdlInterfaceMethodImpl::queryInterface( const Type & rType )
...@@ -452,8 +441,8 @@ Sequence< Reference< XIdlClass > > IdlInterfaceMethodImpl::getExceptionTypes() ...@@ -452,8 +441,8 @@ Sequence< Reference< XIdlClass > > IdlInterfaceMethodImpl::getExceptionTypes()
if (! _pExceptionTypes) if (! _pExceptionTypes)
{ {
sal_Int32 nExc = getMethodTypeDescr()->nExceptions; sal_Int32 nExc = getMethodTypeDescr()->nExceptions;
Sequence< Reference< XIdlClass > > * pTempExceptionTypes = std::unique_ptr<Sequence< Reference< XIdlClass > >> pTempExceptionTypes(
new Sequence< Reference< XIdlClass > >( nExc ); new Sequence< Reference< XIdlClass > >( nExc ));
Reference< XIdlClass > * pExceptionTypes = pTempExceptionTypes->getArray(); Reference< XIdlClass > * pExceptionTypes = pTempExceptionTypes->getArray();
typelib_TypeDescriptionReference ** ppExc = typelib_TypeDescriptionReference ** ppExc =
...@@ -463,7 +452,7 @@ Sequence< Reference< XIdlClass > > IdlInterfaceMethodImpl::getExceptionTypes() ...@@ -463,7 +452,7 @@ Sequence< Reference< XIdlClass > > IdlInterfaceMethodImpl::getExceptionTypes()
while (nExc--) while (nExc--)
pExceptionTypes[nExc] = pRefl->forType( ppExc[nExc] ); pExceptionTypes[nExc] = pRefl->forType( ppExc[nExc] );
_pExceptionTypes = pTempExceptionTypes; _pExceptionTypes = std::move(pTempExceptionTypes);
} }
} }
return *_pExceptionTypes; return *_pExceptionTypes;
...@@ -477,8 +466,8 @@ Sequence< Reference< XIdlClass > > IdlInterfaceMethodImpl::getParameterTypes() ...@@ -477,8 +466,8 @@ Sequence< Reference< XIdlClass > > IdlInterfaceMethodImpl::getParameterTypes()
if (! _pParamTypes) if (! _pParamTypes)
{ {
sal_Int32 nParams = getMethodTypeDescr()->nParams; sal_Int32 nParams = getMethodTypeDescr()->nParams;
Sequence< Reference< XIdlClass > > * pTempParamTypes = std::unique_ptr<Sequence< Reference< XIdlClass > > > pTempParamTypes(
new Sequence< Reference< XIdlClass > >( nParams ); new Sequence< Reference< XIdlClass > >( nParams ));
Reference< XIdlClass > * pParamTypes = pTempParamTypes->getArray(); Reference< XIdlClass > * pParamTypes = pTempParamTypes->getArray();
typelib_MethodParameter * pTypelibParams = typelib_MethodParameter * pTypelibParams =
...@@ -488,7 +477,7 @@ Sequence< Reference< XIdlClass > > IdlInterfaceMethodImpl::getParameterTypes() ...@@ -488,7 +477,7 @@ Sequence< Reference< XIdlClass > > IdlInterfaceMethodImpl::getParameterTypes()
while (nParams--) while (nParams--)
pParamTypes[nParams] = pRefl->forType( pTypelibParams[nParams].pTypeRef ); pParamTypes[nParams] = pRefl->forType( pTypelibParams[nParams].pTypeRef );
_pParamTypes = pTempParamTypes; _pParamTypes = std::move(pTempParamTypes);
} }
} }
return *_pParamTypes; return *_pParamTypes;
...@@ -502,7 +491,7 @@ Sequence< ParamInfo > IdlInterfaceMethodImpl::getParameterInfos() ...@@ -502,7 +491,7 @@ Sequence< ParamInfo > IdlInterfaceMethodImpl::getParameterInfos()
if (! _pParamInfos) if (! _pParamInfos)
{ {
sal_Int32 nParams = getMethodTypeDescr()->nParams; sal_Int32 nParams = getMethodTypeDescr()->nParams;
Sequence< ParamInfo > * pTempParamInfos = new Sequence< ParamInfo >( nParams ); std::unique_ptr<Sequence< ParamInfo > > pTempParamInfos( new Sequence< ParamInfo >( nParams ) );
ParamInfo * pParamInfos = pTempParamInfos->getArray(); ParamInfo * pParamInfos = pTempParamInfos->getArray();
typelib_MethodParameter * pTypelibParams = typelib_MethodParameter * pTypelibParams =
...@@ -526,8 +515,8 @@ Sequence< ParamInfo > IdlInterfaceMethodImpl::getParameterInfos() ...@@ -526,8 +515,8 @@ Sequence< ParamInfo > IdlInterfaceMethodImpl::getParameterInfos()
} }
else // make also param types sequence if not already initialized else // make also param types sequence if not already initialized
{ {
Sequence< Reference< XIdlClass > > * pTempParamTypes = std::unique_ptr<Sequence< Reference< XIdlClass > > > pTempParamTypes(
new Sequence< Reference< XIdlClass > >( nParams ); new Sequence< Reference< XIdlClass > >( nParams ));
Reference< XIdlClass > * pParamTypes = pTempParamTypes->getArray(); Reference< XIdlClass > * pParamTypes = pTempParamTypes->getArray();
IdlReflectionServiceImpl * pRefl = getReflection(); IdlReflectionServiceImpl * pRefl = getReflection();
...@@ -544,10 +533,10 @@ Sequence< ParamInfo > IdlInterfaceMethodImpl::getParameterInfos() ...@@ -544,10 +533,10 @@ Sequence< ParamInfo > IdlInterfaceMethodImpl::getParameterInfos()
rInfo.aType = pParamTypes[nParams] = pRefl->forType( rParam.pTypeRef ); rInfo.aType = pParamTypes[nParams] = pRefl->forType( rParam.pTypeRef );
} }
_pParamTypes = pTempParamTypes; _pParamTypes = std::move(pTempParamTypes);
} }
_pParamInfos = pTempParamInfos; _pParamInfos = std::move(pTempParamInfos);
} }
} }
return *_pParamInfos; return *_pParamInfos;
...@@ -759,8 +748,6 @@ InterfaceIdlClassImpl::~InterfaceIdlClassImpl() ...@@ -759,8 +748,6 @@ InterfaceIdlClassImpl::~InterfaceIdlClassImpl()
{ {
for ( sal_Int32 nPos = _nMethods + _nAttributes; nPos--; ) for ( sal_Int32 nPos = _nMethods + _nAttributes; nPos--; )
typelib_typedescription_release( _pSortedMemberInit[nPos].second ); typelib_typedescription_release( _pSortedMemberInit[nPos].second );
delete [] _pSortedMemberInit;
} }
...@@ -782,7 +769,7 @@ Sequence< Reference< XIdlClass > > InterfaceIdlClassImpl::getSuperclasses() ...@@ -782,7 +769,7 @@ Sequence< Reference< XIdlClass > > InterfaceIdlClassImpl::getSuperclasses()
void InterfaceIdlClassImpl::initMembers() void InterfaceIdlClassImpl::initMembers()
{ {
sal_Int32 nAll = getTypeDescr()->nAllMembers; sal_Int32 nAll = getTypeDescr()->nAllMembers;
MemberInit * pSortedMemberInit = new MemberInit[nAll]; std::unique_ptr<MemberInit[]> pSortedMemberInit(new MemberInit[nAll]);
typelib_TypeDescriptionReference ** ppAllMembers = getTypeDescr()->ppAllMembers; typelib_TypeDescriptionReference ** ppAllMembers = getTypeDescr()->ppAllMembers;
for ( sal_Int32 nPos = 0; nPos < nAll; ++nPos ) for ( sal_Int32 nPos = 0; nPos < nAll; ++nPos )
...@@ -808,7 +795,7 @@ void InterfaceIdlClassImpl::initMembers() ...@@ -808,7 +795,7 @@ void InterfaceIdlClassImpl::initMembers()
pSortedMemberInit[nIndex].second = pTD; pSortedMemberInit[nIndex].second = pTD;
} }
_pSortedMemberInit = pSortedMemberInit; _pSortedMemberInit = std::move(pSortedMemberInit);
} }
sal_Bool InterfaceIdlClassImpl::isAssignableFrom( const Reference< XIdlClass > & xType ) sal_Bool InterfaceIdlClassImpl::isAssignableFrom( const Reference< XIdlClass > & xType )
......
...@@ -79,7 +79,7 @@ int INetMIMEMessageStream::GetBodyLine(sal_Char* pData, sal_uInt32 nSize) ...@@ -79,7 +79,7 @@ int INetMIMEMessageStream::GetBodyLine(sal_Char* pData, sal_uInt32 nSize)
if (pSourceMsg->GetDocumentLB()) if (pSourceMsg->GetDocumentLB())
{ {
if (pMsgStrm == nullptr) if (pMsgStrm == nullptr)
pMsgStrm = new SvStream (pSourceMsg->GetDocumentLB()); pMsgStrm.reset(new SvStream (pSourceMsg->GetDocumentLB()));
sal_uInt32 nRead = pMsgStrm->ReadBytes(pWBuf, (pWEnd - pWBuf)); sal_uInt32 nRead = pMsgStrm->ReadBytes(pWBuf, (pWEnd - pWBuf));
pWBuf += nRead; pWBuf += nRead;
...@@ -156,7 +156,7 @@ int INetMIMEMessageStream::GetMsgLine(sal_Char* pData, sal_uInt32 nSize) ...@@ -156,7 +156,7 @@ int INetMIMEMessageStream::GetMsgLine(sal_Char* pData, sal_uInt32 nSize)
nChildIndex++; nChildIndex++;
// Create child stream. // Create child stream.
pChildStrm = new INetMIMEMessageStream(pChild, false); pChildStrm.reset(new INetMIMEMessageStream(pChild, false));
if (pSourceMsg->IsMultipart()) if (pSourceMsg->IsMultipart())
{ {
...@@ -200,8 +200,7 @@ int INetMIMEMessageStream::GetMsgLine(sal_Char* pData, sal_uInt32 nSize) ...@@ -200,8 +200,7 @@ int INetMIMEMessageStream::GetMsgLine(sal_Char* pData, sal_uInt32 nSize)
else else
{ {
// Cleanup exhausted child stream. // Cleanup exhausted child stream.
delete pChildStrm; pChildStrm.reset();
pChildStrm = nullptr;
} }
} }
} }
...@@ -248,8 +247,7 @@ INetMIMEMessageStream::INetMIMEMessageStream( ...@@ -248,8 +247,7 @@ INetMIMEMessageStream::INetMIMEMessageStream(
INetMIMEMessageStream::~INetMIMEMessageStream() INetMIMEMessageStream::~INetMIMEMessageStream()
{ {
delete pChildStrm; pChildStrm.reset();
delete pMsgStrm;
} }
int INetMIMEMessageStream::Read(sal_Char* pData, sal_uInt32 nSize) int INetMIMEMessageStream::Read(sal_Char* pData, sal_uInt32 nSize)
......
...@@ -368,8 +368,6 @@ SvStream::~SvStream() ...@@ -368,8 +368,6 @@ SvStream::~SvStream()
{ {
if (m_xLockBytes.is()) if (m_xLockBytes.is())
Flush(); Flush();
delete[] m_pRWBuf;
} }
void SvStream::ClearError() void SvStream::ClearError()
...@@ -407,7 +405,7 @@ void SvStream::SetBufferSize( sal_uInt16 nBufferSize ) ...@@ -407,7 +405,7 @@ void SvStream::SetBufferSize( sal_uInt16 nBufferSize )
if (m_nBufSize) if (m_nBufSize)
{ {
delete[] m_pRWBuf; m_pRWBuf.reset();
m_nBufFilePos += m_nBufActualPos; m_nBufFilePos += m_nBufActualPos;
} }
...@@ -416,9 +414,9 @@ void SvStream::SetBufferSize( sal_uInt16 nBufferSize ) ...@@ -416,9 +414,9 @@ void SvStream::SetBufferSize( sal_uInt16 nBufferSize )
m_nBufActualPos = 0; m_nBufActualPos = 0;
m_nBufSize = nBufferSize; m_nBufSize = nBufferSize;
if (m_nBufSize) if (m_nBufSize)
m_pRWBuf = new sal_uInt8[ m_nBufSize ]; m_pRWBuf.reset(new sal_uInt8[ m_nBufSize ]);
m_isConsistent = true; m_isConsistent = true;
m_pBufPos = m_pRWBuf; m_pBufPos = m_pRWBuf.get();
m_isIoRead = m_isIoWrite = false; m_isIoRead = m_isIoWrite = false;
if( !bDontSeek ) if( !bDontSeek )
SeekPos( nActualFilePos ); SeekPos( nActualFilePos );
...@@ -429,7 +427,7 @@ void SvStream::ClearBuffer() ...@@ -429,7 +427,7 @@ void SvStream::ClearBuffer()
m_nBufActualLen = 0; m_nBufActualLen = 0;
m_nBufActualPos = 0; m_nBufActualPos = 0;
m_nBufFilePos = 0; m_nBufFilePos = 0;
m_pBufPos = m_pRWBuf; m_pBufPos = m_pRWBuf.get();
m_isDirty = false; m_isDirty = false;
m_isConsistent = true; m_isConsistent = true;
m_isIoRead = m_isIoWrite = false; m_isIoRead = m_isIoWrite = false;
...@@ -809,7 +807,7 @@ sal_uInt64 SvStream::SeekRel(sal_Int64 const nPos) ...@@ -809,7 +807,7 @@ sal_uInt64 SvStream::SeekRel(sal_Int64 const nPos)
nActualPos -= nAbsPos; nActualPos -= nAbsPos;
} }
m_pBufPos = m_pRWBuf + nActualPos; m_pBufPos = m_pRWBuf.get() + nActualPos;
return Seek( nActualPos ); return Seek( nActualPos );
} }
...@@ -1225,8 +1223,8 @@ void SvStream::FlushBuffer(bool isConsistent) ...@@ -1225,8 +1223,8 @@ void SvStream::FlushBuffer(bool isConsistent)
{ {
SeekPos(m_nBufFilePos); SeekPos(m_nBufFilePos);
if (m_nCryptMask) if (m_nCryptMask)
CryptAndWriteBuffer(m_pRWBuf, m_nBufActualLen); CryptAndWriteBuffer(m_pRWBuf.get(), m_nBufActualLen);
else if (PutData(m_pRWBuf, m_nBufActualLen) != m_nBufActualLen) else if (PutData(m_pRWBuf.get(), m_nBufActualLen) != m_nBufActualLen)
SetError(SVSTREAM_WRITE_ERROR); SetError(SVSTREAM_WRITE_ERROR);
m_isDirty = false; m_isDirty = false;
} }
...@@ -1273,7 +1271,7 @@ std::size_t SvStream::ReadBytes( void* pData, std::size_t nCount ) ...@@ -1273,7 +1271,7 @@ std::size_t SvStream::ReadBytes( void* pData, std::size_t nCount )
SeekPos(m_nBufFilePos + m_nBufActualPos); SeekPos(m_nBufFilePos + m_nBufActualPos);
m_nBufActualLen = 0; m_nBufActualLen = 0;
m_pBufPos = m_pRWBuf; m_pBufPos = m_pRWBuf.get();
nCount = GetData( pData, nCount ); nCount = GetData( pData, nCount );
if (m_nCryptMask) if (m_nCryptMask)
EncryptBuffer(pData, nCount); EncryptBuffer(pData, nCount);
...@@ -1289,17 +1287,17 @@ std::size_t SvStream::ReadBytes( void* pData, std::size_t nCount ) ...@@ -1289,17 +1287,17 @@ std::size_t SvStream::ReadBytes( void* pData, std::size_t nCount )
SeekPos(m_nBufFilePos); SeekPos(m_nBufFilePos);
// TODO: Typecast before GetData, sal_uInt16 nCountTmp // TODO: Typecast before GetData, sal_uInt16 nCountTmp
std::size_t nCountTmp = GetData( m_pRWBuf, m_nBufSize ); std::size_t nCountTmp = GetData( m_pRWBuf.get(), m_nBufSize );
if (m_nCryptMask) if (m_nCryptMask)
EncryptBuffer(m_pRWBuf, nCountTmp); EncryptBuffer(m_pRWBuf.get(), nCountTmp);
m_nBufActualLen = (sal_uInt16)nCountTmp; m_nBufActualLen = (sal_uInt16)nCountTmp;
if( nCount > nCountTmp ) if( nCount > nCountTmp )
{ {
nCount = nCountTmp; // trim count back, EOF see below nCount = nCountTmp; // trim count back, EOF see below
} }
memcpy( pData, m_pRWBuf, (size_t)nCount ); memcpy( pData, m_pRWBuf.get(), (size_t)nCount );
m_nBufActualPos = (sal_uInt16)nCount; m_nBufActualPos = (sal_uInt16)nCount;
m_pBufPos = m_pRWBuf + nCount; m_pBufPos = m_pRWBuf.get() + nCount;
} }
} }
} }
...@@ -1359,7 +1357,7 @@ std::size_t SvStream::WriteBytes( const void* pData, std::size_t nCount ) ...@@ -1359,7 +1357,7 @@ std::size_t SvStream::WriteBytes( const void* pData, std::size_t nCount )
m_nBufFilePos += m_nBufActualPos; m_nBufFilePos += m_nBufActualPos;
m_nBufActualLen = 0; m_nBufActualLen = 0;
m_nBufActualPos = 0; m_nBufActualPos = 0;
m_pBufPos = m_pRWBuf; m_pBufPos = m_pRWBuf.get();
SeekPos(m_nBufFilePos); SeekPos(m_nBufFilePos);
if (m_nCryptMask) if (m_nCryptMask)
nCount = CryptAndWriteBuffer( pData, nCount ); nCount = CryptAndWriteBuffer( pData, nCount );
...@@ -1370,12 +1368,12 @@ std::size_t SvStream::WriteBytes( const void* pData, std::size_t nCount ) ...@@ -1370,12 +1368,12 @@ std::size_t SvStream::WriteBytes( const void* pData, std::size_t nCount )
else else
{ {
// Copy block to buffer // Copy block to buffer
memcpy( m_pRWBuf, pData, (size_t)nCount ); memcpy( m_pRWBuf.get(), pData, (size_t)nCount );
// Mind the order! // Mind the order!
m_nBufFilePos += m_nBufActualPos; m_nBufFilePos += m_nBufActualPos;
m_nBufActualPos = (sal_uInt16)nCount; m_nBufActualPos = (sal_uInt16)nCount;
m_pBufPos = m_pRWBuf + nCount; m_pBufPos = m_pRWBuf.get() + nCount;
m_nBufActualLen = (sal_uInt16)nCount; m_nBufActualLen = (sal_uInt16)nCount;
m_isDirty = true; m_isDirty = true;
} }
...@@ -1399,7 +1397,7 @@ sal_uInt64 SvStream::Seek(sal_uInt64 const nFilePos) ...@@ -1399,7 +1397,7 @@ sal_uInt64 SvStream::Seek(sal_uInt64 const nFilePos)
if (nFilePos >= m_nBufFilePos && nFilePos <= (m_nBufFilePos + m_nBufActualLen)) if (nFilePos >= m_nBufFilePos && nFilePos <= (m_nBufFilePos + m_nBufActualLen))
{ {
m_nBufActualPos = (sal_uInt16)(nFilePos - m_nBufFilePos); m_nBufActualPos = (sal_uInt16)(nFilePos - m_nBufFilePos);
m_pBufPos = m_pRWBuf + m_nBufActualPos; m_pBufPos = m_pRWBuf.get() + m_nBufActualPos;
// Update m_nBufFree to avoid crash upon PutBack // Update m_nBufFree to avoid crash upon PutBack
m_nBufFree = m_nBufActualLen - m_nBufActualPos; m_nBufFree = m_nBufActualLen - m_nBufActualPos;
} }
...@@ -1408,7 +1406,7 @@ sal_uInt64 SvStream::Seek(sal_uInt64 const nFilePos) ...@@ -1408,7 +1406,7 @@ sal_uInt64 SvStream::Seek(sal_uInt64 const nFilePos)
FlushBuffer(m_isConsistent); FlushBuffer(m_isConsistent);
m_nBufActualLen = 0; m_nBufActualLen = 0;
m_nBufActualPos = 0; m_nBufActualPos = 0;
m_pBufPos = m_pRWBuf; m_pBufPos = m_pRWBuf.get();
m_nBufFilePos = SeekPos( nFilePos ); m_nBufFilePos = SeekPos( nFilePos );
} }
return m_nBufFilePos + m_nBufActualPos; return m_nBufFilePos + m_nBufActualPos;
...@@ -1443,11 +1441,11 @@ void SvStream::RefreshBuffer() ...@@ -1443,11 +1441,11 @@ void SvStream::RefreshBuffer()
{ {
FlushBuffer(m_isConsistent); FlushBuffer(m_isConsistent);
SeekPos(m_nBufFilePos); SeekPos(m_nBufFilePos);
m_nBufActualLen = (sal_uInt16)GetData( m_pRWBuf, m_nBufSize ); m_nBufActualLen = (sal_uInt16)GetData( m_pRWBuf.get(), m_nBufSize );
if (m_nBufActualLen && m_nError == ERRCODE_IO_PENDING) if (m_nBufActualLen && m_nError == ERRCODE_IO_PENDING)
m_nError = ERRCODE_NONE; m_nError = ERRCODE_NONE;
if (m_nCryptMask) if (m_nCryptMask)
EncryptBuffer(m_pRWBuf, (std::size_t)m_nBufActualLen); EncryptBuffer(m_pRWBuf.get(), (std::size_t)m_nBufActualLen);
m_isConsistent = true; m_isConsistent = true;
m_isIoRead = m_isIoWrite = false; m_isIoRead = m_isIoWrite = false;
} }
......
...@@ -273,7 +273,7 @@ SvFileStream::SvFileStream( const OUString& rFileName, StreamMode nOpenMode ) ...@@ -273,7 +273,7 @@ SvFileStream::SvFileStream( const OUString& rFileName, StreamMode nOpenMode )
{ {
bIsOpen = false; bIsOpen = false;
m_isWritable = false; m_isWritable = false;
pInstanceData = new StreamData; pInstanceData.reset(new StreamData);
SetBufferSize( 1024 ); SetBufferSize( 1024 );
// convert URL to SystemPath, if necessary // convert URL to SystemPath, if necessary
...@@ -290,15 +290,13 @@ SvFileStream::SvFileStream() ...@@ -290,15 +290,13 @@ SvFileStream::SvFileStream()
{ {
bIsOpen = false; bIsOpen = false;
m_isWritable = false; m_isWritable = false;
pInstanceData = new StreamData; pInstanceData.reset(new StreamData);
SetBufferSize( 1024 ); SetBufferSize( 1024 );
} }
SvFileStream::~SvFileStream() SvFileStream::~SvFileStream()
{ {
Close(); Close();
delete pInstanceData;
} }
std::size_t SvFileStream::GetData( void* pData, std::size_t nSize ) std::size_t SvFileStream::GetData( void* pData, std::size_t nSize )
......
...@@ -109,7 +109,7 @@ SvFileStream::SvFileStream( const OUString& rFileName, StreamMode nMode ) ...@@ -109,7 +109,7 @@ SvFileStream::SvFileStream( const OUString& rFileName, StreamMode nMode )
bIsOpen = false; bIsOpen = false;
nLockCounter = 0; nLockCounter = 0;
m_isWritable = false; m_isWritable = false;
pInstanceData = new StreamData; pInstanceData.reset( new StreamData );
SetBufferSize( 8192 ); SetBufferSize( 8192 );
// convert URL to SystemPath, if necessary // convert URL to SystemPath, if necessary
...@@ -125,7 +125,7 @@ SvFileStream::SvFileStream() ...@@ -125,7 +125,7 @@ SvFileStream::SvFileStream()
bIsOpen = false; bIsOpen = false;
nLockCounter = 0; nLockCounter = 0;
m_isWritable = false; m_isWritable = false;
pInstanceData = new StreamData; pInstanceData.reset( new StreamData );
SetBufferSize( 8192 ); SetBufferSize( 8192 );
} }
...@@ -133,7 +133,6 @@ SvFileStream::SvFileStream() ...@@ -133,7 +133,6 @@ SvFileStream::SvFileStream()
SvFileStream::~SvFileStream() SvFileStream::~SvFileStream()
{ {
Close(); Close();
delete pInstanceData;
} }
/// Does not check for EOF, makes isEof callable /// Does not check for EOF, makes isEof callable
......
...@@ -35,14 +35,11 @@ IntlWrapper::IntlWrapper( ...@@ -35,14 +35,11 @@ IntlWrapper::IntlWrapper(
IntlWrapper::~IntlWrapper() IntlWrapper::~IntlWrapper()
{ {
delete pLocaleData;
delete pCollator;
delete pCaseCollator;
} }
void IntlWrapper::ImplNewLocaleData() const void IntlWrapper::ImplNewLocaleData() const
{ {
const_cast<IntlWrapper*>(this)->pLocaleData = new LocaleDataWrapper( m_xContext, maLanguageTag ); const_cast<IntlWrapper*>(this)->pLocaleData.reset( new LocaleDataWrapper( m_xContext, maLanguageTag ) );
} }
void IntlWrapper::ImplNewCollator( bool bCaseSensitive ) const void IntlWrapper::ImplNewCollator( bool bCaseSensitive ) const
...@@ -51,13 +48,13 @@ void IntlWrapper::ImplNewCollator( bool bCaseSensitive ) const ...@@ -51,13 +48,13 @@ void IntlWrapper::ImplNewCollator( bool bCaseSensitive ) const
if ( bCaseSensitive ) if ( bCaseSensitive )
{ {
p->loadDefaultCollator( maLanguageTag.getLocale(), 0 ); p->loadDefaultCollator( maLanguageTag.getLocale(), 0 );
const_cast<IntlWrapper*>(this)->pCaseCollator = p; const_cast<IntlWrapper*>(this)->pCaseCollator.reset(p);
} }
else else
{ {
p->loadDefaultCollator( maLanguageTag.getLocale(), p->loadDefaultCollator( maLanguageTag.getLocale(),
css::i18n::CollatorOptions::CollatorOptions_IGNORE_CASE ); css::i18n::CollatorOptions::CollatorOptions_IGNORE_CASE );
const_cast<IntlWrapper*>(this)->pCollator = p; const_cast<IntlWrapper*>(this)->pCollator.reset(p);
} }
} }
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <osl/nlsupport.h> #include <osl/nlsupport.h>
#include <vector> #include <vector>
#include <memory>
using namespace osl; using namespace osl;
using namespace com::sun::star; using namespace com::sun::star;
...@@ -45,9 +46,9 @@ std::weak_ptr<SvtSysLocale_Impl> g_pSysLocale; ...@@ -45,9 +46,9 @@ std::weak_ptr<SvtSysLocale_Impl> g_pSysLocale;
class SvtSysLocale_Impl : public utl::ConfigurationListener class SvtSysLocale_Impl : public utl::ConfigurationListener
{ {
public: public:
SvtSysLocaleOptions aSysLocaleOptions; SvtSysLocaleOptions aSysLocaleOptions;
LocaleDataWrapper* pLocaleData; std::unique_ptr<LocaleDataWrapper> pLocaleData;
CharClass* pCharClass; std::unique_ptr<CharClass> pCharClass;
SvtSysLocale_Impl(); SvtSysLocale_Impl();
virtual ~SvtSysLocale_Impl() override; virtual ~SvtSysLocale_Impl() override;
...@@ -61,7 +62,7 @@ private: ...@@ -61,7 +62,7 @@ private:
SvtSysLocale_Impl::SvtSysLocale_Impl() : pCharClass(nullptr) SvtSysLocale_Impl::SvtSysLocale_Impl() : pCharClass(nullptr)
{ {
pLocaleData = new LocaleDataWrapper( aSysLocaleOptions.GetRealLanguageTag() ); pLocaleData.reset(new LocaleDataWrapper( aSysLocaleOptions.GetRealLanguageTag() ));
setDateAcceptancePatternsConfig(); setDateAcceptancePatternsConfig();
// listen for further changes // listen for further changes
...@@ -71,15 +72,13 @@ SvtSysLocale_Impl::SvtSysLocale_Impl() : pCharClass(nullptr) ...@@ -71,15 +72,13 @@ SvtSysLocale_Impl::SvtSysLocale_Impl() : pCharClass(nullptr)
SvtSysLocale_Impl::~SvtSysLocale_Impl() SvtSysLocale_Impl::~SvtSysLocale_Impl()
{ {
aSysLocaleOptions.RemoveListener( this ); aSysLocaleOptions.RemoveListener( this );
delete pCharClass;
delete pLocaleData;
} }
CharClass* SvtSysLocale_Impl::GetCharClass() CharClass* SvtSysLocale_Impl::GetCharClass()
{ {
if ( !pCharClass ) if ( !pCharClass )
pCharClass = new CharClass( aSysLocaleOptions.GetRealLanguageTag() ); pCharClass.reset(new CharClass( aSysLocaleOptions.GetRealLanguageTag() ));
return pCharClass; return pCharClass.get();
} }
void SvtSysLocale_Impl::ConfigurationChanged( utl::ConfigurationBroadcaster*, ConfigurationHints nHint ) void SvtSysLocale_Impl::ConfigurationChanged( utl::ConfigurationBroadcaster*, ConfigurationHints nHint )
...@@ -151,7 +150,7 @@ const LocaleDataWrapper& SvtSysLocale::GetLocaleData() const ...@@ -151,7 +150,7 @@ const LocaleDataWrapper& SvtSysLocale::GetLocaleData() const
const LocaleDataWrapper* SvtSysLocale::GetLocaleDataPtr() const const LocaleDataWrapper* SvtSysLocale::GetLocaleDataPtr() const
{ {
return pImpl->pLocaleData; return pImpl->pLocaleData.get();
} }
const CharClass& SvtSysLocale::GetCharClass() const const CharClass& SvtSysLocale::GetCharClass() const
......
...@@ -373,16 +373,15 @@ TempFile::TempFile( const OUString& rLeadingChars, bool _bStartWithZero, ...@@ -373,16 +373,15 @@ TempFile::TempFile( const OUString& rLeadingChars, bool _bStartWithZero,
} }
TempFile::TempFile(TempFile && other): TempFile::TempFile(TempFile && other):
aName(std::move(other.aName)), pStream(other.pStream), bIsDirectory(other.bIsDirectory), aName(std::move(other.aName)), pStream(std::move(other.pStream)), bIsDirectory(other.bIsDirectory),
bKillingFileEnabled(other.bKillingFileEnabled) bKillingFileEnabled(other.bKillingFileEnabled)
{ {
other.pStream = nullptr;
other.bKillingFileEnabled = false; other.bKillingFileEnabled = false;
} }
TempFile::~TempFile() TempFile::~TempFile()
{ {
delete pStream; pStream.reset();
if ( bKillingFileEnabled ) if ( bKillingFileEnabled )
{ {
if ( bIsDirectory ) if ( bIsDirectory )
...@@ -420,21 +419,17 @@ SvStream* TempFile::GetStream( StreamMode eMode ) ...@@ -420,21 +419,17 @@ SvStream* TempFile::GetStream( StreamMode eMode )
if (!pStream) if (!pStream)
{ {
if (!aName.isEmpty()) if (!aName.isEmpty())
pStream = new SvFileStream(aName, eMode); pStream.reset(new SvFileStream(aName, eMode));
else else
pStream = new SvMemoryStream(nullptr, 0, eMode); pStream.reset(new SvMemoryStream(nullptr, 0, eMode));
} }
return pStream; return pStream.get();
} }
void TempFile::CloseStream() void TempFile::CloseStream()
{ {
if ( pStream ) pStream.reset();
{
delete pStream;
pStream = nullptr;
}
} }
OUString TempFile::SetTempNameBaseDirectory( const OUString &rBaseName ) OUString TempFile::SetTempNameBaseDirectory( const OUString &rBaseName )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment