Kaydet (Commit) 50a0473e authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Clean up uses of Any::getValue() in comphelper

Change-Id: I433cca20fb29c6b6ede934edcb2e200f15b060f2
üst 4833ed2f
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <com/sun/star/container/XIndexAccess.hpp> #include <com/sun/star/container/XIndexAccess.hpp>
#include <com/sun/star/container/XChild.hpp> #include <com/sun/star/container/XChild.hpp>
#include <comphelper/container.hxx> #include <comphelper/container.hxx>
#include <o3tl/any.hxx>
#include <osl/diagnose.h> #include <osl/diagnose.h>
...@@ -65,7 +66,7 @@ css::uno::Reference< css::uno::XInterface> IndexAccessIterator::Next() ...@@ -65,7 +66,7 @@ css::uno::Reference< css::uno::XInterface> IndexAccessIterator::Next()
if (xContainerAccess.is() && xContainerAccess->getCount() && ShouldStepInto(xContainerAccess)) if (xContainerAccess.is() && xContainerAccess->getCount() && ShouldStepInto(xContainerAccess))
{ {
css::uno::Any aElement(xContainerAccess->getByIndex(0)); css::uno::Any aElement(xContainerAccess->getByIndex(0));
xSearchLoop = *static_cast<css::uno::Reference< css::uno::XInterface> const *>(aElement.getValue()); xSearchLoop = *o3tl::doAccess<css::uno::Reference<css::uno::XInterface>>(aElement);
bCheckingStartingPoint = false; bCheckingStartingPoint = false;
m_arrChildIndizies.push_back((sal_Int32)0); m_arrChildIndizies.push_back((sal_Int32)0);
...@@ -90,7 +91,7 @@ css::uno::Reference< css::uno::XInterface> IndexAccessIterator::Next() ...@@ -90,7 +91,7 @@ css::uno::Reference< css::uno::XInterface> IndexAccessIterator::Next()
++nOldSearchChildIndex; ++nOldSearchChildIndex;
// and check the next child // and check the next child
css::uno::Any aElement(xContainerAccess->getByIndex(nOldSearchChildIndex)); css::uno::Any aElement(xContainerAccess->getByIndex(nOldSearchChildIndex));
xSearchLoop = *static_cast<css::uno::Reference< css::uno::XInterface> const *>(aElement.getValue()); xSearchLoop = *o3tl::doAccess<css::uno::Reference<css::uno::XInterface>>(aElement);
bCheckingStartingPoint = false; bCheckingStartingPoint = false;
// and update its position in the list. // and update its position in the list.
m_arrChildIndizies.push_back((sal_Int32)nOldSearchChildIndex); m_arrChildIndizies.push_back((sal_Int32)nOldSearchChildIndex);
......
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * 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/mutex.hxx>
#include <osl/diagnose.h> #include <osl/diagnose.h>
#include <comphelper/eventattachermgr.hxx> #include <comphelper/eventattachermgr.hxx>
...@@ -284,24 +287,24 @@ Any SAL_CALL AttacherAllListener_Impl::approveFiring( const AllEventObject& Even ...@@ -284,24 +287,24 @@ Any SAL_CALL AttacherAllListener_Impl::approveFiring( const AllEventObject& Even
case TypeClass_BOOLEAN: case TypeClass_BOOLEAN:
// FALSE -> Return // FALSE -> Return
if( !(*static_cast<sal_Bool const *>(aRet.getValue())) ) if( !(*o3tl::forceAccess<bool>(aRet)) )
return aRet; return aRet;
break; break;
case TypeClass_STRING: case TypeClass_STRING:
// none empty string -> return // none empty string -> return
if( !(static_cast<OUString const *>(aRet.getValue()))->isEmpty() ) if( !o3tl::forceAccess<OUString>(aRet)->isEmpty() )
return aRet; return aRet;
break; break;
// none zero number -> return // none zero number -> return
case TypeClass_FLOAT: if( *static_cast<float const *>(aRet.getValue()) ) return aRet; break; case TypeClass_FLOAT: if( *o3tl::forceAccess<float>(aRet) ) return aRet; break;
case TypeClass_DOUBLE: if( *static_cast<double const *>(aRet.getValue()) ) return aRet; break; case TypeClass_DOUBLE: if( *o3tl::forceAccess<double>(aRet) ) return aRet; break;
case TypeClass_BYTE: if( *static_cast<sal_uInt8 const *>(aRet.getValue()) ) return aRet; break; case TypeClass_BYTE: if( *o3tl::forceAccess<sal_Int8>(aRet) ) return aRet; break;
case TypeClass_SHORT: if( *static_cast<sal_Int16 const *>(aRet.getValue()) ) return aRet; break; case TypeClass_SHORT: if( *o3tl::forceAccess<sal_Int16>(aRet) ) return aRet; break;
case TypeClass_LONG: if( *static_cast<sal_Int32 const *>(aRet.getValue()) ) return aRet; break; case TypeClass_LONG: if( *o3tl::forceAccess<sal_Int32>(aRet) ) return aRet; break;
case TypeClass_UNSIGNED_SHORT: if( *static_cast<sal_uInt16 const *>(aRet.getValue()) ) return aRet; break; case TypeClass_UNSIGNED_SHORT: if( *o3tl::forceAccess<sal_uInt16>(aRet) ) return aRet; break;
case TypeClass_UNSIGNED_LONG: if( *static_cast<sal_uInt32 const *>(aRet.getValue()) ) return aRet; break; case TypeClass_UNSIGNED_LONG: if( *o3tl::forceAccess<sal_uInt32>(aRet) ) return aRet; break;
default: default:
OSL_ASSERT(false); OSL_ASSERT(false);
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <com/sun/star/awt/FontUnderline.hpp> #include <com/sun/star/awt/FontUnderline.hpp>
#include <com/sun/star/awt/FontStrikeout.hpp> #include <com/sun/star/awt/FontStrikeout.hpp>
#include <com/sun/star/awt/FontDescriptor.hpp> #include <com/sun/star/awt/FontDescriptor.hpp>
#include <o3tl/any.hxx>
#include <osl/diagnose.h> #include <osl/diagnose.h>
#include <typelib/typedescription.hxx> #include <typelib/typedescription.hxx>
...@@ -91,8 +92,8 @@ OUString getString(const Any& _rAny) ...@@ -91,8 +92,8 @@ OUString getString(const Any& _rAny)
bool getBOOL(const Any& _rAny) bool getBOOL(const Any& _rAny)
{ {
bool bReturn = false; bool bReturn = false;
if (_rAny.getValueType() == cppu::UnoType<bool>::get()) if (auto b = o3tl::tryAccess<bool>(_rAny))
bReturn = *static_cast<sal_Bool const *>(_rAny.getValue()); bReturn = *b;
else else
OSL_FAIL("comphelper::getBOOL : invalid argument !"); OSL_FAIL("comphelper::getBOOL : invalid argument !");
return bReturn; return bReturn;
......
...@@ -169,13 +169,11 @@ namespace comphelper ...@@ -169,13 +169,11 @@ namespace comphelper
template <class iface> template <class iface>
bool query_aggregation(const css::uno::Reference< css::uno::XAggregation >& _rxAggregate, css::uno::Reference<iface>& _rxOut) bool query_aggregation(const css::uno::Reference< css::uno::XAggregation >& _rxAggregate, css::uno::Reference<iface>& _rxOut)
{ {
_rxOut = static_cast<iface*>(nullptr); _rxOut.clear();
if (_rxAggregate.is()) if (_rxAggregate.is())
{ {
css::uno::Any aCheck = _rxAggregate->queryAggregation( _rxAggregate->queryAggregation(cppu::UnoType<iface>::get())
cppu::UnoType<iface>::get()); >>= _rxOut;
if (aCheck.hasValue())
_rxOut = *static_cast<const css::uno::Reference<iface>*>(aCheck.getValue());
} }
return _rxOut.is(); return _rxOut.is();
} }
......
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