From 7596535983dfe6978d624cf0ff31b40e85e14a6b Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Tue, 18 Oct 2016 16:53:18 +0200 Subject: Simplify some dynamic/static_casts ...that are unnecessarily complicated after the "remove tools/rtti.hxx" commits Change-Id: I570751a1f81c547b50248fe4e2824c5c7c5dd624 --- basic/source/basmgr/basmgr.cxx | 3 +- basic/source/classes/sbunoobj.cxx | 74 ++++++++++++++++++--------------------- basic/source/runtime/runtime.cxx | 10 +++--- 3 files changed, 42 insertions(+), 45 deletions(-) (limited to 'basic') diff --git a/basic/source/basmgr/basmgr.cxx b/basic/source/basmgr/basmgr.cxx index 6e29cae01b8a..157eed035cd4 100644 --- a/basic/source/basmgr/basmgr.cxx +++ b/basic/source/basmgr/basmgr.cxx @@ -1011,9 +1011,8 @@ bool BasicManager::ImplLoadBasic( SvStream& rStrm, StarBASICRef& rOldBasic ) con bool bLoaded = false; if( xNew.Is() ) { - if( nullptr != dynamic_cast( xNew.get() ) ) + if( auto pNew = dynamic_cast( xNew.get() ) ) { - StarBASIC* pNew = static_cast( xNew.get() ); // Use the Parent of the old BASICs if( rOldBasic.Is() ) { diff --git a/basic/source/classes/sbunoobj.cxx b/basic/source/classes/sbunoobj.cxx index 141a3089fd6c..1933e693bf80 100644 --- a/basic/source/classes/sbunoobj.cxx +++ b/basic/source/classes/sbunoobj.cxx @@ -868,11 +868,8 @@ Type getUnoTypeForSbxValue( const SbxValue* pVal ) return aRetType; } - if( nullptr != dynamic_cast( xObj.get() ) ) + if( auto pArray = dynamic_cast( xObj.get() ) ) { - SbxBase* pObj = xObj.get(); - SbxDimArray* pArray = static_cast(pObj); - short nDims = pArray->GetDims(); Type aElementType = getUnoTypeForSbxBaseType( (SbxDataType)(pArray->GetType() & 0xfff) ); TypeClass eElementTypeClass = aElementType.getTypeClass(); @@ -962,14 +959,14 @@ Type getUnoTypeForSbxValue( const SbxValue* pVal ) } } // No array, but ... - else if( nullptr != dynamic_cast( xObj.get() ) ) + else if( auto obj = dynamic_cast( xObj.get() ) ) { - aRetType = static_cast(xObj.get())->getUnoAny().getValueType(); + aRetType = obj->getUnoAny().getValueType(); } // SbUnoAnyObject? - else if( nullptr != dynamic_cast( xObj.get() ) ) + else if( auto any = dynamic_cast( xObj.get() ) ) { - aRetType = static_cast(xObj.get())->getValue().getValueType(); + aRetType = any->getValue().getValueType(); } // Otherwise it is a No-Uno-Basic-Object -> default==deliver void } @@ -990,12 +987,11 @@ Any sbxToUnoValueImpl( const SbxValue* pVar, bool bBlockConversionToSmallestType SbxBaseRef xObj = pVar->GetObject(); if( xObj.Is() ) { - if( nullptr != dynamic_cast( xObj.get() ) ) - return static_cast(xObj.get())->getValue(); - if( nullptr != dynamic_cast( xObj.get() ) ) + if( auto obj = dynamic_cast( xObj.get() ) ) + return obj->getValue(); + if( auto pClassModuleObj = dynamic_cast( xObj.get() ) ) { Any aRetAny; - SbClassModuleObject* pClassModuleObj = static_cast(xObj.get()); SbModule* pClassModule = pClassModuleObj->getClassModule(); if( pClassModule->createCOMWrapperForIface( aRetAny, pClassModuleObj ) ) return aRetAny; @@ -1189,9 +1185,9 @@ Any sbxToUnoValue( const SbxValue* pVar, const Type& rType, Property* pUnoProper if( eBaseType == SbxOBJECT ) { SbxBaseRef xObj = pVar->GetObject(); - if( xObj.Is() && nullptr != dynamic_cast( xObj.get() ) ) + if ( auto obj = dynamic_cast( xObj.get() ) ) { - return static_cast(xObj.get())->getValue(); + return obj->getValue(); } } @@ -1244,13 +1240,13 @@ Any sbxToUnoValue( const SbxValue* pVar, const Type& rType, Property* pUnoProper } SbxBaseRef pObj = pVar->GetObject(); - if( pObj.Is() && nullptr != dynamic_cast( pObj.get() ) ) + if( auto obj = dynamic_cast( pObj.get() ) ) { - aRetVal = static_cast(pObj.get())->getUnoAny(); + aRetVal = obj->getUnoAny(); } - else if( pObj.Is() && nullptr != dynamic_cast( pObj.get() ) ) + else if( auto structRef = dynamic_cast( pObj.get() ) ) { - aRetVal = static_cast(pObj.get())->getUnoAny(); + aRetVal = structRef->getUnoAny(); } else { @@ -1270,9 +1266,9 @@ Any sbxToUnoValue( const SbxValue* pVar, const Type& rType, Property* pUnoProper Reference< XIdlClass > xIdlClass; SbxBaseRef pObj = pVar->GetObject(); - if( pObj.Is() && nullptr != dynamic_cast( pObj.get() ) ) + if( auto obj = dynamic_cast( pObj.get() ) ) { - Any aUnoAny = static_cast( pObj.get() )->getUnoAny(); + Any aUnoAny = obj->getUnoAny(); aUnoAny >>= xIdlClass; } @@ -1306,11 +1302,8 @@ Any sbxToUnoValue( const SbxValue* pVar, const Type& rType, Property* pUnoProper case TypeClass_SEQUENCE: { SbxBaseRef xObj = pVar->GetObject(); - if( xObj.Is() && nullptr != dynamic_cast( xObj.get() ) ) + if( auto pArray = dynamic_cast( xObj.get() ) ) { - SbxBase* pObj = xObj.get(); - SbxDimArray* pArray = static_cast(pObj); - short nDims = pArray->GetDims(); // Normal case: One dimensional array @@ -3084,11 +3077,12 @@ void RTL_Impl_HasInterfaces( StarBASIC* pBasic, SbxArray& rPar, bool bWrite ) // get the Uno-Object SbxBaseRef pObj = rPar.Get( 1 )->GetObject(); - if( !(pObj.Is() && nullptr != dynamic_cast( pObj.get() )) ) + auto obj = dynamic_cast( pObj.get() ); + if( obj == nullptr ) { return; } - Any aAny = static_cast(pObj.get())->getUnoAny(); + Any aAny = obj->getUnoAny(); auto x = o3tl::tryAccess>(aAny); if( !x ) { @@ -3148,11 +3142,12 @@ void RTL_Impl_IsUnoStruct( StarBASIC* pBasic, SbxArray& rPar, bool bWrite ) return; } SbxBaseRef pObj = rPar.Get( 1 )->GetObject(); - if( !(pObj.Is() && nullptr != dynamic_cast( pObj.get() )) ) + auto obj = dynamic_cast( pObj.get() ); + if( obj == nullptr ) { return; } - Any aAny = static_cast(pObj.get())->getUnoAny(); + Any aAny = obj->getUnoAny(); TypeClass eType = aAny.getValueType().getTypeClass(); if( eType == TypeClass_STRUCT ) { @@ -3183,11 +3178,12 @@ void RTL_Impl_EqualUnoObjects( StarBASIC* pBasic, SbxArray& rPar, bool bWrite ) return; } SbxBaseRef pObj1 = xParam1->GetObject(); - if( !(pObj1.Is() && nullptr != dynamic_cast( pObj1.get() )) ) + auto obj1 = dynamic_cast( pObj1.get() ); + if( obj1 == nullptr ) { return; } - Any aAny1 = static_cast(pObj1.get())->getUnoAny(); + Any aAny1 = obj1->getUnoAny(); TypeClass eType1 = aAny1.getValueType().getTypeClass(); if( eType1 != TypeClass_INTERFACE ) { @@ -3202,11 +3198,12 @@ void RTL_Impl_EqualUnoObjects( StarBASIC* pBasic, SbxArray& rPar, bool bWrite ) return; } SbxBaseRef pObj2 = xParam2->GetObject(); - if( !(pObj2.Is() && nullptr != dynamic_cast( pObj2.get() )) ) + auto obj2 = dynamic_cast( pObj2.get() ); + if( obj2 == nullptr ) { return; } - Any aAny2 = static_cast(pObj2.get())->getUnoAny(); + Any aAny2 = obj2->getUnoAny(); TypeClass eType2 = aAny2.getValueType().getTypeClass(); if( eType2 != TypeClass_INTERFACE ) { @@ -4192,9 +4189,9 @@ void RTL_Impl_CreateUnoValue( StarBASIC* pBasic, SbxArray& rPar, bool bWrite ) Reference< XIdlClass > xIdlClass; SbxBaseRef pObj = pVal->GetObject(); - if( pObj.Is() && nullptr != dynamic_cast( pObj.get() ) ) + if( auto obj = dynamic_cast( pObj.get() ) ) { - Any aUnoAny = static_cast(pObj.get())->getUnoAny(); + Any aUnoAny = obj->getUnoAny(); aUnoAny >>= xIdlClass; } @@ -4307,7 +4304,7 @@ void SAL_CALL ModuleInvocationProxy::setValue(const OUString& rProperty, const A + rProperty; SbxVariable* p = m_xScopeObj->Find( aPropertyFunctionName, SbxClassType::Method ); - SbMethod* pMeth = p != nullptr ? dynamic_cast( p ) : nullptr; + SbMethod* pMeth = dynamic_cast( p ); if( pMeth == nullptr ) { // TODO: Check vba behavior concernig missing function @@ -4346,7 +4343,7 @@ Any SAL_CALL ModuleInvocationProxy::getValue(const OUString& rProperty) + rProperty; SbxVariable* p = m_xScopeObj->Find( aPropertyFunctionName, SbxClassType::Method ); - SbMethod* pMeth = p != nullptr ? dynamic_cast( p ) : nullptr; + SbMethod* pMeth = dynamic_cast( p ); if( pMeth == nullptr ) { // TODO: Check vba behavior concernig missing function @@ -4403,7 +4400,7 @@ Any SAL_CALL ModuleInvocationProxy::invoke( const OUString& rFunction, } SbxVariable* p = xScopeObj->Find( aFunctionName, SbxClassType::Method ); - SbMethod* pMeth = p != nullptr ? dynamic_cast( p ) : nullptr; + SbMethod* pMeth = dynamic_cast( p ); if( pMeth == nullptr ) { // TODO: Check vba behavior concernig missing function @@ -4670,8 +4667,7 @@ bool handleToStringForCOMObjects( SbxObject* pObj, SbxValue* pVal ) { bool bSuccess = false; - SbUnoObject* pUnoObj = nullptr; - if( pObj != nullptr && (pUnoObj = dynamic_cast( pObj)) != nullptr ) + if( auto pUnoObj = dynamic_cast( pObj) ) { // Only for native COM objects if( pUnoObj->isNativeCOMObject() ) diff --git a/basic/source/runtime/runtime.cxx b/basic/source/runtime/runtime.cxx index 1d9bacb93f19..67108d849f31 100644 --- a/basic/source/runtime/runtime.cxx +++ b/basic/source/runtime/runtime.cxx @@ -1885,7 +1885,7 @@ void SbiRuntime::StepSET_Impl( SbxVariableRef& refVal, SbxVariableRef& refVar, b Reference< XInterface > xComListener; SbxBase* pObj = refVal->GetObject(); - SbUnoObject* pUnoObj = (pObj != nullptr) ? dynamic_cast( pObj ) : nullptr; + SbUnoObject* pUnoObj = dynamic_cast( pObj ); if( pUnoObj != nullptr ) { Any aControlAny = pUnoObj->getUnoAny(); @@ -3189,10 +3189,12 @@ bool SbiRuntime::checkClass_Impl( const SbxVariableRef& refVal, SbxDataType t = refVal->GetType(); SbxVariable* pVal = refVal.get(); // we don't know the type of uno properties that are (maybevoid) - if ( t == SbxEMPTY && nullptr != dynamic_cast( refVal.get() ) ) + if ( t == SbxEMPTY ) { - SbUnoProperty* pProp = static_cast(pVal); - t = pProp->getRealType(); + if ( auto pProp = dynamic_cast( refVal.get() ) ) + { + t = pProp->getRealType(); + } } if( t == SbxOBJECT ) { -- cgit