include/vcl/ppdparser.hxx | 4 +-- vcl/unx/generic/printer/ppdparser.cxx | 42 +++++++++++++++----------------- xmloff/source/text/XMLRedlineExport.cxx | 12 ++------- xmloff/source/text/XMLRedlineExport.hxx | 3 +- 4 files changed, 27 insertions(+), 34 deletions(-)
New commits: commit 60c08199f215ff7db335a692cbbcb72d1ac582d1 Author: Noel Grandin <[email protected]> AuthorDate: Mon Jul 16 08:42:33 2018 +0200 Commit: Noel Grandin <[email protected]> CommitDate: Tue Jul 17 08:38:53 2018 +0200 loplugin:useuniqueptr in PPDParser Change-Id: Id7ffe7967d2b6a7f394a4e096c04218c10aeda37 Reviewed-on: https://gerrit.libreoffice.org/57514 Tested-by: Jenkins Reviewed-by: Noel Grandin <[email protected]> diff --git a/include/vcl/ppdparser.hxx b/include/vcl/ppdparser.hxx index b0bddea9acb1..b88d859840c8 100644 --- a/include/vcl/ppdparser.hxx +++ b/include/vcl/ppdparser.hxx @@ -124,10 +124,10 @@ class VCL_DLLPUBLIC PPDParser friend class CPDManager; friend class PPDCache; - typedef std::unordered_map< OUString, PPDKey* > hash_type; + typedef std::unordered_map< OUString, std::unique_ptr<PPDKey> > hash_type; typedef std::vector< PPDKey* > value_type; - void insertKey( const OUString& rKey, PPDKey* pKey ); + void insertKey( std::unique_ptr<PPDKey> pKey ); public: struct PPDConstraint { diff --git a/vcl/unx/generic/printer/ppdparser.cxx b/vcl/unx/generic/printer/ppdparser.cxx index af2dfbe0e249..0caf55d81532 100644 --- a/vcl/unx/generic/printer/ppdparser.cxx +++ b/vcl/unx/generic/printer/ppdparser.cxx @@ -597,9 +597,9 @@ PPDParser::PPDParser( const OUString& rFile, std::vector<PPDKey*> keys) : m_pDefaultResolution( nullptr ), m_pTranslator( new PPDTranslator() ) { - for (PPDKey* key: keys) + for (auto & key: keys) { - insertKey( key -> getKey(), key ); + insertKey( std::unique_ptr<PPDKey>(key) ); } // fill in shortcuts @@ -608,8 +608,8 @@ PPDParser::PPDParser( const OUString& rFile, std::vector<PPDKey*> keys) : pKey = getKey( OUString( "PageSize" ) ); if ( pKey ) { - PPDKey* pImageableAreas = new PPDKey("ImageableArea"); - PPDKey* pPaperDimensions = new PPDKey("PaperDimension"); + std::unique_ptr<PPDKey> pImageableAreas(new PPDKey("ImageableArea")); + std::unique_ptr<PPDKey> pPaperDimensions(new PPDKey("PaperDimension")); #if defined(CUPS_VERSION_MAJOR) #if (CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR >= 7) || CUPS_VERSION_MAJOR > 1 for (int i = 0; i < pKey->countValues(); i++) { @@ -641,8 +641,8 @@ PPDParser::PPDParser( const OUString& rFile, std::vector<PPDKey*> keys) : } #endif // HAVE_CUPS_API_1_7 #endif - insertKey("ImageableArea", pImageableAreas); - insertKey("PaperDimension", pPaperDimensions); + insertKey(std::move(pImageableAreas)); + insertKey(std::move(pPaperDimensions)); } m_pImageableAreas = getKey( OUString( "ImageableArea" ) ); @@ -863,15 +863,13 @@ PPDParser::PPDParser( const OUString& rFile ) : PPDParser::~PPDParser() { - for (auto const& key : m_aKeys) - delete key.second; m_pTranslator.reset(); } -void PPDParser::insertKey( const OUString& rKey, PPDKey* pKey ) +void PPDParser::insertKey( std::unique_ptr<PPDKey> pKey ) { - m_aKeys[ rKey ] = pKey; - m_aOrderedKeys.push_back( pKey ); + m_aOrderedKeys.push_back( pKey.get() ); + m_aKeys[ pKey->getKey() ] = std::move(pKey); } const PPDKey* PPDParser::getKey( int n ) const @@ -882,7 +880,7 @@ const PPDKey* PPDParser::getKey( int n ) const const PPDKey* PPDParser::getKey( const OUString& rKey ) const { PPDParser::hash_type::const_iterator it = m_aKeys.find( rKey ); - return it != m_aKeys.end() ? it->second : nullptr; + return it != m_aKeys.end() ? it->second.get() : nullptr; } bool PPDParser::hasKey( const PPDKey* pKey ) const @@ -1037,7 +1035,7 @@ void PPDParser::parse( ::std::vector< OString >& rLines ) keyit = m_aKeys.find( aUniKey ); if(keyit != m_aKeys.end()) { - PPDKey* pKey = keyit->second; + PPDKey* pKey = keyit->second.get(); pKey->insertValue("Custom", eInvocation, true); } continue; @@ -1193,10 +1191,10 @@ void PPDParser::parse( ::std::vector< OString >& rLines ) if( keyit == m_aKeys.end() ) { pKey = new PPDKey( aUniKey ); - insertKey( aUniKey, pKey ); + insertKey( std::unique_ptr<PPDKey>(pKey) ); } else - pKey = keyit->second; + pKey = keyit->second.get(); if( eType == eNo && bQuery ) continue; @@ -1238,7 +1236,7 @@ void PPDParser::parse( ::std::vector< OString >& rLines ) keyit = m_aKeys.find( aKey ); if( keyit != m_aKeys.end() ) { - PPDKey* pKey = keyit->second; + PPDKey* pKey = keyit->second.get(); const PPDValue* pDefValue = pKey->getValue( aOption ); if( pKey->m_pDefaultValue == nullptr ) pKey->m_pDefaultValue = pDefValue; @@ -1249,10 +1247,10 @@ void PPDParser::parse( ::std::vector< OString >& rLines ) // do not exist otherwise // (example: DefaultResolution) // so invent that key here and have a default value - PPDKey* pKey = new PPDKey( aKey ); + std::unique_ptr<PPDKey> pKey(new PPDKey( aKey )); pKey->insertValue( aOption, eInvocation /*or what ?*/ ); pKey->m_pDefaultValue = pKey->getValue( aOption ); - insertKey( aKey, pKey ); + insertKey( std::move(pKey) ); } } } @@ -1287,10 +1285,10 @@ void PPDParser::parseOpenUI(const OString& rLine, const OString& rPPDGroup) if( keyit == m_aKeys.end() ) { pKey = new PPDKey( aUniKey ); - insertKey( aUniKey, pKey ); + insertKey( std::unique_ptr<PPDKey>(pKey) ); } else - pKey = keyit->second; + pKey = keyit->second.get(); pKey->m_bUIOption = true; m_pTranslator->insertKey( pKey->getKey(), aTranslation ); @@ -1317,10 +1315,10 @@ void PPDParser::parseOrderDependency(const OString& rLine) if( keyit == m_aKeys.end() ) { pKey = new PPDKey( aKey ); - insertKey( aKey, pKey ); + insertKey( std::unique_ptr<PPDKey>(pKey) ); } else - pKey = keyit->second; + pKey = keyit->second.get(); pKey->m_nOrderDependency = nOrder; if( aSetup == "ExitServer" ) commit 76db1242ad6944dea42a09d3e5575a890bf6f7c2 Author: Noel Grandin <[email protected]> AuthorDate: Mon Jul 16 08:42:10 2018 +0200 Commit: Noel Grandin <[email protected]> CommitDate: Tue Jul 17 08:38:43 2018 +0200 loplugin:useuniqueptr in XMLRedlineExport Change-Id: I337b6c068e28a5cf69d9c0b6a30b480834d8a227 Reviewed-on: https://gerrit.libreoffice.org/57513 Tested-by: Jenkins Reviewed-by: Noel Grandin <[email protected]> diff --git a/xmloff/source/text/XMLRedlineExport.cxx b/xmloff/source/text/XMLRedlineExport.cxx index 4a0e076a3c78..6e23cd2d4743 100644 --- a/xmloff/source/text/XMLRedlineExport.cxx +++ b/xmloff/source/text/XMLRedlineExport.cxx @@ -71,12 +71,6 @@ XMLRedlineExport::XMLRedlineExport(SvXMLExport& rExp) XMLRedlineExport::~XMLRedlineExport() { - // delete changes lists - for (auto const& change : aChangeMap) - { - delete change.second; - } - aChangeMap.clear(); } @@ -129,7 +123,7 @@ void XMLRedlineExport::ExportChangesList( ChangesMapType::iterator aFind = aChangeMap.find(rText); if (aFind != aChangeMap.end()) { - ChangesVectorType* pChangesList = aFind->second; + ChangesVectorType* pChangesList = aFind->second.get(); // export only if changes are found if (pChangesList->size() > 0) @@ -160,11 +154,11 @@ void XMLRedlineExport::SetCurrentXText( if (aIter == aChangeMap.end()) { ChangesVectorType* pList = new ChangesVectorType; - aChangeMap[rText] = pList; + aChangeMap[rText].reset( pList ); pCurrentChangesList = pList; } else - pCurrentChangesList = aIter->second; + pCurrentChangesList = aIter->second.get(); } else { diff --git a/xmloff/source/text/XMLRedlineExport.hxx b/xmloff/source/text/XMLRedlineExport.hxx index 0d7ab3114401..22169d4a0b97 100644 --- a/xmloff/source/text/XMLRedlineExport.hxx +++ b/xmloff/source/text/XMLRedlineExport.hxx @@ -25,6 +25,7 @@ #include <com/sun/star/uno/Sequence.h> #include <vector> +#include <memory> #include <map> class SvXMLExport; @@ -43,7 +44,7 @@ typedef ::std::vector< // store a list of redline properties for each XText typedef ::std::map< css::uno::Reference< css::text::XText>, - ChangesVectorType* > ChangesMapType; + std::unique_ptr<ChangesVectorType> > ChangesMapType; /** _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
