[Libreoffice-commits] core.git: forms/source include/tools tools/source
Noel Grandin
noel.grandin at collabora.co.uk
Tue Oct 17 10:58:56 UTC 2017
forms/source/component/DatabaseForm.cxx | 10 ++++------
include/tools/inetmsg.hxx | 15 ++++++++-------
tools/source/inet/inetmsg.cxx | 13 ++++---------
3 files changed, 16 insertions(+), 22 deletions(-)
New commits:
commit 01b9fdb2712e1a10e9a24b11976bb4fb94ac5bd9
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date: Tue Oct 17 12:04:45 2017 +0200
loplugin:useuniqueptr in tools/inetmsg.hxx
Change-Id: Ifdf0da7f59af1777f214cbafeb75b46136775f67
Reviewed-on: https://gerrit.libreoffice.org/43450
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/forms/source/component/DatabaseForm.cxx b/forms/source/component/DatabaseForm.cxx
index 4c2b039442cc..73bbd8a8afcc 100644
--- a/forms/source/component/DatabaseForm.cxx
+++ b/forms/source/component/DatabaseForm.cxx
@@ -938,10 +938,8 @@ void ODatabaseForm::Encode( OUString& rString )
void ODatabaseForm::InsertTextPart( INetMIMEMessage& rParent, const OUString& rName,
const OUString& rData )
{
-
// Create part as MessageChild
- INetMIMEMessage* pChild = new INetMIMEMessage();
-
+ std::unique_ptr<INetMIMEMessage> pChild(new INetMIMEMessage);
// Header
//TODO: Encode rName into a properly formatted Content-Disposition header
@@ -965,7 +963,7 @@ void ODatabaseForm::InsertTextPart( INetMIMEMessage& rParent, const OUString& rN
pStream->Flush();
pStream->Seek( 0 );
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
// Create part as MessageChild
- INetMIMEMessage* pChild = new INetMIMEMessage;
+ std::unique_ptr<INetMIMEMessage> pChild(new INetMIMEMessage);
// Header
@@ -1025,7 +1023,7 @@ bool ODatabaseForm::InsertFilePart( INetMIMEMessage& rParent, const OUString& rN
// Body
pChild->SetDocumentLB( new SvLockBytes(pStream, true) );
- rParent.AttachChild( *pChild );
+ rParent.AttachChild( std::move(pChild) );
return true;
}
diff --git a/include/tools/inetmsg.hxx b/include/tools/inetmsg.hxx
index bb99ee3296be..e1b26dbe43b7 100644
--- a/include/tools/inetmsg.hxx
+++ b/include/tools/inetmsg.hxx
@@ -28,6 +28,7 @@
#include <vector>
#include <map>
+#include <memory>
class DateTime;
@@ -72,14 +73,15 @@ enum class InetMessageMime
class SAL_WARN_UNUSED TOOLS_DLLPUBLIC INetMIMEMessage
{
- ::std::vector< INetMessageHeader* >
+ ::std::vector< std::unique_ptr<INetMessageHeader> >
m_aHeaderList;
SvLockBytesRef m_xDocLB;
::std::map<InetMessageMime, sal_uIntPtr> m_nMIMEIndex;
INetMIMEMessage* pParent;
- ::std::vector< INetMIMEMessage* > aChildren;
+ ::std::vector< std::unique_ptr<INetMIMEMessage> >
+ aChildren;
OString m_aBoundary;
OUString GetHeaderValue_Impl (
@@ -99,12 +101,11 @@ class SAL_WARN_UNUSED TOOLS_DLLPUBLIC INetMIMEMessage
if (m_aHeaderList.size() <= rnIndex)
{
rnIndex = m_aHeaderList.size();
- m_aHeaderList.push_back( p );
+ m_aHeaderList.emplace_back( p );
}
else
{
- delete m_aHeaderList[ rnIndex ];
- m_aHeaderList[ rnIndex ] = p;
+ m_aHeaderList[ rnIndex ].reset(p);
}
}
@@ -170,12 +171,12 @@ public:
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; }
void EnableAttachMultipartFormDataChild();
- void AttachChild( INetMIMEMessage& rChildMsg );
+ void AttachChild( std::unique_ptr<INetMIMEMessage> pChildMsg );
const OString& GetMultipartBoundary() const { return m_aBoundary; }
};
diff --git a/tools/source/inet/inetmsg.cxx b/tools/source/inet/inetmsg.cxx
index 704c44fad587..b3dc426ad7b6 100644
--- a/tools/source/inet/inetmsg.cxx
+++ b/tools/source/inet/inetmsg.cxx
@@ -218,12 +218,6 @@ INetMIMEMessage::INetMIMEMessage()
INetMIMEMessage::~INetMIMEMessage()
{
- for (auto i: m_aHeaderList) {
- delete i;
- }
- for (auto i: aChildren) {
- delete i;
- }
}
void INetMIMEMessage::SetMIMEVersion (const OUString& rVersion)
@@ -293,12 +287,13 @@ void INetMIMEMessage::EnableAttachMultipartFormDataChild()
SetContentTransferEncoding("7bit");
}
-void INetMIMEMessage::AttachChild(INetMIMEMessage& rChildMsg)
+void INetMIMEMessage::AttachChild(std::unique_ptr<INetMIMEMessage> pChildMsg)
{
+ assert(IsContainer());
if (IsContainer())
{
- rChildMsg.pParent = this;
- aChildren.push_back( &rChildMsg );
+ pChildMsg->pParent = this;
+ aChildren.push_back( std::move(pChildMsg) );
}
}
More information about the Libreoffice-commits
mailing list