include/com/sun/star/uno/Reference.h      |   16 ++++++++++++++++
 include/com/sun/star/uno/Reference.hxx    |   14 ++++++++++++++
 sw/qa/extras/ooxmlimport/ooxmlimport2.cxx |    3 +--
 3 files changed, 31 insertions(+), 2 deletions(-)

New commits:
commit f3ffdc1a5fe965016550f20ada405ef638bf5f75
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Thu Mar 23 10:14:45 2023 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Thu Mar 23 11:31:17 2023 +0000

    Introduce non-static query() and queryThrow() to css::uno::Reference
    
    As a syntactic sugar for the respective ctors:
    
      css::uno::Reference<css::SomeNamespace::SomeInterface> 
xSomeInterface(xAnotherInterface, css::uno::UNO_QUERY);
    
    would become
    
      auto 
xSomeInterface(xAnotherInterface.query<css::SomeNamespace::SomeInterface>());
    
    and
    
      css::uno::Reference<css::SomeNamespace::SomeInterface> 
xSomeInterface(xAnotherInterface, css::uno::UNO_QUERY_THROW);
    
    would become
    
      auto 
xSomeInterface(xAnotherInterface.queryThrow<css::SomeNamespace::SomeInterface>());
    
    Change-Id: Ic42da364562b702cd468cc708fbda70394c4f2a2
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149368
    Tested-by: Mike Kaganski <mike.kagan...@collabora.com>
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/include/com/sun/star/uno/Reference.h 
b/include/com/sun/star/uno/Reference.h
index 85c0d929ea9c..1a6e6a10cee5 100644
--- a/include/com/sun/star/uno/Reference.h
+++ b/include/com/sun/star/uno/Reference.h
@@ -559,6 +559,22 @@ public:
         @return interface reference of demanded type (may be null)
     */
     SAL_WARN_UNUSED_RESULT inline static Reference< interface_type > SAL_CALL 
query( XInterface * pInterface );
+#if defined LIBO_INTERNAL_ONLY
+    /** Queries this for the required interface, and returns the requested 
reference, possibly empty.
+        A syntactic sugar for 'Reference< other_type > xOther(xThis, 
UNO_QUERY)' that avoids some
+        verbocity.
+
+        @return new reference
+    */
+    template< class other_type > inline Reference< other_type > query();
+    /** Queries this for the required interface, and returns the requested 
reference, or throws
+        on failure. A syntactic sugar for 'Reference< other_type > 
xOther(xThis, UNO_QUERY_THROW)'
+        that avoids some verbocity.
+
+        @return new reference
+    */
+    template< class other_type > inline Reference< other_type > queryThrow();
+#endif
 };
 
 }
diff --git a/include/com/sun/star/uno/Reference.hxx 
b/include/com/sun/star/uno/Reference.hxx
index 7632c55045ca..12511d7d280f 100644
--- a/include/com/sun/star/uno/Reference.hxx
+++ b/include/com/sun/star/uno/Reference.hxx
@@ -385,6 +385,20 @@ inline Reference< interface_type > Reference< 
interface_type >::query(
         castFromXInterface(iquery( pInterface )), SAL_NO_ACQUIRE );
 }
 
+#if defined LIBO_INTERNAL_ONLY
+template< class interface_type > template< class other_type >
+inline Reference< other_type > Reference< interface_type >::query()
+{
+    return Reference< other_type >(*this, UNO_QUERY);
+}
+
+template< class interface_type > template< class other_type >
+inline Reference< other_type > Reference< interface_type >::queryThrow()
+{
+    return Reference< other_type >(*this, UNO_QUERY_THROW);
+}
+#endif
+
 
 inline bool BaseReference::operator == ( XInterface * pInterface ) const
 {
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx 
b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
index e556d3e08625..ba97147876e7 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
@@ -1041,8 +1041,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf154319)
 {
     createSwDoc("tdf154319-ToC_with_s_and_d.docx");
 
-    css::uno::Reference<css::text::XDocumentIndexesSupplier> 
xSupplier(mxComponent,
-                                                                       
css::uno::UNO_QUERY_THROW);
+    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);

Reply via email to