Kaydet (Commit) 13aa5950 authored tarafından Noel Grandin's avatar Noel Grandin

use rtl::Reference in Model

instead of storing both raw pointers and an uno::Reference

Change-Id: I93871eaf9807d0fa846a4e1090d7ee7b1db01c5e
Reviewed-on: https://gerrit.libreoffice.org/33571Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 068edb65
...@@ -81,7 +81,7 @@ using namespace xforms; ...@@ -81,7 +81,7 @@ using namespace xforms;
void Model::ensureAtLeastOneInstance() void Model::ensureAtLeastOneInstance()
{ {
if( ! mpInstances->hasItems() ) if( ! mxInstances->hasItems() )
{ {
// create a default instance // create a default instance
newInstance( OUString(), OUString(), true ); newInstance( OUString(), OUString(), true );
...@@ -92,13 +92,8 @@ void Model::ensureAtLeastOneInstance() ...@@ -92,13 +92,8 @@ void Model::ensureAtLeastOneInstance()
/** Model default constructor; create empty model */ /** Model default constructor; create empty model */
Model::Model() : Model::Model() :
msID(), msID(),
mpBindings( nullptr ), mxInstances( new InstanceCollection ),
mpSubmissions( nullptr ),
mpInstances( new InstanceCollection ),
mxNamespaces( new NameContainer<OUString>() ), mxNamespaces( new NameContainer<OUString>() ),
mxBindings( mpBindings ),
mxSubmissions( mpSubmissions ),
mxInstances( mpInstances ),
mbInitialized( false ), mbInitialized( false ),
mbExternalData( true ) mbExternalData( true )
{ {
...@@ -106,11 +101,8 @@ Model::Model() : ...@@ -106,11 +101,8 @@ Model::Model() :
// initialize bindings collections // initialize bindings collections
// (not in initializer list to avoid use of incomplete 'this') // (not in initializer list to avoid use of incomplete 'this')
mpBindings = new BindingCollection( this ); mxBindings = new BindingCollection( this );
mxBindings = mpBindings; mxSubmissions = new SubmissionCollection( this );
mpSubmissions = new SubmissionCollection( this );
mxSubmissions = mpSubmissions;
// invariant only holds after construction // invariant only holds after construction
DBG_INVARIANT(); DBG_INVARIANT();
...@@ -118,10 +110,6 @@ Model::Model() : ...@@ -118,10 +110,6 @@ Model::Model() :
Model::~Model() throw() 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 ) static Model* lcl_getModel( const Reference<XUnoTunnel>& xTunnel )
...@@ -194,14 +182,9 @@ void Model::setExternalData( bool _bData ) ...@@ -194,14 +182,9 @@ void Model::setExternalData( bool _bData )
#if OSL_DEBUG_LEVEL > 0 #if OSL_DEBUG_LEVEL > 0
void Model::dbg_assertInvariant() const void Model::dbg_assertInvariant() const
{ {
assert(mpInstances && "no instances found"); assert(mxInstances && "no instances found");
assert(mxInstances.is() && "No instance container!"); assert(mxBindings && "no bindings element");
assert(mxSubmissions && "no submissions element");
assert(mpBindings && "no bindings element");
assert(mxBindings.is() && "No Bindings container");
assert(mpSubmissions && "no submissions element");
assert(mxSubmissions.is() && "No Submission container");
} }
#endif #endif
...@@ -262,13 +245,13 @@ MIP Model::queryMIP( const XNode_t& xNode ) const ...@@ -262,13 +245,13 @@ MIP Model::queryMIP( const XNode_t& xNode ) const
void Model::rebind() void Model::rebind()
{ {
OSL_ENSURE( mpBindings != nullptr, "bindings?" ); OSL_ENSURE( mxBindings, "bindings?" );
// iterate over all bindings and call update // 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++ ) 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?" ); OSL_ENSURE( pBind != nullptr, "binding?" );
pBind->update(); pBind->update();
} }
...@@ -278,10 +261,10 @@ void Model::rebind() ...@@ -278,10 +261,10 @@ void Model::rebind()
void Model::deferNotifications( bool bDefer ) void Model::deferNotifications( bool bDefer )
{ {
// iterate over all bindings and defer notifications // 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++ ) 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?" ); OSL_ENSURE( pBind != nullptr, "binding?" );
pBind->deferNotifications( bDefer ); pBind->deferNotifications( bDefer );
} }
...@@ -353,7 +336,7 @@ bool Model::setSimpleContent( const XNode_t& xConstNode, ...@@ -353,7 +336,7 @@ bool Model::setSimpleContent( const XNode_t& xConstNode,
void Model::loadInstance( sal_Int32 nInstance ) void Model::loadInstance( sal_Int32 nInstance )
{ {
Sequence<PropertyValue> aSequence = mpInstances->getItem( nInstance ); Sequence<PropertyValue> aSequence = mxInstances->getItem( nInstance );
// find URL from instance // find URL from instance
OUString sURL; OUString sURL;
...@@ -376,7 +359,7 @@ void Model::loadInstance( sal_Int32 nInstance ) ...@@ -376,7 +359,7 @@ void Model::loadInstance( sal_Int32 nInstance )
OUString sEmpty; OUString sEmpty;
setInstanceData( aSequence, nullptr, &xInstance, setInstanceData( aSequence, nullptr, &xInstance,
bOnce ? &sEmpty : &sURL, nullptr); bOnce ? &sEmpty : &sURL, nullptr);
mpInstances->setItem( nInstance, aSequence ); mxInstances->setItem( nInstance, aSequence );
} }
} }
} }
...@@ -390,7 +373,7 @@ void Model::loadInstance( sal_Int32 nInstance ) ...@@ -390,7 +373,7 @@ void Model::loadInstance( sal_Int32 nInstance )
void Model::loadInstances() void Model::loadInstances()
{ {
// iterate over instance array to get PropertyValue-Sequence // 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++ ) for( sal_Int32 nInstance = 0; nInstance < nInstances; nInstance++ )
{ {
loadInstance( nInstance ); loadInstance( nInstance );
...@@ -401,10 +384,10 @@ void Model::loadInstances() ...@@ -401,10 +384,10 @@ void Model::loadInstances()
bool Model::isValid() const bool Model::isValid() const
{ {
bool bValid = true; bool bValid = true;
sal_Int32 nCount = mpBindings->countItems(); sal_Int32 nCount = mxBindings->countItems();
for( sal_Int32 i = 0; bValid && i < nCount; i++ ) 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?" ); OSL_ENSURE( pBind != nullptr, "binding?" );
bValid = pBind->isValid(); bValid = pBind->isValid();
} }
...@@ -479,10 +462,10 @@ void SAL_CALL Model::submitWithInteraction( ...@@ -479,10 +462,10 @@ void SAL_CALL Model::submitWithInteraction(
{ {
DBG_INVARIANT(); DBG_INVARIANT();
if( mpSubmissions->hasItem( sID ) ) if( mxSubmissions->hasItem( sID ) )
{ {
Submission* pSubmission = Submission* pSubmission =
Submission::getSubmission( mpSubmissions->getItem( sID ) ); Submission::getSubmission( mxSubmissions->getItem( sID ) );
OSL_ENSURE( pSubmission != nullptr, "no submission?" ); OSL_ENSURE( pSubmission != nullptr, "no submission?" );
OSL_ENSURE( pSubmission->getModel() == Reference<XModel>( this ), OSL_ENSURE( pSubmission->getModel() == Reference<XModel>( this ),
"wrong model" ); "wrong model" );
...@@ -514,7 +497,7 @@ css::uno::Reference<css::xforms::XDataTypeRepository> SAL_CALL Model::getDataTyp ...@@ -514,7 +497,7 @@ css::uno::Reference<css::xforms::XDataTypeRepository> SAL_CALL Model::getDataTyp
css::uno::Reference<css::container::XSet> Model::getInstances() css::uno::Reference<css::container::XSet> Model::getInstances()
throw( RuntimeException, std::exception ) throw( RuntimeException, std::exception )
{ {
return mxInstances; return mxInstances.get();
} }
css::uno::Reference<css::xml::dom::XDocument> Model::getInstanceDocument( const OUString& rName ) 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 ...@@ -522,9 +505,9 @@ css::uno::Reference<css::xml::dom::XDocument> Model::getInstanceDocument( const
{ {
ensureAtLeastOneInstance(); ensureAtLeastOneInstance();
Reference<XDocument> aInstance; Reference<XDocument> aInstance;
sal_Int32 nInstance = lcl_findInstance( mpInstances, rName ); sal_Int32 nInstance = lcl_findInstance( mxInstances.get(), rName );
if( nInstance != -1 ) if( nInstance != -1 )
getInstanceData( mpInstances->getItem( nInstance ), getInstanceData( mxInstances->getItem( nInstance ),
nullptr, &aInstance, nullptr, nullptr ); nullptr, &aInstance, nullptr, nullptr );
return aInstance; return aInstance;
} }
...@@ -533,9 +516,9 @@ css::uno::Reference<css::xml::dom::XDocument> SAL_CALL Model::getDefaultInstance ...@@ -533,9 +516,9 @@ css::uno::Reference<css::xml::dom::XDocument> SAL_CALL Model::getDefaultInstance
throw( RuntimeException, std::exception ) throw( RuntimeException, std::exception )
{ {
ensureAtLeastOneInstance(); ensureAtLeastOneInstance();
DBG_ASSERT( mpInstances->countItems() > 0, "no instance?" ); DBG_ASSERT( mxInstances->countItems() > 0, "no instance?" );
Reference<XDocument> aInstance; Reference<XDocument> aInstance;
getInstanceData( mpInstances->getItem( 0 ), nullptr, &aInstance, nullptr, nullptr ); getInstanceData( mxInstances->getItem( 0 ), nullptr, &aInstance, nullptr, nullptr );
return aInstance; return aInstance;
} }
...@@ -563,14 +546,14 @@ Model::XPropertySet_t Model::getBinding( const OUString& sId ) ...@@ -563,14 +546,14 @@ Model::XPropertySet_t Model::getBinding( const OUString& sId )
throw( RuntimeException, std::exception ) throw( RuntimeException, std::exception )
{ {
DBG_INVARIANT(); 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() css::uno::Reference<css::container::XSet> Model::getBindings()
throw( RuntimeException, std::exception ) throw( RuntimeException, std::exception )
{ {
DBG_INVARIANT(); DBG_INVARIANT();
return mxBindings; return mxBindings.get();
} }
...@@ -599,8 +582,8 @@ css::uno::Reference<css::xforms::XSubmission> Model::getSubmission( const OUStri ...@@ -599,8 +582,8 @@ css::uno::Reference<css::xforms::XSubmission> Model::getSubmission( const OUStri
{ {
DBG_INVARIANT(); DBG_INVARIANT();
css::uno::Reference<css::xforms::XSubmission> xSubmission; css::uno::Reference<css::xforms::XSubmission> xSubmission;
if ( mpSubmissions->hasItem( sId ) ) if ( mxSubmissions->hasItem( sId ) )
xSubmission.set(mpSubmissions->getItem( sId ), css::uno::UNO_QUERY); xSubmission.set(mxSubmissions->getItem( sId ), css::uno::UNO_QUERY);
return xSubmission; return xSubmission;
} }
...@@ -608,7 +591,7 @@ css::uno::Reference<css::container::XSet> Model::getSubmissions() ...@@ -608,7 +591,7 @@ css::uno::Reference<css::container::XSet> Model::getSubmissions()
throw( RuntimeException, std::exception ) throw( RuntimeException, std::exception )
{ {
DBG_INVARIANT(); DBG_INVARIANT();
return mxSubmissions; return mxSubmissions.get();
} }
......
...@@ -27,8 +27,8 @@ ...@@ -27,8 +27,8 @@
#include <com/sun/star/util/XUpdatable.hpp> #include <com/sun/star/util/XUpdatable.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/XUnoTunnel.hpp> #include <com/sun/star/lang/XUnoTunnel.hpp>
#include <com/sun/star/uno/Reference.hxx> #include <com/sun/star/uno/Reference.hxx>
#include <rtl/ref.hxx>
#include "mip.hxx" #include "mip.hxx"
#include <map> #include <map>
...@@ -86,9 +86,9 @@ class Model : public Model_t ...@@ -86,9 +86,9 @@ class Model : public Model_t
private: private:
OUString msID; /// the model ID OUString msID; /// the model ID
BindingCollection* mpBindings; /// the bindings rtl::Reference<BindingCollection> mxBindings; /// the bindings
SubmissionCollection* mpSubmissions; /// the submissions rtl::Reference<SubmissionCollection> mxSubmissions; /// the submissions
InstanceCollection* mpInstances; /// the instance(s) rtl::Reference<InstanceCollection> mxInstances; /// the instance(s)
css::uno::Reference<css::xforms::XDataTypeRepository> mxDataTypes; /// the XSD data-types used 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 css::uno::Reference<css::xml::dom::XDocument> mxForeignSchema; /// the XSD-schema part we cannot
...@@ -97,12 +97,6 @@ private: ...@@ -97,12 +97,6 @@ private:
css::uno::Reference<css::container::XNameContainer> mxNamespaces; /// namespaces for entire model 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 MIPs_t maMIPs; /// map nodes to their MIPs
bool mbInitialized; /// has model been initialized ? bool mbInitialized; /// has model been initialized ?
......
...@@ -391,7 +391,7 @@ void Model::removeBindingIfUseless( const XPropertySet_t& xBinding ) ...@@ -391,7 +391,7 @@ void Model::removeBindingIfUseless( const XPropertySet_t& xBinding )
if( pBinding != nullptr ) if( pBinding != nullptr )
{ {
if( ! pBinding->isUseful() ) if( ! pBinding->isUseful() )
mpBindings->removeItem( pBinding ); mxBindings->removeItem( pBinding );
} }
} }
...@@ -411,7 +411,7 @@ css::uno::Reference<css::xml::dom::XDocument> Model::newInstance( const OUString ...@@ -411,7 +411,7 @@ css::uno::Reference<css::xml::dom::XDocument> Model::newInstance( const OUString
Sequence<PropertyValue> aSequence; Sequence<PropertyValue> aSequence;
bool bOnce = bURLOnce; // bool, so we can take address in setInstanceData bool bOnce = bURLOnce; // bool, so we can take address in setInstanceData
setInstanceData( aSequence, &sName, &xInstance, &sURL, &bOnce ); setInstanceData( aSequence, &sName, &xInstance, &sURL, &bOnce );
sal_Int32 nInstance = mpInstances->addItem( aSequence ); sal_Int32 nInstance = mxInstances->addItem( aSequence );
loadInstance( nInstance ); loadInstance( nInstance );
return xInstance; return xInstance;
...@@ -451,10 +451,10 @@ void Model::renameInstance( const OUString& sFrom, ...@@ -451,10 +451,10 @@ void Model::renameInstance( const OUString& sFrom,
sal_Bool bURLOnce ) sal_Bool bURLOnce )
throw( RuntimeException, std::exception ) throw( RuntimeException, std::exception )
{ {
sal_Int32 nPos = lcl_findInstance( mpInstances, sFrom ); sal_Int32 nPos = lcl_findInstance( mxInstances.get(), sFrom );
if( nPos != -1 ) if( nPos != -1 )
{ {
Sequence<PropertyValue> aSeq = mpInstances->getItem( nPos ); Sequence<PropertyValue> aSeq = mxInstances->getItem( nPos );
PropertyValue* pSeq = aSeq.getArray(); PropertyValue* pSeq = aSeq.getArray();
sal_Int32 nLength = aSeq.getLength(); sal_Int32 nLength = aSeq.getLength();
...@@ -482,16 +482,16 @@ void Model::renameInstance( const OUString& sFrom, ...@@ -482,16 +482,16 @@ void Model::renameInstance( const OUString& sFrom,
pSeq[ nProp ].Value <<= bURLOnce; pSeq[ nProp ].Value <<= bURLOnce;
// set instance // set instance
mpInstances->setItem( nPos, aSeq ); mxInstances->setItem( nPos, aSeq );
} }
} }
void Model::removeInstance( const OUString& sName ) void Model::removeInstance( const OUString& sName )
throw( RuntimeException, std::exception ) throw( RuntimeException, std::exception )
{ {
sal_Int32 nPos = lcl_findInstance( mpInstances, sName ); sal_Int32 nPos = lcl_findInstance( mxInstances.get(), sName );
if( nPos != -1 ) if( nPos != -1 )
mpInstances->removeItem( mpInstances->getItem( nPos ) ); mxInstances->removeItem( mxInstances->getItem( nPos ) );
} }
static Reference<XNameContainer> lcl_getModels( static Reference<XNameContainer> lcl_getModels(
...@@ -666,10 +666,10 @@ Model::XNode_t Model::renameNode( const XNode_t& xNode, ...@@ -666,10 +666,10 @@ Model::XNode_t Model::renameNode( const XNode_t& xNode,
// iterate over bindings and replace default expressions // iterate over bindings and replace default expressions
OUString sNewDefaultBindingExpression = OUString sNewDefaultBindingExpression =
getDefaultBindingExpressionForNode( xNew ); getDefaultBindingExpressionForNode( xNew );
for( sal_Int32 n = 0; n < mpBindings->countItems(); n++ ) for( sal_Int32 n = 0; n < mxBindings->countItems(); n++ )
{ {
Binding* pBinding = Binding::getBinding( Binding* pBinding = Binding::getBinding(
mpBindings->Collection<XPropertySet_t>::getItem( n ) ); mxBindings->Collection<XPropertySet_t>::getItem( n ) );
if( pBinding->getBindingExpression() if( pBinding->getBindingExpression()
== sOldDefaultBindingExpression ) == sOldDefaultBindingExpression )
...@@ -694,10 +694,10 @@ Model::XPropertySet_t Model::getBindingForNode( const XNode_t& xNode, ...@@ -694,10 +694,10 @@ Model::XPropertySet_t Model::getBindingForNode( const XNode_t& xNode,
Binding* pBestBinding = nullptr; Binding* pBestBinding = nullptr;
sal_Int32 nBestScore = 0; 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( Binding* pBinding = Binding::getBinding(
mpBindings->Collection<XPropertySet_t>::getItem( n ) ); mxBindings->Collection<XPropertySet_t>::getItem( n ) );
OSL_ENSURE( pBinding != nullptr, "no binding?" ); OSL_ENSURE( pBinding != nullptr, "no binding?" );
Reference<XNodeList> xNodeList = pBinding->getXNodeList(); Reference<XNodeList> xNodeList = pBinding->getXNodeList();
...@@ -732,7 +732,7 @@ Model::XPropertySet_t Model::getBindingForNode( const XNode_t& xNode, ...@@ -732,7 +732,7 @@ Model::XPropertySet_t Model::getBindingForNode( const XNode_t& xNode,
pBestBinding = new Binding(); pBestBinding = new Binding();
pBestBinding->setBindingExpression( pBestBinding->setBindingExpression(
getDefaultBindingExpressionForNode( xNode ) ); getDefaultBindingExpressionForNode( xNode ) );
mpBindings->addItem( pBestBinding ); mxBindings->addItem( pBestBinding );
} }
return pBestBinding; return pBestBinding;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment