Branch data Line data Source code
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 : : #ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_
20 : : #define _COM_SUN_STAR_UNO_REFERENCE_HXX_
21 : :
22 : : #include <com/sun/star/uno/Reference.h>
23 : : #include <com/sun/star/uno/RuntimeException.hpp>
24 : : #include <com/sun/star/uno/XInterface.hpp>
25 : : #include <com/sun/star/uno/genfunc.hxx>
26 : :
27 : : namespace com
28 : : {
29 : : namespace sun
30 : : {
31 : : namespace star
32 : : {
33 : : namespace uno
34 : : {
35 : :
36 : : //__________________________________________________________________________________________________
37 : 21267365 : inline XInterface * BaseReference::iquery(
38 : : XInterface * pInterface, const Type & rType )
39 : : SAL_THROW( (RuntimeException) )
40 : : {
41 [ + + ]: 21267365 : if (pInterface)
42 : : {
43 [ + - ]: 18475493 : Any aRet( pInterface->queryInterface( rType ) );
44 [ + + ]: 18475492 : if (typelib_TypeClass_INTERFACE == aRet.pType->eTypeClass)
45 : : {
46 : 17313628 : XInterface * pRet = static_cast< XInterface * >( aRet.pReserved );
47 : 17313628 : aRet.pReserved = 0;
48 : 18475492 : return pRet;
49 [ + + ]: 18475492 : }
50 : : }
51 : 21267365 : return 0;
52 : : }
53 : : //__________________________________________________________________________________________________
54 : : template< class interface_type >
55 : 19648420 : inline XInterface * Reference< interface_type >::iquery(
56 : : XInterface * pInterface ) SAL_THROW( (RuntimeException) )
57 : : {
58 : 19648420 : return BaseReference::iquery(pInterface, interface_type::static_type());
59 : : }
60 : : #ifndef EXCEPTIONS_OFF
61 : : extern "C" rtl_uString * SAL_CALL cppu_unsatisfied_iquery_msg(
62 : : typelib_TypeDescriptionReference * pType )
63 : : SAL_THROW_EXTERN_C();
64 : : extern "C" rtl_uString * SAL_CALL cppu_unsatisfied_iset_msg(
65 : : typelib_TypeDescriptionReference * pType )
66 : : SAL_THROW_EXTERN_C();
67 : : //__________________________________________________________________________________________________
68 : 1627395 : inline XInterface * BaseReference::iquery_throw(
69 : : XInterface * pInterface, const Type & rType )
70 : : SAL_THROW( (RuntimeException) )
71 : : {
72 : 1627395 : XInterface * pQueried = iquery( pInterface, rType );
73 [ + + ]: 1627395 : if (pQueried)
74 : 1614279 : return pQueried;
75 : : throw RuntimeException(
76 : : ::rtl::OUString( cppu_unsatisfied_iquery_msg( rType.getTypeLibType() ), SAL_NO_ACQUIRE ),
77 [ + - ][ + - ]: 13116 : Reference< XInterface >( pInterface ) );
78 : : }
79 : : //__________________________________________________________________________________________________
80 : : template< class interface_type >
81 : 1627395 : inline XInterface * Reference< interface_type >::iquery_throw(
82 : : XInterface * pInterface ) SAL_THROW( (RuntimeException) )
83 : : {
84 : : return BaseReference::iquery_throw(
85 : 1627395 : pInterface, interface_type::static_type());
86 : : }
87 : : //__________________________________________________________________________________________________
88 : : template< class interface_type >
89 : 100606 : inline interface_type * Reference< interface_type >::iset_throw(
90 : : interface_type * pInterface ) SAL_THROW( (RuntimeException) )
91 : : {
92 [ + + ][ + - ]: 100606 : if (pInterface)
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
93 : : {
94 : 100483 : pInterface->acquire();
95 : 100483 : return pInterface;
96 : : }
97 : : throw RuntimeException(
98 : : ::rtl::OUString( cppu_unsatisfied_iset_msg( interface_type::static_type().getTypeLibType() ), SAL_NO_ACQUIRE ),
99 [ + - ][ + - ]: 123 : NULL );
[ + - ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
100 : : }
101 : : #endif
102 : :
103 : : //__________________________________________________________________________________________________
104 : : template< class interface_type >
105 : 162714528 : inline Reference< interface_type >::~Reference() SAL_THROW(())
106 : : {
107 [ + + ][ + + ]: 162714528 : if (_pInterface)
[ + + ][ + + ]
[ + + ][ + + ]
[ + + ][ + + ]
[ + + ][ + + ]
[ + + ][ + + ]
[ + + ][ + + ]
[ + + ][ + + ]
[ + + ][ + + ]
[ + + ][ + + ]
[ + + ][ + + ]
[ + + ][ + + ]
[ + + ][ + + ]
[ + + ][ + + ]
[ + + ][ + + ]
[ + + ][ + + ]
[ + + ][ + + ]
[ + + ][ + + ]
[ + + ][ + + ]
[ + + ][ + + ]
[ + + ][ + + ]
[ + + ][ + + ]
[ + + ][ + + ]
[ + + ][ + + ]
[ + + ][ + + ]
[ # # ][ + - ]
[ + - ][ # # ]
[ + + ][ + - ]
[ # # ][ + + ]
[ + - ][ # # ]
[ + - ][ # # ]
[ + - ][ # # ]
[ # # ][ + + ]
[ + - ][ + - ]
[ + - ][ # # ]
[ + - ][ # # ]
[ + - ][ # # ]
[ # # ][ + - ]
[ + - ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
108 : 81893894 : _pInterface->release();
109 : 162714530 : }
110 : : //__________________________________________________________________________________________________
111 : : template< class interface_type >
112 : 79852219 : inline Reference< interface_type >::Reference() SAL_THROW(())
113 : : {
114 : 79852237 : _pInterface = 0;
115 : 79852237 : }
116 : : //__________________________________________________________________________________________________
117 : : template< class interface_type >
118 : 40936978 : inline Reference< interface_type >::Reference( const Reference< interface_type > & rRef ) SAL_THROW(())
119 : : {
120 : 40936978 : _pInterface = rRef._pInterface;
121 [ + + + + : 40936978 : if (_pInterface)
+ + + + +
+ + + + +
+ + + + +
- + - + +
+ + + - #
# + - + -
# # # # #
# # # #
# ]
122 : 27098322 : _pInterface->acquire();
123 : 40936978 : }
124 : : //__________________________________________________________________________________________________
125 : : template< class interface_type >
126 : 21940690 : inline Reference< interface_type >::Reference( interface_type * pInterface ) SAL_THROW(())
127 : : {
128 : 21940692 : _pInterface = castToXInterface(pInterface);
129 [ + + + + : 21940691 : if (_pInterface)
+ + + + +
+ + + + +
+ + + + +
+ + - + +
+ + + + +
- + - + -
+ - + - +
- + - + +
+ - # # +
+ + + + -
+ - + - +
- + - # #
+ - # # +
- + - + -
+ + + - +
- + - + -
+ - + - +
- + - + -
+ - + - #
# + - + -
+ - + - +
- # # + -
+ - + - +
+ # # # #
# # + + +
- + - # #
+ - + - +
- + - # #
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - # # #
# ]
130 : 19528255 : _pInterface->acquire();
131 : 21940690 : }
132 : : //__________________________________________________________________________________________________
133 : : template< class interface_type >
134 : 3150112 : inline Reference< interface_type >::Reference( interface_type * pInterface, __sal_NoAcquire ) SAL_THROW(())
135 : : {
136 : 3150112 : _pInterface = castToXInterface(pInterface);
137 : 3150112 : }
138 : : //__________________________________________________________________________________________________
139 : : template< class interface_type >
140 : 4 : inline Reference< interface_type >::Reference( interface_type * pInterface, UnoReference_NoAcquire ) SAL_THROW(())
141 : : {
142 : 4 : _pInterface = castToXInterface(pInterface);
143 : 4 : }
144 : : //__________________________________________________________________________________________________
145 : : template< class interface_type >
146 : 13397448 : inline Reference< interface_type >::Reference( const BaseReference & rRef, UnoReference_Query ) SAL_THROW( (RuntimeException) )
147 : : {
148 : 13397449 : _pInterface = iquery( rRef.get() );
149 : 13397449 : }
150 : : //__________________________________________________________________________________________________
151 : : template< class interface_type >
152 : 2209338 : inline Reference< interface_type >::Reference( XInterface * pInterface, UnoReference_Query ) SAL_THROW( (RuntimeException) )
153 : : {
154 : 2209338 : _pInterface = iquery( pInterface );
155 : 2209338 : }
156 : : //__________________________________________________________________________________________________
157 : : template< class interface_type >
158 : 261474 : inline Reference< interface_type >::Reference( const Any & rAny, UnoReference_Query ) SAL_THROW( (RuntimeException) )
159 : : {
160 [ + + ][ + + ]: 261474 : _pInterface = (typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass
[ + + ][ + + ]
[ + - ][ + - ]
[ + - ][ + - ]
[ # # ][ + - ]
[ + + ]
161 : : ? iquery( static_cast< XInterface * >( rAny.pReserved ) ) : 0);
162 : 261474 : }
163 : : #ifndef EXCEPTIONS_OFF
164 : : //__________________________________________________________________________________________________
165 : : template< class interface_type >
166 : 1199049 : inline Reference< interface_type >::Reference( const BaseReference & rRef, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
167 : : {
168 : 1199049 : _pInterface = iquery_throw( rRef.get() );
169 : 1189143 : }
170 : : //__________________________________________________________________________________________________
171 : : template< class interface_type >
172 : 96245 : inline Reference< interface_type >::Reference( XInterface * pInterface, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
173 : : {
174 : 96245 : _pInterface = iquery_throw( pInterface );
175 : 96245 : }
176 : : //__________________________________________________________________________________________________
177 : : template< class interface_type >
178 : 95931 : inline Reference< interface_type >::Reference( const Any & rAny, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
179 : : {
180 [ + - ][ + - ]: 95931 : _pInterface = iquery_throw( typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass
[ + - ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ + + ]
181 : : ? static_cast< XInterface * >( rAny.pReserved ) : 0 );
182 : 95018 : }
183 : : //__________________________________________________________________________________________________
184 : : template< class interface_type >
185 : 97474 : inline Reference< interface_type >::Reference( const Reference< interface_type > & rRef, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) )
186 : : {
187 : 97474 : _pInterface = iset_throw( rRef.get() );
188 : 97366 : }
189 : : //__________________________________________________________________________________________________
190 : : template< class interface_type >
191 : 946 : inline Reference< interface_type >::Reference( interface_type * pInterface, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) )
192 : : {
193 : 946 : _pInterface = iset_throw( pInterface );
194 : 941 : }
195 : : #endif
196 : :
197 : : //__________________________________________________________________________________________________
198 : : template< class interface_type >
199 : 3936384 : inline void Reference< interface_type >::clear() SAL_THROW(())
200 : : {
201 [ + + ][ + + ]: 3936384 : if (_pInterface)
[ + + ][ + + ]
[ + + ][ + + ]
[ + + ][ + + ]
[ # # ][ # # ]
202 : : {
203 : 1976139 : XInterface * const pOld = _pInterface;
204 : 1976139 : _pInterface = 0;
205 : 1976139 : pOld->release();
206 : : }
207 : 3936384 : }
208 : : //__________________________________________________________________________________________________
209 : : template< class interface_type >
210 : 32602313 : inline sal_Bool Reference< interface_type >::set(
211 : : interface_type * pInterface ) SAL_THROW(())
212 : : {
213 [ + + ][ + + ]: 32602313 : if (pInterface)
[ + + ][ + + ]
[ + + ][ + + ]
[ + + ][ + + ]
[ + + ][ + + ]
[ + + ][ + + ]
[ + + ][ + + ]
[ + + ][ + + ]
[ + - ][ # # ]
[ # # ][ # # ]
214 : 29450252 : castToXInterface(pInterface)->acquire();
215 : 32602310 : XInterface * const pOld = _pInterface;
216 : 32602310 : _pInterface = castToXInterface(pInterface);
217 [ + + + + : 32602314 : if (pOld)
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + - + -
+ + + - +
# # # # #
# ]
218 : 1521531 : pOld->release();
219 : 32602314 : return (0 != pInterface);
220 : : }
221 : : //__________________________________________________________________________________________________
222 : : template< class interface_type >
223 : 870400 : inline sal_Bool Reference< interface_type >::set(
224 : : interface_type * pInterface, __sal_NoAcquire ) SAL_THROW(())
225 : : {
226 : 870400 : XInterface * const pOld = _pInterface;
227 : 870400 : _pInterface = castToXInterface(pInterface);
228 [ + + + + : 870400 : if (pOld)
+ + + + +
+ - + - +
- + # # #
# # # #
# ]
229 : 132829 : pOld->release();
230 : 870400 : return (0 != pInterface);
231 : : }
232 : : //__________________________________________________________________________________________________
233 : : template< class interface_type >
234 : : inline sal_Bool Reference< interface_type >::set(
235 : : interface_type * pInterface, UnoReference_NoAcquire ) SAL_THROW(())
236 : : {
237 : : return set( pInterface, SAL_NO_ACQUIRE );
238 : : }
239 : :
240 : : //__________________________________________________________________________________________________
241 : : template< class interface_type >
242 : 344033 : inline sal_Bool Reference< interface_type >::set(
243 : : const Reference< interface_type > & rRef ) SAL_THROW(())
244 : : {
245 : 344033 : return set( castFromXInterface( rRef._pInterface ) );
246 : : }
247 : : //__________________________________________________________________________________________________
248 : : template< class interface_type >
249 : 80 : inline sal_Bool Reference< interface_type >::set(
250 : : XInterface * pInterface, UnoReference_Query ) SAL_THROW( (RuntimeException) )
251 : : {
252 : 80 : return set( castFromXInterface(iquery( pInterface )), SAL_NO_ACQUIRE );
253 : : }
254 : : //__________________________________________________________________________________________________
255 : : template< class interface_type >
256 : 187334 : inline sal_Bool Reference< interface_type >::set(
257 : : const BaseReference & rRef, UnoReference_Query ) SAL_THROW( (RuntimeException) )
258 : : {
259 : 187334 : return set( castFromXInterface(iquery( rRef.get() )), SAL_NO_ACQUIRE );
260 : : }
261 : :
262 : : //______________________________________________________________________________
263 : : template< class interface_type >
264 : 446937 : inline bool Reference< interface_type >::set(
265 : : Any const & rAny, UnoReference_Query )
266 : : {
267 : : return set(
268 : : castFromXInterface(
269 : : iquery(
270 : : rAny.pType->eTypeClass == typelib_TypeClass_INTERFACE
271 : : ? static_cast< XInterface * >( rAny.pReserved ) : 0 )),
272 [ + + ][ + - ]: 446937 : SAL_NO_ACQUIRE );
[ + - ][ + - ]
273 : : }
274 : :
275 : : #ifndef EXCEPTIONS_OFF
276 : : //__________________________________________________________________________________________________
277 : : template< class interface_type >
278 : 8 : inline void Reference< interface_type >::set(
279 : : XInterface * pInterface, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
280 : : {
281 : 8 : set( castFromXInterface(iquery_throw( pInterface )), SAL_NO_ACQUIRE );
282 : 8 : }
283 : : //__________________________________________________________________________________________________
284 : : template< class interface_type >
285 : 218874 : inline void Reference< interface_type >::set(
286 : : const BaseReference & rRef, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
287 : : {
288 : 218874 : set( castFromXInterface(iquery_throw( rRef.get() )), SAL_NO_ACQUIRE );
289 : 216577 : }
290 : :
291 : : //______________________________________________________________________________
292 : : template< class interface_type >
293 : 17288 : inline void Reference< interface_type >::set(
294 : : Any const & rAny, UnoReference_QueryThrow )
295 : : {
296 [ + - ][ + - ]: 17288 : set( castFromXInterface(
[ # # ]
297 : : iquery_throw(
298 : : rAny.pType->eTypeClass == typelib_TypeClass_INTERFACE
299 : : ? static_cast< XInterface * >( rAny.pReserved ) : 0 )),
300 : : SAL_NO_ACQUIRE );
301 : 17288 : }
302 : : //__________________________________________________________________________________________________
303 : : template< class interface_type >
304 : 2186 : inline void Reference< interface_type >::set(
305 : : interface_type * pInterface, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) )
306 : : {
307 : 2186 : set( iset_throw( pInterface ), SAL_NO_ACQUIRE );
308 : 2176 : }
309 : : //__________________________________________________________________________________________________
310 : : template< class interface_type >
311 : 2176 : inline void Reference< interface_type >::set(
312 : : const Reference< interface_type > & rRef, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) )
313 : : {
314 : 2176 : set( rRef.get(), UNO_SET_THROW );
315 : 2171 : }
316 : :
317 : : #endif
318 : :
319 : : //__________________________________________________________________________________________________
320 : : template< class interface_type >
321 : 2220657 : inline Reference< interface_type > & Reference< interface_type >::operator = (
322 : : interface_type * pInterface ) SAL_THROW(())
323 : : {
324 : 2220657 : set( pInterface );
325 : 2220657 : return *this;
326 : : }
327 : : //__________________________________________________________________________________________________
328 : : template< class interface_type >
329 : 29977161 : inline Reference< interface_type > & Reference< interface_type >::operator = (
330 : : const Reference< interface_type > & rRef ) SAL_THROW(())
331 : : {
332 : 29977161 : set( castFromXInterface( rRef._pInterface ) );
333 : 29977163 : return *this;
334 : : }
335 : :
336 : : //__________________________________________________________________________________________________
337 : : template< class interface_type >
338 : 3106237 : inline Reference< interface_type > Reference< interface_type >::query(
339 : : const BaseReference & rRef ) SAL_THROW( (RuntimeException) )
340 : : {
341 : : return Reference< interface_type >(
342 : 3106237 : castFromXInterface(iquery( rRef.get() )), SAL_NO_ACQUIRE );
343 : : }
344 : : //__________________________________________________________________________________________________
345 : : template< class interface_type >
346 : 40830 : inline Reference< interface_type > Reference< interface_type >::query(
347 : : XInterface * pInterface ) SAL_THROW( (RuntimeException) )
348 : : {
349 : : return Reference< interface_type >(
350 : 40830 : castFromXInterface(iquery( pInterface )), SAL_NO_ACQUIRE );
351 : : }
352 : :
353 : : //##################################################################################################
354 : :
355 : : //__________________________________________________________________________________________________
356 : 1548842 : inline sal_Bool BaseReference::operator == ( XInterface * pInterface ) const SAL_THROW(())
357 : : {
358 [ + + ]: 1548842 : if (_pInterface == pInterface)
359 : 1215659 : return sal_True;
360 : : #ifndef EXCEPTIONS_OFF
361 : : try
362 : : {
363 : : #endif
364 : : // only the query to XInterface must return the same pointer if they belong to same objects
365 [ + - ]: 333183 : Reference< XInterface > x1( _pInterface, UNO_QUERY );
366 [ + - ]: 333183 : Reference< XInterface > x2( pInterface, UNO_QUERY );
367 [ # # ]: 1548842 : return (x1._pInterface == x2._pInterface);
368 : : #ifndef EXCEPTIONS_OFF
369 : : }
370 : 0 : catch (RuntimeException &)
371 : : {
372 : 0 : return sal_False;
373 : : }
374 : : #endif
375 : : }
376 : :
377 : : //______________________________________________________________________________
378 : 129566 : inline sal_Bool BaseReference::operator < (
379 : : const BaseReference & rRef ) const SAL_THROW(())
380 : : {
381 [ + + ]: 129566 : if (_pInterface == rRef._pInterface)
382 : 62648 : return sal_False;
383 : : #if ! defined EXCEPTIONS_OFF
384 : : try
385 : : {
386 : : #endif
387 : : // only the query to XInterface must return the same pointer:
388 [ + - ]: 66918 : Reference< XInterface > x1( _pInterface, UNO_QUERY );
389 [ + - ]: 66918 : Reference< XInterface > x2( rRef, UNO_QUERY );
390 [ # # ]: 129566 : return (x1._pInterface < x2._pInterface);
391 : : #if ! defined EXCEPTIONS_OFF
392 : : }
393 : 0 : catch (RuntimeException &)
394 : : {
395 : 0 : return sal_False;
396 : : }
397 : : #endif
398 : : }
399 : :
400 : : //__________________________________________________________________________________________________
401 : 1754 : inline sal_Bool BaseReference::operator != ( XInterface * pInterface ) const SAL_THROW(())
402 : : {
403 : 1754 : return (! operator == ( pInterface ));
404 : : }
405 : : //__________________________________________________________________________________________________
406 : 1362183 : inline sal_Bool BaseReference::operator == ( const BaseReference & rRef ) const SAL_THROW(())
407 : : {
408 : 1362183 : return operator == ( rRef._pInterface );
409 : : }
410 : : //__________________________________________________________________________________________________
411 : 184566 : inline sal_Bool BaseReference::operator != ( const BaseReference & rRef ) const SAL_THROW(())
412 : : {
413 : 184566 : return (! operator == ( rRef._pInterface ));
414 : : }
415 : :
416 : : }
417 : : }
418 : : }
419 : : }
420 : :
421 : : #endif
422 : :
423 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|