diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2016-06-21 14:05:17 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2016-06-21 14:05:17 +0200 |
commit | 9cef658364e4d8441f490e4fe89c3bfa14cd24b3 (patch) | |
tree | d3759856838bb9fc6af85694bbe4c594f728e8f7 /stoc | |
parent | 7669bf3884ac053baca04e09d7c9994870983a4a (diff) |
Clean up uses of Any::getValue() in stoc
Change-Id: I455b708bfcc9d5aa71bb0ffc21efec205302169e
Diffstat (limited to 'stoc')
-rw-r--r-- | stoc/source/corereflection/base.hxx | 7 | ||||
-rw-r--r-- | stoc/source/corereflection/crefl.cxx | 9 | ||||
-rw-r--r-- | stoc/source/corereflection/criface.cxx | 25 | ||||
-rw-r--r-- | stoc/source/inspect/introspection.cxx | 57 | ||||
-rw-r--r-- | stoc/source/invocation/invocation.cxx | 6 | ||||
-rw-r--r-- | stoc/source/servicemanager/servicemanager.cxx | 19 | ||||
-rw-r--r-- | stoc/source/typeconv/convert.cxx | 80 |
7 files changed, 95 insertions, 108 deletions
diff --git a/stoc/source/corereflection/base.hxx b/stoc/source/corereflection/base.hxx index f28a600ac75a..cdfcb3f2f7b1 100644 --- a/stoc/source/corereflection/base.hxx +++ b/stoc/source/corereflection/base.hxx @@ -21,6 +21,9 @@ #ifndef INCLUDED_STOC_SOURCE_COREREFLECTION_BASE_HXX #define INCLUDED_STOC_SOURCE_COREREFLECTION_BASE_HXX +#include <sal/config.h> + +#include <o3tl/any.hxx> #include <osl/diagnose.h> #include <osl/mutex.hxx> #include <uno/mapping.hxx> @@ -366,9 +369,9 @@ inline bool extract( reinterpret_cast< uno_AcquireFunc >(css::uno::cpp_acquire), reinterpret_cast< uno_ReleaseFunc >(css::uno::cpp_release) ); } - else if (rObj.getValueTypeClass() == css::uno::TypeClass_TYPE) + else if (auto t = o3tl::tryAccess<css::uno::Type>(rObj)) { - rDest = pRefl->forType( static_cast< const css::uno::Type * >( rObj.getValue() )->getTypeLibType() ); + rDest = pRefl->forType( t->getTypeLibType() ); return rDest.is(); } } diff --git a/stoc/source/corereflection/crefl.cxx b/stoc/source/corereflection/crefl.cxx index d9e9007e2dc4..9275e453c40e 100644 --- a/stoc/source/corereflection/crefl.cxx +++ b/stoc/source/corereflection/crefl.cxx @@ -25,6 +25,7 @@ #include <com/sun/star/reflection/XConstantTypeDescription.hpp> #include <com/sun/star/reflection/XTypeDescription.hpp> #include <com/sun/star/uno/RuntimeException.hpp> +#include <o3tl/any.hxx> #include <uno/lbnames.h> using namespace css; @@ -223,8 +224,7 @@ Reference< XIdlClass > IdlReflectionServiceImpl::forName( const OUString & rType if (aAny.hasValue()) { - if (aAny.getValueTypeClass() == TypeClass_INTERFACE) - xRet = *static_cast<const Reference< XIdlClass > *>(aAny.getValue()); + aAny >>= xRet; } else { @@ -254,7 +254,7 @@ Any IdlReflectionServiceImpl::getByHierarchicalName( const OUString & rName ) if (aRet.getValueTypeClass() == TypeClass_INTERFACE) { // type retrieved from tdmgr - OSL_ASSERT( (*static_cast<Reference< XInterface > const *>(aRet.getValue()))->queryInterface( + OSL_ASSERT( (*o3tl::forceAccess<Reference<XInterface>>(aRet))->queryInterface( cppu::UnoType<XTypeDescription>::get()).hasValue() ); css::uno::Reference< css::reflection::XConstantTypeDescription > @@ -321,8 +321,7 @@ Reference< XIdlClass > IdlReflectionServiceImpl::forType( typelib_TypeDescriptio if (aAny.hasValue()) { - if (aAny.getValueTypeClass() == TypeClass_INTERFACE) - xRet = *static_cast<const Reference< XIdlClass > *>(aAny.getValue()); + aAny >>= xRet; } else { diff --git a/stoc/source/corereflection/criface.cxx b/stoc/source/corereflection/criface.cxx index 22b12db3abae..91d42ae34d1a 100644 --- a/stoc/source/corereflection/criface.cxx +++ b/stoc/source/corereflection/criface.cxx @@ -24,6 +24,7 @@ #if !(defined(MACOSX) || defined(IOS) || defined(FREEBSD)) #include <malloc.h> #endif +#include <o3tl/any.hxx> #include <rtl/alloc.h> #include <typelib/typedescription.hxx> #include <uno/data.h> @@ -189,9 +190,7 @@ Any IdlAttributeFieldImpl::get( const Any & rObj ) (*pUnoI->pDispatcher)( pUnoI, getTypeDescr(), pReturn, nullptr, &pExc ); (*pUnoI->release)( pUnoI ); - checkException( - pExc, - *static_cast< Reference< XInterface > const * >(rObj.getValue())); + checkException(pExc, *o3tl::doAccess<Reference<XInterface>>(rObj)); Any aRet; uno_any_destruct( &aRet, reinterpret_cast< uno_ReleaseFunc >(cpp_release) ); @@ -277,17 +276,14 @@ void IdlAttributeFieldImpl::set( Any & rObj, const Any & rValue ) (*pUnoI->release)( pUnoI ); uno_destructData( pArg, pTD, nullptr ); - checkException( - pExc, - *static_cast< Reference< XInterface > const * >( - rObj.getValue())); + checkException(pExc, *o3tl::doAccess<Reference<XInterface>>(rObj)); return; } (*pUnoI->release)( pUnoI ); throw IllegalArgumentException( "illegal value given!", - *static_cast<const Reference< XInterface > *>(rObj.getValue()), 1 ); + *o3tl::doAccess<Reference<XInterface>>(rObj), 1 ); } throw IllegalArgumentException( "illegal destination object given!", @@ -575,19 +571,20 @@ Any SAL_CALL IdlInterfaceMethodImpl::invoke( const Any & rObj, Sequence< Any > & css::reflection::InvocationTargetException, css::uno::RuntimeException, std::exception) { - if (rObj.getValueTypeClass() == TypeClass_INTERFACE) + if (auto ifc = o3tl::tryAccess<css::uno::Reference<css::uno::XInterface>>( + rObj)) { // acquire()/ release() if (rtl_ustr_ascii_compare( getTypeDescr()->pTypeName->buffer, "com.sun.star.uno.XInterface::acquire" ) == 0) { - (*static_cast<const Reference< XInterface > *>(rObj.getValue()))->acquire(); + (*ifc)->acquire(); return Any(); } else if (rtl_ustr_ascii_compare( getTypeDescr()->pTypeName->buffer, "com.sun.star.uno.XInterface::release" ) == 0) { - (*static_cast<const Reference< XInterface > *>(rObj.getValue()))->release(); + (*ifc)->release(); return Any(); } } @@ -603,7 +600,7 @@ Any SAL_CALL IdlInterfaceMethodImpl::invoke( const Any & rObj, Sequence< Any > & (*pUnoI->release)( pUnoI ); throw IllegalArgumentException( "arguments len differ!", - *static_cast<const Reference< XInterface > *>(rObj.getValue()), 1 ); + *o3tl::doAccess<Reference<XInterface>>(rObj), 1 ); } Any * pCppArgs = rArgs.getArray(); @@ -677,7 +674,7 @@ Any SAL_CALL IdlInterfaceMethodImpl::invoke( const Any & rObj, Sequence< Any > & { IllegalArgumentException aExc( "cannot coerce argument type during corereflection call!", - *static_cast<const Reference< XInterface > *>(rObj.getValue()), (sal_Int16)nPos ); + *o3tl::doAccess<Reference<XInterface>>(rObj), (sal_Int16)nPos ); // cleanup while (nPos--) @@ -714,7 +711,7 @@ Any SAL_CALL IdlInterfaceMethodImpl::invoke( const Any & rObj, Sequence< Any > & TYPELIB_DANGER_RELEASE( pReturnType ); InvocationTargetException aExc; - aExc.Context = *static_cast<const Reference< XInterface > *>(rObj.getValue()); + aExc.Context = *o3tl::doAccess<Reference<XInterface>>(rObj); aExc.Message = "exception occurred during invocation!"; uno_any_destruct( &aExc.TargetException, diff --git a/stoc/source/inspect/introspection.cxx b/stoc/source/inspect/introspection.cxx index c755eef4e90b..102fc93ecce4 100644 --- a/stoc/source/inspect/introspection.cxx +++ b/stoc/source/inspect/introspection.cxx @@ -25,6 +25,7 @@ #include <map> #include <set> +#include <o3tl/any.hxx> #include <osl/diagnose.h> #include <osl/mutex.hxx> #include <osl/thread.h> @@ -383,16 +384,14 @@ void IntrospectionAccessStatic_Impl::setPropertyValueByIndex(const Any& obj, sal //void IntrospectionAccessStatic_Impl::setPropertyValueByIndex( Any& obj, sal_Int32 nSequenceIndex, const Any& aValue) const { // Is the passed object something that fits? - TypeClass eObjType = obj.getValueType().getTypeClass(); - Reference<XInterface> xInterface; - if( eObjType == TypeClass_INTERFACE ) - { - xInterface = *static_cast<Reference<XInterface> const *>(obj.getValue()); - } - else if( nSequenceIndex >= mnPropCount || ( eObjType != TypeClass_STRUCT && eObjType != TypeClass_EXCEPTION ) ) + if( !(obj >>= xInterface) ) { - throw IllegalArgumentException(); + TypeClass eObjType = obj.getValueType().getTypeClass(); + if( nSequenceIndex >= mnPropCount || ( eObjType != TypeClass_STRUCT && eObjType != TypeClass_EXCEPTION ) ) + { + throw IllegalArgumentException(); + } } // Test flags @@ -412,8 +411,8 @@ void IntrospectionAccessStatic_Impl::setPropertyValueByIndex(const Any& obj, sal bool bUseCopy = false; Any aRealValue; - TypeClass eValType = aValue.getValueType().getTypeClass(); - if( eValType == TypeClass_INTERFACE ) + if( auto valInterface = o3tl::tryAccess< + css::uno::Reference<css::uno::XInterface>>(aValue) ) { Type aPropType = rProp.Type; OUString aTypeName( aPropType.getTypeName() ); @@ -421,11 +420,10 @@ void IntrospectionAccessStatic_Impl::setPropertyValueByIndex(const Any& obj, sal //Reference<XIdlClass> xPropClass = rProp.Type; if( xPropClass.is() && xPropClass->getTypeClass() == TypeClass_INTERFACE ) { - Reference<XInterface> valInterface = *static_cast<Reference<XInterface> const *>(aValue.getValue()); - if( valInterface.is() ) + if( valInterface->is() ) { //Any queryInterface( const Type& rType ); - aRealValue = valInterface->queryInterface( aPropType ); + aRealValue = (*valInterface)->queryInterface( aPropType ); if( aRealValue.hasValue() ) bUseCopy = true; } @@ -525,17 +523,15 @@ Any IntrospectionAccessStatic_Impl::getPropertyValueByIndex(const Any& obj, sal_ Any aRet; // Is there anything suitable in the passed object? - TypeClass eObjType = obj.getValueType().getTypeClass(); - Reference<XInterface> xInterface; - if( eObjType == TypeClass_INTERFACE ) + if( !(obj >>= xInterface) ) { - xInterface = *static_cast<Reference<XInterface> const *>(obj.getValue()); - } - else if( nSequenceIndex >= mnPropCount || ( eObjType != TypeClass_STRUCT && eObjType != TypeClass_EXCEPTION ) ) - { - // throw IllegalArgumentException(); - return aRet; + TypeClass eObjType = obj.getValueType().getTypeClass(); + if( nSequenceIndex >= mnPropCount || ( eObjType != TypeClass_STRUCT && eObjType != TypeClass_EXCEPTION ) ) + { + // throw IllegalArgumentException(); + return aRet; + } } switch( maMapTypeSeq[ nSequenceIndex ] ) @@ -831,9 +827,7 @@ ImplIntrospectionAccess::ImplIntrospectionAccess : maInspectedObject( obj ), mpStaticImpl( pStaticImpl_ ) //, maAdapter() { // Save object as an interface if possible - TypeClass eType = maInspectedObject.getValueType().getTypeClass(); - if( eType == TypeClass_INTERFACE ) - mxIface = *static_cast<Reference<XInterface> const *>(maInspectedObject.getValue()); + maInspectedObject >>= mxIface; mnLastPropertyConcept = -1; mnLastMethodConcept = -1; @@ -1699,12 +1693,9 @@ css::uno::Reference<css::beans::XIntrospectionAccess> Implementation::inspect( if( eType != TypeClass_INTERFACE && eType != TypeClass_STRUCT && eType != TypeClass_EXCEPTION ) return css::uno::Reference<css::beans::XIntrospectionAccess>(); - Reference<XInterface> x; - if( eType == TypeClass_INTERFACE ) + if( auto x = o3tl::tryAccess<Reference<XInterface>>(aToInspectObj) ) { - // Get the interface out of the Any - x = *static_cast<Reference<XInterface> const *>(aToInspectObj.getValue()); - if( !x.is() ) + if( !x->is() ) return css::uno::Reference<css::beans::XIntrospectionAccess>(); } @@ -1721,7 +1712,7 @@ css::uno::Reference<css::beans::XIntrospectionAccess> Implementation::inspect( // Look for interfaces XTypeProvider and PropertySet if( eType == TypeClass_INTERFACE ) { - xTypeProvider.set( x, UNO_QUERY ); + xTypeProvider.set( aToInspectObj, UNO_QUERY ); if( xTypeProvider.is() ) { SupportedTypesSeq = comphelper::sequenceToContainer<std::vector<Type>>(xTypeProvider->getTypes()); @@ -1733,7 +1724,7 @@ css::uno::Reference<css::beans::XIntrospectionAccess> Implementation::inspect( SupportedTypesSeq = { aToInspectObj.getValueType() }; } // Now try to get the PropertySetInfo - xPropSet.set( x, UNO_QUERY ); + xPropSet.set( aToInspectObj, UNO_QUERY ); if( xPropSet.is() ) xPropSetInfo = xPropSet->getPropertySetInfo(); @@ -1791,7 +1782,7 @@ css::uno::Reference<css::beans::XIntrospectionAccess> Implementation::inspect( if( xPropSet.is() && xPropSetInfo.is() ) { // Is there also a FastPropertySet? - Reference<XFastPropertySet> xDummy( x, UNO_QUERY ); + Reference<XFastPropertySet> xDummy( aToInspectObj, UNO_QUERY ); bool bFast = pAccess->mbFastPropSet = xDummy.is(); Sequence<Property> aPropSeq = xPropSetInfo->getProperties(); diff --git a/stoc/source/invocation/invocation.cxx b/stoc/source/invocation/invocation.cxx index 0d405d53ba45..eee3da6905c7 100644 --- a/stoc/source/invocation/invocation.cxx +++ b/stoc/source/invocation/invocation.cxx @@ -360,14 +360,10 @@ Any Invocation_Impl::getMaterial() throw(RuntimeException, std::exception) void Invocation_Impl::setMaterial( const Any& rMaterial ) { // set the material first and only once - Reference<XInterface> xObj; - - if (rMaterial.getValueType().getTypeClass() == TypeClass_INTERFACE) - xObj = *static_cast<Reference<XInterface> const *>(rMaterial.getValue()); _aMaterial = rMaterial; // First do this outside the guard - _xDirect.set( xObj, UNO_QUERY ); + _xDirect.set( rMaterial, UNO_QUERY ); if( _xDirect.is() ) { diff --git a/stoc/source/servicemanager/servicemanager.cxx b/stoc/source/servicemanager/servicemanager.cxx index 19de2de8017c..283facc5f3e3 100644 --- a/stoc/source/servicemanager/servicemanager.cxx +++ b/stoc/source/servicemanager/servicemanager.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 <osl/diagnose.h> #include <rtl/ref.hxx> @@ -1111,12 +1114,10 @@ sal_Bool OServiceManager::has( const Any & Element ) return m_ImplementationMap.find( xEle ) != m_ImplementationMap.end(); } - else if (Element.getValueTypeClass() == TypeClass_STRING) + else if (auto implName = o3tl::tryAccess<OUString>(Element)) { - OUString const & implName = - *static_cast< OUString const * >(Element.getValue()); MutexGuard aGuard( m_mutex ); - return m_ImplementationNameMap.find( implName ) != + return m_ImplementationNameMap.find( *implName ) != m_ImplementationNameMap.end(); } return false; @@ -1160,7 +1161,7 @@ void OServiceManager::insert( const Any & Element ) for( sal_Int32 i = 0; i < aServiceNames.getLength(); i++ ) { m_ServiceMap.insert( HashMultimap_OWString_Interface::value_type( - pArray[i], *static_cast<Reference<XInterface > const *>(Element.getValue()) ) ); + pArray[i], *o3tl::doAccess<Reference<XInterface>>(Element) ) ); } } } @@ -1190,17 +1191,15 @@ void OServiceManager::remove( const Any & Element ) { xEle.set( Element, UNO_QUERY_THROW ); } - else if (Element.getValueTypeClass() == TypeClass_STRING) + else if (auto implName = o3tl::tryAccess<OUString>(Element)) { - OUString const & implName = - *static_cast< OUString const * >(Element.getValue()); MutexGuard aGuard( m_mutex ); HashMap_OWString_Interface::const_iterator const iFind( - m_ImplementationNameMap.find( implName ) ); + m_ImplementationNameMap.find( *implName ) ); if (iFind == m_ImplementationNameMap.end()) { throw NoSuchElementException( - "element is not in: " + implName, + "element is not in: " + *implName, static_cast< OWeakObject * >(this) ); } xEle = iFind->second; diff --git a/stoc/source/typeconv/convert.cxx b/stoc/source/typeconv/convert.cxx index 7b21b926d543..10d0ec539279 100644 --- a/stoc/source/typeconv/convert.cxx +++ b/stoc/source/typeconv/convert.cxx @@ -17,7 +17,9 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <sal/config.h> +#include <o3tl/any.hxx> #include <osl/diagnose.h> #include <cppuhelper/factory.hxx> #include <cppuhelper/implementationentry.hxx> @@ -303,39 +305,39 @@ sal_Int64 TypeConverter_Impl::toHyper( const Any& rAny, sal_Int64 min, sal_uInt6 break; // BOOL case TypeClass_BOOLEAN: - nRet = (*static_cast<sal_Bool const *>(rAny.getValue()) ? 1 : 0); + nRet = *o3tl::forceAccess<bool>(rAny) ? 1 : 0; break; // CHAR, BYTE case TypeClass_CHAR: - nRet = *static_cast<sal_Unicode const *>(rAny.getValue()); + nRet = *o3tl::forceAccess<sal_Unicode>(rAny); break; case TypeClass_BYTE: - nRet = *static_cast<sal_Int8 const *>(rAny.getValue()); + nRet = *o3tl::forceAccess<sal_Int8>(rAny); break; // SHORT case TypeClass_SHORT: - nRet = *static_cast<sal_Int16 const *>(rAny.getValue()); + nRet = *o3tl::forceAccess<sal_Int16>(rAny); break; // UNSIGNED SHORT case TypeClass_UNSIGNED_SHORT: - nRet = *static_cast<sal_uInt16 const *>(rAny.getValue()); + nRet = *o3tl::forceAccess<sal_uInt16>(rAny); break; // LONG case TypeClass_LONG: - nRet = *static_cast<sal_Int32 const *>(rAny.getValue()); + nRet = *o3tl::forceAccess<sal_Int32>(rAny); break; // UNSIGNED LONG case TypeClass_UNSIGNED_LONG: - nRet = *static_cast<sal_uInt32 const *>(rAny.getValue()); + nRet = *o3tl::forceAccess<sal_uInt32>(rAny); break; // HYPER case TypeClass_HYPER: - nRet = *static_cast<sal_Int64 const *>(rAny.getValue()); + nRet = *o3tl::forceAccess<sal_Int64>(rAny); break; // UNSIGNED HYPER case TypeClass_UNSIGNED_HYPER: { - nRet = *static_cast<sal_Int64 const *>(rAny.getValue()); + nRet = static_cast<sal_Int64>(*o3tl::forceAccess<sal_uInt64>(rAny)); if ((min < 0 || (sal_uInt64)nRet >= (sal_uInt64)min) && // lower bound (sal_uInt64)nRet <= max) // upper bound { @@ -349,7 +351,7 @@ sal_Int64 TypeConverter_Impl::toHyper( const Any& rAny, sal_Int64 min, sal_uInt6 // FLOAT, DOUBLE case TypeClass_FLOAT: { - double fVal = round( *static_cast<float const *>(rAny.getValue()) ); + double fVal = round( *o3tl::forceAccess<float>(rAny) ); nRet = (fVal > SAL_INT64_MAX ? (sal_Int64)(sal_uInt64)fVal : (sal_Int64)fVal); if (fVal >= min && fVal <= unsigned_int64_to_double( max )) { @@ -361,7 +363,7 @@ sal_Int64 TypeConverter_Impl::toHyper( const Any& rAny, sal_Int64 min, sal_uInt6 } case TypeClass_DOUBLE: { - double fVal = round( *static_cast<double const *>(rAny.getValue()) ); + double fVal = round( *o3tl::forceAccess<double>(rAny) ); nRet = (fVal > SAL_INT64_MAX ? (sal_Int64)(sal_uInt64)fVal : (sal_Int64)fVal); if (fVal >= min && fVal <= unsigned_int64_to_double( max )) { @@ -376,7 +378,7 @@ sal_Int64 TypeConverter_Impl::toHyper( const Any& rAny, sal_Int64 min, sal_uInt6 case TypeClass_STRING: { sal_Int64 nVal = SAL_CONST_INT64(0); - if (! getHyperValue( nVal, *static_cast<OUString const *>(rAny.getValue()) )) + if (! getHyperValue( nVal, *o3tl::forceAccess<OUString>(rAny) )) { throw CannotConvertException( "invalid STRING value!", @@ -418,51 +420,51 @@ double TypeConverter_Impl::toDouble( const Any& rAny, double min, double max ) break; // BOOL case TypeClass_BOOLEAN: - fRet = (*static_cast<sal_Bool const *>(rAny.getValue()) ? 1.0 : 0.0); + fRet = *o3tl::forceAccess<bool>(rAny) ? 1.0 : 0.0; break; // CHAR, BYTE case TypeClass_CHAR: - fRet = *static_cast<sal_Unicode const *>(rAny.getValue()); + fRet = *o3tl::forceAccess<sal_Unicode>(rAny); break; case TypeClass_BYTE: - fRet = *static_cast<sal_Int8 const *>(rAny.getValue()); + fRet = *o3tl::forceAccess<sal_Int8>(rAny); break; // SHORT case TypeClass_SHORT: - fRet = *static_cast<sal_Int16 const *>(rAny.getValue()); + fRet = *o3tl::forceAccess<sal_Int16>(rAny); break; // UNSIGNED SHORT case TypeClass_UNSIGNED_SHORT: - fRet = *static_cast<sal_uInt16 const *>(rAny.getValue()); + fRet = *o3tl::forceAccess<sal_uInt16>(rAny); break; // LONG case TypeClass_LONG: - fRet = *static_cast<sal_Int32 const *>(rAny.getValue()); + fRet = *o3tl::forceAccess<sal_Int32>(rAny); break; // UNSIGNED LONG case TypeClass_UNSIGNED_LONG: - fRet = *static_cast<sal_uInt32 const *>(rAny.getValue()); + fRet = *o3tl::forceAccess<sal_uInt32>(rAny); break; // HYPER case TypeClass_HYPER: - fRet = (double)*static_cast<sal_Int64 const *>(rAny.getValue()); + fRet = (double)*o3tl::forceAccess<sal_Int64>(rAny); break; // UNSIGNED HYPER case TypeClass_UNSIGNED_HYPER: - fRet = unsigned_int64_to_double( *static_cast<sal_uInt64 const *>(rAny.getValue()) ); + fRet = unsigned_int64_to_double( *o3tl::forceAccess<sal_uInt64>(rAny) ); break; // FLOAT, DOUBLE case TypeClass_FLOAT: - fRet = *static_cast<float const *>(rAny.getValue()); + fRet = *o3tl::forceAccess<float>(rAny); break; case TypeClass_DOUBLE: - fRet = *static_cast<double const *>(rAny.getValue()); + fRet = *o3tl::forceAccess<double>(rAny); break; // STRING case TypeClass_STRING: { - if (! getNumericValue( fRet, *static_cast<OUString const *>(rAny.getValue()) )) + if (! getNumericValue( fRet, *o3tl::forceAccess<OUString>(rAny) )) { throw CannotConvertException( "invalid STRING value!", @@ -538,15 +540,15 @@ Any SAL_CALL TypeConverter_Impl::convertTo( const Any& rVal, const Type& aDestTy break; } - if (rVal.getValueTypeClass() != TypeClass_INTERFACE || - !*static_cast<XInterface * const *>(rVal.getValue())) + auto ifc = o3tl::tryAccess<css::uno::Reference<css::uno::XInterface>>( + rVal); + if (!ifc || !ifc->is()) { throw CannotConvertException( "value is no interface!", Reference< XInterface >(), aDestinationClass, FailReason::NO_SUCH_INTERFACE, 0 ); } - if (! (aRet = (*static_cast<XInterface * const *>(rVal.getValue()))->queryInterface( - aDestType )).hasValue()) + if (! (aRet = (*ifc)->queryInterface(aDestType )).hasValue()) { throw CannotConvertException( "value has no such interface!", @@ -626,7 +628,7 @@ Any SAL_CALL TypeConverter_Impl::convertTo( const Any& rVal, const Type& aDestTy { for ( nPos = reinterpret_cast<typelib_EnumTypeDescription *>(aEnumTD.get())->nEnumValues; nPos--; ) { - if (static_cast<const OUString *>(rVal.getValue())->equalsIgnoreAsciiCase( + if (o3tl::forceAccess<OUString>(rVal)->equalsIgnoreAsciiCase( reinterpret_cast<typelib_EnumTypeDescription *>(aEnumTD.get())->ppEnumNames[nPos] )) break; } @@ -737,7 +739,7 @@ Any TypeConverter_Impl::convertToSimpleType( const Any& rVal, TypeClass aDestina case TypeClass_STRING: { - const OUString & aStr = *static_cast<const OUString *>(rVal.getValue()); + const OUString & aStr = *o3tl::forceAccess<OUString>(rVal); if ( aStr == "0" || aStr.equalsIgnoreAsciiCase( "false" )) { aRet <<= false; @@ -761,7 +763,7 @@ Any TypeConverter_Impl::convertToSimpleType( const Any& rVal, TypeClass aDestina { if (aSourceClass==TypeClass_STRING) { - auto const s = static_cast<const OUString *>(rVal.getValue()); + auto const s = o3tl::forceAccess<OUString>(rVal); if (s->getLength() == 1) // single char aRet <<= (*s)[0]; } @@ -838,31 +840,31 @@ Any TypeConverter_Impl::convertToSimpleType( const Any& rVal, TypeClass aDestina } case TypeClass_BOOLEAN: - aRet <<= *static_cast<sal_Bool const *>(rVal.getValue()) ? + aRet <<= *o3tl::forceAccess<bool>(rVal) ? OUString("true") : OUString("false"); break; case TypeClass_CHAR: - aRet <<= OUString( static_cast<sal_Unicode const *>(rVal.getValue()), 1 ); + aRet <<= OUString(*o3tl::forceAccess<sal_Unicode>(rVal)); break; case TypeClass_BYTE: - aRet <<= OUString::number( *static_cast<sal_Int8 const *>(rVal.getValue()) ); + aRet <<= OUString::number( *o3tl::forceAccess<sal_Int8>(rVal) ); break; case TypeClass_SHORT: - aRet <<= OUString::number( *static_cast<sal_Int16 const *>(rVal.getValue()) ); + aRet <<= OUString::number( *o3tl::forceAccess<sal_Int16>(rVal) ); break; case TypeClass_UNSIGNED_SHORT: - aRet <<= OUString::number( *static_cast<sal_uInt16 const *>(rVal.getValue()) ); + aRet <<= OUString::number( *o3tl::forceAccess<sal_uInt16>(rVal) ); break; case TypeClass_LONG: - aRet <<= OUString::number( *static_cast<sal_Int32 const *>(rVal.getValue()) ); + aRet <<= OUString::number( *o3tl::forceAccess<sal_Int32>(rVal) ); break; case TypeClass_UNSIGNED_LONG: - aRet <<= OUString::number( *static_cast<sal_uInt32 const *>(rVal.getValue()) ); + aRet <<= OUString::number( *o3tl::forceAccess<sal_uInt32>(rVal) ); break; case TypeClass_HYPER: - aRet <<= OUString::number( *static_cast<sal_Int64 const *>(rVal.getValue()) ); + aRet <<= OUString::number( *o3tl::forceAccess<sal_Int64>(rVal) ); break; // case TypeClass_UNSIGNED_HYPER: // aRet <<= OUString::valueOf( (sal_Int64)*(sal_uInt64 const *)rVal.getValue() ); |