summaryrefslogtreecommitdiff
path: root/sdext
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-11-17 10:53:06 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-11-17 14:58:58 +0100
commit328cdfd4a75f5e29c3a1b3ba4ee0ed9475603442 (patch)
tree90a57eb519c312c3631599f601d38605ea53ee88 /sdext
parent01cc5c2bc927fa1515d04cb509e420b86a02e74d (diff)
loplugin:useuniqueptr in PDFContainer
Change-Id: I25c2a5a078450ed921c7e981f4c9fac242aa7178 Reviewed-on: https://gerrit.libreoffice.org/44863 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sdext')
-rw-r--r--sdext/source/pdfimport/filterdet.cxx6
-rw-r--r--sdext/source/pdfimport/inc/pdfparse.hxx4
-rw-r--r--sdext/source/pdfimport/pdfparse/pdfentries.cxx61
-rw-r--r--sdext/source/pdfimport/pdfparse/pdfparse.cxx10
-rw-r--r--sdext/source/pdfimport/test/pdfunzip.cxx8
5 files changed, 41 insertions, 48 deletions
diff --git a/sdext/source/pdfimport/filterdet.cxx b/sdext/source/pdfimport/filterdet.cxx
index 57e8681544e8..5ca60e4282e5 100644
--- a/sdext/source/pdfimport/filterdet.cxx
+++ b/sdext/source/pdfimport/filterdet.cxx
@@ -486,7 +486,7 @@ uno::Reference< io::XStream > getAdditionalStream( const OUString&
unsigned int nElements = pPDFFile->m_aSubElements.size();
while( nElements-- > 0 )
{
- pdfparse::PDFTrailer* pTrailer = dynamic_cast<pdfparse::PDFTrailer*>(pPDFFile->m_aSubElements[nElements]);
+ pdfparse::PDFTrailer* pTrailer = dynamic_cast<pdfparse::PDFTrailer*>(pPDFFile->m_aSubElements[nElements].get());
if( pTrailer && pTrailer->m_pDict )
{
// search document checksum entry
@@ -527,8 +527,8 @@ uno::Reference< io::XStream > getAdditionalStream( const OUString&
continue;
// extract addstream and mimetype
- pdfparse::PDFName* pMimeType = dynamic_cast<pdfparse::PDFName*>(pStreams->m_aSubElements[0]);
- pdfparse::PDFObjectRef* pStreamRef = dynamic_cast<pdfparse::PDFObjectRef*>(pStreams->m_aSubElements[1]);
+ pdfparse::PDFName* pMimeType = dynamic_cast<pdfparse::PDFName*>(pStreams->m_aSubElements[0].get());
+ pdfparse::PDFObjectRef* pStreamRef = dynamic_cast<pdfparse::PDFObjectRef*>(pStreams->m_aSubElements[1].get());
SAL_WARN_IF( !pMimeType, "sdext.pdfimport", "error: no mimetype element" );
SAL_WARN_IF( !pStreamRef, "sdext.pdfimport", "error: no stream ref element" );
diff --git a/sdext/source/pdfimport/inc/pdfparse.hxx b/sdext/source/pdfimport/inc/pdfparse.hxx
index 462cf46955fa..90aaeab292ae 100644
--- a/sdext/source/pdfimport/inc/pdfparse.hxx
+++ b/sdext/source/pdfimport/inc/pdfparse.hxx
@@ -157,14 +157,14 @@ struct PDFObject;
struct PDFContainer : public PDFEntry
{
sal_Int32 m_nOffset;
- std::vector<PDFEntry*> m_aSubElements;
+ std::vector<std::unique_ptr<PDFEntry>> m_aSubElements;
// this is an abstract base class for identifying
// entries that can contain sub elements besides comments
PDFContainer() : PDFEntry(), m_nOffset( 0 ) {}
virtual ~PDFContainer() override;
bool emitSubElements( EmitContext& rWriteContext ) const;
- void cloneSubElements( std::vector<PDFEntry*>& rNewSubElements ) const;
+ void cloneSubElements( std::vector<std::unique_ptr<PDFEntry>>& rNewSubElements ) const;
PDFObject* findObject( unsigned int nNumber, unsigned int nGeneration ) const;
PDFObject* findObject( PDFObjectRef const * pRef ) const
diff --git a/sdext/source/pdfimport/pdfparse/pdfentries.cxx b/sdext/source/pdfimport/pdfparse/pdfentries.cxx
index 7a4f457fe0a4..16563868f25c 100644
--- a/sdext/source/pdfimport/pdfparse/pdfentries.cxx
+++ b/sdext/source/pdfimport/pdfparse/pdfentries.cxx
@@ -442,9 +442,6 @@ PDFEntry* PDFObjectRef::clone() const
PDFContainer::~PDFContainer()
{
- int nEle = m_aSubElements.size();
- for( int i = 0; i < nEle; i++ )
- delete m_aSubElements[i];
}
bool PDFContainer::emitSubElements( EmitContext& rWriteContext ) const
@@ -454,7 +451,7 @@ bool PDFContainer::emitSubElements( EmitContext& rWriteContext ) const
{
if( rWriteContext.m_bDecrypt )
{
- const PDFName* pName = dynamic_cast<PDFName*>(m_aSubElements[i]);
+ const PDFName* pName = dynamic_cast<PDFName*>(m_aSubElements[i].get());
if (pName && pName->m_aName == "Encrypt")
{
i++;
@@ -467,11 +464,11 @@ bool PDFContainer::emitSubElements( EmitContext& rWriteContext ) const
return true;
}
-void PDFContainer::cloneSubElements( std::vector<PDFEntry*>& rNewSubElements ) const
+void PDFContainer::cloneSubElements( std::vector<std::unique_ptr<PDFEntry>>& rNewSubElements ) const
{
int nEle = m_aSubElements.size();
for( int i = 0; i < nEle; i++ )
- rNewSubElements.push_back( m_aSubElements[i]->clone() );
+ rNewSubElements.emplace_back( m_aSubElements[i]->clone() );
}
PDFObject* PDFContainer::findObject( unsigned int nNumber, unsigned int nGeneration ) const
@@ -479,7 +476,7 @@ PDFObject* PDFContainer::findObject( unsigned int nNumber, unsigned int nGenerat
unsigned int nEle = m_aSubElements.size();
for( unsigned int i = 0; i < nEle; i++ )
{
- PDFObject* pObject = dynamic_cast<PDFObject*>(m_aSubElements[i]);
+ PDFObject* pObject = dynamic_cast<PDFObject*>(m_aSubElements[i].get());
if( pObject &&
pObject->m_nNumber == nNumber &&
pObject->m_nGeneration == nGeneration )
@@ -532,16 +529,15 @@ void PDFDict::insertValue( const OString& rName, PDFEntry* pValue )
if( it == m_aMap.end() )
{
// new name/value, pair, append it
- m_aSubElements.push_back( new PDFName( rName ) );
- m_aSubElements.push_back( pValue );
+ m_aSubElements.emplace_back( new PDFName( rName ) );
+ m_aSubElements.emplace_back( pValue );
}
else
{
unsigned int nSub = m_aSubElements.size();
for( unsigned int i = 0; i < nSub; i++ )
- if( m_aSubElements[i] == it->second )
- m_aSubElements[i] = pValue;
- delete it->second;
+ if( m_aSubElements[i].get() == it->second )
+ m_aSubElements[i].reset(pValue);
}
m_aMap[ rName ] = pValue;
}
@@ -551,17 +547,14 @@ void PDFDict::eraseValue( const OString& rName )
unsigned int nEle = m_aSubElements.size();
for( unsigned int i = 0; i < nEle; i++ )
{
- PDFName* pName = dynamic_cast<PDFName*>(m_aSubElements[i]);
+ PDFName* pName = dynamic_cast<PDFName*>(m_aSubElements[i].get());
if( pName && pName->m_aName == rName )
{
for( unsigned int j = i+1; j < nEle; j++ )
{
- if( dynamic_cast<PDFComment*>(m_aSubElements[j]) == nullptr )
+ if( dynamic_cast<PDFComment*>(m_aSubElements[j].get()) == nullptr )
{
- // free name and value
- delete m_aSubElements[j];
- delete m_aSubElements[i];
- // remove subelements from vector
+ // remove and free subelements from vector
m_aSubElements.erase( m_aSubElements.begin()+j );
m_aSubElements.erase( m_aSubElements.begin()+i );
buildMap();
@@ -581,15 +574,15 @@ PDFEntry* PDFDict::buildMap()
PDFName* pName = nullptr;
for( unsigned int i = 0; i < nEle; i++ )
{
- if( dynamic_cast<PDFComment*>(m_aSubElements[i]) == nullptr )
+ if( dynamic_cast<PDFComment*>(m_aSubElements[i].get()) == nullptr )
{
if( pName )
{
- m_aMap[ pName->m_aName ] = m_aSubElements[i];
+ m_aMap[ pName->m_aName ] = m_aSubElements[i].get();
pName = nullptr;
}
- else if( (pName = dynamic_cast<PDFName*>(m_aSubElements[i])) == nullptr )
- return m_aSubElements[i];
+ else if( (pName = dynamic_cast<PDFName*>(m_aSubElements[i].get())) == nullptr )
+ return m_aSubElements[i].get();
}
}
return pName;
@@ -635,7 +628,7 @@ unsigned int PDFStream::getDictLength( const PDFContainer* pContainer ) const
int nEle = pContainer->m_aSubElements.size();
for( int i = 0; i < nEle && ! pNum; i++ )
{
- PDFObject* pObj = dynamic_cast<PDFObject*>(pContainer->m_aSubElements[i]);
+ PDFObject* pObj = dynamic_cast<PDFObject*>(pContainer->m_aSubElements[i].get());
if( pObj &&
pObj->m_nNumber == pRef->m_nNumber &&
pObj->m_nGeneration == pRef->m_nGeneration )
@@ -682,7 +675,7 @@ bool PDFObject::getDeflatedStream( char** ppStream, unsigned int* pBytes, const
PDFArray* pArray = dynamic_cast<PDFArray*>(it->second);
if( pArray && ! pArray->m_aSubElements.empty() )
{
- pFilter = dynamic_cast<PDFName*>(pArray->m_aSubElements.front());
+ pFilter = dynamic_cast<PDFName*>(pArray->m_aSubElements.front().get());
}
}
@@ -850,7 +843,7 @@ bool PDFObject::emit( EmitContext& rWriteContext ) const
PDFArray* pArray = dynamic_cast<PDFArray*>(it->second);
if( pArray && ! pArray->m_aSubElements.empty() )
{
- pFilter = dynamic_cast<PDFName*>(pArray->m_aSubElements.front());
+ pFilter = dynamic_cast<PDFName*>(pArray->m_aSubElements.front().get());
if (pFilter && pFilter->m_aName == "FlateDecode")
{
delete pFilter;
@@ -866,7 +859,7 @@ bool PDFObject::emit( EmitContext& rWriteContext ) const
unsigned int nEle = pClone->m_aSubElements.size();
for( unsigned int i = 0; i < nEle && bRet; i++ )
{
- if( pClone->m_aSubElements[i] != pClone->m_pStream )
+ if( pClone->m_aSubElements[i].get() != pClone->m_pStream )
bRet = pClone->m_aSubElements[i]->emit( rWriteContext );
}
delete pClone;
@@ -903,11 +896,11 @@ PDFEntry* PDFObject::clone() const
unsigned int nEle = m_aSubElements.size();
for( unsigned int i = 0; i < nEle; i++ )
{
- if( m_aSubElements[i] == m_pObject )
- pNewOb->m_pObject = pNewOb->m_aSubElements[i];
- else if( m_aSubElements[i] == m_pStream && pNewOb->m_pObject )
+ if( m_aSubElements[i].get() == m_pObject )
+ pNewOb->m_pObject = pNewOb->m_aSubElements[i].get();
+ else if( m_aSubElements[i].get() == m_pStream && pNewOb->m_pObject )
{
- pNewOb->m_pStream = dynamic_cast<PDFStream*>(pNewOb->m_aSubElements[i]);
+ pNewOb->m_pStream = dynamic_cast<PDFStream*>(pNewOb->m_aSubElements[i].get());
PDFDict* pNewDict = dynamic_cast<PDFDict*>(pNewOb->m_pObject);
if (pNewDict && pNewOb->m_pStream)
pNewOb->m_pStream->m_pDict = pNewDict;
@@ -995,9 +988,9 @@ PDFEntry* PDFTrailer::clone() const
unsigned int nEle = m_aSubElements.size();
for( unsigned int i = 0; i < nEle; i++ )
{
- if( m_aSubElements[i] == m_pDict )
+ if( m_aSubElements[i].get() == m_pDict )
{
- pNewTr->m_pDict = dynamic_cast<PDFDict*>(pNewTr->m_aSubElements[i]);
+ pNewTr->m_pDict = dynamic_cast<PDFDict*>(pNewTr->m_aSubElements[i].get());
break;
}
}
@@ -1273,7 +1266,7 @@ PDFFileImplData* PDFFile::impl_getData() const
unsigned int nElements = m_aSubElements.size();
while( nElements-- > 0 )
{
- PDFTrailer* pTrailer = dynamic_cast<PDFTrailer*>(m_aSubElements[nElements]);
+ PDFTrailer* pTrailer = dynamic_cast<PDFTrailer*>(m_aSubElements[nElements].get());
if( pTrailer && pTrailer->m_pDict )
{
// search doc id
@@ -1283,7 +1276,7 @@ PDFFileImplData* PDFFile::impl_getData() const
PDFArray* pArr = dynamic_cast<PDFArray*>(doc_id->second);
if( pArr && pArr->m_aSubElements.size() > 0 )
{
- PDFString* pStr = dynamic_cast<PDFString*>(pArr->m_aSubElements[0]);
+ PDFString* pStr = dynamic_cast<PDFString*>(pArr->m_aSubElements[0].get());
if( pStr )
m_pData->m_aDocID = pStr->getFilteredString();
#if OSL_DEBUG_LEVEL > 0
diff --git a/sdext/source/pdfimport/pdfparse/pdfparse.cxx b/sdext/source/pdfimport/pdfparse/pdfparse.cxx
index 5db85cc18e87..28f0857986ac 100644
--- a/sdext/source/pdfimport/pdfparse/pdfparse.cxx
+++ b/sdext/source/pdfimport/pdfparse/pdfparse.cxx
@@ -309,7 +309,7 @@ public:
PDFContainer* pContainer = dynamic_cast<PDFContainer*>(m_aObjectStack.back());
if( pContainer == nullptr )
parseError( "comment without container", first );
- pContainer->m_aSubElements.push_back( pComment );
+ pContainer->m_aSubElements.emplace_back( pComment );
}
void insertNewValue( PDFEntry* pNewValue, iteratorT pPos )
@@ -351,7 +351,7 @@ public:
}
}
if( pContainer )
- pContainer->m_aSubElements.push_back( pNewValue );
+ pContainer->m_aSubElements.emplace_back( pNewValue );
else
{
if( ! pMsg )
@@ -410,7 +410,7 @@ public:
( dynamic_cast<PDFFile*>(pContainer) ||
dynamic_cast<PDFPart*>(pContainer) ) )
{
- pContainer->m_aSubElements.push_back( pObj );
+ pContainer->m_aSubElements.emplace_back( pObj );
m_aObjectStack.push_back( pObj );
}
else
@@ -502,7 +502,7 @@ public:
PDFStream* pStream = new PDFStream( first - m_aGlobalBegin, last - m_aGlobalBegin, pDict );
pObj->m_pStream = pStream;
- pObj->m_aSubElements.push_back( pStream );
+ pObj->m_aSubElements.emplace_back( pStream );
}
}
else
@@ -522,7 +522,7 @@ public:
( dynamic_cast<PDFFile*>(pContainer) ||
dynamic_cast<PDFPart*>(pContainer) ) )
{
- pContainer->m_aSubElements.push_back( pTrailer );
+ pContainer->m_aSubElements.emplace_back( pTrailer );
m_aObjectStack.push_back( pTrailer );
}
else
diff --git a/sdext/source/pdfimport/test/pdfunzip.cxx b/sdext/source/pdfimport/test/pdfunzip.cxx
index faf54efcb601..0a2ff0819574 100644
--- a/sdext/source/pdfimport/test/pdfunzip.cxx
+++ b/sdext/source/pdfimport/test/pdfunzip.cxx
@@ -250,8 +250,8 @@ int write_addStreamArray( const char* pOutFile, PDFArray* pStreams, PDFFile* pPD
unsigned int nArrayElements = pStreams->m_aSubElements.size();
for( unsigned int i = 0; i < nArrayElements-1 && nRet == 0; i++ )
{
- PDFName* pMimeType = dynamic_cast<PDFName*>(pStreams->m_aSubElements[i]);
- PDFObjectRef* pStreamRef = dynamic_cast<PDFObjectRef*>(pStreams->m_aSubElements[i+1]);
+ PDFName* pMimeType = dynamic_cast<PDFName*>(pStreams->m_aSubElements[i].get());
+ PDFObjectRef* pStreamRef = dynamic_cast<PDFObjectRef*>(pStreams->m_aSubElements[i+1].get());
if( ! pMimeType )
fprintf( stderr, "error: no mimetype element\n" );
if( ! pStreamRef )
@@ -292,7 +292,7 @@ int write_addStreams( const char* pInFile, const char* pOutFile, PDFFile* pPDFFi
unsigned int nElements = pPDFFile->m_aSubElements.size();
for( unsigned i = 0; i < nElements && nRet == 0; i++ )
{
- PDFTrailer* pTrailer = dynamic_cast<PDFTrailer*>(pPDFFile->m_aSubElements[i]);
+ PDFTrailer* pTrailer = dynamic_cast<PDFTrailer*>(pPDFFile->m_aSubElements[i].get());
if( pTrailer && pTrailer->m_pDict )
{
// search for AdditionalStreams entry
@@ -316,7 +316,7 @@ int write_fonts( const char* i_pInFile, const char* i_pOutFile, PDFFile* i_pPDFF
for( unsigned i = 0; i < nElements && nRet == 0; i++ )
{
// search FontDescriptors
- PDFObject* pObj = dynamic_cast<PDFObject*>(i_pPDFFile->m_aSubElements[i]);
+ PDFObject* pObj = dynamic_cast<PDFObject*>(i_pPDFFile->m_aSubElements[i].get());
if( ! pObj )
continue;
PDFDict* pDict = dynamic_cast<PDFDict*>(pObj->m_pObject);