diff options
author | Arnaud Versini <arnaud.versini@gmail.com> | 2016-02-21 17:51:28 +0100 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2016-02-22 12:33:52 +0000 |
commit | 14420e83296fd393cba956047370564c3517cdae (patch) | |
tree | 9c566a9de39f81a85885f565ce46781857fe7956 /basic | |
parent | 1b287f14b2adc79586ae2dde6b08cd8eb960e0ce (diff) |
BASIC : Add tools::make_ref and simplify SvRef usage
Change-Id: I8fe846dbd353bace05a8732a9b961f3507d97ef8
Reviewed-on: https://gerrit.libreoffice.org/22587
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'basic')
-rw-r--r-- | basic/source/classes/propacc.cxx | 4 | ||||
-rw-r--r-- | basic/source/classes/sb.cxx | 2 | ||||
-rw-r--r-- | basic/source/classes/sbunoobj.cxx | 67 | ||||
-rw-r--r-- | basic/source/classes/sbxmod.cxx | 16 | ||||
-rw-r--r-- | basic/source/sbx/sbxexec.cxx | 31 | ||||
-rw-r--r-- | basic/source/uno/scriptcont.cxx | 6 |
6 files changed, 53 insertions, 73 deletions
diff --git a/basic/source/classes/propacc.cxx b/basic/source/classes/propacc.cxx index ede6abb23156..856b42d2c8eb 100644 --- a/basic/source/classes/propacc.cxx +++ b/basic/source/classes/propacc.cxx @@ -209,11 +209,11 @@ void RTL_Impl_CreatePropertySet( StarBASIC* pBasic, SbxArray& rPar, bool bWrite // Build a SbUnoObject and return it Any aAny; aAny <<= xInterface; - SbUnoObjectRef xUnoObj = new SbUnoObject( "stardiv.uno.beans.PropertySet", aAny ); + auto xUnoObj = tools::make_ref<SbUnoObject>( "stardiv.uno.beans.PropertySet", aAny ); if( xUnoObj->getUnoAny().getValueType().getTypeClass() != TypeClass_VOID ) { // Return object - refVar->PutObject( static_cast<SbUnoObject*>(xUnoObj) ); + refVar->PutObject( xUnoObj.get() ); return; } } diff --git a/basic/source/classes/sb.cxx b/basic/source/classes/sb.cxx index 4e547af4309d..40d1bc4e789f 100644 --- a/basic/source/classes/sb.cxx +++ b/basic/source/classes/sb.cxx @@ -2198,7 +2198,7 @@ void BasicCollection::CollAdd( SbxArray* pPar_ ) } } - SbxVariableRef pNewItem = new SbxVariable( *pItem ); + auto pNewItem = tools::make_ref<SbxVariable>( *pItem ); if( nCount >= 3 ) { SbxVariable* pKey = pPar_->Get(2); diff --git a/basic/source/classes/sbunoobj.cxx b/basic/source/classes/sbunoobj.cxx index 4b41c39b6559..d6cf5611051c 100644 --- a/basic/source/classes/sbunoobj.cxx +++ b/basic/source/classes/sbunoobj.cxx @@ -593,11 +593,11 @@ static void implSequenceToMultiDimArray( SbxDimArray*& pArray, Sequence< sal_Int if ( pArray ) { - SbxVariableRef xVar = new SbxVariable( eSbxElementType ); - unoToSbxValue( static_cast<SbxVariable*>(xVar), aValue ); + auto xVar = tools::make_ref<SbxVariable>( eSbxElementType ); + unoToSbxValue( xVar.get(), aValue ); sal_Int32* pIndices = indices.getArray(); - pArray->Put32( static_cast<SbxVariable*>(xVar), pIndices ); + pArray->Put32( xVar.get(), pIndices ); } } @@ -770,11 +770,11 @@ void unoToSbxValue( SbxVariable* pVar, const Any& aValue ) { // convert elements Any aElementAny = xIdlArray->get( aValue, (sal_uInt32)i ); - SbxVariableRef xVar = new SbxVariable( eSbxElementType ); - unoToSbxValue( static_cast<SbxVariable*>(xVar), aElementAny ); + auto xVar = tools::make_ref<SbxVariable>( eSbxElementType ); + unoToSbxValue( xVar.get(), aElementAny ); // put into the Array - xArray->Put32( static_cast<SbxVariable*>(xVar), &i ); + xArray->Put32( xVar.get(), &i ); } } else @@ -891,7 +891,7 @@ Type getUnoTypeForSbxValue( const SbxValue* pVal ) { // coverity[callee_ptr_arith] SbxVariableRef xVar = pArray->Get32( &nIdx ); - Type aType = getUnoTypeForSbxValue( static_cast<SbxVariable*>(xVar) ); + Type aType = getUnoTypeForSbxValue( xVar.get() ); if( bNeedsInit ) { if( aType.getTypeClass() == TypeClass_VOID ) @@ -928,7 +928,7 @@ Type getUnoTypeForSbxValue( const SbxValue* pVal ) for( sal_uInt32 i = 0 ; i < nFlatArraySize ; i++ ) { SbxVariableRef xVar = pArray->SbxArray::Get32( i ); - Type aType = getUnoTypeForSbxValue( static_cast<SbxVariable*>(xVar) ); + Type aType = getUnoTypeForSbxValue( xVar.get() ); if( bNeedsInit ) { if( aType.getTypeClass() == TypeClass_VOID ) @@ -1338,7 +1338,7 @@ Any sbxToUnoValue( const SbxValue* pVar, const Type& rType, Property* pUnoProper SbxVariableRef xVar = pArray->Get32( &nIdx ); // Convert the value of Sbx to Uno - Any aAnyValue = sbxToUnoValue( static_cast<SbxVariable*>(xVar), aElemType ); + Any aAnyValue = sbxToUnoValue( xVar.get(), aElemType ); try { @@ -2647,10 +2647,9 @@ SbxVariable* SbUnoObject::Find( const OUString& rName, SbxClassType t ) SbxDataType eRealSbxType = ( ( rProp.Attributes & PropertyAttribute::MAYBEVOID ) ? unoToSbxType( rProp.Type.getTypeClass() ) : eSbxType ); // create the property and superimpose it - SbUnoProperty* pProp = new SbUnoProperty( rProp.Name, eSbxType, eRealSbxType, rProp, 0, false, ( rProp.Type.getTypeClass() == css::uno::TypeClass_STRUCT ) ); - SbxVariableRef xVarRef = pProp; - QuickInsert( static_cast<SbxVariable*>(xVarRef) ); - pRes = xVarRef; + auto pProp = tools::make_ref<SbUnoProperty>( rProp.Name, eSbxType, eRealSbxType, rProp, 0, false, ( rProp.Type.getTypeClass() == css::uno::TypeClass_STRUCT ) ); + QuickInsert( pProp.get() ); + pRes = pProp; } else if( mxUnoAccess->hasMethod( aUName, MethodConcept::ALL - MethodConcept::DANGEROUS ) ) @@ -2660,9 +2659,9 @@ SbxVariable* SbUnoObject::Find( const OUString& rName, SbxClassType t ) getMethod( aUName, MethodConcept::ALL - MethodConcept::DANGEROUS ); // create SbUnoMethod and superimpose it - SbxVariableRef xMethRef = new SbUnoMethod( rxMethod->getName(), + auto xMethRef = tools::make_ref<SbUnoMethod>( rxMethod->getName(), unoToSbxType( rxMethod->getReturnType() ), rxMethod, false ); - QuickInsert( static_cast<SbxVariable*>(xMethRef) ); + QuickInsert( xMethRef.get() ); pRes = xMethRef; } @@ -2719,15 +2718,15 @@ SbxVariable* SbUnoObject::Find( const OUString& rName, SbxClassType t ) if( mxInvocation->hasProperty( aUName ) ) { // create a property and superimpose it - SbxVariableRef xVarRef = new SbUnoProperty( aUName, SbxVARIANT, SbxVARIANT, aDummyProp, 0, true, false ); - QuickInsert( static_cast<SbxVariable*>(xVarRef) ); + auto xVarRef = tools::make_ref<SbUnoProperty>( aUName, SbxVARIANT, SbxVARIANT, aDummyProp, 0, true, false ); + QuickInsert( xVarRef.get() ); pRes = xVarRef; } else if( mxInvocation->hasMethod( aUName ) ) { // create SbUnoMethode and superimpose it - SbxVariableRef xMethRef = new SbUnoMethod( aUName, SbxVARIANT, xDummyMethod, true ); - QuickInsert( static_cast<SbxVariable*>(xMethRef) ); + auto xMethRef = tools::make_ref<SbUnoMethod>( aUName, SbxVARIANT, xDummyMethod, true ); + QuickInsert( xMethRef.get() ); pRes = xMethRef; } else @@ -2735,8 +2734,8 @@ SbxVariable* SbUnoObject::Find( const OUString& rName, SbxClassType t ) Reference< XDirectInvocation > xDirectInvoke( mxInvocation, UNO_QUERY ); if ( xDirectInvoke.is() && xDirectInvoke->hasMember( aUName ) ) { - SbxVariableRef xMethRef = new SbUnoMethod( aUName, SbxVARIANT, xDummyMethod, true ); - QuickInsert( static_cast<SbxVariable*>(xMethRef) ); + auto xMethRef = tools::make_ref<SbUnoMethod>( aUName, SbxVARIANT, xDummyMethod, true ); + QuickInsert( xMethRef.get() ); pRes = xMethRef; } @@ -2778,23 +2777,23 @@ void SbUnoObject::implCreateDbgProperties() Property aProp; // Id == -1: display the implemented interfaces corresponding the ClassProvider - SbxVariableRef xVarRef = new SbUnoProperty( OUString(ID_DBG_SUPPORTEDINTERFACES), SbxSTRING, SbxSTRING, aProp, -1, false, false ); - QuickInsert( static_cast<SbxVariable*>(xVarRef) ); + auto xVarRef = tools::make_ref<SbUnoProperty>( OUString(ID_DBG_SUPPORTEDINTERFACES), SbxSTRING, SbxSTRING, aProp, -1, false, false ); + QuickInsert( xVarRef.get() ); // Id == -2: output the properties - xVarRef = new SbUnoProperty( OUString(ID_DBG_PROPERTIES), SbxSTRING, SbxSTRING, aProp, -2, false, false ); - QuickInsert( static_cast<SbxVariable*>(xVarRef) ); + xVarRef = tools::make_ref<SbUnoProperty>( OUString(ID_DBG_PROPERTIES), SbxSTRING, SbxSTRING, aProp, -2, false, false ); + QuickInsert( xVarRef.get() ); // Id == -3: output the Methods - xVarRef = new SbUnoProperty( OUString(ID_DBG_METHODS), SbxSTRING, SbxSTRING, aProp, -3, false, false ); - QuickInsert( static_cast<SbxVariable*>(xVarRef) ); + xVarRef = tools::make_ref<SbUnoProperty>( OUString(ID_DBG_METHODS), SbxSTRING, SbxSTRING, aProp, -3, false, false ); + QuickInsert( xVarRef.get() ); } void SbUnoObject::implCreateAll() { // throw away all existing methods and properties - pMethods = new SbxArray; - pProps = new SbxArray; + pMethods = tools::make_ref<SbxArray>(); + pProps = tools::make_ref<SbxArray>(); if( bNeedIntrospection ) doIntrospection(); @@ -2829,8 +2828,8 @@ void SbUnoObject::implCreateAll() SbxDataType eRealSbxType = ( ( rProp.Attributes & PropertyAttribute::MAYBEVOID ) ? unoToSbxType( rProp.Type.getTypeClass() ) : eSbxType ); // Create property and superimpose it - SbxVariableRef xVarRef = new SbUnoProperty( rProp.Name, eSbxType, eRealSbxType, rProp, i, false, ( rProp.Type.getTypeClass() == css::uno::TypeClass_STRUCT ) ); - QuickInsert( static_cast<SbxVariable*>(xVarRef) ); + auto xVarRef = tools::make_ref<SbUnoProperty>( rProp.Name, eSbxType, eRealSbxType, rProp, i, false, ( rProp.Type.getTypeClass() == css::uno::TypeClass_STRUCT ) ); + QuickInsert( xVarRef.get() ); } // Create Dbg_-Properties @@ -2847,9 +2846,9 @@ void SbUnoObject::implCreateAll() const Reference< XIdlMethod >& rxMethod = pMethods_[i]; // Create SbUnoMethod and superimpose it - SbxVariableRef xMethRef = new SbUnoMethod + auto xMethRef = tools::make_ref<SbUnoMethod> ( rxMethod->getName(), unoToSbxType( rxMethod->getReturnType() ), rxMethod, false ); - QuickInsert( static_cast<SbxVariable*>(xMethRef) ); + QuickInsert( xMethRef.get() ); } } @@ -2961,7 +2960,7 @@ void RTL_Impl_CreateUnoStruct( StarBASIC* pBasic, SbxArray& rPar, bool bWrite ) } // return the object SbxVariableRef refVar = rPar.Get(0); - refVar->PutObject( static_cast<SbUnoObject*>(xUnoObj) ); + refVar->PutObject( xUnoObj.get() ); } void RTL_Impl_CreateUnoService( StarBASIC* pBasic, SbxArray& rPar, bool bWrite ) diff --git a/basic/source/classes/sbxmod.cxx b/basic/source/classes/sbxmod.cxx index 410c321666a2..4d9a9f0bdb08 100644 --- a/basic/source/classes/sbxmod.cxx +++ b/basic/source/classes/sbxmod.cxx @@ -755,7 +755,7 @@ void SbModule::Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) sal_uInt16 nVarParCount = (pArg != nullptr) ? pArg->Count() : 0; if( nVarParCount > 1 ) { - SbxArrayRef xMethParameters = new SbxArray; + auto xMethParameters = tools::make_ref<SbxArray>(); xMethParameters->Put( pMethVar, 0 ); // Method as parameter 0 for( sal_uInt16 i = 1 ; i < nVarParCount ; ++i ) { @@ -2086,12 +2086,9 @@ ErrCode SbMethod::Call( SbxValue* pRet, SbxVariable* pCaller ) mCaller = pCaller; } // RefCount vom Modul hochzaehlen - SbModule* pMod_ = static_cast<SbModule*>(GetParent()); - pMod_->AddFirstRef(); + tools::SvRef<SbModule> pMod_ = static_cast<SbModule*>(GetParent()); - // Increment the RefCount of the Basic - StarBASIC* pBasic = static_cast<StarBASIC*>(pMod_->GetParent()); - pBasic->AddFirstRef(); + tools::SvRef<StarBASIC> pBasic = static_cast<StarBASIC*>(pMod_->GetParent()); // Establish the values to get the return value SbxValues aVals; @@ -2109,9 +2106,6 @@ ErrCode SbMethod::Call( SbxValue* pRet, SbxVariable* pCaller ) ErrCode nErr = SbxBase::GetError(); SbxBase::ResetError(); - // Release objects - pMod_->ReleaseRef(); - pBasic->ReleaseRef(); mCaller = nullptr; return nErr; } @@ -2476,12 +2470,12 @@ void SbUserFormModule::triggerMethod( const OUString& aMethodToRun, Sequence< An { if ( aArguments.getLength() > 0 ) // Setup parameters { - SbxArrayRef xArray = new SbxArray; + auto xArray = tools::make_ref<SbxArray>(); xArray->Put( pMeth, 0 ); // Method as parameter 0 for ( sal_Int32 i = 0; i < aArguments.getLength(); ++i ) { - SbxVariableRef xSbxVar = new SbxVariable( SbxVARIANT ); + auto xSbxVar = tools::make_ref<SbxVariable>( SbxVARIANT ); unoToSbxValue( static_cast< SbxVariable* >( xSbxVar ), aArguments[i] ); xArray->Put( xSbxVar, static_cast< sal_uInt16 >( i ) + 1 ); diff --git a/basic/source/sbx/sbxexec.cxx b/basic/source/sbx/sbxexec.cxx index 0910aef37f26..0465bbeefd25 100644 --- a/basic/source/sbx/sbxexec.cxx +++ b/basic/source/sbx/sbxexec.cxx @@ -23,7 +23,7 @@ #include <rtl/character.hxx> -static SbxVariable* Element +static SbxVariableRef Element ( SbxObject* pObj, SbxObject* pGbl, const sal_Unicode** ppBuf, SbxClassType ); @@ -78,7 +78,7 @@ static const sal_Unicode* Symbol( const sal_Unicode* p, OUString& rSym ) // Qualified name. Element.Element.... -static SbxVariable* QualifiedName +static SbxVariableRef QualifiedName ( SbxObject* pObj, SbxObject* pGbl, const sal_Unicode** ppBuf, SbxClassType t ) { @@ -107,15 +107,13 @@ static SbxVariable* QualifiedName else SbxBase::SetError( ERRCODE_SBX_SYNTAX ); *ppBuf = p; - if( refVar.Is() ) - refVar->AddFirstRef(); return refVar; } // Read in of an operand. This could be a number, a string or // a function (with optional parameters). -static SbxVariable* Operand +static SbxVariableRef Operand ( SbxObject* pObj, SbxObject* pGbl, const sal_Unicode** ppBuf, bool bVar ) { SbxVariableRef refVar( new SbxVariable ); @@ -165,15 +163,13 @@ static SbxVariable* Operand refVar = QualifiedName( pObj, pGbl, &p, SbxCLASS_DONTCARE ); } *ppBuf = p; - if( refVar.Is() ) - refVar->AddFirstRef(); return refVar; } // Read in of a simple term. The operands +, -, * and / // are supported. -static SbxVariable* MulDiv( SbxObject* pObj, SbxObject* pGbl, const sal_Unicode** ppBuf ) +static SbxVariableRef MulDiv( SbxObject* pObj, SbxObject* pGbl, const sal_Unicode** ppBuf ) { const sal_Unicode* p = *ppBuf; SbxVariableRef refVar( Operand( pObj, pGbl, &p, false ) ); @@ -200,12 +196,10 @@ static SbxVariable* MulDiv( SbxObject* pObj, SbxObject* pGbl, const sal_Unicode* } } *ppBuf = p; - if( refVar.Is() ) - refVar->AddFirstRef(); return refVar; } -static SbxVariable* PlusMinus( SbxObject* pObj, SbxObject* pGbl, const sal_Unicode** ppBuf ) +static SbxVariableRef PlusMinus( SbxObject* pObj, SbxObject* pGbl, const sal_Unicode** ppBuf ) { const sal_Unicode* p = *ppBuf; SbxVariableRef refVar( MulDiv( pObj, pGbl, &p ) ); @@ -232,12 +226,10 @@ static SbxVariable* PlusMinus( SbxObject* pObj, SbxObject* pGbl, const sal_Unico } } *ppBuf = p; - if( refVar.Is() ) - refVar->AddFirstRef(); return refVar; } -static SbxVariable* Assign( SbxObject* pObj, SbxObject* pGbl, const sal_Unicode** ppBuf ) +static SbxVariableRef Assign( SbxObject* pObj, SbxObject* pGbl, const sal_Unicode** ppBuf ) { const sal_Unicode* p = *ppBuf; SbxVariableRef refVar( Operand( pObj, pGbl, &p, true ) ); @@ -270,8 +262,6 @@ static SbxVariable* Assign( SbxObject* pObj, SbxObject* pGbl, const sal_Unicode* refVar->Broadcast( SBX_HINT_DATAWANTED ); } *ppBuf = p; - if( refVar.Is() ) - refVar->AddFirstRef(); return refVar; } @@ -279,7 +269,7 @@ static SbxVariable* Assign( SbxObject* pObj, SbxObject* pGbl, const sal_Unicode* // by a parameter list. The symbol will be searched in the // specified object and the parameter list will be attached if necessary. -static SbxVariable* Element +static SbxVariableRef Element ( SbxObject* pObj, SbxObject* pGbl, const sal_Unicode** ppBuf, SbxClassType t ) { @@ -303,7 +293,7 @@ static SbxVariable* Element if( *p == '(' ) { p++; - SbxArrayRef refPar = new SbxArray; + auto refPar = tools::make_ref<SbxArray>(); sal_uInt16 nArg = 0; // We are once relaxed and accept as well // the line- or commandend as delimiter @@ -321,8 +311,7 @@ static SbxVariable* Element // One copies the parameter, so that // one have the current status (triggers also // the call per access) - SbxVariable* pArg = refArg; - refPar->Put( new SbxVariable( *pArg ), ++nArg ); + refPar->Put( new SbxVariable( *(refArg.get()) ), ++nArg ); } p = SkipWhitespace( p ); if( *p == ',' ) @@ -338,8 +327,6 @@ static SbxVariable* Element SbxBase::SetError( ERRCODE_SBX_NO_METHOD ); } *ppBuf = p; - if( refVar.Is() ) - refVar->AddFirstRef(); return refVar; } diff --git a/basic/source/uno/scriptcont.cxx b/basic/source/uno/scriptcont.cxx index ca57a71580eb..e315d3ef34b3 100644 --- a/basic/source/uno/scriptcont.cxx +++ b/basic/source/uno/scriptcont.cxx @@ -334,10 +334,10 @@ SfxLibraryContainer* SfxScriptLibraryContainer::createInstanceImpl() void SAL_CALL SfxScriptLibraryContainer::importFromOldStorage( const OUString& aFile ) { // TODO: move loading from old storage to binary filters? - tools::SvRef<SotStorage> xStorage = new SotStorage( false, aFile ); - if( xStorage.Is() && xStorage->GetError() == ERRCODE_NONE ) + auto xStorage = tools::make_ref<SotStorage>( false, aFile ); + if( xStorage->GetError() == ERRCODE_NONE ) { - BasicManager* pBasicManager = new BasicManager( *static_cast<SotStorage*>(xStorage), aFile ); + BasicManager* pBasicManager = new BasicManager( *(xStorage.get()), aFile ); // Set info LibraryContainerInfo aInfo( this, nullptr, static_cast< OldBasicPassword* >( this ) ); |