include/com/sun/star/uno/Any.h | 9 +++++++++ include/com/sun/star/uno/Reference.hxx | 12 ++++++++++++ sw/qa/extras/ooxmlimport/ooxmlimport2.cxx | 3 +-- 3 files changed, 22 insertions(+), 2 deletions(-)
New commits: commit 2a145d8667196838bd5e1bf635234fce564faea6 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Fri Mar 24 19:56:23 2023 +0300 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Fri Mar 24 18:38:26 2023 +0000 Introduce query() and queryThrow() to css::uno::Any Similar to commit f3ffdc1a5fe965016550f20ada405ef638bf5f75 (Introduce non-static query() and queryThrow() to css::uno::Reference, 2023-03-23), this adds a syntactic sugar for css::uno::Reference ctors: css::uno::Reference<css::SomeNamespace::SomeInterface> xSomeInterface(anAny, css::uno::UNO_QUERY); would become auto xSomeInterface(anAny.query<css::SomeNamespace::SomeInterface>()); and css::uno::Reference<css::SomeNamespace::SomeInterface> xSomeInterface(anAny, css::uno::UNO_QUERY_THROW); would become auto xSomeInterface(anAny.queryThrow<css::SomeNamespace::SomeInterface>()); Change-Id: I06f8d97fe200a7dd03ecc965a431eb54b10a3c91 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149549 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/include/com/sun/star/uno/Any.h b/include/com/sun/star/uno/Any.h index b453f5fa5b0c..181b58ae4b4a 100644 --- a/include/com/sun/star/uno/Any.h +++ b/include/com/sun/star/uno/Any.h @@ -44,6 +44,7 @@ namespace uno { class Type; +template<class interface_type> class Reference; /** C++ class representing an IDL any. This class is used to transport any type defined in IDL. The class inherits from the @@ -287,6 +288,14 @@ public: */ inline bool SAL_CALL operator != ( const Any & rAny ) const; +#if defined LIBO_INTERNAL_ONLY + // Similar to Reference::query/queryThrow, these allow to simplify calling constructors of + // Reference taking Any. queryThrow is functionally similar to get(), but doesn't require + // to specify the full Reference type explicitly, only the interface type. + template<class interface_type> inline Reference<interface_type> query() const; + template<class interface_type> inline Reference<interface_type> queryThrow() const; +#endif + private: #if !defined LIBO_INTERNAL_ONLY /// @cond INTERNAL diff --git a/include/com/sun/star/uno/Reference.hxx b/include/com/sun/star/uno/Reference.hxx index 40297cc086d7..76b01b6c57cf 100644 --- a/include/com/sun/star/uno/Reference.hxx +++ b/include/com/sun/star/uno/Reference.hxx @@ -397,6 +397,18 @@ inline Reference< other_type > Reference< interface_type >::queryThrow() const { return Reference< other_type >(*this, UNO_QUERY_THROW); } + +template< class interface_type > +inline Reference< interface_type > Any::query() const +{ + return Reference< interface_type >(*this, UNO_QUERY); +} + +template< class interface_type > +inline Reference< interface_type > Any::queryThrow() const +{ + return Reference< interface_type >(*this, UNO_QUERY_THROW); +} #endif diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx index c12c5deeac1c..6436d68ec89e 100644 --- a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx +++ b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx @@ -1043,8 +1043,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf154319) auto xSupplier(mxComponent.queryThrow<css::text::XDocumentIndexesSupplier>()); auto xIndexes = xSupplier->getDocumentIndexes(); - css::uno::Reference<css::beans::XPropertySet> xTOCIndex(xIndexes->getByIndex(0), - css::uno::UNO_QUERY_THROW); + auto xTOCIndex(xIndexes->getByIndex(0).queryThrow<css::beans::XPropertySet>()); css::uno::Reference<css::container::XIndexReplace> xLevelFormats; CPPUNIT_ASSERT(xTOCIndex->getPropertyValue("LevelFormat") >>= xLevelFormats); CPPUNIT_ASSERT_EQUAL(sal_Int32(11), xLevelFormats->getCount());