diff options
author | Noel <noel.grandin@collabora.co.uk> | 2021-02-19 08:38:41 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-02-19 08:46:06 +0100 |
commit | 85e51d1fb5ed3019ef2409c8c8a7721148bb4178 (patch) | |
tree | 4a27a3de9cf6560acd2b78a7e2b978786575f78e /xmlscript | |
parent | efb093893ffe9aa6340bde72e12d0512200d2100 (diff) |
loplugin:refcounting in xmlscript
Change-Id: I82e3fe7ec8f45d9e99ec51688df97a0e5a33f58c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111169
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'xmlscript')
-rw-r--r-- | xmlscript/source/xmldlg_imexp/xmldlg_expmodels.cxx | 27 | ||||
-rw-r--r-- | xmlscript/source/xmldlg_imexp/xmldlg_export.cxx | 22 | ||||
-rw-r--r-- | xmlscript/source/xmldlg_imexp/xmldlg_impmodels.cxx | 12 | ||||
-rw-r--r-- | xmlscript/source/xmlflat_imexp/xmlbas_export.cxx | 26 | ||||
-rw-r--r-- | xmlscript/source/xmllib_imexp/xmllib_export.cxx | 5 | ||||
-rw-r--r-- | xmlscript/source/xmlmod_imexp/xmlmod_export.cxx | 6 |
6 files changed, 44 insertions, 54 deletions
diff --git a/xmlscript/source/xmldlg_imexp/xmldlg_expmodels.cxx b/xmlscript/source/xmldlg_imexp/xmldlg_expmodels.cxx index 0646be0cc824..be5899fb72d9 100644 --- a/xmlscript/source/xmldlg_imexp/xmldlg_expmodels.cxx +++ b/xmlscript/source/xmldlg_imexp/xmldlg_expmodels.cxx @@ -26,6 +26,7 @@ #include <com/sun/star/util/XNumberFormatsSupplier.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <o3tl/any.hxx> +#include <rtl/ref.hxx> using namespace ::com::sun::star; using namespace ::com::sun::star::uno; @@ -87,7 +88,7 @@ void ElementDescriptor::readMultiPageModel( StyleBag * all_styles ) uno::Reference< container::XNameContainer > xPagesContainer( _xProps, uno::UNO_QUERY ); if ( xPagesContainer.is() && xPagesContainer->getElementNames().hasElements() ) { - ElementDescriptor * pElem = new ElementDescriptor( _xProps, _xPropState, XMLNS_DIALOGS_PREFIX ":bulletinboard", _xDocument ); + rtl::Reference<ElementDescriptor> pElem = new ElementDescriptor( _xProps, _xPropState, XMLNS_DIALOGS_PREFIX ":bulletinboard", _xDocument ); pElem->readBullitinBoard( all_styles ); addSubElement( pElem ); } @@ -115,14 +116,14 @@ void ElementDescriptor::readFrameModel( StyleBag * all_styles ) if ( readProp( "Label" ) >>= aTitle) { - ElementDescriptor * title = new ElementDescriptor( _xProps, _xPropState, XMLNS_DIALOGS_PREFIX ":title", _xDocument ); + rtl::Reference<ElementDescriptor> title = new ElementDescriptor( _xProps, _xPropState, XMLNS_DIALOGS_PREFIX ":title", _xDocument ); title->addAttribute( XMLNS_DIALOGS_PREFIX ":value", aTitle ); addSubElement( title ); } uno::Reference< container::XNameContainer > xControlContainer( _xProps, uno::UNO_QUERY ); if ( xControlContainer.is() && xControlContainer->getElementNames().hasElements() ) { - ElementDescriptor * pElem = new ElementDescriptor( _xProps, _xPropState, XMLNS_DIALOGS_PREFIX ":bulletinboard", _xDocument ); + rtl::Reference<ElementDescriptor> pElem = new ElementDescriptor( _xProps, _xPropState, XMLNS_DIALOGS_PREFIX ":bulletinboard", _xDocument ); pElem->readBullitinBoard( all_styles ); addSubElement( pElem ); } @@ -152,7 +153,7 @@ void ElementDescriptor::readPageModel( StyleBag * all_styles ) uno::Reference< container::XNameContainer > xControlContainer( _xProps, uno::UNO_QUERY ); if ( xControlContainer.is() && xControlContainer->getElementNames().hasElements() ) { - ElementDescriptor * pElem = new ElementDescriptor( _xProps, _xPropState, XMLNS_DIALOGS_PREFIX ":bulletinboard", _xDocument ); + rtl::Reference<ElementDescriptor> pElem = new ElementDescriptor( _xProps, _xPropState, XMLNS_DIALOGS_PREFIX ":bulletinboard", _xDocument ); pElem->readBullitinBoard( all_styles ); addSubElement( pElem ); } @@ -312,11 +313,11 @@ void ElementDescriptor::readComboBoxModel( StyleBag * all_styles ) Sequence< OUString > itemValues; if ((readProp( "StringItemList" ) >>= itemValues) && itemValues.hasElements()) { - ElementDescriptor * popup = new ElementDescriptor( _xProps, _xPropState, XMLNS_DIALOGS_PREFIX ":menupopup", _xDocument ); + rtl::Reference<ElementDescriptor> popup = new ElementDescriptor( _xProps, _xPropState, XMLNS_DIALOGS_PREFIX ":menupopup", _xDocument ); for ( const auto& rItemValue : std::as_const(itemValues) ) { - ElementDescriptor * item = new ElementDescriptor( _xProps, _xPropState, XMLNS_DIALOGS_PREFIX ":menuitem", _xDocument ); + rtl::Reference<ElementDescriptor> item = new ElementDescriptor( _xProps, _xPropState, XMLNS_DIALOGS_PREFIX ":menuitem", _xDocument ); item->addAttribute( XMLNS_DIALOGS_PREFIX ":value", rItemValue ); popup->addSubElement( item ); } @@ -359,11 +360,11 @@ void ElementDescriptor::readListBoxModel( StyleBag * all_styles ) Sequence< OUString > itemValues; if ((readProp( "StringItemList" ) >>= itemValues) && itemValues.hasElements()) { - ElementDescriptor * popup = new ElementDescriptor( _xProps, _xPropState, XMLNS_DIALOGS_PREFIX ":menupopup", _xDocument ); + rtl::Reference<ElementDescriptor> popup = new ElementDescriptor( _xProps, _xPropState, XMLNS_DIALOGS_PREFIX ":menupopup", _xDocument ); for ( const auto& rItemValue : std::as_const(itemValues) ) { - ElementDescriptor * item = new ElementDescriptor(_xProps, _xPropState, XMLNS_DIALOGS_PREFIX ":menuitem", _xDocument ); + rtl::Reference<ElementDescriptor> item = new ElementDescriptor(_xProps, _xPropState, XMLNS_DIALOGS_PREFIX ":menuitem", _xDocument ); item->addAttribute( XMLNS_DIALOGS_PREFIX ":value", rItemValue ); popup->addSubElement( item ); } @@ -456,7 +457,7 @@ void ElementDescriptor::readGroupBoxModel( StyleBag * all_styles ) OUString aTitle; if (readProp( "Label" ) >>= aTitle) { - ElementDescriptor * title = new ElementDescriptor( _xProps, _xPropState, XMLNS_DIALOGS_PREFIX ":title", _xDocument ); + rtl::Reference<ElementDescriptor> title = new ElementDescriptor( _xProps, _xPropState, XMLNS_DIALOGS_PREFIX ":title", _xDocument ); title->addAttribute( XMLNS_DIALOGS_PREFIX ":value", aTitle ); addSubElement( title ); } @@ -1077,14 +1078,14 @@ void ElementDescriptor::readDialogModel( StyleBag * all_styles ) void ElementDescriptor::readBullitinBoard( StyleBag * all_styles ) { // collect elements - ::std::vector< ElementDescriptor* > all_elements; + ::std::vector< rtl::Reference<ElementDescriptor> > all_elements; // read out all props Reference< container::XNameContainer > xDialogModel( _xProps, UNO_QUERY ); if ( !xDialogModel.is() ) return; // #TODO throw??? const Sequence< OUString > aElements( xDialogModel->getElementNames() ); - ElementDescriptor * pRadioGroup = nullptr; + rtl::Reference<ElementDescriptor> pRadioGroup; for ( const auto& rElement : aElements ) { @@ -1102,7 +1103,7 @@ void ElementDescriptor::readBullitinBoard( StyleBag * all_styles ) if (! xServiceInfo.is()) continue; - ElementDescriptor * pElem = nullptr; + rtl::Reference<ElementDescriptor> pElem; // group up radio buttons if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlRadioButtonModel" ) ) @@ -1259,7 +1260,7 @@ void ElementDescriptor::readBullitinBoard( StyleBag * all_styles ) } } } - for (ElementDescriptor* p : all_elements) + for (rtl::Reference<ElementDescriptor> & p : all_elements) { addSubElement( p ); } diff --git a/xmlscript/source/xmldlg_imexp/xmldlg_export.cxx b/xmlscript/source/xmldlg_imexp/xmldlg_export.cxx index 77f606728d0a..55ee293bc464 100644 --- a/xmlscript/source/xmldlg_imexp/xmldlg_export.cxx +++ b/xmlscript/source/xmldlg_imexp/xmldlg_export.cxx @@ -68,6 +68,7 @@ #include <comphelper/processfactory.hxx> #include <i18nlangtag/languagetag.hxx> +#include <rtl/ref.hxx> using namespace ::com::sun::star; using namespace ::com::sun::star::uno; @@ -77,7 +78,7 @@ namespace xmlscript Reference< xml::sax::XAttributeList > Style::createElement() { - ElementDescriptor * pStyle = new ElementDescriptor( XMLNS_DIALOGS_PREFIX ":style" ); + rtl::Reference<ElementDescriptor> pStyle = new ElementDescriptor( XMLNS_DIALOGS_PREFIX ":style" ); // style-id pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":style-id", _id ); @@ -1188,21 +1189,16 @@ void ElementDescriptor::readEvents() } } - ElementDescriptor * pElem; - Reference< xml::sax::XAttributeList > xElem; + rtl::Reference<ElementDescriptor> pElem; if (!aEventName.isEmpty()) // script:event { pElem = new ElementDescriptor( XMLNS_SCRIPT_PREFIX ":event" ); - xElem = pElem; - pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":event-name", aEventName ); } else // script:listener-event { pElem = new ElementDescriptor( XMLNS_SCRIPT_PREFIX ":listener-event" ); - xElem = pElem; - pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":listener-type", descr.ListenerType ); pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":listener-method", descr.EventMethod ); @@ -1233,7 +1229,7 @@ void ElementDescriptor::readEvents() // language pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":language", descr.ScriptType ); - addSubElement( xElem ); + addSubElement( pElem ); } else { @@ -1378,8 +1374,7 @@ void exportDialogModel( Reference< beans::XPropertyState > xPropState( xProps, UNO_QUERY ); OSL_ASSERT( xPropState.is() ); - ElementDescriptor * pElem = new ElementDescriptor( xProps, xPropState, XMLNS_DIALOGS_PREFIX ":bulletinboard", xDocument ); - Reference< xml::sax::XAttributeList > xElem( pElem ); + rtl::Reference<ElementDescriptor> pElem = new ElementDescriptor( xProps, xPropState, XMLNS_DIALOGS_PREFIX ":bulletinboard", xDocument ); pElem->readBullitinBoard( &all_styles ); xOut->startDocument(); @@ -1390,11 +1385,10 @@ void exportDialogModel( xOut->ignorableWhitespace( OUString() ); OUString aWindowName( XMLNS_DIALOGS_PREFIX ":window" ); - ElementDescriptor * pWindow = new ElementDescriptor( xProps, xPropState, aWindowName, xDocument ); - Reference< xml::sax::XAttributeList > xWindow( pWindow ); + rtl::Reference<ElementDescriptor> pWindow = new ElementDescriptor( xProps, xPropState, aWindowName, xDocument ); pWindow->readDialogModel( &all_styles ); xOut->ignorableWhitespace( OUString() ); - xOut->startElement( aWindowName, xWindow ); + xOut->startElement( aWindowName, pWindow ); // dump out events pWindow->dumpSubElements( xOut ); // dump out stylebag @@ -1405,7 +1399,7 @@ void exportDialogModel( // open up bulletinboard OUString aBBoardName( XMLNS_DIALOGS_PREFIX ":bulletinboard" ); xOut->ignorableWhitespace( OUString() ); - xOut->startElement( aBBoardName, xElem ); + xOut->startElement( aBBoardName, pElem ); pElem->dumpSubElements( xOut ); // end bulletinboard diff --git a/xmlscript/source/xmldlg_imexp/xmldlg_impmodels.cxx b/xmlscript/source/xmldlg_imexp/xmldlg_impmodels.cxx index 9f324465cf48..424058cd28fa 100644 --- a/xmlscript/source/xmldlg_imexp/xmldlg_impmodels.cxx +++ b/xmlscript/source/xmldlg_imexp/xmldlg_impmodels.cxx @@ -47,9 +47,9 @@ Reference< xml::input::XElement > Frame::startChildElement( else if ( rLocalName == "bulletinboard" ) { // Create new DialogImport for this container - DialogImport* pFrameImport = new DialogImport( *m_xImport ); + rtl::Reference<DialogImport> pFrameImport = new DialogImport( *m_xImport ); pFrameImport->_xDialogModel = m_xContainer; - return new BulletinBoardElement( rLocalName, xAttributes, this, pFrameImport ); + return new BulletinBoardElement( rLocalName, xAttributes, this, pFrameImport.get() ); } else if ( rLocalName == "title" ) { @@ -111,9 +111,9 @@ Reference< xml::input::XElement > MultiPage::startChildElement( { // Create new DialogImport for this container - DialogImport* pMultiPageImport = new DialogImport( *m_xImport ); + rtl::Reference<DialogImport> pMultiPageImport = new DialogImport( *m_xImport ); pMultiPageImport->_xDialogModel = m_xContainer; - return new BulletinBoardElement( rLocalName, xAttributes, this, pMultiPageImport ); + return new BulletinBoardElement( rLocalName, xAttributes, this, pMultiPageImport.get() ); } else { @@ -164,9 +164,9 @@ Reference< xml::input::XElement > Page::startChildElement( else if ( rLocalName == "bulletinboard" ) { - DialogImport* pPageImport = new DialogImport( *m_xImport ); + rtl::Reference<DialogImport> pPageImport = new DialogImport( *m_xImport ); pPageImport->_xDialogModel = m_xContainer; - return new BulletinBoardElement( rLocalName, xAttributes, this, pPageImport ); + return new BulletinBoardElement( rLocalName, xAttributes, this, pPageImport.get() ); } else { diff --git a/xmlscript/source/xmlflat_imexp/xmlbas_export.cxx b/xmlscript/source/xmlflat_imexp/xmlbas_export.cxx index 8a7ade47d61a..fcec0985dbec 100644 --- a/xmlscript/source/xmlflat_imexp/xmlbas_export.cxx +++ b/xmlscript/source/xmlflat_imexp/xmlbas_export.cxx @@ -31,6 +31,7 @@ #include <com/sun/star/xml/sax/SAXException.hpp> #include <cppuhelper/supportsservice.hxx> #include <tools/diagnose_ex.h> +#include <rtl/ref.hxx> using namespace ::com::sun::star; using namespace ::com::sun::star::lang; @@ -118,8 +119,7 @@ sal_Bool XMLBasicExporterBase::filter( const Sequence< beans::PropertyValue >& / // ooo/script:libraries element OUString aLibContElementName = aPrefix + ":libraries"; - XMLElement* pLibContElement = new XMLElement( aLibContElementName ); - Reference< xml::sax::XAttributeList > xLibContAttribs( pLibContElement ); + rtl::Reference<XMLElement> pLibContElement = new XMLElement( aLibContElementName ); // ooo/script namespace attribute pLibContElement->addAttribute( "xmlns:" + aPrefix, aURI ); @@ -129,7 +129,7 @@ sal_Bool XMLBasicExporterBase::filter( const Sequence< beans::PropertyValue >& / // <ooo/script:libraries... m_xHandler->ignorableWhitespace( OUString() ); - m_xHandler->startElement( aLibContElementName, xLibContAttribs ); + m_xHandler->startElement( aLibContElementName, pLibContElement ); Reference< script::XLibraryContainer2 > xLibContainer; @@ -161,8 +161,7 @@ sal_Bool XMLBasicExporterBase::filter( const Sequence< beans::PropertyValue >& / { // ooo/script:library-linked element OUString aLibElementName = aPrefix + ":library-linked"; - XMLElement* pLibElement = new XMLElement( aLibElementName ); - Reference< xml::sax::XAttributeList > xLibAttribs = static_cast< xml::sax::XAttributeList* >( pLibElement ); + rtl::Reference<XMLElement> pLibElement = new XMLElement( aLibElementName ); // ooo/script:name attribute pLibElement->addAttribute( aPrefix + ":name", rLibName ); @@ -185,7 +184,7 @@ sal_Bool XMLBasicExporterBase::filter( const Sequence< beans::PropertyValue >& / // <ooo/script:library-linked... m_xHandler->ignorableWhitespace( OUString() ); - m_xHandler->startElement( aLibElementName, xLibAttribs ); + m_xHandler->startElement( aLibElementName, pLibElement ); // ...ooo/script:library-linked> m_xHandler->ignorableWhitespace( OUString() ); @@ -195,8 +194,7 @@ sal_Bool XMLBasicExporterBase::filter( const Sequence< beans::PropertyValue >& / { // ooo/script:library-embedded element OUString aLibElementName = aPrefix + ":library-embedded"; - XMLElement* pLibElement = new XMLElement( aLibElementName ); - Reference< xml::sax::XAttributeList > xLibAttribs = static_cast< xml::sax::XAttributeList* >( pLibElement ); + rtl::Reference<XMLElement> pLibElement = new XMLElement( aLibElementName ); // ooo/script:name attribute pLibElement->addAttribute( aPrefix + ":name", rLibName ); @@ -214,7 +212,7 @@ sal_Bool XMLBasicExporterBase::filter( const Sequence< beans::PropertyValue >& / // <ooo/script:library-embedded... m_xHandler->ignorableWhitespace( OUString() ); - m_xHandler->startElement( aLibElementName, xLibAttribs ); + m_xHandler->startElement( aLibElementName, pLibElement ); if ( !xLibContainer->isLibraryLoaded( rLibName ) ) xLibContainer->loadLibrary( rLibName ); @@ -231,24 +229,22 @@ sal_Bool XMLBasicExporterBase::filter( const Sequence< beans::PropertyValue >& / { // ooo/script:module element OUString aModElementName = aPrefix + ":module"; - XMLElement* pModElement = new XMLElement( aModElementName ); - Reference< xml::sax::XAttributeList > xModAttribs = static_cast< xml::sax::XAttributeList* >( pModElement ); + rtl::Reference<XMLElement> pModElement = new XMLElement( aModElementName ); // ooo/script:name attribute pModElement->addAttribute( aPrefix + ":name", rModName ); // <ooo/script:module... m_xHandler->ignorableWhitespace( OUString() ); - m_xHandler->startElement( aModElementName, xModAttribs ); + m_xHandler->startElement( aModElementName, pModElement ); // ooo/script:source-code element OUString aSourceElementName = aPrefix + ":source-code"; - XMLElement* pSourceElement = new XMLElement( aSourceElementName ); - Reference< xml::sax::XAttributeList > xSourceAttribs = static_cast< xml::sax::XAttributeList* >( pSourceElement ); + rtl::Reference<XMLElement> pSourceElement = new XMLElement( aSourceElementName ); // <ooo/script:source-code... m_xHandler->ignorableWhitespace( OUString() ); - m_xHandler->startElement( aSourceElementName, xSourceAttribs ); + m_xHandler->startElement( aSourceElementName, pSourceElement ); // module data // TODO: write encrypted data for password protected libraries diff --git a/xmlscript/source/xmllib_imexp/xmllib_export.cxx b/xmlscript/source/xmllib_imexp/xmllib_export.cxx index 33e531ac14c5..00f8045a0b0c 100644 --- a/xmlscript/source/xmllib_imexp/xmllib_export.cxx +++ b/xmlscript/source/xmllib_imexp/xmllib_export.cxx @@ -45,14 +45,13 @@ exportLibraryContainer( xOut->ignorableWhitespace( OUString() ); OUString aLibrariesName( XMLNS_LIBRARY_PREFIX ":libraries" ); - XMLElement* pLibsElement = new XMLElement( aLibrariesName ); - Reference< xml::sax::XAttributeList > xAttributes( pLibsElement ); + rtl::Reference<XMLElement> pLibsElement = new XMLElement( aLibrariesName ); pLibsElement->addAttribute( "xmlns:" XMLNS_LIBRARY_PREFIX, XMLNS_LIBRARY_URI ); pLibsElement->addAttribute( "xmlns:" XMLNS_XLINK_PREFIX, XMLNS_XLINK_URI ); xOut->ignorableWhitespace( OUString() ); - xOut->startElement( aLibrariesName, xAttributes ); + xOut->startElement( aLibrariesName, pLibsElement ); OUString sTrueStr(aTrueStr); OUString sFalseStr(aFalseStr); diff --git a/xmlscript/source/xmlmod_imexp/xmlmod_export.cxx b/xmlscript/source/xmlmod_imexp/xmlmod_export.cxx index 57c3b1dcceb1..55b447561544 100644 --- a/xmlscript/source/xmlmod_imexp/xmlmod_export.cxx +++ b/xmlscript/source/xmlmod_imexp/xmlmod_export.cxx @@ -21,6 +21,7 @@ #include <xmlscript/xml_helper.hxx> #include <xmlscript/xmlns.h> #include <com/sun/star/xml/sax/XWriter.hpp> +#include <rtl/ref.hxx> using namespace com::sun::star::uno; using namespace com::sun::star; @@ -41,8 +42,7 @@ exportScriptModule( xOut->ignorableWhitespace( OUString() ); OUString aModuleName( XMLNS_SCRIPT_PREFIX ":module" ); - XMLElement* pModElement = new XMLElement( aModuleName ); - Reference< xml::sax::XAttributeList > xAttributes( pModElement ); + rtl::Reference<XMLElement> pModElement = new XMLElement( aModuleName ); pModElement->addAttribute( "xmlns:" XMLNS_SCRIPT_PREFIX, XMLNS_SCRIPT_URI ); @@ -52,7 +52,7 @@ exportScriptModule( pModElement->addAttribute( XMLNS_SCRIPT_PREFIX ":moduleType", rMod.aModuleType ); xOut->ignorableWhitespace( OUString() ); - xOut->startElement( aModuleName, xAttributes ); + xOut->startElement( aModuleName, pModElement ); xOut->characters( rMod.aCode ); xOut->endElement( aModuleName ); xOut->endDocument(); |