diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-01-26 10:24:01 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-01-26 09:22:50 +0000 |
commit | 13aa595069250cc4b52ff4795a90317b2e9f50f0 (patch) | |
tree | c77ede67b21afcc0696b9fd448f37b4e5cddb09f /forms | |
parent | 068edb65b1dce375223d8642a01b07db3948ac03 (diff) |
use rtl::Reference in Model
instead of storing both raw pointers and an uno::Reference
Change-Id: I93871eaf9807d0fa846a4e1090d7ee7b1db01c5e
Reviewed-on: https://gerrit.libreoffice.org/33571
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'forms')
-rw-r--r-- | forms/source/xforms/model.cxx | 75 | ||||
-rw-r--r-- | forms/source/xforms/model.hxx | 14 | ||||
-rw-r--r-- | forms/source/xforms/model_ui.cxx | 24 |
3 files changed, 45 insertions, 68 deletions
diff --git a/forms/source/xforms/model.cxx b/forms/source/xforms/model.cxx index dfd1d008ee97..5420394189a3 100644 --- a/forms/source/xforms/model.cxx +++ b/forms/source/xforms/model.cxx @@ -81,7 +81,7 @@ using namespace xforms; void Model::ensureAtLeastOneInstance() { - if( ! mpInstances->hasItems() ) + if( ! mxInstances->hasItems() ) { // create a default instance newInstance( OUString(), OUString(), true ); @@ -92,13 +92,8 @@ void Model::ensureAtLeastOneInstance() /** Model default constructor; create empty model */ Model::Model() : msID(), - mpBindings( nullptr ), - mpSubmissions( nullptr ), - mpInstances( new InstanceCollection ), + mxInstances( new InstanceCollection ), mxNamespaces( new NameContainer<OUString>() ), - mxBindings( mpBindings ), - mxSubmissions( mpSubmissions ), - mxInstances( mpInstances ), mbInitialized( false ), mbExternalData( true ) { @@ -106,11 +101,8 @@ Model::Model() : // initialize bindings collections // (not in initializer list to avoid use of incomplete 'this') - mpBindings = new BindingCollection( this ); - mxBindings = mpBindings; - - mpSubmissions = new SubmissionCollection( this ); - mxSubmissions = mpSubmissions; + mxBindings = new BindingCollection( this ); + mxSubmissions = new SubmissionCollection( this ); // invariant only holds after construction DBG_INVARIANT(); @@ -118,10 +110,6 @@ Model::Model() : Model::~Model() throw() { - // give up bindings & submissions; the mxBindings/mxSubmissions - // references will then delete them - mpBindings = nullptr; - mpSubmissions = nullptr; } static Model* lcl_getModel( const Reference<XUnoTunnel>& xTunnel ) @@ -194,14 +182,9 @@ void Model::setExternalData( bool _bData ) #if OSL_DEBUG_LEVEL > 0 void Model::dbg_assertInvariant() const { - assert(mpInstances && "no instances found"); - assert(mxInstances.is() && "No instance container!"); - - assert(mpBindings && "no bindings element"); - assert(mxBindings.is() && "No Bindings container"); - - assert(mpSubmissions && "no submissions element"); - assert(mxSubmissions.is() && "No Submission container"); + assert(mxInstances && "no instances found"); + assert(mxBindings && "no bindings element"); + assert(mxSubmissions && "no submissions element"); } #endif @@ -262,13 +245,13 @@ MIP Model::queryMIP( const XNode_t& xNode ) const void Model::rebind() { - OSL_ENSURE( mpBindings != nullptr, "bindings?" ); + OSL_ENSURE( mxBindings, "bindings?" ); // iterate over all bindings and call update - sal_Int32 nCount = mpBindings->countItems(); + sal_Int32 nCount = mxBindings->countItems(); for( sal_Int32 i = 0; i < nCount; i++ ) { - Binding* pBind = Binding::getBinding( mpBindings->Collection<XPropertySet_t>::getItem( i ) ); + Binding* pBind = Binding::getBinding( mxBindings->Collection<XPropertySet_t>::getItem( i ) ); OSL_ENSURE( pBind != nullptr, "binding?" ); pBind->update(); } @@ -278,10 +261,10 @@ void Model::rebind() void Model::deferNotifications( bool bDefer ) { // iterate over all bindings and defer notifications - sal_Int32 nCount = mpBindings->countItems(); + sal_Int32 nCount = mxBindings->countItems(); for( sal_Int32 i = 0; i < nCount; i++ ) { - Binding* pBind = Binding::getBinding( mpBindings->Collection<XPropertySet_t>::getItem( i ) ); + Binding* pBind = Binding::getBinding( mxBindings->Collection<XPropertySet_t>::getItem( i ) ); OSL_ENSURE( pBind != nullptr, "binding?" ); pBind->deferNotifications( bDefer ); } @@ -353,7 +336,7 @@ bool Model::setSimpleContent( const XNode_t& xConstNode, void Model::loadInstance( sal_Int32 nInstance ) { - Sequence<PropertyValue> aSequence = mpInstances->getItem( nInstance ); + Sequence<PropertyValue> aSequence = mxInstances->getItem( nInstance ); // find URL from instance OUString sURL; @@ -376,7 +359,7 @@ void Model::loadInstance( sal_Int32 nInstance ) OUString sEmpty; setInstanceData( aSequence, nullptr, &xInstance, bOnce ? &sEmpty : &sURL, nullptr); - mpInstances->setItem( nInstance, aSequence ); + mxInstances->setItem( nInstance, aSequence ); } } } @@ -390,7 +373,7 @@ void Model::loadInstance( sal_Int32 nInstance ) void Model::loadInstances() { // iterate over instance array to get PropertyValue-Sequence - const sal_Int32 nInstances = mpInstances->countItems(); + const sal_Int32 nInstances = mxInstances->countItems(); for( sal_Int32 nInstance = 0; nInstance < nInstances; nInstance++ ) { loadInstance( nInstance ); @@ -401,10 +384,10 @@ void Model::loadInstances() bool Model::isValid() const { bool bValid = true; - sal_Int32 nCount = mpBindings->countItems(); + sal_Int32 nCount = mxBindings->countItems(); for( sal_Int32 i = 0; bValid && i < nCount; i++ ) { - Binding* pBind = Binding::getBinding( mpBindings->Collection<XPropertySet_t>::getItem( i ) ); + Binding* pBind = Binding::getBinding( mxBindings->Collection<XPropertySet_t>::getItem( i ) ); OSL_ENSURE( pBind != nullptr, "binding?" ); bValid = pBind->isValid(); } @@ -479,10 +462,10 @@ void SAL_CALL Model::submitWithInteraction( { DBG_INVARIANT(); - if( mpSubmissions->hasItem( sID ) ) + if( mxSubmissions->hasItem( sID ) ) { Submission* pSubmission = - Submission::getSubmission( mpSubmissions->getItem( sID ) ); + Submission::getSubmission( mxSubmissions->getItem( sID ) ); OSL_ENSURE( pSubmission != nullptr, "no submission?" ); OSL_ENSURE( pSubmission->getModel() == Reference<XModel>( this ), "wrong model" ); @@ -514,7 +497,7 @@ css::uno::Reference<css::xforms::XDataTypeRepository> SAL_CALL Model::getDataTyp css::uno::Reference<css::container::XSet> Model::getInstances() throw( RuntimeException, std::exception ) { - return mxInstances; + return mxInstances.get(); } css::uno::Reference<css::xml::dom::XDocument> Model::getInstanceDocument( const OUString& rName ) @@ -522,9 +505,9 @@ css::uno::Reference<css::xml::dom::XDocument> Model::getInstanceDocument( const { ensureAtLeastOneInstance(); Reference<XDocument> aInstance; - sal_Int32 nInstance = lcl_findInstance( mpInstances, rName ); + sal_Int32 nInstance = lcl_findInstance( mxInstances.get(), rName ); if( nInstance != -1 ) - getInstanceData( mpInstances->getItem( nInstance ), + getInstanceData( mxInstances->getItem( nInstance ), nullptr, &aInstance, nullptr, nullptr ); return aInstance; } @@ -533,9 +516,9 @@ css::uno::Reference<css::xml::dom::XDocument> SAL_CALL Model::getDefaultInstance throw( RuntimeException, std::exception ) { ensureAtLeastOneInstance(); - DBG_ASSERT( mpInstances->countItems() > 0, "no instance?" ); + DBG_ASSERT( mxInstances->countItems() > 0, "no instance?" ); Reference<XDocument> aInstance; - getInstanceData( mpInstances->getItem( 0 ), nullptr, &aInstance, nullptr, nullptr ); + getInstanceData( mxInstances->getItem( 0 ), nullptr, &aInstance, nullptr, nullptr ); return aInstance; } @@ -563,14 +546,14 @@ Model::XPropertySet_t Model::getBinding( const OUString& sId ) throw( RuntimeException, std::exception ) { DBG_INVARIANT(); - return mpBindings->hasItem( sId ) ? mpBindings->getItem( sId ) : nullptr; + return mxBindings->hasItem( sId ) ? mxBindings->getItem( sId ) : nullptr; } css::uno::Reference<css::container::XSet> Model::getBindings() throw( RuntimeException, std::exception ) { DBG_INVARIANT(); - return mxBindings; + return mxBindings.get(); } @@ -599,8 +582,8 @@ css::uno::Reference<css::xforms::XSubmission> Model::getSubmission( const OUStri { DBG_INVARIANT(); css::uno::Reference<css::xforms::XSubmission> xSubmission; - if ( mpSubmissions->hasItem( sId ) ) - xSubmission.set(mpSubmissions->getItem( sId ), css::uno::UNO_QUERY); + if ( mxSubmissions->hasItem( sId ) ) + xSubmission.set(mxSubmissions->getItem( sId ), css::uno::UNO_QUERY); return xSubmission; } @@ -608,7 +591,7 @@ css::uno::Reference<css::container::XSet> Model::getSubmissions() throw( RuntimeException, std::exception ) { DBG_INVARIANT(); - return mxSubmissions; + return mxSubmissions.get(); } diff --git a/forms/source/xforms/model.hxx b/forms/source/xforms/model.hxx index 87fe6066be3d..2b79153a22b5 100644 --- a/forms/source/xforms/model.hxx +++ b/forms/source/xforms/model.hxx @@ -27,8 +27,8 @@ #include <com/sun/star/util/XUpdatable.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/lang/XUnoTunnel.hpp> - #include <com/sun/star/uno/Reference.hxx> +#include <rtl/ref.hxx> #include "mip.hxx" #include <map> @@ -86,9 +86,9 @@ class Model : public Model_t private: OUString msID; /// the model ID - BindingCollection* mpBindings; /// the bindings - SubmissionCollection* mpSubmissions; /// the submissions - InstanceCollection* mpInstances; /// the instance(s) + rtl::Reference<BindingCollection> mxBindings; /// the bindings + rtl::Reference<SubmissionCollection> mxSubmissions; /// the submissions + rtl::Reference<InstanceCollection> mxInstances; /// the instance(s) css::uno::Reference<css::xforms::XDataTypeRepository> mxDataTypes; /// the XSD data-types used css::uno::Reference<css::xml::dom::XDocument> mxForeignSchema; /// the XSD-schema part we cannot @@ -97,12 +97,6 @@ private: css::uno::Reference<css::container::XNameContainer> mxNamespaces; /// namespaces for entire model - - // references to mpBindings/mpSubmissions, for UNO reference counting - css::uno::Reference<css::container::XSet> mxBindings; - css::uno::Reference<css::container::XSet> mxSubmissions; - css::uno::Reference<css::container::XSet> mxInstances; - MIPs_t maMIPs; /// map nodes to their MIPs bool mbInitialized; /// has model been initialized ? diff --git a/forms/source/xforms/model_ui.cxx b/forms/source/xforms/model_ui.cxx index fa4be64f2e54..b279301ad8fc 100644 --- a/forms/source/xforms/model_ui.cxx +++ b/forms/source/xforms/model_ui.cxx @@ -391,7 +391,7 @@ void Model::removeBindingIfUseless( const XPropertySet_t& xBinding ) if( pBinding != nullptr ) { if( ! pBinding->isUseful() ) - mpBindings->removeItem( pBinding ); + mxBindings->removeItem( pBinding ); } } @@ -411,7 +411,7 @@ css::uno::Reference<css::xml::dom::XDocument> Model::newInstance( const OUString Sequence<PropertyValue> aSequence; bool bOnce = bURLOnce; // bool, so we can take address in setInstanceData setInstanceData( aSequence, &sName, &xInstance, &sURL, &bOnce ); - sal_Int32 nInstance = mpInstances->addItem( aSequence ); + sal_Int32 nInstance = mxInstances->addItem( aSequence ); loadInstance( nInstance ); return xInstance; @@ -451,10 +451,10 @@ void Model::renameInstance( const OUString& sFrom, sal_Bool bURLOnce ) throw( RuntimeException, std::exception ) { - sal_Int32 nPos = lcl_findInstance( mpInstances, sFrom ); + sal_Int32 nPos = lcl_findInstance( mxInstances.get(), sFrom ); if( nPos != -1 ) { - Sequence<PropertyValue> aSeq = mpInstances->getItem( nPos ); + Sequence<PropertyValue> aSeq = mxInstances->getItem( nPos ); PropertyValue* pSeq = aSeq.getArray(); sal_Int32 nLength = aSeq.getLength(); @@ -482,16 +482,16 @@ void Model::renameInstance( const OUString& sFrom, pSeq[ nProp ].Value <<= bURLOnce; // set instance - mpInstances->setItem( nPos, aSeq ); + mxInstances->setItem( nPos, aSeq ); } } void Model::removeInstance( const OUString& sName ) throw( RuntimeException, std::exception ) { - sal_Int32 nPos = lcl_findInstance( mpInstances, sName ); + sal_Int32 nPos = lcl_findInstance( mxInstances.get(), sName ); if( nPos != -1 ) - mpInstances->removeItem( mpInstances->getItem( nPos ) ); + mxInstances->removeItem( mxInstances->getItem( nPos ) ); } static Reference<XNameContainer> lcl_getModels( @@ -666,10 +666,10 @@ Model::XNode_t Model::renameNode( const XNode_t& xNode, // iterate over bindings and replace default expressions OUString sNewDefaultBindingExpression = getDefaultBindingExpressionForNode( xNew ); - for( sal_Int32 n = 0; n < mpBindings->countItems(); n++ ) + for( sal_Int32 n = 0; n < mxBindings->countItems(); n++ ) { Binding* pBinding = Binding::getBinding( - mpBindings->Collection<XPropertySet_t>::getItem( n ) ); + mxBindings->Collection<XPropertySet_t>::getItem( n ) ); if( pBinding->getBindingExpression() == sOldDefaultBindingExpression ) @@ -694,10 +694,10 @@ Model::XPropertySet_t Model::getBindingForNode( const XNode_t& xNode, Binding* pBestBinding = nullptr; sal_Int32 nBestScore = 0; - for( sal_Int32 n = 0; n < mpBindings->countItems(); n++ ) + for( sal_Int32 n = 0; n < mxBindings->countItems(); n++ ) { Binding* pBinding = Binding::getBinding( - mpBindings->Collection<XPropertySet_t>::getItem( n ) ); + mxBindings->Collection<XPropertySet_t>::getItem( n ) ); OSL_ENSURE( pBinding != nullptr, "no binding?" ); Reference<XNodeList> xNodeList = pBinding->getXNodeList(); @@ -732,7 +732,7 @@ Model::XPropertySet_t Model::getBindingForNode( const XNode_t& xNode, pBestBinding = new Binding(); pBestBinding->setBindingExpression( getDefaultBindingExpressionForNode( xNode ) ); - mpBindings->addItem( pBestBinding ); + mxBindings->addItem( pBestBinding ); } return pBestBinding; |