[Libreoffice-commits] core.git: basic/source
Stephan Bergmann
sbergman at redhat.com
Tue Jun 14 14:07:48 UTC 2016
basic/source/classes/propacc.cxx | 6 +--
basic/source/classes/sbunoobj.cxx | 65 +++++++++++++++-----------------------
basic/source/runtime/runtime.cxx | 15 ++------
3 files changed, 35 insertions(+), 51 deletions(-)
New commits:
commit 9c6a58f8c4291686a6190f142ef5d33dd20617fb
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Tue Jun 14 16:02:55 2016 +0200
Clean up uses of Any::getValue() in basic
Change-Id: Ice269eae6b0278d5e089d973aae72b3f871c1272
diff --git a/basic/source/classes/propacc.cxx b/basic/source/classes/propacc.cxx
index 2da061bd..143ec4d 100644
--- a/basic/source/classes/propacc.cxx
+++ b/basic/source/classes/propacc.cxx
@@ -26,6 +26,7 @@
#include <comphelper/propertysetinfo.hxx>
#include <comphelper/sequence.hxx>
+#include <o3tl/any.hxx>
#include <algorithm>
#include <limits.h>
@@ -201,14 +202,13 @@ void RTL_Impl_CreatePropertySet( StarBASIC* pBasic, SbxArray& rPar, bool bWrite
// Set PropertyValues
Any aArgAsAny = sbxToUnoValue( rPar.Get(1),
cppu::UnoType<Sequence<PropertyValue>>::get() );
- Sequence<PropertyValue> const *pArg =
- static_cast<Sequence<PropertyValue> const *>(aArgAsAny.getValue());
+ auto pArg = o3tl::doAccess<Sequence<PropertyValue>>(aArgAsAny);
Reference< XPropertyAccess > xPropAcc( xInterface, UNO_QUERY );
xPropAcc->setPropertyValues( *pArg );
// Build a SbUnoObject and return it
auto xUnoObj = tools::make_ref<SbUnoObject>( "stardiv.uno.beans.PropertySet", Any(xInterface) );
- if( xUnoObj->getUnoAny().getValueType().getTypeClass() != TypeClass_VOID )
+ if( xUnoObj->getUnoAny().hasValue() )
{
// Return object
refVar->PutObject( xUnoObj.get() );
diff --git a/basic/source/classes/sbunoobj.cxx b/basic/source/classes/sbunoobj.cxx
index 8154782..6622cde 100644
--- a/basic/source/classes/sbunoobj.cxx
+++ b/basic/source/classes/sbunoobj.cxx
@@ -17,6 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+
+#include <o3tl/any.hxx>
#include <osl/mutex.hxx>
#include <vcl/svapp.hxx>
#include <tools/errcode.hxx>
@@ -312,12 +315,13 @@ OUString implGetExceptionMsg( const Exception& e, const OUString& aExceptionType
OUString implGetExceptionMsg( const Any& _rCaughtException )
{
- OSL_PRECOND( _rCaughtException.getValueTypeClass() == TypeClass_EXCEPTION, "implGetExceptionMsg: illegal argument!" );
- if ( _rCaughtException.getValueTypeClass() != TypeClass_EXCEPTION )
+ auto e = o3tl::tryAccess<Exception>(_rCaughtException);
+ OSL_PRECOND( e, "implGetExceptionMsg: illegal argument!" );
+ if ( !e )
{
return OUString();
}
- return implGetExceptionMsg( *static_cast< const Exception* >( _rCaughtException.getValue() ), _rCaughtException.getValueTypeName() );
+ return implGetExceptionMsg( *e, _rCaughtException.getValueTypeName() );
}
Any convertAny( const Any& rVal, const Type& aDestType )
@@ -406,10 +410,10 @@ void implHandleWrappedTargetException( const Any& _rWrappedTargetException )
++nLevel;
}
- if ( aExamine.getValueTypeClass() == TypeClass_EXCEPTION )
+ if ( auto e = o3tl::tryAccess<Exception>(aExamine) )
{
// the last element in the chain is still an exception, but no WrappedTargetException
- implAppendExceptionMsg( aMessageBuf, *static_cast< const Exception* >( aExamine.getValue() ), aExamine.getValueTypeName(), nLevel );
+ implAppendExceptionMsg( aMessageBuf, *e, aExamine.getValueTypeName(), nLevel );
}
StarBASIC::Error( nError, aMessageBuf.makeStringAndClear() );
@@ -622,7 +626,7 @@ void unoToSbxValue( SbxVariable* pVar, const Any& aValue )
SbxObjectRef xWrapper = static_cast<SbxObject*>(pSbUnoObject);
// If the object is invalid deliver null
- if( pSbUnoObject->getUnoAny().getValueType().getTypeClass() == TypeClass_VOID )
+ if( !pSbUnoObject->getUnoAny().hasValue() )
{
pVar->PutObject( nullptr );
}
@@ -723,7 +727,7 @@ void unoToSbxValue( SbxVariable* pVar, const Any& aValue )
SbxObjectRef xWrapper = static_cast<SbxObject*>(pSbUnoObject);
// If the object is invalid deliver null
- if( pSbUnoObject->getUnoAny().getValueType().getTypeClass() == TypeClass_VOID )
+ if( !pSbUnoObject->getUnoAny().hasValue() )
{
pVar->PutObject( nullptr );
}
@@ -790,10 +794,10 @@ void unoToSbxValue( SbxVariable* pVar, const Any& aValue )
break;
- case TypeClass_BOOLEAN: pVar->PutBool( *static_cast<sal_Bool const *>(aValue.getValue()) ); break;
+ case TypeClass_BOOLEAN: pVar->PutBool( *o3tl::forceAccess<bool>(aValue) ); break;
case TypeClass_CHAR:
{
- pVar->PutChar( *static_cast<sal_Unicode const *>(aValue.getValue()) );
+ pVar->PutChar( *o3tl::forceAccess<sal_Unicode>(aValue) );
break;
}
case TypeClass_STRING: { OUString val; aValue >>= val; pVar->PutString( val ); } break;
@@ -1596,10 +1600,7 @@ OUString getDbgObjectNameImpl(SbUnoObject& rUnoObj)
if( aName.isEmpty() )
{
Any aToInspectObj = rUnoObj.getUnoAny();
- TypeClass eType = aToInspectObj.getValueType().getTypeClass();
- Reference< XInterface > xObj;
- if( eType == TypeClass_INTERFACE )
- xObj = *static_cast<Reference< XInterface > const *>(aToInspectObj.getValue());
+ Reference< XInterface > xObj(aToInspectObj, css::uno::UNO_QUERY);
if( xObj.is() )
{
Reference< XServiceInfo > xServiceInfo( xObj, UNO_QUERY );
@@ -1646,21 +1647,15 @@ OUString getBasicObjectTypeName( SbxObject* pObj )
bool checkUnoObjectType(SbUnoObject& rUnoObj, const OUString& rClass)
{
Any aToInspectObj = rUnoObj.getUnoAny();
- TypeClass eType = aToInspectObj.getValueType().getTypeClass();
- if( eType != TypeClass_INTERFACE )
- {
- return false;
- }
- const Reference< XInterface > x = *static_cast<Reference< XInterface > const *>(aToInspectObj.getValue());
// Return true for XInvocation based objects as interface type names don't count then
- Reference< XInvocation > xInvocation( x, UNO_QUERY );
+ Reference< XInvocation > xInvocation( aToInspectObj, UNO_QUERY );
if( xInvocation.is() )
{
return true;
}
bool bResult = false;
- Reference< XTypeProvider > xTypeProvider( x, UNO_QUERY );
+ Reference< XTypeProvider > xTypeProvider( aToInspectObj, UNO_QUERY );
if( xTypeProvider.is() )
{
/* Although interfaces in the ooo.vba namespace obey the IDL rules and
@@ -1744,19 +1739,16 @@ OUString Impl_GetSupportedInterfaces(SbUnoObject& rUnoObj)
Any aToInspectObj = rUnoObj.getUnoAny();
// allow only TypeClass interface
- TypeClass eType = aToInspectObj.getValueType().getTypeClass();
OUStringBuffer aRet;
- if( eType != TypeClass_INTERFACE )
+ auto x = o3tl::tryAccess<Reference<XInterface>>(aToInspectObj);
+ if( !x )
{
aRet.append( ID_DBG_SUPPORTEDINTERFACES );
aRet.append( " not available.\n(TypeClass is not TypeClass_INTERFACE)\n" );
}
else
{
- // get the interface from the Any
- const Reference< XInterface > x = *static_cast<Reference< XInterface > const *>(aToInspectObj.getValue());
-
- Reference< XTypeProvider > xTypeProvider( x, UNO_QUERY );
+ Reference< XTypeProvider > xTypeProvider( *x, UNO_QUERY );
aRet.append( "Supported interfaces by object " );
aRet.append(getDbgObjectName(rUnoObj));
@@ -1774,7 +1766,7 @@ OUString Impl_GetSupportedInterfaces(SbUnoObject& rUnoObj)
Reference<XIdlClass> xClass = TypeToIdlClass( rType );
if( xClass.is() )
{
- aRet.append( Impl_GetInterfaceInfo( x, xClass, 1 ) );
+ aRet.append( Impl_GetInterfaceInfo( *x, xClass, 1 ) );
}
else
{
@@ -2321,7 +2313,7 @@ SbUnoObject::SbUnoObject( const OUString& aName_, const Any& aUnoObj_ )
if( eType == TypeClass_INTERFACE )
{
// get the interface from the Any
- x = *static_cast<Reference< XInterface > const *>(aUnoObj_.getValue());
+ aUnoObj_ >>= x;
if( !x.is() )
return;
}
@@ -2990,7 +2982,7 @@ void RTL_Impl_CreateUnoService( StarBASIC* pBasic, SbxArray& rPar, bool bWrite )
{
// Create a SbUnoObject out of it and return it
SbUnoObjectRef xUnoObj = new SbUnoObject( aServiceName, Any(xInterface) );
- if( xUnoObj->getUnoAny().getValueType().getTypeClass() != TypeClass_VOID )
+ if( xUnoObj->getUnoAny().hasValue() )
{
// return the object
refVar->PutObject( static_cast<SbUnoObject*>(xUnoObj) );
@@ -3042,7 +3034,7 @@ void RTL_Impl_CreateUnoServiceWithArguments( StarBASIC* pBasic, SbxArray& rPar,
{
// Create a SbUnoObject out of it and return it
SbUnoObjectRef xUnoObj = new SbUnoObject( aServiceName, Any(xInterface) );
- if( xUnoObj->getUnoAny().getValueType().getTypeClass() != TypeClass_VOID )
+ if( xUnoObj->getUnoAny().hasValue() )
{
// return the object
refVar->PutObject( static_cast<SbUnoObject*>(xUnoObj) );
@@ -3097,13 +3089,11 @@ void RTL_Impl_HasInterfaces( StarBASIC* pBasic, SbxArray& rPar, bool bWrite )
return;
}
Any aAny = static_cast<SbUnoObject*>(static_cast<SbxBase*>(pObj))->getUnoAny();
- TypeClass eType = aAny.getValueType().getTypeClass();
- if( eType != TypeClass_INTERFACE )
+ auto x = o3tl::tryAccess<Reference<XInterface>>(aAny);
+ if( !x )
{
return;
}
- // get the interface out of the Any
- Reference< XInterface > x = *static_cast<Reference< XInterface > const *>(aAny.getValue());
// get CoreReflection
Reference< XIdlReflection > xCoreReflection = getCoreReflection_Impl();
@@ -3125,7 +3115,7 @@ void RTL_Impl_HasInterfaces( StarBASIC* pBasic, SbxArray& rPar, bool bWrite )
// check if the interface will be supported
OUString aClassName = xClass->getName();
Type aClassType( xClass->getTypeClass(), aClassName.getStr() );
- if( !x->queryInterface( aClassType ).hasValue() )
+ if( !(*x)->queryInterface( aClassType ).hasValue() )
{
return;
}
@@ -3426,8 +3416,7 @@ SbxVariable* SbUnoClass::Find( const OUString& rName, SbxClassType )
// Interface located? Then it is a class
if( eType == TypeClass_INTERFACE )
{
- Reference< XInterface > xIface = *static_cast<Reference< XInterface > const *>(aValue.getValue());
- Reference< XIdlClass > xClass( xIface, UNO_QUERY );
+ Reference< XIdlClass > xClass( aValue, UNO_QUERY );
if( xClass.is() )
{
pRes = new SbxVariable( SbxVARIANT );
diff --git a/basic/source/runtime/runtime.cxx b/basic/source/runtime/runtime.cxx
index 2c0bdbe..fddabbb 100644
--- a/basic/source/runtime/runtime.cxx
+++ b/basic/source/runtime/runtime.cxx
@@ -3691,8 +3691,7 @@ void SbiRuntime::SetupArgs( SbxVariable* p, sal_uInt32 nOp1 )
if( aAny.getValueType().getTypeClass() == TypeClass_INTERFACE )
{
- Reference< XInterface > x = *static_cast<Reference< XInterface > const *>(aAny.getValue());
- Reference< XDefaultMethod > xDfltMethod( x, UNO_QUERY );
+ Reference< XDefaultMethod > xDfltMethod( aAny, UNO_QUERY );
OUString sDefaultMethod;
if ( xDfltMethod.is() )
@@ -3820,8 +3819,7 @@ SbxVariable* SbiRuntime::CheckArray( SbxVariable* pElem )
if( aAny.getValueType().getTypeClass() == TypeClass_INTERFACE )
{
- Reference< XInterface > x = *static_cast<Reference< XInterface > const *>(aAny.getValue());
- Reference< XIndexAccess > xIndexAccess( x, UNO_QUERY );
+ Reference< XIndexAccess > xIndexAccess( aAny, UNO_QUERY );
if ( !bVBAEnabled )
{
if( xIndexAccess.is() )
@@ -3839,11 +3837,7 @@ SbxVariable* SbiRuntime::CheckArray( SbxVariable* pElem )
try
{
Any aAny2 = xIndexAccess->getByIndex( nIndex );
- TypeClass eType = aAny2.getValueType().getTypeClass();
- if( eType == TypeClass_INTERFACE )
- {
- xRet = *static_cast<Reference< XInterface > const *>(aAny2.getValue());
- }
+ aAny2 >>= xRet;
}
catch (const IndexOutOfBoundsException&)
{
@@ -3877,6 +3871,7 @@ SbxVariable* SbiRuntime::CheckArray( SbxVariable* pElem )
// "
// val = rst1("FirstName")
// has the default 'Fields' member between rst1 and '("FirstName")'
+ Any x = aAny;
SbxVariable* pDflt = getDefaultProp( pElem );
if ( pDflt )
{
@@ -3890,7 +3885,7 @@ SbxVariable* SbiRuntime::CheckArray( SbxVariable* pElem )
Any aUnoAny = pUnoObj->getUnoAny();
if( aUnoAny.getValueType().getTypeClass() == TypeClass_INTERFACE )
- x = *static_cast<Reference< XInterface > const *>(aUnoAny.getValue());
+ x = aUnoAny;
pElem = pDflt;
}
}
More information about the Libreoffice-commits
mailing list