[Libreoffice-commits] core.git: 3 commits - connectivity/source include/o3tl scaddins/source
Stephan Bergmann
sbergman at redhat.com
Mon Jun 6 07:48:00 UTC 2016
connectivity/source/commontools/dbexception.cxx | 17 ++--
connectivity/source/commontools/dbtools.cxx | 73 ++++++++----------
connectivity/source/commontools/warningscontainer.cxx | 3
connectivity/source/drivers/postgresql/pq_tools.cxx | 35 ++++----
include/o3tl/any.hxx | 41 ++++++++--
scaddins/source/analysis/analysis.cxx | 3
scaddins/source/analysis/analysishelper.cxx | 14 +--
7 files changed, 111 insertions(+), 75 deletions(-)
New commits:
commit 9f0ed9d8ebdc31fe546ba280966481a0b2a6994e
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Mon Jun 6 09:47:11 2016 +0200
Use o3tl/any.hxx in scaddins
Change-Id: Ifb19d216a00db90d6a267099077f90e6c54cd942
diff --git a/scaddins/source/analysis/analysis.cxx b/scaddins/source/analysis/analysis.cxx
index 3375481..b7e1c98 100644
--- a/scaddins/source/analysis/analysis.cxx
+++ b/scaddins/source/analysis/analysis.cxx
@@ -24,6 +24,7 @@
#include <comphelper/processfactory.hxx>
#include <comphelper/random.hxx>
#include <cppuhelper/supportsservice.hxx>
+#include <o3tl/any.hxx>
#include <osl/diagnose.h>
#include <rtl/ustrbuf.hxx>
#include <rtl/math.hxx>
@@ -1150,7 +1151,7 @@ OUString SAL_CALL AnalysisAddIn::getComplex( double fR, double fI, const uno::An
break;
case uno::TypeClass_STRING:
{
- const OUString* pSuff = static_cast<const OUString*>(rSuff.getValue());
+ auto pSuff = o3tl::forceGet<OUString>(rSuff);
bi = *pSuff == "i" || pSuff->isEmpty();
if( !bi && *pSuff != "j" )
throw lang::IllegalArgumentException();
diff --git a/scaddins/source/analysis/analysishelper.cxx b/scaddins/source/analysis/analysishelper.cxx
index 8c65fcb..8bb963e 100644
--- a/scaddins/source/analysis/analysishelper.cxx
+++ b/scaddins/source/analysis/analysishelper.cxx
@@ -22,6 +22,7 @@
#include <string.h>
#include <stdio.h>
+#include <o3tl/any.hxx>
#include <tools/resary.hxx>
#include <rtl/math.hxx>
#include <sal/macros.h>
@@ -1591,8 +1592,9 @@ void ScaDoubleList::Append(
const uno::Any& rAny,
bool bIgnoreEmpty ) throw( uno::RuntimeException, lang::IllegalArgumentException )
{
- if( rAny.getValueTypeClass() == uno::TypeClass_SEQUENCE )
- Append( rAnyConv, *static_cast< const uno::Sequence< uno::Sequence< uno::Any > >* >( rAny.getValue() ), bIgnoreEmpty );
+ if( auto s = o3tl::tryGet<
+ css::uno::Sequence<css::uno::Sequence<css::uno::Any>>>(rAny) )
+ Append( rAnyConv, *s, bIgnoreEmpty );
else
{
double fValue;
@@ -2120,10 +2122,10 @@ void ComplexList::Append( const uno::Sequence< uno::Any >& aMultPars, ComplListA
case uno::TypeClass_VOID: break;
case uno::TypeClass_STRING:
{
- const OUString* pStr = static_cast<const OUString*>(r.getValue());
+ auto pStr = o3tl::forceGet<OUString>(r);
if( !pStr->isEmpty() )
- Append( new Complex( *static_cast<OUString const *>(r.getValue()) ) );
+ Append( new Complex( *pStr ) );
else if( bEmpty0 )
Append( new Complex( 0.0 ) );
else if( bErrOnEmpty )
@@ -2131,7 +2133,7 @@ void ComplexList::Append( const uno::Sequence< uno::Any >& aMultPars, ComplListA
}
break;
case uno::TypeClass_DOUBLE:
- Append( new Complex( *static_cast<double const *>(r.getValue()), 0.0 ) );
+ Append( new Complex( *o3tl::forceGet<double>(r), 0.0 ) );
break;
case uno::TypeClass_SEQUENCE:
{
@@ -2870,7 +2872,7 @@ bool ScaAnyConverter::getDouble(
break;
case uno::TypeClass_STRING:
{
- const OUString* pString = static_cast< const OUString* >( rAny.getValue() );
+ auto pString = o3tl::forceGet< OUString >( rAny );
if( !pString->isEmpty() )
rfResult = convertToDouble( *pString );
else
commit 61e0433fdf1bfd391378ff9fcbf697aec4c5e61a
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Mon Jun 6 09:47:01 2016 +0200
Use o3tl/any.hxx in connectivity
Change-Id: I5c0d84b20b9146c4fc65bfdc0e9c65a05c93d71c
diff --git a/connectivity/source/commontools/dbexception.cxx b/connectivity/source/commontools/dbexception.cxx
index f718a3c..38251b7 100644
--- a/connectivity/source/commontools/dbexception.cxx
+++ b/connectivity/source/commontools/dbexception.cxx
@@ -20,6 +20,7 @@
#include <connectivity/dbexception.hxx>
#include <comphelper/types.hxx>
#include <cppuhelper/exc_hlp.hxx>
+#include <o3tl/any.hxx>
#include <osl/diagnose.h>
#include <com/sun/star/sdb/SQLContext.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
{
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
{
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;
}
- SQLException* pAppendException( static_cast< SQLException* >( const_cast< void* >( aAppend.getValue() ) ) );
- pAppendException->Message = _rErrorMessage;
- pAppendException->SQLState = _rSQLState;
- pAppendException->ErrorCode = _nErrorCode;
+ SQLException& pAppendException = const_cast<SQLException &>(*o3tl::forceGet<SQLException>(aAppend));
+ pAppendException.Message = _rErrorMessage;
+ pAppendException.SQLState = _rSQLState;
+ pAppendException.ErrorCode = _nErrorCode;
// find the end of the current chain
Any* pChainIterator = &m_aContent;
@@ -229,7 +230,7 @@ void SQLExceptionInfo::append( TYPE _eType, const OUString& _rErrorMessage, cons
if ( !isAssignableFrom( aSQLExceptionType, pChainIterator->getValueType() ) )
break;
- pLastException = static_cast< SQLException* >( const_cast< void* >( pChainIterator->getValue() ) );
+ pLastException = const_cast< SQLException* >( o3tl::doGet<SQLException>( *pChainIterator ) );
pChainIterator = &pLastException->NextException;
}
@@ -313,7 +314,7 @@ const css::sdbc::SQLException* SQLExceptionIteratorHelper::next()
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
const Type aTypeContext( ::cppu::UnoType< SQLContext >::get() );
diff --git a/connectivity/source/commontools/dbtools.cxx b/connectivity/source/commontools/dbtools.cxx
index 45e0e36..b71ff9a 100644
--- a/connectivity/source/commontools/dbtools.cxx
+++ b/connectivity/source/commontools/dbtools.cxx
@@ -73,6 +73,7 @@
#include <connectivity/dbexception.hxx>
#include <connectivity/dbtools.hxx>
#include <connectivity/statementcomposer.hxx>
+#include <o3tl/any.hxx>
#include <osl/diagnose.h>
#include <rtl/ustrbuf.hxx>
#include <tools/diagnose_ex.h>
@@ -1155,14 +1156,14 @@ try
{
Any aDate( xOldProps->getPropertyValue(sPropDefaultDate) );
if (aDate.hasValue())
- aNewDefault <<= DBTypeConversion::toDouble(*static_cast<Date const *>(aDate.getValue()));
+ aNewDefault <<= DBTypeConversion::toDouble(*o3tl::doGet<Date>(aDate));
}
if (hasProperty(sPropDefaultTime, xOldProps))
{
Any aTime( xOldProps->getPropertyValue(sPropDefaultTime) );
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
@@ -1449,29 +1450,29 @@ bool implUpdateObject(const Reference< XRowUpdate >& _rxUpdatedObject,
break;
case TypeClass_STRING:
- _rxUpdatedObject->updateString(_nColumnIndex, *static_cast<OUString const *>(_rValue.getValue()));
+ _rxUpdatedObject->updateString(_nColumnIndex, *o3tl::forceGet<OUString>(_rValue));
break;
case TypeClass_BOOLEAN:
- _rxUpdatedObject->updateBoolean(_nColumnIndex, *static_cast<sal_Bool const *>(_rValue.getValue()));
+ _rxUpdatedObject->updateBoolean(_nColumnIndex, *o3tl::forceGet<bool>(_rValue));
break;
case TypeClass_BYTE:
- _rxUpdatedObject->updateByte(_nColumnIndex, *static_cast<sal_Int8 const *>(_rValue.getValue()));
+ _rxUpdatedObject->updateByte(_nColumnIndex, *o3tl::forceGet<sal_Int8>(_rValue));
break;
case TypeClass_UNSIGNED_SHORT:
case TypeClass_SHORT:
- _rxUpdatedObject->updateShort(_nColumnIndex, *static_cast<sal_Int16 const *>(_rValue.getValue()));
+ _rxUpdatedObject->updateShort(_nColumnIndex, *o3tl::forceGet<sal_Int16>(_rValue));
break;
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;
case TypeClass_UNSIGNED_LONG:
case TypeClass_LONG:
- _rxUpdatedObject->updateInt(_nColumnIndex, *static_cast<sal_Int32 const *>(_rValue.getValue()));
+ _rxUpdatedObject->updateInt(_nColumnIndex, *o3tl::forceGet<sal_Int32>(_rValue));
break;
case TypeClass_HYPER:
@@ -1483,36 +1484,34 @@ bool implUpdateObject(const Reference< XRowUpdate >& _rxUpdatedObject,
break;
case TypeClass_FLOAT:
- _rxUpdatedObject->updateFloat(_nColumnIndex, *static_cast<float const *>(_rValue.getValue()));
+ _rxUpdatedObject->updateFloat(_nColumnIndex, *o3tl::forceGet<float>(_rValue));
break;
case TypeClass_DOUBLE:
- _rxUpdatedObject->updateDouble(_nColumnIndex, *static_cast<double const *>(_rValue.getValue()));
+ _rxUpdatedObject->updateDouble(_nColumnIndex, *o3tl::forceGet<double>(_rValue));
break;
case TypeClass_SEQUENCE:
- if (_rValue.getValueType() == cppu::UnoType< Sequence< sal_Int8 > >::get())
- _rxUpdatedObject->updateBytes(_nColumnIndex, *static_cast<Sequence<sal_Int8> const *>(_rValue.getValue()));
+ if (auto s = o3tl::tryGet<Sequence< sal_Int8 >>(_rValue))
+ _rxUpdatedObject->updateBytes(_nColumnIndex, *s);
else
bSuccessfullyReRouted = false;
break;
case TypeClass_STRUCT:
- if (_rValue.getValueType() == cppu::UnoType<DateTime>::get())
- _rxUpdatedObject->updateTimestamp(_nColumnIndex, *static_cast<DateTime const *>(_rValue.getValue()));
- else if (_rValue.getValueType() == cppu::UnoType<Date>::get())
- _rxUpdatedObject->updateDate(_nColumnIndex, *static_cast<Date const *>(_rValue.getValue()));
- else if (_rValue.getValueType() == cppu::UnoType<Time>::get())
- _rxUpdatedObject->updateTime(_nColumnIndex, *static_cast<Time const *>(_rValue.getValue()));
+ if (auto s1 = o3tl::tryGet<DateTime>(_rValue))
+ _rxUpdatedObject->updateTimestamp(_nColumnIndex, *s1);
+ else if (auto s2 = o3tl::tryGet<Date>(_rValue))
+ _rxUpdatedObject->updateDate(_nColumnIndex, *s2);
+ else if (auto s3 = o3tl::tryGet<Time>(_rValue))
+ _rxUpdatedObject->updateTime(_nColumnIndex, *s3);
else
bSuccessfullyReRouted = false;
break;
case TypeClass_INTERFACE:
- if (_rValue.getValueType() == cppu::UnoType<XInputStream>::get())
+ if (auto xStream = o3tl::tryGet<Reference<XInputStream>>(_rValue))
{
- Reference< XInputStream > xStream;
- _rValue >>= xStream;
- _rxUpdatedObject->updateBinaryStream(_nColumnIndex, xStream, xStream->available());
+ _rxUpdatedObject->updateBinaryStream(_nColumnIndex, *xStream, (*xStream)->available());
break;
}
SAL_FALLTHROUGH;
@@ -1559,23 +1558,23 @@ bool implSetObject( const Reference< XParameters >& _rxParameters,
break;
case TypeClass_STRING:
- _rxParameters->setString(_nColumnIndex, *static_cast<OUString const *>(_rValue.getValue()));
+ _rxParameters->setString(_nColumnIndex, *o3tl::forceGet<OUString>(_rValue));
break;
case TypeClass_BOOLEAN:
- _rxParameters->setBoolean(_nColumnIndex, *static_cast<sal_Bool const *>(_rValue.getValue()));
+ _rxParameters->setBoolean(_nColumnIndex, *o3tl::forceGet<bool>(_rValue));
break;
case TypeClass_BYTE:
- _rxParameters->setByte(_nColumnIndex, *static_cast<sal_Int8 const *>(_rValue.getValue()));
+ _rxParameters->setByte(_nColumnIndex, *o3tl::forceGet<sal_Int8>(_rValue));
break;
case TypeClass_SHORT:
- _rxParameters->setShort(_nColumnIndex, *static_cast<sal_Int16 const *>(_rValue.getValue()));
+ _rxParameters->setShort(_nColumnIndex, *o3tl::forceGet<sal_Int16>(_rValue));
break;
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;
case TypeClass_UNSIGNED_SHORT:
@@ -1588,28 +1587,28 @@ bool implSetObject( const Reference< XParameters >& _rxParameters,
}
case TypeClass_FLOAT:
- _rxParameters->setFloat(_nColumnIndex, *static_cast<float const *>(_rValue.getValue()));
+ _rxParameters->setFloat(_nColumnIndex, *o3tl::forceGet<float>(_rValue));
break;
case TypeClass_DOUBLE:
- _rxParameters->setDouble(_nColumnIndex, *static_cast<double const *>(_rValue.getValue()));
+ _rxParameters->setDouble(_nColumnIndex, *o3tl::forceGet<double>(_rValue));
break;
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
bSuccessfullyReRouted = false;
break;
case TypeClass_STRUCT:
- if (_rValue.getValueType() == cppu::UnoType<DateTime>::get())
- _rxParameters->setTimestamp(_nColumnIndex, *static_cast<DateTime const *>(_rValue.getValue()));
- else if (_rValue.getValueType() == cppu::UnoType<Date>::get())
- _rxParameters->setDate(_nColumnIndex, *static_cast<Date const *>(_rValue.getValue()));
- else if (_rValue.getValueType() == cppu::UnoType<Time>::get())
- _rxParameters->setTime(_nColumnIndex, *static_cast<Time const *>(_rValue.getValue()));
+ if (auto s1 = o3tl::tryGet<DateTime>(_rValue))
+ _rxParameters->setTimestamp(_nColumnIndex, *s1);
+ else if (auto s2 = o3tl::tryGet<Date>(_rValue))
+ _rxParameters->setDate(_nColumnIndex, *s2);
+ else if (auto s3 = o3tl::tryGet<Time>(_rValue))
+ _rxParameters->setTime(_nColumnIndex, *s3);
else
bSuccessfullyReRouted = false;
break;
diff --git a/connectivity/source/commontools/warningscontainer.cxx b/connectivity/source/commontools/warningscontainer.cxx
index 5d35532..787b6cf 100644
--- a/connectivity/source/commontools/warningscontainer.cxx
+++ b/connectivity/source/commontools/warningscontainer.cxx
@@ -21,6 +21,7 @@
#include <connectivity/warningscontainer.hxx>
#include <connectivity/dbexception.hxx>
+#include <o3tl/any.hxx>
#include <osl/diagnose.h>
@@ -44,7 +45,7 @@ namespace dbtools
OSL_ENSURE( SQLExceptionInfo( _rChainLeft ).isValid(),
"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 );
while ( aReferenceIterHelper.hasMoreElements() )
pChainTravel = aReferenceIterHelper.next();
diff --git a/connectivity/source/drivers/postgresql/pq_tools.cxx b/connectivity/source/drivers/postgresql/pq_tools.cxx
index d698287..06898e9 100644
--- a/connectivity/source/drivers/postgresql/pq_tools.cxx
+++ b/connectivity/source/drivers/postgresql/pq_tools.cxx
@@ -34,6 +34,9 @@
*
************************************************************************/
+#include <sal/config.h>
+
+#include <o3tl/any.hxx>
#include <rtl/strbuf.hxx>
#include <rtl/ustrbuf.hxx>
@@ -1163,54 +1166,54 @@ bool implSetObject( const Reference< XParameters >& _rxParameters,
break;
case typelib_TypeClass_STRING:
- _rxParameters->setString(_nColumnIndex, *static_cast<OUString const *>(_rValue.getValue()));
+ _rxParameters->setString(_nColumnIndex, *o3tl::forceGet<OUString>(_rValue));
break;
case typelib_TypeClass_BOOLEAN:
- _rxParameters->setBoolean(_nColumnIndex, *static_cast<sal_Bool const *>(_rValue.getValue()));
+ _rxParameters->setBoolean(_nColumnIndex, *o3tl::forceGet<bool>(_rValue));
break;
case typelib_TypeClass_BYTE:
- _rxParameters->setByte(_nColumnIndex, *static_cast<sal_Int8 const *>(_rValue.getValue()));
+ _rxParameters->setByte(_nColumnIndex, *o3tl::forceGet<sal_Int8>(_rValue));
break;
case typelib_TypeClass_UNSIGNED_SHORT:
case typelib_TypeClass_SHORT:
- _rxParameters->setShort(_nColumnIndex, *static_cast<sal_Int16 const *>(_rValue.getValue()));
+ _rxParameters->setShort(_nColumnIndex, *o3tl::forceGet<sal_Int16>(_rValue));
break;
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;
case typelib_TypeClass_UNSIGNED_LONG:
case typelib_TypeClass_LONG:
- _rxParameters->setInt(_nColumnIndex, *static_cast<sal_Int32 const *>(_rValue.getValue()));
+ _rxParameters->setInt(_nColumnIndex, *o3tl::forceGet<sal_Int32>(_rValue));
break;
case typelib_TypeClass_FLOAT:
- _rxParameters->setFloat(_nColumnIndex, *static_cast<float const *>(_rValue.getValue()));
+ _rxParameters->setFloat(_nColumnIndex, *o3tl::forceGet<float>(_rValue));
break;
case typelib_TypeClass_DOUBLE:
- _rxParameters->setDouble(_nColumnIndex, *static_cast<double const *>(_rValue.getValue()));
+ _rxParameters->setDouble(_nColumnIndex, *o3tl::forceGet<double>(_rValue));
break;
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
bSuccessfullyReRouted = false;
break;
case typelib_TypeClass_STRUCT:
- if (_rValue.getValueType() == cppu::UnoType<css::util::DateTime>::get())
- _rxParameters->setTimestamp(_nColumnIndex, *static_cast<css::util::DateTime const *>(_rValue.getValue()));
- else if (_rValue.getValueType() == cppu::UnoType<css::util::Date>::get())
- _rxParameters->setDate(_nColumnIndex, *static_cast<css::util::Date const *>(_rValue.getValue()));
- else if (_rValue.getValueType() == cppu::UnoType<css::util::Time>::get())
- _rxParameters->setTime(_nColumnIndex, *static_cast<css::util::Time const *>(_rValue.getValue()));
+ if (auto s1 = o3tl::tryGet<css::util::DateTime>(_rValue))
+ _rxParameters->setTimestamp(_nColumnIndex, *s1);
+ else if (auto s2 = o3tl::tryGet<css::util::Date>(_rValue))
+ _rxParameters->setDate(_nColumnIndex, *s2);
+ else if (auto s3 = o3tl::tryGet<css::util::Time>(_rValue))
+ _rxParameters->setTime(_nColumnIndex, *s3);
else
bSuccessfullyReRouted = false;
break;
commit e5d45064fc2e858c27ab7d97a7a7fa024d210133
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Mon Jun 6 09:44:12 2016 +0200
Improve o3tl/any.hxx
* Ensure tryGet<XFoo> (instead of tryGet<css::uno::Reference<XFoo>>) doesn't
compile.
* Add forceGet (as discussed at 0d7c5823124696f80583ac2a5f0e28f329f6f786 "New
o3tl::try/doGet to obtain value from Any", to be used momentarily).
Change-Id: I57eb6ef18a6ab0d52bb26df7eb4e51b485fc83ed
diff --git a/include/o3tl/any.hxx b/include/o3tl/any.hxx
index 268ae20..023f468 100644
--- a/include/o3tl/any.hxx
+++ b/include/o3tl/any.hxx
@@ -12,6 +12,7 @@
#include <sal/config.h>
+#include <cassert>
#include <type_traits>
#include <utility>
@@ -20,6 +21,7 @@
#include <com/sun/star/uno/Any.hxx>
#include <com/sun/star/uno/RuntimeException.hpp>
#include <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/uno/XInterface.hpp>
#include <cppu/unotype.hxx>
#include <rtl/ustring.hxx>
#include <sal/types.h>
@@ -27,10 +29,6 @@
// Some functionality related to css::uno::Any that would ideally be part of
// <com/sun/star/uno/Any.hxx>, but (for now) cannot be for some reason.
-namespace com { namespace sun { namespace star { namespace uno {
- class XInterface;
-} } } }
-
namespace o3tl {
namespace detail {
@@ -116,7 +114,8 @@ template<typename T> inline boost::optional<T> tryGetConverted(
@tparam T the C++ representation of a UNO type that can be contained in a
UNO ANY (i.e., any UNO type other than ANY itself). The legacy C++
representations sal_Bool, cppu::UnoVoidType, cppu::UnoUnsignedShortType,
- cppu::UnoCharType, and cppu::UnoSequenceType are not supported.
+ cppu::UnoCharType, and cppu::UnoSequenceType are not supported. Must be a
+ complete type or void.
@param any an Any value.
@@ -126,7 +125,8 @@ template<typename T> inline boost::optional<T> tryGetConverted(
template<typename T> inline
typename std::enable_if<
!(detail::IsDerivedReference<T>::value
- || detail::IsUnoSequenceType<T>::value),
+ || detail::IsUnoSequenceType<T>::value
+ || std::is_base_of<css::uno::XInterface, T>::value),
typename detail::Optional<T>::type>::type
tryGet(css::uno::Any const & any) {
// CHAR, STRING, TYPE, sequence types, enum types, struct types, exception
@@ -209,6 +209,11 @@ template<> detail::Optional<css::uno::Any>::type tryGet<css::uno::Any>(
template<> detail::Optional<sal_Bool>::type tryGet<sal_Bool>(
css::uno::Any const &) = delete;
+/*
+
+// Already prevented by std::is_base_of<css::uno::XInterface, T> requiring T to
+// be complete:
+
template<> detail::Optional<cppu::UnoVoidType>::type tryGet<cppu::UnoVoidType>(
css::uno::Any const &) = delete;
@@ -218,6 +223,8 @@ tryGet<cppu::UnoUnsignedShortType>(css::uno::Any const &) = delete;
template<> detail::Optional<cppu::UnoCharType>::type tryGet<cppu::UnoCharType>(
css::uno::Any const &) = delete;
+*/
+
template<typename T> inline
typename std::enable_if<
detail::IsDerivedReference<T>::value,
@@ -257,6 +264,28 @@ template<typename T> inline typename detail::Optional<T>::type doGet(
return opt;
}
+/** Get the value of a specific type from an Any, knowing the Any contains a
+ value of a matching type.
+
+ @note Ideally this would be a public member function of css::uno::Any. See
+ tryGet for details.
+
+ @tparam T the C++ representation of a UNO type that can be contained in a
+ UNO ANY. See tryGet for details.
+
+ @param any an Any value.
+
+ @return a positive proxy for the value of the specfied type obtained from
+ the given Any. See tryGet for details.
+*/
+template<typename T> inline typename detail::Optional<T>::type forceGet(
+ css::uno::Any const & any)
+{
+ auto opt = tryGet<T>(any);
+ assert(opt);
+ return opt;
+}
+
}
#endif
More information about the Libreoffice-commits
mailing list