Use o3tl/any.hxx in connectivity

Change-Id: I5c0d84b20b9146c4fc65bfdc0e9c65a05c93d71c
This commit is contained in:
Stephan Bergmann
2016-06-06 09:47:01 +02:00
parent e5d45064fc
commit 61e0433fdf
4 changed files with 66 additions and 62 deletions

View File

@@ -20,6 +20,7 @@
#include <connectivity/dbexception.hxx> #include <connectivity/dbexception.hxx>
#include <comphelper/types.hxx> #include <comphelper/types.hxx>
#include <cppuhelper/exc_hlp.hxx> #include <cppuhelper/exc_hlp.hxx>
#include <o3tl/any.hxx>
#include <osl/diagnose.h> #include <osl/diagnose.h>
#include <com/sun/star/sdb/SQLContext.hpp> #include <com/sun/star/sdb/SQLContext.hpp>
#include <com/sun/star/sdbc/SQLWarning.hpp> #include <com/sun/star/sdbc/SQLWarning.hpp>
@@ -174,14 +175,14 @@ bool SQLExceptionInfo::isKindOf(TYPE _eType) const
SQLExceptionInfo::operator const css::sdbc::SQLException*() const SQLExceptionInfo::operator const css::sdbc::SQLException*() const
{ {
OSL_ENSURE(isKindOf(TYPE::SQLException), "SQLExceptionInfo::operator SQLException* : invalid call !"); OSL_ENSURE(isKindOf(TYPE::SQLException), "SQLExceptionInfo::operator SQLException* : invalid call !");
return static_cast<const css::sdbc::SQLException*>(m_aContent.getValue()); return o3tl::doGet<css::sdbc::SQLException>(m_aContent);
} }
SQLExceptionInfo::operator const css::sdb::SQLContext*() const SQLExceptionInfo::operator const css::sdb::SQLContext*() const
{ {
OSL_ENSURE(isKindOf(TYPE::SQLContext), "SQLExceptionInfo::operator SQLException* : invalid call !"); OSL_ENSURE(isKindOf(TYPE::SQLContext), "SQLExceptionInfo::operator SQLException* : invalid call !");
return static_cast<const css::sdb::SQLContext*>(m_aContent.getValue()); return o3tl::doGet<css::sdb::SQLContext>(m_aContent);
} }
@@ -212,10 +213,10 @@ void SQLExceptionInfo::append( TYPE _eType, const OUString& _rErrorMessage, cons
break; break;
} }
SQLException* pAppendException( static_cast< SQLException* >( const_cast< void* >( aAppend.getValue() ) ) ); SQLException& pAppendException = const_cast<SQLException &>(*o3tl::forceGet<SQLException>(aAppend));
pAppendException->Message = _rErrorMessage; pAppendException.Message = _rErrorMessage;
pAppendException->SQLState = _rSQLState; pAppendException.SQLState = _rSQLState;
pAppendException->ErrorCode = _nErrorCode; pAppendException.ErrorCode = _nErrorCode;
// find the end of the current chain // find the end of the current chain
Any* pChainIterator = &m_aContent; Any* pChainIterator = &m_aContent;
@@ -229,7 +230,7 @@ void SQLExceptionInfo::append( TYPE _eType, const OUString& _rErrorMessage, cons
if ( !isAssignableFrom( aSQLExceptionType, pChainIterator->getValueType() ) ) if ( !isAssignableFrom( aSQLExceptionType, pChainIterator->getValueType() ) )
break; break;
pLastException = static_cast< SQLException* >( const_cast< void* >( pChainIterator->getValue() ) ); pLastException = const_cast< SQLException* >( o3tl::doGet<SQLException>( *pChainIterator ) );
pChainIterator = &pLastException->NextException; pChainIterator = &pLastException->NextException;
} }
@@ -313,7 +314,7 @@ const css::sdbc::SQLException* SQLExceptionIteratorHelper::next()
return pReturn; return pReturn;
} }
m_pCurrent = static_cast< const SQLException* >( m_pCurrent->NextException.getValue() ); m_pCurrent = o3tl::doGet< SQLException >( m_pCurrent->NextException );
// no finally determine the proper type of the exception // no finally determine the proper type of the exception
const Type aTypeContext( ::cppu::UnoType< SQLContext >::get() ); const Type aTypeContext( ::cppu::UnoType< SQLContext >::get() );

View File

