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

loplugin:useuniqueptr in tools/inetmsg.hxx

Change-Id: Ifdf0da7f59af1777f214cbafeb75b46136775f67
Reviewed-on: https://gerrit.libreoffice.org/43450Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst d728492f
...@@ -938,10 +938,8 @@ void ODatabaseForm::Encode( OUString& rString ) ...@@ -938,10 +938,8 @@ void ODatabaseForm::Encode( OUString& rString )
void ODatabaseForm::InsertTextPart( INetMIMEMessage& rParent, const OUString& rName, void ODatabaseForm::InsertTextPart( INetMIMEMessage& rParent, const OUString& rName,
const OUString& rData ) const OUString& rData )
{ {
// Create part as MessageChild // Create part as MessageChild
INetMIMEMessage* pChild = new INetMIMEMessage(); std::unique_ptr<INetMIMEMessage> pChild(new INetMIMEMessage);
// Header // Header
//TODO: Encode rName into a properly formatted Content-Disposition header //TODO: Encode rName into a properly formatted Content-Disposition header
...@@ -965,7 +963,7 @@ void ODatabaseForm::InsertTextPart( INetMIMEMessage& rParent, const OUString& rN ...@@ -965,7 +963,7 @@ void ODatabaseForm::InsertTextPart( INetMIMEMessage& rParent, const OUString& rN
pStream->Flush(); pStream->Flush();
pStream->Seek( 0 ); pStream->Seek( 0 );
pChild->SetDocumentLB( new SvLockBytes(pStream, true) ); pChild->SetDocumentLB( new SvLockBytes(pStream, true) );
rParent.AttachChild( *pChild ); rParent.AttachChild( std::move(pChild) );
} }
...@@ -1005,7 +1003,7 @@ bool ODatabaseForm::InsertFilePart( INetMIMEMessage& rParent, const OUString& rN ...@@ -1005,7 +1003,7 @@ bool ODatabaseForm::InsertFilePart( INetMIMEMessage& rParent, const OUString& rN
// Create part as MessageChild // Create part as MessageChild
INetMIMEMessage* pChild = new INetMIMEMessage; std::unique_ptr<INetMIMEMessage> pChild(new INetMIMEMessage);
// Header // Header
...@@ -1025,7 +1023,7 @@ bool ODatabaseForm::InsertFilePart( INetMIMEMessage& rParent, const OUString& rN ...@@ -1025,7 +1023,7 @@ bool ODatabaseForm::InsertFilePart( INetMIMEMessage& rParent, const OUString& rN
// Body // Body
pChild->SetDocumentLB( new SvLockBytes(pStream, true) ); pChild->SetDocumentLB( new SvLockBytes(pStream, true) );
rParent.AttachChild( *pChild ); rParent.AttachChild( std::move(pChild) );
return true; return true;
} }
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <vector> #include <vector>
#include <map> #include <map>
#include <memory>
class DateTime; class DateTime;
...@@ -72,14 +73,15 @@ enum class InetMessageMime ...@@ -72,14 +73,15 @@ enum class InetMessageMime
class SAL_WARN_UNUSED TOOLS_DLLPUBLIC INetMIMEMessage class SAL_WARN_UNUSED TOOLS_DLLPUBLIC INetMIMEMessage
{ {
::std::vector< INetMessageHeader* > ::std::vector< std::unique_ptr<INetMessageHeader> >
m_aHeaderList; m_aHeaderList;
SvLockBytesRef m_xDocLB; SvLockBytesRef m_xDocLB;
::std::map<InetMessageMime, sal_uIntPtr> m_nMIMEIndex; ::std::map<InetMessageMime, sal_uIntPtr> m_nMIMEIndex;
INetMIMEMessage* pParent; INetMIMEMessage* pParent;
::std::vector< INetMIMEMessage* > aChildren; ::std::vector< std::unique_ptr<INetMIMEMessage> >
aChildren;
OString m_aBoundary; OString m_aBoundary;
OUString GetHeaderValue_Impl ( OUString GetHeaderValue_Impl (
...@@ -99,12 +101,11 @@ class SAL_WARN_UNUSED TOOLS_DLLPUBLIC INetMIMEMessage ...@@ -99,12 +101,11 @@ class SAL_WARN_UNUSED TOOLS_DLLPUBLIC INetMIMEMessage
if (m_aHeaderList.size() <= rnIndex) if (m_aHeaderList.size() <= rnIndex)
{ {
rnIndex = m_aHeaderList.size(); rnIndex = m_aHeaderList.size();
m_aHeaderList.push_back( p ); m_aHeaderList.emplace_back( p );
} }
else else
{ {
delete m_aHeaderList[ rnIndex ]; m_aHeaderList[ rnIndex ].reset(p);
m_aHeaderList[ rnIndex ] = p;
} }
} }
...@@ -170,12 +171,12 @@ public: ...@@ -170,12 +171,12 @@ public:
INetMIMEMessage* GetChild (sal_uIntPtr nIndex) const INetMIMEMessage* GetChild (sal_uIntPtr nIndex) const
{ {
return ( nIndex < aChildren.size() ) ? aChildren[ nIndex ] : nullptr; return ( nIndex < aChildren.size() ) ? aChildren[ nIndex ].get() : nullptr;
} }
INetMIMEMessage* GetParent() const { return pParent; } INetMIMEMessage* GetParent() const { return pParent; }
void EnableAttachMultipartFormDataChild(); void EnableAttachMultipartFormDataChild();
void AttachChild( INetMIMEMessage& rChildMsg ); void AttachChild( std::unique_ptr<INetMIMEMessage> pChildMsg );
const OString& GetMultipartBoundary() const { return m_aBoundary; } const OString& GetMultipartBoundary() const { return m_aBoundary; }
}; };
......
...@@ -218,12 +218,6 @@ INetMIMEMessage::INetMIMEMessage() ...@@ -218,12 +218,6 @@ INetMIMEMessage::INetMIMEMessage()
INetMIMEMessage::~INetMIMEMessage() INetMIMEMessage::~INetMIMEMessage()
{ {
for (auto i: m_aHeaderList) {
delete i;
}
for (auto i: aChildren) {
delete i;
}
} }
void INetMIMEMessage::SetMIMEVersion (const OUString& rVersion) void INetMIMEMessage::SetMIMEVersion (const OUString& rVersion)
...@@ -293,12 +287,13 @@ void INetMIMEMessage::EnableAttachMultipartFormDataChild() ...@@ -293,12 +287,13 @@ void INetMIMEMessage::EnableAttachMultipartFormDataChild()
SetContentTransferEncoding("7bit"); SetContentTransferEncoding("7bit");
} }
void INetMIMEMessage::AttachChild(INetMIMEMessage& rChildMsg) void INetMIMEMessage::AttachChild(std::unique_ptr<INetMIMEMessage> pChildMsg)
{ {
assert(IsContainer());
if (IsContainer()) if (IsContainer())
{ {
rChildMsg.pParent = this; pChildMsg->pParent = this;
aChildren.push_back( &rChildMsg ); aChildren.push_back( std::move(pChildMsg) );
} }
} }
......
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