LibreOffice Module comphelper (master) 1
uno3.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#ifndef INCLUDED_COMPHELPER_UNO3_HXX
21#define INCLUDED_COMPHELPER_UNO3_HXX
22
23#include <com/sun/star/uno/XAggregation.hpp>
25
26
27namespace comphelper
28{
31 #define DECLARE_UNO3_DEFAULTS(classname, baseclass) \
32 virtual void SAL_CALL acquire() noexcept override { baseclass::acquire(); } \
33 virtual void SAL_CALL release() noexcept override { baseclass::release(); }
34
38 #define DECLARE_UNO3_AGG_DEFAULTS(classname, baseclass) \
39 virtual void SAL_CALL acquire() noexcept override { baseclass::acquire(); } \
40 virtual void SAL_CALL release() noexcept override { baseclass::release(); } \
41 virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type& _rType) override \
42 { return baseclass::queryInterface(_rType); }
43
66 #define DECLARE_UNO3_XCOMPONENT_AGG_DEFAULTS(classname, baseclass, implhelper) \
67 virtual void SAL_CALL acquire() noexcept override { baseclass::acquire(); } \
68 virtual void SAL_CALL release() noexcept override { baseclass::release(); } \
69 virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type& _rType) override \
70 { return baseclass::queryInterface(_rType); } \
71 virtual void SAL_CALL dispose() override \
72 { \
73 implhelper::dispose(); \
74 } \
75 virtual void SAL_CALL addEventListener( \
76 css::uno::Reference< css::lang::XEventListener > const & xListener ) override \
77 { \
78 implhelper::addEventListener(xListener); \
79 } \
80 virtual void SAL_CALL removeEventListener( \
81 css::uno::Reference< css::lang::XEventListener > const & xListener ) override \
82 { \
83 implhelper::removeEventListener(xListener); \
84 }
85
86 //= deriving from multiple XInterface-derived classes
87
88 //= forwarding/merging XInterface functionality
89
90 #define DECLARE_XINTERFACE( ) \
91 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override; \
92 virtual void SAL_CALL acquire() noexcept override; \
93 virtual void SAL_CALL release() noexcept override;
94
95 #define IMPLEMENT_FORWARD_REFCOUNT( classname, refcountbase ) \
96 void SAL_CALL classname::acquire() noexcept { refcountbase::acquire(); } \
97 void SAL_CALL classname::release() noexcept { refcountbase::release(); }
98
99 #define IMPLEMENT_FORWARD_XINTERFACE2( classname, refcountbase, baseclass2 ) \
100 IMPLEMENT_FORWARD_REFCOUNT( classname, refcountbase ) \
101 css::uno::Any SAL_CALL classname::queryInterface( const css::uno::Type& _rType ) \
102 { \
103 css::uno::Any aReturn = refcountbase::queryInterface( _rType ); \
104 if ( !aReturn.hasValue() ) \
105 aReturn = baseclass2::queryInterface( _rType ); \
106 return aReturn; \
107 }
108
109 #define IMPLEMENT_FORWARD_XINTERFACE3( classname, refcountbase, baseclass2, baseclass3 ) \
110 IMPLEMENT_FORWARD_REFCOUNT( classname, refcountbase ) \
111 css::uno::Any SAL_CALL classname::queryInterface( const css::uno::Type& _rType ) \
112 { \
113 css::uno::Any aReturn = refcountbase::queryInterface( _rType ); \
114 if ( !aReturn.hasValue() ) \
115 { \
116 aReturn = baseclass2::queryInterface( _rType ); \
117 if ( !aReturn.hasValue() ) \
118 aReturn = baseclass3::queryInterface( _rType ); \
119 } \
120 return aReturn; \
121 }
122
123
124 //= forwarding/merging XTypeProvider functionality
125
126 #define DECLARE_XTYPEPROVIDER( ) \
127 virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; \
128 virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) override;
129
130 #define IMPLEMENT_GET_IMPLEMENTATION_ID( classname ) \
131 css::uno::Sequence< sal_Int8 > SAL_CALL classname::getImplementationId( ) \
132 { \
133 return css::uno::Sequence<sal_Int8>(); \
134 }
135
136 #define IMPLEMENT_FORWARD_XTYPEPROVIDER2( classname, baseclass1, baseclass2 ) \
137 css::uno::Sequence< css::uno::Type > SAL_CALL classname::getTypes( ) \
138 { \
139 return ::comphelper::concatSequences( \
140 baseclass1::getTypes(), \
141 baseclass2::getTypes() \
142 ); \
143 } \
144 \
145 IMPLEMENT_GET_IMPLEMENTATION_ID( classname )
146
153 template <class iface>
154 bool query_aggregation(const css::uno::Reference< css::uno::XAggregation >& _rxAggregate, css::uno::Reference<iface>& _rxOut)
155 {
156 _rxOut.clear();
157 if (_rxAggregate.is())
158 {
159 _rxAggregate->queryAggregation(cppu::UnoType<iface>::get())
160 >>= _rxOut;
161 }
162 return _rxOut.is();
163 }
164} // namespace comphelper
165
166
167#endif // INCLUDED_COMPHELPER_UNO3_HXX
168
169/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool query_aggregation(const css::uno::Reference< css::uno::XAggregation > &_rxAggregate, css::uno::Reference< iface > &_rxOut)
ask for an iface of an aggregated object usage: Reference<XFoo> xFoo; if (query_aggregation(xAggreg...
Definition: uno3.hxx:154