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

loplugin:useuniqueptr in PDFGrammar

Change-Id: I8eff505de0d2821a33bbbc8e4acc2cbee7c1058e
Reviewed-on: https://gerrit.libreoffice.org/59232
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst c751fd0e
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include <rtl/ustrbuf.hxx> #include <rtl/ustrbuf.hxx>
#include <rtl/alloc.h> #include <rtl/alloc.h>
#include <sal/log.hxx> #include <sal/log.hxx>
#include <o3tl/make_unique.hxx>
// disable warnings again because someone along the line has enabled them // disable warnings again because someone along the line has enabled them
// (we have included boost headers, what did you expect?) // (we have included boost headers, what did you expect?)
...@@ -322,7 +323,7 @@ public: ...@@ -322,7 +323,7 @@ public:
pContainer->m_aSubElements.emplace_back( pComment ); pContainer->m_aSubElements.emplace_back( pComment );
} }
void insertNewValue( PDFEntry* pNewValue, iteratorT pPos ) void insertNewValue( std::unique_ptr<PDFEntry> pNewValue, iteratorT pPos )
{ {
PDFContainer* pContainer = nullptr; PDFContainer* pContainer = nullptr;
const char* pMsg = nullptr; const char* pMsg = nullptr;
...@@ -336,20 +337,20 @@ public: ...@@ -336,20 +337,20 @@ public:
if( pObj ) if( pObj )
{ {
if( pObj->m_pObject == nullptr ) if( pObj->m_pObject == nullptr )
pObj->m_pObject = pNewValue; pObj->m_pObject = pNewValue.release();
else else
{ {
pMsg = "second value for object"; pMsg = "second value for object";
pContainer = nullptr; pContainer = nullptr;
} }
} }
else if( dynamic_cast<PDFDict*>(pNewValue) ) else if( dynamic_cast<PDFDict*>(pNewValue.get()) )
{ {
PDFTrailer* pTrailer = dynamic_cast<PDFTrailer*>(pContainer); PDFTrailer* pTrailer = dynamic_cast<PDFTrailer*>(pContainer);
if( pTrailer ) if( pTrailer )
{ {
if( pTrailer->m_pDict == nullptr ) if( pTrailer->m_pDict == nullptr )
pTrailer->m_pDict = dynamic_cast<PDFDict*>(pNewValue); pTrailer->m_pDict = dynamic_cast<PDFDict*>(pNewValue.get());
else else
pContainer = nullptr; pContainer = nullptr;
} }
...@@ -361,44 +362,43 @@ public: ...@@ -361,44 +362,43 @@ public:
} }
} }
if( pContainer ) if( pContainer )
pContainer->m_aSubElements.emplace_back( pNewValue ); pContainer->m_aSubElements.emplace_back( std::move(pNewValue) );
else else
{ {
if( ! pMsg ) if( ! pMsg )
{ {
if( dynamic_cast<PDFContainer*>(pNewValue) ) if( dynamic_cast<PDFContainer*>(pNewValue.get()) )
pMsg = "array without container"; pMsg = "array without container";
else else
pMsg = "value without container"; pMsg = "value without container";
} }
delete pNewValue;
parseError( pMsg, pPos ); parseError( pMsg, pPos );
} }
} }
void pushName( iteratorT first, iteratorT last ) void pushName( iteratorT first, iteratorT last )
{ {
insertNewValue( new PDFName(iteratorToString(first,last)), first ); insertNewValue( o3tl::make_unique<PDFName>(iteratorToString(first,last)), first );
} }
void pushDouble( iteratorT first, SAL_UNUSED_PARAMETER iteratorT /*last*/ ) void pushDouble( iteratorT first, SAL_UNUSED_PARAMETER iteratorT /*last*/ )
{ {
insertNewValue( new PDFNumber(m_fDouble), first ); insertNewValue( o3tl::make_unique<PDFNumber>(m_fDouble), first );
} }
void pushString( iteratorT first, iteratorT last ) void pushString( iteratorT first, iteratorT last )
{ {
insertNewValue( new PDFString(iteratorToString(first,last)), first ); insertNewValue( o3tl::make_unique<PDFString>(iteratorToString(first,last)), first );
} }
void pushBool( iteratorT first, iteratorT last ) void pushBool( iteratorT first, iteratorT last )
{ {
insertNewValue( new PDFBool( (last-first == 4) ), first ); insertNewValue( o3tl::make_unique<PDFBool>( last-first == 4 ), first );
} }
void pushNull( iteratorT first, SAL_UNUSED_PARAMETER iteratorT ) void pushNull( iteratorT first, SAL_UNUSED_PARAMETER iteratorT )
{ {
insertNewValue( new PDFNull(), first ); insertNewValue( o3tl::make_unique<PDFNull>(), first );
} }
...@@ -443,7 +443,7 @@ public: ...@@ -443,7 +443,7 @@ public:
m_aUIntStack.pop_back(); m_aUIntStack.pop_back();
unsigned int nObject = m_aUIntStack.back(); unsigned int nObject = m_aUIntStack.back();
m_aUIntStack.pop_back(); m_aUIntStack.pop_back();
insertNewValue( new PDFObjectRef(nObject,nGeneration), first ); insertNewValue( o3tl::make_unique<PDFObjectRef>(nObject,nGeneration), first );
} }
void beginDict( iteratorT first, SAL_UNUSED_PARAMETER iteratorT ) void beginDict( iteratorT first, SAL_UNUSED_PARAMETER iteratorT )
...@@ -451,7 +451,7 @@ public: ...@@ -451,7 +451,7 @@ public:
PDFDict* pDict = new PDFDict(); PDFDict* pDict = new PDFDict();
pDict->m_nOffset = first - m_aGlobalBegin; pDict->m_nOffset = first - m_aGlobalBegin;
insertNewValue( pDict, first ); insertNewValue( std::unique_ptr<PDFEntry>(pDict), first );
// will not come here if insertion fails (exception) // will not come here if insertion fails (exception)
m_aObjectStack.push_back( pDict ); m_aObjectStack.push_back( pDict );
} }
...@@ -481,7 +481,7 @@ public: ...@@ -481,7 +481,7 @@ public:
PDFArray* pArray = new PDFArray(); PDFArray* pArray = new PDFArray();
pArray->m_nOffset = first - m_aGlobalBegin; pArray->m_nOffset = first - m_aGlobalBegin;
insertNewValue( pArray, first ); insertNewValue( std::unique_ptr<PDFEntry>(pArray), first );
// will not come here if insertion fails (exception) // will not come here if insertion fails (exception)
m_aObjectStack.push_back( pArray ); m_aObjectStack.push_back( pArray );
} }
......
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