[Libreoffice-commits] core.git: include/vcl vcl/qa vcl/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Mon Sep 3 14:19:49 UTC 2018
include/vcl/errinf.hxx | 2 +-
vcl/qa/cppunit/errorhandler.cxx | 4 ++--
vcl/source/window/errinf.cxx | 27 ++++++++++++---------------
3 files changed, 15 insertions(+), 18 deletions(-)
New commits:
commit dbcabd8f46af3c0e609be44cabbcfa2ebdbd5742
Author: Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Mon Sep 3 14:37:04 2018 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Mon Sep 3 16:19:28 2018 +0200
return by std::unique_ptr from GetErrorInfo
Change-Id: I80f1643b252d0b38d279b402a422733c0c4749b9
Reviewed-on: https://gerrit.libreoffice.org/59938
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/include/vcl/errinf.hxx b/include/vcl/errinf.hxx
index 95e16213981b..a7160dfd695d 100644
--- a/include/vcl/errinf.hxx
+++ b/include/vcl/errinf.hxx
@@ -146,7 +146,7 @@ public:
ErrCode const & GetErrorCode() const { return nUserId; }
- static ErrorInfo* GetErrorInfo(ErrCode);
+ static std::unique_ptr<ErrorInfo> GetErrorInfo(ErrCode);
private:
ErrCode nUserId;
diff --git a/vcl/qa/cppunit/errorhandler.cxx b/vcl/qa/cppunit/errorhandler.cxx
index f59abb0f9a96..7848c4368c6e 100644
--- a/vcl/qa/cppunit/errorhandler.cxx
+++ b/vcl/qa/cppunit/errorhandler.cxx
@@ -51,13 +51,13 @@ void ErrorHandlerTest::testGetErrorString()
CPPUNIT_ASSERT_MESSAGE("GetErrorString(ERRCODE_ABORT, aErrStr) should return false",
!ErrorHandler::GetErrorString(ERRCODE_ABORT, aErrStr));
// normally protected, but MockErrorHandler is a friend of this class
- xErrorInfo.reset(ErrorInfo::GetErrorInfo(ERRCODE_ABORT));
+ xErrorInfo = ErrorInfo::GetErrorInfo(ERRCODE_ABORT);
aErrHdlr.CreateString(xErrorInfo.get(), aErrStr);
CPPUNIT_ASSERT_EQUAL_MESSAGE("error message should be non-dynamic", OUString("Non-dynamic error"), aErrStr);
CPPUNIT_ASSERT_MESSAGE("GetErrorString(ERRCODE_NONE, aErrStr) should return false",
!ErrorHandler::GetErrorString(ERRCODE_NONE, aErrStr));
- xErrorInfo.reset(ErrorInfo::GetErrorInfo(ERRCODE_NONE));
+ xErrorInfo = ErrorInfo::GetErrorInfo(ERRCODE_NONE);
aErrHdlr.CreateString(xErrorInfo.get(), aErrStr);
CPPUNIT_ASSERT_EQUAL_MESSAGE("error message should be non-dynamic", OUString("Non-dynamic error"), aErrStr);
}
diff --git a/vcl/source/window/errinf.cxx b/vcl/source/window/errinf.cxx
index 0ec0ca504b68..ec001e0a2b30 100644
--- a/vcl/source/window/errinf.cxx
+++ b/vcl/source/window/errinf.cxx
@@ -23,6 +23,7 @@
#include <vcl/errinf.hxx>
#include <vcl/window.hxx>
+#include <o3tl/make_unique.hxx>
#include <vector>
#include <limits.h>
@@ -97,15 +98,14 @@ bool ErrorHandler::GetErrorString(ErrCode nErrCodeId, OUString& rErrStr)
if(!nErrCodeId || nErrCodeId == ERRCODE_ABORT)
return false;
- ErrorInfo *pInfo = ErrorInfo::GetErrorInfo(nErrCodeId);
+ std::unique_ptr<ErrorInfo> pInfo = ErrorInfo::GetErrorInfo(nErrCodeId);
- if (ErrorStringFactory::CreateString(pInfo,aErr))
+ if (ErrorStringFactory::CreateString(pInfo.get(),aErr))
{
rErrStr = aErr;
return true;
}
- delete pInfo;
return false;
}
@@ -115,7 +115,7 @@ DialogMask ErrorHandler::HandleError(ErrCode nErrCodeId, weld::Window *pParent,
return DialogMask::NONE;
ErrorRegistry &rData = TheErrorRegistry::get();
- ErrorInfo *pInfo = ErrorInfo::GetErrorInfo(nErrCodeId);
+ std::unique_ptr<ErrorInfo> pInfo = ErrorInfo::GetErrorInfo(nErrCodeId);
OUString aAction;
if (!rData.contexts.empty())
@@ -139,7 +139,7 @@ DialogMask ErrorHandler::HandleError(ErrCode nErrCodeId, weld::Window *pParent,
else
nErrFlags |= DialogMask::MessageError;
- DynamicErrorInfo* pDynPtr = dynamic_cast<DynamicErrorInfo*>(pInfo);
+ DynamicErrorInfo* pDynPtr = dynamic_cast<DynamicErrorInfo*>(pInfo.get());
if(pDynPtr)
{
DialogMask nDynFlags = pDynPtr->GetDialogMask();
@@ -148,7 +148,7 @@ DialogMask ErrorHandler::HandleError(ErrCode nErrCodeId, weld::Window *pParent,
}
OUString aErr;
- if (ErrorStringFactory::CreateString(pInfo, aErr))
+ if (ErrorStringFactory::CreateString(pInfo.get(), aErr))
{
if(!rData.pDsp)
{
@@ -156,8 +156,6 @@ DialogMask ErrorHandler::HandleError(ErrCode nErrCodeId, weld::Window *pParent,
}
else
{
- delete pInfo;
-
if(!rData.bIsWindowDsp)
{
(*reinterpret_cast<BasicDisplayErrorFunc*>(rData.pDsp))(aErr,aAction);
@@ -181,7 +179,6 @@ DialogMask ErrorHandler::HandleError(ErrCode nErrCodeId, weld::Window *pParent,
else
OSL_FAIL("ERRCODE_ABORT not handled");
- delete pInfo;
return DialogMask::NONE;
}
@@ -225,7 +222,7 @@ private:
}
void RegisterError(DynamicErrorInfo *);
static void UnRegisterError(DynamicErrorInfo const *);
- static ErrorInfo* GetDynamicErrorInfo(ErrCode nId);
+ static std::unique_ptr<ErrorInfo> GetDynamicErrorInfo(ErrCode nId);
ErrCode nErrId;
DialogMask nMask;
@@ -258,23 +255,23 @@ void ImplDynamicErrorInfo::UnRegisterError(DynamicErrorInfo const *pDynErrInfo)
ppDynErrInfo[nIdx]=nullptr;
}
-ErrorInfo* ImplDynamicErrorInfo::GetDynamicErrorInfo(ErrCode nId)
+std::unique_ptr<ErrorInfo> ImplDynamicErrorInfo::GetDynamicErrorInfo(ErrCode nId)
{
sal_uInt32 nIdx = nId.GetDynamic() - 1;
DynamicErrorInfo* pDynErrInfo = TheErrorRegistry::get().ppDynErrInfo[nIdx];
if(pDynErrInfo && ErrCode(*pDynErrInfo)==nId)
- return pDynErrInfo;
+ return std::unique_ptr<ErrorInfo>(pDynErrInfo);
else
- return new ErrorInfo(nId.StripDynamic());
+ return o3tl::make_unique<ErrorInfo>(nId.StripDynamic());
}
-ErrorInfo *ErrorInfo::GetErrorInfo(ErrCode nId)
+std::unique_ptr<ErrorInfo> ErrorInfo::GetErrorInfo(ErrCode nId)
{
if(nId.IsDynamic())
return ImplDynamicErrorInfo::GetDynamicErrorInfo(nId);
else
- return new ErrorInfo(nId);
+ return o3tl::make_unique<ErrorInfo>(nId);
}
ErrorInfo::~ErrorInfo()
More information about the Libreoffice-commits
mailing list