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

use unique_ptr in sdext

Change-Id: I8362cf42dd6a838752b25a4b184da614eb81805e
Reviewed-on: https://gerrit.libreoffice.org/65532
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 441d38ea
...@@ -191,7 +191,7 @@ struct PDFDict : public PDFContainer ...@@ -191,7 +191,7 @@ struct PDFDict : public PDFContainer
// inserting a value of NULL will remove rName and the previous value // inserting a value of NULL will remove rName and the previous value
// from the dictionary // from the dictionary
void insertValue( const OString& rName, PDFEntry* pValue ); void insertValue( const OString& rName, std::unique_ptr<PDFEntry> pValue );
// removes a name/value pair from the dict // removes a name/value pair from the dict
void eraseValue( const OString& rName ); void eraseValue( const OString& rName );
// builds new map as of sub elements // builds new map as of sub elements
......
...@@ -523,26 +523,32 @@ bool PDFDict::emit( EmitContext& rWriteContext ) const ...@@ -523,26 +523,32 @@ bool PDFDict::emit( EmitContext& rWriteContext ) const
return rWriteContext.write( "\n>>\n", 4 ); return rWriteContext.write( "\n>>\n", 4 );
} }
void PDFDict::insertValue( const OString& rName, PDFEntry* pValue ) void PDFDict::insertValue( const OString& rName, std::unique_ptr<PDFEntry> pValue )
{ {
if( ! pValue ) if( ! pValue )
eraseValue( rName ); eraseValue( rName );
auto pValueTmp = pValue.get();
std::unordered_map<OString,PDFEntry*>::iterator it = m_aMap.find( rName ); std::unordered_map<OString,PDFEntry*>::iterator it = m_aMap.find( rName );
if( it == m_aMap.end() ) if( it == m_aMap.end() )
{ {
// new name/value, pair, append it // new name/value, pair, append it
m_aSubElements.emplace_back(o3tl::make_unique<PDFName>(rName)); m_aSubElements.emplace_back(o3tl::make_unique<PDFName>(rName));
m_aSubElements.emplace_back( pValue ); m_aSubElements.emplace_back( std::move(pValue) );
} }
else else
{ {
unsigned int nSub = m_aSubElements.size(); unsigned int nSub = m_aSubElements.size();
for( unsigned int i = 0; i < nSub; i++ ) bool bFound = false;
for( unsigned int i = 0; i < nSub && !bFound; i++ )
if( m_aSubElements[i].get() == it->second ) if( m_aSubElements[i].get() == it->second )
m_aSubElements[i].reset(pValue); {
m_aSubElements[i] = std::move(pValue);
bFound = true;
break;
}
} }
m_aMap[ rName ] = pValue; m_aMap[ rName ] = pValueTmp;
} }
void PDFDict::eraseValue( const OString& rName ) void PDFDict::eraseValue( const OString& rName )
...@@ -833,10 +839,10 @@ bool PDFObject::emit( EmitContext& rWriteContext ) const ...@@ -833,10 +839,10 @@ bool PDFObject::emit( EmitContext& rWriteContext ) const
if( nOutBytes ) if( nOutBytes )
{ {
// clone this object // clone this object
PDFObject* pClone = static_cast<PDFObject*>(clone()); std::unique_ptr<PDFObject> pClone(static_cast<PDFObject*>(clone()));
// set length in the dictionary to new stream length // set length in the dictionary to new stream length
PDFNumber* pNewLen = new PDFNumber( double(nOutBytes) ); std::unique_ptr<PDFNumber> pNewLen(new PDFNumber( double(nOutBytes) ));
pClone->m_pStream->m_pDict->insertValue( "Length", pNewLen ); pClone->m_pStream->m_pDict->insertValue( "Length", std::move(pNewLen) );
if( bDeflate && rWriteContext.m_bDeflate ) if( bDeflate && rWriteContext.m_bDeflate )
{ {
...@@ -871,7 +877,7 @@ bool PDFObject::emit( EmitContext& rWriteContext ) const ...@@ -871,7 +877,7 @@ bool PDFObject::emit( EmitContext& rWriteContext ) const
if( pClone->m_aSubElements[i].get() != pClone->m_pStream ) if( pClone->m_aSubElements[i].get() != pClone->m_pStream )
bRet = pClone->m_aSubElements[i]->emit( rWriteContext ); bRet = pClone->m_aSubElements[i]->emit( rWriteContext );
} }
delete pClone; pClone.reset();
// write stream // write stream
if( bRet ) if( bRet )
bRet = rWriteContext.write("stream\n", 7) bRet = rWriteContext.write("stream\n", 7)
......
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