use unique_ptr in sdext
Change-Id: I8362cf42dd6a838752b25a4b184da614eb81805e Reviewed-on: https://gerrit.libreoffice.org/65532 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
@@ -191,7 +191,7 @@ struct PDFDict : public PDFContainer
|
||||
|
||||
// inserting a value of NULL will remove rName and the previous value
|
||||
// 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
|
||||
void eraseValue( const OString& rName );
|
||||
// builds new map as of sub elements
|
||||
|
||||
@@ -523,26 +523,32 @@ bool PDFDict::emit( EmitContext& rWriteContext ) const
|
||||
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 )
|
||||
eraseValue( rName );
|
||||
|
||||
auto pValueTmp = pValue.get();
|
||||
std::unordered_map<OString,PDFEntry*>::iterator it = m_aMap.find( rName );
|
||||
if( it == m_aMap.end() )
|
||||
{
|
||||
// new name/value, pair, append it
|
||||
m_aSubElements.emplace_back(o3tl::make_unique<PDFName>(rName));
|
||||
m_aSubElements.emplace_back( pValue );
|
||||
m_aSubElements.emplace_back( std::move(pValue) );
|
||||
}
|
||||
else
|
||||
{
|
||||
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 )
|
||||
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 )
|
||||
@@ -833,10 +839,10 @@ bool PDFObject::emit( EmitContext& rWriteContext ) const
|
||||
if( nOutBytes )
|
||||
{
|
||||
// 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
|
||||
PDFNumber* pNewLen = new PDFNumber( double(nOutBytes) );
|
||||
pClone->m_pStream->m_pDict->insertValue( "Length", pNewLen );
|
||||
std::unique_ptr<PDFNumber> pNewLen(new PDFNumber( double(nOutBytes) ));
|
||||
pClone->m_pStream->m_pDict->insertValue( "Length", std::move(pNewLen) );
|
||||
|
||||
if( bDeflate && rWriteContext.m_bDeflate )
|
||||
{
|
||||
@@ -871,7 +877,7 @@ bool PDFObject::emit( EmitContext& rWriteContext ) const
|
||||
if( pClone->m_aSubElements[i].get() != pClone->m_pStream )
|
||||
bRet = pClone->m_aSubElements[i]->emit( rWriteContext );
|
||||
}
|
||||
delete pClone;
|
||||
pClone.reset();
|
||||
// write stream
|
||||
if( bRet )
|
||||
bRet = rWriteContext.write("stream\n", 7)
|
||||
|
||||
Reference in New Issue
Block a user