diff options
author | Noel Grandin <noel@peralex.com> | 2015-08-18 11:33:49 +0200 |
---|---|---|
committer | Noel Grandin <noel@peralex.com> | 2015-08-20 09:55:43 +0200 |
commit | fb2ad7ce2d201d9d2504274ad7e1bd0e803d9902 (patch) | |
tree | 77f343733eee6cafe3fc115ecab0af0a61862ab2 /l10ntools | |
parent | af6daec72b71b1d72a2555efdc5b2fb2e0ba2b90 (diff) |
new loplugin automem
find places where we should be using std::unique_ptr
Change-Id: I5b9defe778fdc4738ecea381215396874db59e66
Diffstat (limited to 'l10ntools')
-rw-r--r-- | l10ntools/inc/cfgmerge.hxx | 2 | ||||
-rw-r--r-- | l10ntools/inc/po.hxx | 3 | ||||
-rw-r--r-- | l10ntools/inc/xmlparse.hxx | 17 | ||||
-rw-r--r-- | l10ntools/inc/xrmmerge.hxx | 4 | ||||
-rw-r--r-- | l10ntools/source/cfgmerge.cxx | 9 | ||||
-rw-r--r-- | l10ntools/source/po.cxx | 16 | ||||
-rw-r--r-- | l10ntools/source/xmlparse.cxx | 67 | ||||
-rw-r--r-- | l10ntools/source/xrmmerge.cxx | 23 |
8 files changed, 56 insertions, 85 deletions
diff --git a/l10ntools/inc/cfgmerge.hxx b/l10ntools/inc/cfgmerge.hxx index c61ff03ed261..c2342b5c12cf 100644 --- a/l10ntools/inc/cfgmerge.hxx +++ b/l10ntools/inc/cfgmerge.hxx @@ -159,7 +159,7 @@ class CfgMerge : public CfgParser private: MergeDataFile *pMergeDataFile; std::vector<OString> aLanguages; - ResData *pResData; + std::unique_ptr<ResData> pResData; OString sFilename; bool bEnglish; diff --git a/l10ntools/inc/po.hxx b/l10ntools/inc/po.hxx index e1a584d99311..830db7d9e054 100644 --- a/l10ntools/inc/po.hxx +++ b/l10ntools/inc/po.hxx @@ -11,6 +11,7 @@ #define INCLUDED_L10NTOOLS_INC_PO_HXX #include <fstream> +#include <memory> #include <rtl/string.hxx> #include <boost/noncopyable.hpp> @@ -32,7 +33,7 @@ class PoEntry { private: - GenPoEntry* m_pGenPo; + std::unique_ptr<GenPoEntry> m_pGenPo; bool m_bIsInitialized; public: diff --git a/l10ntools/inc/xmlparse.hxx b/l10ntools/inc/xmlparse.hxx index 69ee3f9317ca..8b94d31648db 100644 --- a/l10ntools/inc/xmlparse.hxx +++ b/l10ntools/inc/xmlparse.hxx @@ -110,12 +110,12 @@ class XMLData; class XMLParentNode : public XMLChildNode { private: - XMLChildNodeList* m_pChildList; + std::unique_ptr<XMLChildNodeList> m_pChildList; protected: XMLParentNode( XMLParentNode *pPar ) - : XMLChildNode( pPar ), m_pChildList( NULL ){} - XMLParentNode(): m_pChildList(NULL){} + : XMLChildNode( pPar ) {} + XMLParentNode() {} XMLParentNode( const XMLParentNode& ); @@ -124,7 +124,7 @@ protected: public: /// returns child list of this node - XMLChildNodeList *GetChildList() { return m_pChildList; } + XMLChildNodeList *GetChildList() { return m_pChildList.get(); } /// adds a new child void AddChild( @@ -158,7 +158,7 @@ public: void SearchL10NElements( XMLChildNode *pCur, int pos = 0 ); void Extract( XMLFile *pCur = NULL ); - XMLHashMap* GetStrings(){ return m_pXMLStrings; } + XMLHashMap* GetStrings(){ return m_pXMLStrings.get(); } void Write( OString const &rFilename ); bool Write( std::ofstream &rStream, XMLNode *pCur = NULL ); @@ -181,7 +181,7 @@ protected: OString m_sFileName; TagMap m_aNodes_localize; - XMLHashMap* m_pXMLStrings; + std::unique_ptr<XMLHashMap> m_pXMLStrings; std::vector <OString> m_vOrder; }; @@ -201,7 +201,7 @@ class XMLElement : public XMLParentNode { private: OString m_sElementName; - XMLAttributeList *m_pAttributes; + std::unique_ptr<XMLAttributeList> m_pAttributes; OString m_sProject; OString m_sFilename; OString m_sId; @@ -230,7 +230,7 @@ public: OString GetName() const { return m_sElementName; } /// returns list of attributes of this element - XMLAttributeList *GetAttributeList() { return m_pAttributes; } + XMLAttributeList *GetAttributeList() { return m_pAttributes.get(); } /// adds a new attribute to this element, typically used by parser void AddAttribute( const OString &rAttribute, const OString &rValue ); @@ -338,7 +338,6 @@ private: XML_Parser m_aParser; XMLError m_aErrorInformation; - XMLFile *m_pXMLFile; XMLParentNode *m_pCurNode; XMLData *m_pCurData; diff --git a/l10ntools/inc/xrmmerge.hxx b/l10ntools/inc/xrmmerge.hxx index df2ddafaf5c3..c3820b4ec6b5 100644 --- a/l10ntools/inc/xrmmerge.hxx +++ b/l10ntools/inc/xrmmerge.hxx @@ -72,7 +72,7 @@ public: class XRMResExport : public XRMResParser { private: - ResData *pResData; + std::unique_ptr<ResData> pResData; OString sPath; PoOfstream pOutputStream; protected: @@ -105,7 +105,7 @@ class XRMResMerge : public XRMResParser private: MergeDataFile *pMergeDataFile; OString sFilename; - ResData *pResData; + std::unique_ptr<ResData> pResData; std::ofstream pOutputStream; std::vector<OString> aLanguages; diff --git a/l10ntools/source/cfgmerge.cxx b/l10ntools/source/cfgmerge.cxx index 5093bd4adfb1..de7ccea88419 100644 --- a/l10ntools/source/cfgmerge.cxx +++ b/l10ntools/source/cfgmerge.cxx @@ -399,7 +399,6 @@ CfgMerge::CfgMerge( const OString &rMergeSource, const OString &rOutputFile, const OString &rFilename, const OString &rLanguage ) : pMergeDataFile( NULL ), - pResData( NULL ), sFilename( rFilename ), bEnglish( false ) { @@ -429,7 +428,6 @@ CfgMerge::~CfgMerge() { pOutputStream.close(); delete pMergeDataFile; - delete pResData; } void CfgMerge::WorkOnText(OString &, const OString& rLangIndex) @@ -447,7 +445,7 @@ void CfgMerge::WorkOnText(OString &, const OString& rLangIndex) sGroupId = aStack.GetAccessPath( aStack.size() - 2 ); } - pResData = new ResData( sGroupId, sFilename ); + pResData.reset( new ResData( sGroupId, sFilename ) ); pResData->sId = sLocalId; pResData->sResTyp = pStackData->sResTyp; } @@ -466,7 +464,7 @@ void CfgMerge::WorkOnResourceEnd() { if ( pMergeDataFile && pResData && bLocalize && bEnglish ) { - MergeEntrys *pEntrys = pMergeDataFile->GetMergeEntrysCaseSensitive( pResData ); + MergeEntrys *pEntrys = pMergeDataFile->GetMergeEntrysCaseSensitive( pResData.get() ); if ( pEntrys ) { OString sCur; @@ -511,8 +509,7 @@ void CfgMerge::WorkOnResourceEnd() } } } - delete pResData; - pResData = NULL; + pResData.reset(); bEnglish = false; } diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index c2acc2e25e8a..5dfa0b7a5f45 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -224,8 +224,7 @@ void GenPoEntry::readFromFile(std::ifstream& rIFStream) PoEntry::PoEntry() - : m_pGenPo( 0 ) - , m_bIsInitialized( false ) + : m_bIsInitialized( false ) { } @@ -233,8 +232,7 @@ PoEntry::PoEntry( const OString& rSourceFile, const OString& rResType, const OString& rGroupId, const OString& rLocalId, const OString& rHelpText, const OString& rText, const TYPE eType ) - : m_pGenPo( 0 ) - , m_bIsInitialized( false ) + : m_bIsInitialized( false ) { if( rSourceFile.isEmpty() ) throw NOSOURCFILE; @@ -247,7 +245,7 @@ PoEntry::PoEntry( else if ( rHelpText.getLength() == 5 ) throw WRONGHELPTEXT; - m_pGenPo = new GenPoEntry(); + m_pGenPo.reset( new GenPoEntry() ); m_pGenPo->setReference(rSourceFile.copy(rSourceFile.lastIndexOf('/')+1)); OString sMsgCtxt = @@ -273,7 +271,6 @@ PoEntry::PoEntry( PoEntry::~PoEntry() { - delete m_pGenPo; } PoEntry::PoEntry( const PoEntry& rPo ) @@ -296,13 +293,12 @@ PoEntry& PoEntry::operator=(const PoEntry& rPo) } else { - m_pGenPo = new GenPoEntry( *(rPo.m_pGenPo) ); + m_pGenPo.reset( new GenPoEntry( *(rPo.m_pGenPo) ) ); } } else { - delete m_pGenPo; - m_pGenPo = 0; + m_pGenPo.reset(); } m_bIsInitialized = rPo.m_bIsInitialized; return *this; @@ -594,7 +590,7 @@ void PoIfstream::readEntry( PoEntry& rPoEntry ) } else { - rPoEntry.m_pGenPo = new GenPoEntry( aGenPo ); + rPoEntry.m_pGenPo.reset( new GenPoEntry( aGenPo ) ); } rPoEntry.m_bIsInitialized = true; } diff --git a/l10ntools/source/xmlparse.cxx b/l10ntools/source/xmlparse.cxx index 06fcef004530..3d2292026500 100644 --- a/l10ntools/source/xmlparse.cxx +++ b/l10ntools/source/xmlparse.cxx @@ -78,17 +78,16 @@ XMLParentNode::~XMLParentNode() { if( m_pChildList ) { - RemoveAndDeleteAllChildren(); - delete m_pChildList; + RemoveAndDeleteAllChildren(); } - m_pChildList = NULL; } + XMLParentNode::XMLParentNode( const XMLParentNode& rObj) : XMLChildNode( rObj ) { if( rObj.m_pChildList ) { - m_pChildList=new XMLChildNodeList(); + m_pChildList.reset( new XMLChildNodeList() ); for ( size_t i = 0; i < rObj.m_pChildList->size(); i++ ) { XMLChildNode* pNode = (*rObj.m_pChildList)[ i ]; @@ -109,9 +108,8 @@ XMLParentNode::XMLParentNode( const XMLParentNode& rObj) } } } - else - m_pChildList = NULL; } + XMLParentNode& XMLParentNode::operator=(const XMLParentNode& rObj) { if(this!=&rObj) @@ -120,17 +118,15 @@ XMLParentNode& XMLParentNode::operator=(const XMLParentNode& rObj) if( m_pChildList ) { RemoveAndDeleteAllChildren(); - delete m_pChildList; - m_pChildList = NULL; } if( rObj.m_pChildList ) { - m_pChildList=new XMLChildNodeList(); + m_pChildList.reset( new XMLChildNodeList() ); for ( size_t i = 0; i < rObj.m_pChildList->size(); i++ ) AddChild( (*rObj.m_pChildList)[ i ] ); } else - m_pChildList = NULL; + m_pChildList.reset(); } return *this; @@ -138,7 +134,7 @@ XMLParentNode& XMLParentNode::operator=(const XMLParentNode& rObj) void XMLParentNode::AddChild( XMLChildNode *pChild ) { if ( !m_pChildList ) - m_pChildList = new XMLChildNodeList(); + m_pChildList.reset( new XMLChildNodeList() ); m_pChildList->push_back( pChild ); } @@ -313,14 +309,12 @@ XMLFile::~XMLFile() { delete pos->second; // Check and delete content also ? } - delete m_pXMLStrings; - m_pXMLStrings = NULL; } } + XMLFile::XMLFile( const OString &rFileName ) // the file name, empty if created from memory stream : XMLParentNode( NULL ) , m_sFileName( rFileName ) - , m_pXMLStrings( NULL ) { m_aNodes_localize.insert( TagMap::value_type(OString("bookmark") , sal_True) ); m_aNodes_localize.insert( TagMap::value_type(OString("variable") , sal_True) ); @@ -333,9 +327,7 @@ XMLFile::XMLFile( const OString &rFileName ) // the file name, empty if created void XMLFile::Extract( XMLFile *pCur ) { - delete m_pXMLStrings; // Elements ? - - m_pXMLStrings = new XMLHashMap(); + m_pXMLStrings.reset( new XMLHashMap() ); if ( !pCur ) SearchL10NElements( this ); else @@ -401,7 +393,6 @@ void XMLFile::InsertL10NElement( XMLElement* pElement ) XMLFile::XMLFile( const XMLFile& rObj ) : XMLParentNode( rObj ) , m_sFileName( rObj.m_sFileName ) - , m_pXMLStrings( 0 ) { if( this != &rObj ) { @@ -419,11 +410,11 @@ XMLFile& XMLFile::operator=(const XMLFile& rObj) m_aNodes_localize = rObj.m_aNodes_localize; m_vOrder = rObj.m_vOrder; - delete m_pXMLStrings; + m_pXMLStrings.reset(); if( rObj.m_pXMLStrings ) { - m_pXMLStrings = new XMLHashMap(); + m_pXMLStrings.reset( new XMLHashMap() ); for( XMLHashMap::iterator pos = rObj.m_pXMLStrings->begin() ; pos != rObj.m_pXMLStrings->end() ; ++pos ) { LangHashMap* pElem=pos->second; @@ -577,7 +568,6 @@ XMLElement::XMLElement( ) : XMLParentNode( pParent ) , m_sElementName( rName ) - , m_pAttributes( NULL ) , m_sProject(OString()) , m_sFilename(OString()) , m_sId(OString()) @@ -591,7 +581,6 @@ XMLElement::XMLElement( XMLElement::XMLElement(const XMLElement& rObj) : XMLParentNode( rObj ) , m_sElementName( rObj.m_sElementName ) - , m_pAttributes( 0 ) , m_sProject( rObj.m_sProject ) , m_sFilename( rObj.m_sFilename ) , m_sId( rObj.m_sId ) @@ -602,7 +591,7 @@ XMLElement::XMLElement(const XMLElement& rObj) { if ( rObj.m_pAttributes ) { - m_pAttributes = new XMLAttributeList(); + m_pAttributes.reset( new XMLAttributeList() ); for ( size_t i = 0; i < rObj.m_pAttributes->size(); i++ ) AddAttribute( (*rObj.m_pAttributes)[ i ]->GetName(), (*rObj.m_pAttributes)[ i ]->GetValue() ); } @@ -626,11 +615,11 @@ XMLElement& XMLElement::operator=(const XMLElement& rObj) { for ( size_t i = 0; i < m_pAttributes->size(); i++ ) delete (*m_pAttributes)[ i ]; - delete m_pAttributes; + m_pAttributes.reset(); } if ( rObj.m_pAttributes ) { - m_pAttributes = new XMLAttributeList(); + m_pAttributes.reset( new XMLAttributeList() ); for ( size_t i = 0; i < rObj.m_pAttributes->size(); i++ ) AddAttribute( (*rObj.m_pAttributes)[ i ]->GetName(), (*rObj.m_pAttributes)[ i ]->GetValue() ); } @@ -641,7 +630,7 @@ XMLElement& XMLElement::operator=(const XMLElement& rObj) void XMLElement::AddAttribute( const OString &rAttribute, const OString &rValue ) { if ( !m_pAttributes ) - m_pAttributes = new XMLAttributeList(); + m_pAttributes.reset( new XMLAttributeList() ); m_pAttributes->push_back( new XMLAttribute( rAttribute, rValue ) ); } @@ -682,9 +671,6 @@ XMLElement::~XMLElement() { for ( size_t i = 0; i < m_pAttributes->size(); i++ ) delete (*m_pAttributes)[ i ]; - - delete m_pAttributes; - m_pAttributes = NULL; } } @@ -817,8 +803,7 @@ static OUString lcl_pathnameToAbsoluteUrl(const OString& rPathname) SimpleXMLParser::SimpleXMLParser() - : m_pXMLFile(NULL) - , m_pCurNode(NULL) + : m_pCurNode(NULL) , m_pCurData(NULL) { m_aParser = XML_ParserCreate( NULL ); @@ -942,18 +927,18 @@ XMLFile *SimpleXMLParser::Execute( const OString &rFileName, XMLFile* pXMLFileIn return 0; } - m_pXMLFile = pXMLFileIn; - m_pXMLFile->SetName( rFileName ); + XMLFile* pXMLFile = pXMLFileIn; + pXMLFile->SetName( rFileName ); - m_pCurNode = m_pXMLFile; + m_pCurNode = pXMLFile; m_pCurData = NULL; m_aErrorInformation.m_eCode = XML_ERROR_NONE; m_aErrorInformation.m_nLine = 0; m_aErrorInformation.m_nColumn = 0; - if ( !m_pXMLFile->GetName().isEmpty()) + if ( !pXMLFile->GetName().isEmpty()) { - m_aErrorInformation.m_sMessage = "File " + m_pXMLFile->GetName() + " parsed successfully"; + m_aErrorInformation.m_sMessage = "File " + pXMLFile->GetName() + " parsed successfully"; } else m_aErrorInformation.m_sMessage = "XML-File parsed successfully"; @@ -965,8 +950,8 @@ XMLFile *SimpleXMLParser::Execute( const OString &rFileName, XMLFile* pXMLFileIn m_aErrorInformation.m_nColumn = XML_GetErrorColumnNumber( m_aParser ); m_aErrorInformation.m_sMessage = "ERROR: "; - if ( !m_pXMLFile->GetName().isEmpty()) - m_aErrorInformation.m_sMessage += m_pXMLFile->GetName(); + if ( !pXMLFile->GetName().isEmpty()) + m_aErrorInformation.m_sMessage += pXMLFile->GetName(); else m_aErrorInformation.m_sMessage += OString( "XML-File ("); @@ -1047,14 +1032,14 @@ XMLFile *SimpleXMLParser::Execute( const OString &rFileName, XMLFile* pXMLFileIn default: break; } - delete m_pXMLFile; - m_pXMLFile = NULL; + delete pXMLFile; + pXMLFile = NULL; } osl_unmapMappedFile(h, p, s); osl_closeFile(h); - return m_pXMLFile; + return pXMLFile; } namespace diff --git a/l10ntools/source/xrmmerge.cxx b/l10ntools/source/xrmmerge.cxx index a0f5b7dbc245..480ec2913b34 100644 --- a/l10ntools/source/xrmmerge.cxx +++ b/l10ntools/source/xrmmerge.cxx @@ -296,7 +296,6 @@ void XRMResParser::Error( const OString &rError ) XRMResExport::XRMResExport( const OString &rOutputFile, const OString &rFilePath ) : XRMResParser(), - pResData( NULL ), sPath( rFilePath ) { pOutputStream.open( rOutputFile, PoOfstream::APP ); @@ -311,7 +310,6 @@ XRMResExport::XRMResExport( XRMResExport::~XRMResExport() { pOutputStream.close(); - delete pResData; } void XRMResExport::Output( const OString& ) {} @@ -345,7 +343,7 @@ void XRMResExport::WorkOnText( if ( !pResData ) { - pResData = new ResData( GetGID() ); + pResData.reset( new ResData( GetGID() ) ); } pResData->sText[sLang] = rText; } @@ -363,8 +361,7 @@ void XRMResExport::EndOfText( "Xrmex", pOutputStream, sPath, sResourceType, pResData->sGId, OString(), OString(), sAct ); } - delete pResData; - pResData = NULL; + pResData.reset(); } @@ -376,8 +373,7 @@ XRMResMerge::XRMResMerge( const OString &rFilename ) : XRMResParser(), pMergeDataFile( NULL ), - sFilename( rFilename ) , - pResData( NULL ) + sFilename( rFilename ) { if (!rMergeSource.isEmpty() && sLanguage.equalsIgnoreAsciiCase("ALL")) { @@ -400,7 +396,6 @@ XRMResMerge::~XRMResMerge() { pOutputStream.close(); delete pMergeDataFile; - delete pResData; } void XRMResMerge::WorkOnDesc( @@ -409,7 +404,7 @@ void XRMResMerge::WorkOnDesc( { WorkOnText( rOpenTag, rText); if ( pMergeDataFile && pResData ) { - MergeEntrys *pEntrys = pMergeDataFile->GetMergeEntrys( pResData ); + MergeEntrys *pEntrys = pMergeDataFile->GetMergeEntrys( pResData.get() ); if ( pEntrys ) { OString sCur; OString sDescFilename = GetAttribute ( rOpenTag, "xlink:href" ); @@ -470,8 +465,7 @@ void XRMResMerge::WorkOnDesc( } } } - delete pResData; - pResData = NULL; + pResData.reset(); } void XRMResMerge::WorkOnText( @@ -480,7 +474,7 @@ void XRMResMerge::WorkOnText( { if ( pMergeDataFile ) { if ( !pResData ) { - pResData = new ResData( GetGID(), sFilename ); + pResData.reset( new ResData( GetGID(), sFilename ) ); pResData->sResTyp = sResourceType; } } @@ -499,7 +493,7 @@ void XRMResMerge::EndOfText( Output( rCloseTag ); if ( pMergeDataFile && pResData ) { - MergeEntrys *pEntrys = pMergeDataFile->GetMergeEntrys( pResData ); + MergeEntrys *pEntrys = pMergeDataFile->GetMergeEntrys( pResData.get() ); if ( pEntrys ) { OString sCur; for( size_t n = 0; n < aLanguages.size(); n++ ){ @@ -532,8 +526,7 @@ void XRMResMerge::EndOfText( } } } - delete pResData; - pResData = NULL; + pResData.reset(); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |