diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2023-03-23 10:14:45 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2023-03-23 11:31:17 +0000 |
commit | f3ffdc1a5fe965016550f20ada405ef638bf5f75 (patch) | |
tree | 1a23cb2c27a85a77edf482acb26053d678c47cb6 /include | |
parent | fe3234718539ef65e384f1393cfd859cb81b8233 (diff) |
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.kaganski@collabora.com>
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/com/sun/star/uno/Reference.h | 16 | ||||
-rw-r--r-- | include/com/sun/star/uno/Reference.hxx | 14 |
2 files changed, 30 insertions, 0 deletions
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 { |