@@ -73,6 +73,7 @@
#include <connectivity/dbexception.hxx> #include <connectivity/dbexception.hxx>
#include <connectivity/dbtools.hxx> #include <connectivity/dbtools.hxx>
#include <connectivity/statementcomposer.hxx> #include <connectivity/statementcomposer.hxx>
#include <o3tl/any.hxx>
#include <osl/diagnose.h> #include <osl/diagnose.h>
#include <rtl/ustrbuf.hxx> #include <rtl/ustrbuf.hxx>
#include <tools/diagnose_ex.h> #include <tools/diagnose_ex.h>
@@ -1155,14 +1156,14 @@ try
{ {
Any aDate( xOldProps->getPropertyValue(sPropDefaultDate) ); Any aDate( xOldProps->getPropertyValue(sPropDefaultDate) );
if (aDate.hasValue()) if (aDate.hasValue())
aNewDefault <<= DBTypeConversion::toDouble(*static_cast<Date const *>(aDate.getValue())); aNewDefault <<= DBTypeConversion::toDouble(*o3tl::doGet<Date>(aDate));
} }
if (hasProperty(sPropDefaultTime, xOldProps)) if (hasProperty(sPropDefaultTime, xOldProps))
{ {
Any aTime( xOldProps->getPropertyValue(sPropDefaultTime) ); Any aTime( xOldProps->getPropertyValue(sPropDefaultTime) );
if (aTime.hasValue()) if (aTime.hasValue())
aNewDefault <<= DBTypeConversion::toDouble(*static_cast<Time const *>(aTime.getValue())); aNewDefault <<= DBTypeConversion::toDouble(*o3tl::doGet<Time>(aTime));
} }
// double or OUString will be copied directly // double or OUString will be copied directly
@@ -1449,29 +1450,29 @@ bool implUpdateObject(const Reference< XRowUpdate >& _rxUpdatedObject,
break; break;
case TypeClass_STRING: case TypeClass_STRING:
_rxUpdatedObject->updateString(_nColumnIndex, *static_cast<OUString const *>(_rValue.getValue())); _rxUpdatedObject->updateString(_nColumnIndex, *o3tl::forceGet<OUString>(_rValue));
break; break;
case TypeClass_BOOLEAN: case TypeClass_BOOLEAN:
_rxUpdatedObject->updateBoolean(_nColumnIndex, *static_cast<sal_Bool const *>(_rValue.getValue())); _rxUpdatedObject->updateBoolean(_nColumnIndex, *o3tl::forceGet<bool>(_rValue));
break; break;
case TypeClass_BYTE: case TypeClass_BYTE:
_rxUpdatedObject->updateByte(_nColumnIndex, *static_cast<sal_Int8 const *>(_rValue.getValue())); _rxUpdatedObject->updateByte(_nColumnIndex, *o3tl::forceGet<sal_Int8>(_rValue));
break; break;
case TypeClass_UNSIGNED_SHORT: case TypeClass_UNSIGNED_SHORT:
case TypeClass_SHORT: case TypeClass_SHORT:
_rxUpdatedObject->updateShort(_nColumnIndex, *static_cast<sal_Int16 const *>(_rValue.getValue())); _rxUpdatedObject->updateShort(_nColumnIndex, *o3tl::forceGet<sal_Int16>(_rValue));
break; break;
case TypeClass_CHAR: case TypeClass_CHAR:
_rxUpdatedObject->updateString(_nColumnIndex,OUString(static_cast<sal_Unicode const *>(_rValue.getValue()),1)); _rxUpdatedObject->updateString(_nColumnIndex,OUString(*o3tl::forceGet<sal_Unicode>(_rValue)));
break; break;
case TypeClass_UNSIGNED_LONG: case TypeClass_UNSIGNED_LONG:
case TypeClass_LONG: case TypeClass_LONG:
_rxUpdatedObject->updateInt(_nColumnIndex, *static_cast<sal_Int32 const *>(_rValue.getValue())); _rxUpdatedObject->updateInt(_nColumnIndex, *o3tl::forceGet<sal_Int32>(_rValue));
break; break;
case TypeClass_HYPER: case TypeClass_HYPER:
@@ -1483,36 +1484,34 @@ bool implUpdateObject(const Reference< XRowUpdate >& _rxUpdatedObject,
break; break;
case TypeClass_FLOAT: case TypeClass_FLOAT:
_rxUpdatedObject->updateFloat(_nColumnIndex, *static_cast<float const *>(_rValue.getValue())); _rxUpdatedObject->updateFloat(_nColumnIndex, *o3tl::forceGet<float>(_rValue));
break; break;
case TypeClass_DOUBLE: case TypeClass_DOUBLE:
_rxUpdatedObject->updateDouble(_nColumnIndex, *static_cast<double const *>(_rValue.getValue())); _rxUpdatedObject->updateDouble(_nColumnIndex, *o3tl::forceGet<double>(_rValue));
break; break;
case TypeClass_SEQUENCE: case TypeClass_SEQUENCE:
if (_rValue.getValueType() == cppu::UnoType< Sequence< sal_Int8 > >::get()) if (auto s = o3tl::tryGet<Sequence< sal_Int8 >>(_rValue))
_rxUpdatedObject->updateBytes(_nColumnIndex, *static_cast<Sequence<sal_Int8> const *>(_rValue.getValue())); _rxUpdatedObject->updateBytes(_nColumnIndex, *s);
else else
bSuccessfullyReRouted = false; bSuccessfullyReRouted = false;
break; break;
case TypeClass_STRUCT: case TypeClass_STRUCT:
if (_rValue.getValueType() == cppu::UnoType<DateTime>::get()) if (auto s1 = o3tl::tryGet<DateTime>(_rValue))
_rxUpdatedObject->updateTimestamp(_nColumnIndex, *static_cast<DateTime const *>(_rValue.getValue())); _rxUpdatedObject->updateTimestamp(_nColumnIndex, *s1);
else if (_rValue.getValueType() == cppu::UnoType<Date>::get()) else if (auto s2 = o3tl::tryGet<Date>(_rValue))
_rxUpdatedObject->updateDate(_nColumnIndex, *static_cast<Date const *>(_rValue.getValue())); _rxUpdatedObject->updateDate(_nColumnIndex, *s2);
else if (_rValue.getValueType() == cppu::UnoType<Time>::get()) else if (auto s3 = o3tl::tryGet<Time>(_rValue))
_rxUpdatedObject->updateTime(_nColumnIndex, *static_cast<Time const *>(_rValue.getValue())); _rxUpdatedObject->updateTime(_nColumnIndex, *s3);
else else
bSuccessfullyReRouted = false; bSuccessfullyReRouted = false;
break; break;
case TypeClass_INTERFACE: case TypeClass_INTERFACE:
if (_rValue.getValueType() == cppu::UnoType<XInputStream>::get()) if (auto xStream = o3tl::tryGet<Reference<XInputStream>>(_rValue))
{ {
Reference< XInputStream > xStream; _rxUpdatedObject->updateBinaryStream(_nColumnIndex, *xStream, (*xStream)->available());
_rValue >>= xStream;
_rxUpdatedObject->updateBinaryStream(_nColumnIndex, xStream, xStream->available());
break; break;
} }
SAL_FALLTHROUGH; SAL_FALLTHROUGH;
@@ -1559,23 +1558,23 @@ bool implSetObject( const Reference< XParameters >& _rxParameters,
break; break;
case TypeClass_STRING: case TypeClass_STRING:
_rxParameters->setString(_nColumnIndex, *static_cast<OUString const *>(_rValue.getValue())); _rxParameters->setString(_nColumnIndex, *o3tl::forceGet<OUString>(_rValue));
break; break;
case TypeClass_BOOLEAN: case TypeClass_BOOLEAN:
_rxParameters->setBoolean(_nColumnIndex, *static_cast<sal_Bool const *>(_rValue.getValue())); _rxParameters->setBoolean(_nColumnIndex, *o3tl::forceGet<bool>(_rValue));
break; break;
case TypeClass_BYTE: case TypeClass_BYTE:
_rxParameters->setByte(_nColumnIndex, *static_cast<sal_Int8 const *>(_rValue.getValue())); _rxParameters->setByte(_nColumnIndex, *o3tl::forceGet<sal_Int8>(_rValue));
break; break;
case TypeClass_SHORT: case TypeClass_SHORT:
_rxParameters->setShort(_nColumnIndex, *static_cast<sal_Int16 const *>(_rValue.getValue())); _rxParameters->setShort(_nColumnIndex, *o3tl::forceGet<sal_Int16>(_rValue));
break; break;
case TypeClass_CHAR: case TypeClass_CHAR:
_rxParameters->setString(_nColumnIndex, OUString(static_cast<sal_Unicode const *>(_rValue.getValue()),1)); _rxParameters->setString(_nColumnIndex, OUString(*o3tl::forceGet<sal_Unicode>(_rValue)));
break; break;
case TypeClass_UNSIGNED_SHORT: case TypeClass_UNSIGNED_SHORT:
@@ -1588,28 +1587,28 @@ bool implSetObject( const Reference< XParameters >& _rxParameters,
} }
case TypeClass_FLOAT: case TypeClass_FLOAT:
_rxParameters->setFloat(_nColumnIndex, *static_cast<float const *>(_rValue.getValue())); _rxParameters->setFloat(_nColumnIndex, *o3tl::forceGet<float>(_rValue));
break; break;
case TypeClass_DOUBLE: case TypeClass_DOUBLE:
_rxParameters->setDouble(_nColumnIndex, *static_cast<double const *>(_rValue.getValue())); _rxParameters->setDouble(_nColumnIndex, *o3tl::forceGet<double>(_rValue));
break; break;
case TypeClass_SEQUENCE: case TypeClass_SEQUENCE:
if (_rValue.getValueType() == cppu::UnoType< Sequence< sal_Int8 > >::get()) if (auto s = o3tl::tryGet<Sequence< sal_Int8 >>(_rValue))
{ {
_rxParameters->setBytes(_nColumnIndex, *static_cast<Sequence<sal_Int8> const *>(_rValue.getValue())); _rxParameters->setBytes(_nColumnIndex, *s);
} }
else else
bSuccessfullyReRouted = false; bSuccessfullyReRouted = false;
break; break;
case TypeClass_STRUCT: case TypeClass_STRUCT:
if (_rValue.getValueType() == cppu::UnoType<DateTime>::get()) if (auto s1 = o3tl::tryGet<DateTime>(_rValue))
_rxParameters->setTimestamp(_nColumnIndex, *static_cast<DateTime const *>(_rValue.getValue())); _rxParameters->setTimestamp(_nColumnIndex, *s1);
else if (_rValue.getValueType() == cppu::UnoType<Date>::get()) else if (auto s2 = o3tl::tryGet<Date>(_rValue))
_rxParameters->setDate(_nColumnIndex, *static_cast<Date const *>(_rValue.getValue())); _rxParameters->setDate(_nColumnIndex, *s2);
else if (_rValue.getValueType() == cppu::UnoType<Time>::get()) else if (auto s3 = o3tl::tryGet<Time>(_rValue))
_rxParameters->setTime(_nColumnIndex, *static_cast<Time const *>(_rValue.getValue())); _rxParameters->setTime(_nColumnIndex, *s3);
else else
bSuccessfullyReRouted = false; bSuccessfullyReRouted = false;
break; break;

View File

@@ -21,6 +21,7 @@
#include <connectivity/warningscontainer.hxx> #include <connectivity/warningscontainer.hxx>
#include <connectivity/dbexception.hxx> #include <connectivity/dbexception.hxx>
#include <o3tl/any.hxx>
#include <osl/diagnose.h> #include <osl/diagnose.h>
@@ -44,7 +45,7 @@ namespace dbtools
OSL_ENSURE( SQLExceptionInfo( _rChainLeft ).isValid(), OSL_ENSURE( SQLExceptionInfo( _rChainLeft ).isValid(),
"lcl_concatWarnings: invalid warnings chain (this will crash)!" ); "lcl_concatWarnings: invalid warnings chain (this will crash)!" );
const SQLException* pChainTravel = static_cast< const SQLException* >( _rChainLeft.getValue() ); const SQLException* pChainTravel = o3tl::doGet<SQLException>( _rChainLeft );
SQLExceptionIteratorHelper aReferenceIterHelper( *pChainTravel ); SQLExceptionIteratorHelper aReferenceIterHelper( *pChainTravel );
while ( aReferenceIterHelper.hasMoreElements() ) while ( aReferenceIterHelper.hasMoreElements() )
pChainTravel = aReferenceIterHelper.next(); pChainTravel = aReferenceIterHelper.next();

View File

@@ -34,6 +34,9 @@
* *
************************************************************************/ ************************************************************************/
#include <sal/config.h>
#include <o3tl/any.hxx>
#include <rtl/strbuf.hxx> #include <rtl/strbuf.hxx>
#include <rtl/ustrbuf.hxx> #include <rtl/ustrbuf.hxx>
@@ -1163,54 +1166,54 @@ bool implSetObject( const Reference< XParameters >& _rxParameters,
break; break;
case typelib_TypeClass_STRING: case typelib_TypeClass_STRING:
_rxParameters->setString(_nColumnIndex, *static_cast<OUString const *>(_rValue.getValue())); _rxParameters->setString(_nColumnIndex, *o3tl::forceGet<OUString>(_rValue));
break; break;
case typelib_TypeClass_BOOLEAN: case typelib_TypeClass_BOOLEAN:
_rxParameters->setBoolean(_nColumnIndex, *static_cast<sal_Bool const *>(_rValue.getValue())); _rxParameters->setBoolean(_nColumnIndex, *o3tl::forceGet<bool>(_rValue));
break; break;
case typelib_TypeClass_BYTE: case typelib_TypeClass_BYTE:
_rxParameters->setByte(_nColumnIndex, *static_cast<sal_Int8 const *>(_rValue.getValue())); _rxParameters->setByte(_nColumnIndex, *o3tl::forceGet<sal_Int8>(_rValue));
break; break;
case typelib_TypeClass_UNSIGNED_SHORT: case typelib_TypeClass_UNSIGNED_SHORT:
case typelib_TypeClass_SHORT: case typelib_TypeClass_SHORT:
_rxParameters->setShort(_nColumnIndex, *static_cast<sal_Int16 const *>(_rValue.getValue())); _rxParameters->setShort(_nColumnIndex, *o3tl::forceGet<sal_Int16>(_rValue));
break; break;
case typelib_TypeClass_CHAR: case typelib_TypeClass_CHAR:
_rxParameters->setString(_nColumnIndex, OUString(static_cast<sal_Unicode const *>(_rValue.getValue()),1)); _rxParameters->setString(_nColumnIndex, OUString(*o3tl::forceGet<sal_Unicode>(_rValue)));
break; break;
case typelib_TypeClass_UNSIGNED_LONG: case typelib_TypeClass_UNSIGNED_LONG:
case typelib_TypeClass_LONG: case typelib_TypeClass_LONG:
_rxParameters->setInt(_nColumnIndex, *static_cast<sal_Int32 const *>(_rValue.getValue())); _rxParameters->setInt(_nColumnIndex, *o3tl::forceGet<sal_Int32>(_rValue));
break; break;
case typelib_TypeClass_FLOAT: case typelib_TypeClass_FLOAT:
_rxParameters->setFloat(_nColumnIndex, *static_cast<float const *>(_rValue.getValue())); _rxParameters->setFloat(_nColumnIndex, *o3tl::forceGet<float>(_rValue));
break; break;
case typelib_TypeClass_DOUBLE: case typelib_TypeClass_DOUBLE:
_rxParameters->setDouble(_nColumnIndex, *static_cast<double const *>(_rValue.getValue())); _rxParameters->setDouble(_nColumnIndex, *o3tl::forceGet<double>(_rValue));
break; break;
case typelib_TypeClass_SEQUENCE: case typelib_TypeClass_SEQUENCE:
if (_rValue.getValueType() == cppu::UnoType<Sequence< sal_Int8 >>::get()) if (auto s = o3tl::tryGet<Sequence< sal_Int8 >>(_rValue))
{ {
_rxParameters->setBytes(_nColumnIndex, *static_cast<Sequence<sal_Int8> const *>(_rValue.getValue())); _rxParameters->setBytes(_nColumnIndex, *s);
} }
else else
bSuccessfullyReRouted = false; bSuccessfullyReRouted = false;
break; break;
case typelib_TypeClass_STRUCT: case typelib_TypeClass_STRUCT:
if (_rValue.getValueType() == cppu::UnoType<css::util::DateTime>::get()) if (auto s1 = o3tl::tryGet<css::util::DateTime>(_rValue))
_rxParameters->setTimestamp(_nColumnIndex, *static_cast<css::util::DateTime const *>(_rValue.getValue())); _rxParameters->setTimestamp(_nColumnIndex, *s1);
else if (_rValue.getValueType() == cppu::UnoType<css::util::Date>::get()) else if (auto s2 = o3tl::tryGet<css::util::Date>(_rValue))
_rxParameters->setDate(_nColumnIndex, *static_cast<css::util::Date const *>(_rValue.getValue())); _rxParameters->setDate(_nColumnIndex, *s2);
else if (_rValue.getValueType() == cppu::UnoType<css::util::Time>::get()) else if (auto s3 = o3tl::tryGet<css::util::Time>(_rValue))
_rxParameters->setTime(_nColumnIndex, *static_cast<css::util::Time const *>(_rValue.getValue())); _rxParameters->setTime(_nColumnIndex, *s3);
else else
bSuccessfullyReRouted = false; bSuccessfullyReRouted = false;
break; break;