From 878be73a990b4e55523c7553c69492fabcc36d1a Mon Sep 17 00:00:00 2001 From: "sangwan.kwon" Date: Tue, 27 Dec 2016 17:28:46 +0900 Subject: [PATCH] Replace custom-smart-pointer to std::unique_ptr Change-Id: I4f45929627210aa8d669b0b46a141404742c9689 Signed-off-by: sangwan.kwon --- src/vcore/XmlsecAdapter.cpp | 51 ++++++++++----------------------------------- 1 file changed, 11 insertions(+), 40 deletions(-) diff --git a/src/vcore/XmlsecAdapter.cpp b/src/vcore/XmlsecAdapter.cpp index f39f89e..7705613 100644 --- a/src/vcore/XmlsecAdapter.cpp +++ b/src/vcore/XmlsecAdapter.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -52,38 +53,6 @@ IMPLEMENT_SINGLETON(ValidationCore::XmlSec) namespace { -template -struct CustomPtr { - Type ptr; - std::function deleter; - - CustomPtr() = delete; - - explicit CustomPtr(Type in, std::function d) - : ptr(in) - , deleter(d) {} - - ~CustomPtr() - { - deleter(ptr); - } - - inline Type get(void) const - { - return ptr; - } - - inline Type operator->() const - { - return ptr; - } - - inline bool operator!() const - { - return (ptr == nullptr) ? true : false; - } -}; - struct FileWrapper { FileWrapper(void *argFile, bool argReleased) : file(argFile) @@ -273,8 +242,8 @@ void XmlSec::validateFile(XmlSecContext &context, xmlSecKeysMngrPtr mngrPtr) fileOpenCallback, fileReadCallback, fileCloseCallback); - CustomPtr docPtr(xmlParseFile(context.signatureFile.c_str()), - xmlFreeDoc); + std::unique_ptr> docPtr( + xmlParseFile(context.signatureFile.c_str()), xmlFreeDoc); if (!docPtr || xmlDocGetRootElement(docPtr.get()) == nullptr) ThrowMsg(Exception::InvalidFormat, @@ -289,11 +258,12 @@ void XmlSec::validateFile(XmlSecContext &context, xmlSecKeysMngrPtr mngrPtr) ThrowMsg(Exception::InvalidFormat, "Start node not found in " << context.signatureFile); - CustomPtr dsigCtx(xmlSecDSigCtxCreate(mngrPtr), - [](xmlSecDSigCtxPtr dsigCtx) { - xmlSecProxyCtxDestroy(dsigCtx->skipReferences); - xmlSecProxyCtxDestroy(dsigCtx->checkReferences); - xmlSecDSigCtxDestroy(dsigCtx); + std::unique_ptr> dsigCtx( + xmlSecDSigCtxCreate(mngrPtr), + [](xmlSecDSigCtxPtr dsigCtx) { + xmlSecProxyCtxDestroy(dsigCtx->skipReferences); + xmlSecProxyCtxDestroy(dsigCtx->checkReferences); + xmlSecDSigCtxDestroy(dsigCtx); }); if (!dsigCtx) @@ -438,7 +408,8 @@ void XmlSec::validateInternal(XmlSecContext &context) if (!m_initialized) ThrowMsg(Exception::InternalError, "XmlSec is not initialized"); - CustomPtr mngrPtr(xmlSecKeysMngrCreate(), xmlSecKeysMngrDestroy); + std::unique_ptr> + mngrPtr(xmlSecKeysMngrCreate(), xmlSecKeysMngrDestroy); if (!mngrPtr) ThrowMsg(Exception::InternalError, "Failed to create keys manager."); -- 2.7.4