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 INCLUDED_COM_SUN_STAR_UNO_REFERENCE_HXX
20 : #define INCLUDED_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 75303139 : inline XInterface * BaseReference::iquery(
38 : XInterface * pInterface, const Type & rType )
39 : {
40 75303139 : if (pInterface)
41 : {
42 68720370 : Any aRet( pInterface->queryInterface( rType ) );
43 68720371 : if (typelib_TypeClass_INTERFACE == aRet.pType->eTypeClass)
44 : {
45 64740492 : XInterface * pRet = static_cast< XInterface * >( aRet.pReserved );
46 64740492 : aRet.pReserved = 0;
47 64740492 : return pRet;
48 3979879 : }
49 : }
50 10562648 : return 0;
51 : }
52 :
53 : template< class interface_type >
54 68891702 : inline XInterface * Reference< interface_type >::iquery(
55 : XInterface * pInterface )
56 : {
57 68891702 : return BaseReference::iquery(pInterface, interface_type::static_type());
58 : }
59 : extern "C" rtl_uString * SAL_CALL cppu_unsatisfied_iquery_msg(
60 : typelib_TypeDescriptionReference * pType )
61 : SAL_THROW_EXTERN_C();
62 : extern "C" rtl_uString * SAL_CALL cppu_unsatisfied_iset_msg(
63 : typelib_TypeDescriptionReference * pType )
64 : SAL_THROW_EXTERN_C();
65 :
66 6411439 : inline XInterface * BaseReference::iquery_throw(
67 : XInterface * pInterface, const Type & rType )
68 : {
69 6411439 : XInterface * pQueried = iquery( pInterface, rType );
70 6411439 : if (pQueried)
71 12655342 : return pQueried;
72 : throw RuntimeException(
73 : ::rtl::OUString( cppu_unsatisfied_iquery_msg( rType.getTypeLibType() ), SAL_NO_ACQUIRE ),
74 83768 : Reference< XInterface >( pInterface ) );
75 : }
76 :
77 : template< class interface_type >
78 6411439 : inline XInterface * Reference< interface_type >::iquery_throw(
79 : XInterface * pInterface )
80 : {
81 : return BaseReference::iquery_throw(
82 6411439 : pInterface, interface_type::static_type());
83 : }
84 :
85 : template< class interface_type >
86 225343 : inline interface_type * Reference< interface_type >::iset_throw(
87 : interface_type * pInterface )
88 : {
89 225343 : if (pInterface)
90 : {
91 219905 : castToXInterface(pInterface)->acquire();
92 439810 : return pInterface;
93 : }
94 10876 : throw RuntimeException(
95 5438 : ::rtl::OUString( cppu_unsatisfied_iset_msg( interface_type::static_type().getTypeLibType() ), SAL_NO_ACQUIRE ),
96 5438 : NULL );
97 : }
98 :
99 :
100 : template< class interface_type >
101 507804518 : inline Reference< interface_type >::~Reference()
102 : {
103 507804518 : if (_pInterface)
104 316607623 : _pInterface->release();
105 507804535 : }
106 :
107 : template< class interface_type >
108 258878248 : inline Reference< interface_type >::Reference()
109 : {
110 258878245 : _pInterface = 0;
111 258878245 : }
112 :
113 : template< class interface_type >
114 77051639 : inline Reference< interface_type >::Reference( const Reference< interface_type > & rRef )
115 : {
116 77051636 : _pInterface = rRef._pInterface;
117 77051636 : if (_pInterface)
118 58988551 : _pInterface->acquire();
119 77051639 : }
120 :
121 : template< class interface_type > template< class derived_type >
122 817826 : inline Reference< interface_type >::Reference(
123 : const Reference< derived_type > & rRef,
124 817826 : typename detail::UpCast< interface_type, derived_type >::t )
125 : {
126 817826 : interface_type * p = rRef.get();
127 817826 : _pInterface = p;
128 817826 : if (_pInterface)
129 817824 : _pInterface->acquire();
130 817826 : }
131 :
132 : template< class interface_type >
133 101472697 : inline Reference< interface_type >::Reference( interface_type * pInterface )
134 : {
135 101472698 : _pInterface = castToXInterface(pInterface);
136 101472697 : if (_pInterface)
137 96300523 : _pInterface->acquire();
138 101472698 : }
139 :
140 : template< class interface_type >
141 16043270 : inline Reference< interface_type >::Reference( interface_type * pInterface, __sal_NoAcquire )
142 : {
143 16043270 : _pInterface = castToXInterface(pInterface);
144 16043270 : }
145 :
146 : template< class interface_type >
147 4 : inline Reference< interface_type >::Reference( interface_type * pInterface, UnoReference_NoAcquire )
148 : {
149 4 : _pInterface = castToXInterface(pInterface);
150 4 : }
151 :
152 : template< class interface_type >
153 36360560 : inline Reference< interface_type >::Reference( const BaseReference & rRef, UnoReference_Query )
154 : {
155 36360562 : _pInterface = iquery( rRef.get() );
156 36360562 : }
157 :
158 : template< class interface_type >
159 10033454 : inline Reference< interface_type >::Reference( XInterface * pInterface, UnoReference_Query )
160 : {
161 10033454 : _pInterface = iquery( pInterface );
162 10033454 : }
163 :
164 : template< class interface_type >
165 1915962 : inline Reference< interface_type >::Reference( const Any & rAny, UnoReference_Query )
166 : {
167 3819520 : _pInterface = (typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass
168 1903558 : ? iquery( static_cast< XInterface * >( rAny.pReserved ) ) : 0);
169 1915962 : }
170 :
171 : template< class interface_type >
172 4423990 : inline Reference< interface_type >::Reference( const BaseReference & rRef, UnoReference_QueryThrow )
173 : {
174 4423990 : _pInterface = iquery_throw( rRef.get() );
175 4349466 : }
176 :
177 : template< class interface_type >
178 349698 : inline Reference< interface_type >::Reference( XInterface * pInterface, UnoReference_QueryThrow )
179 : {
180 349698 : _pInterface = iquery_throw( pInterface );
181 349698 : }
182 :
183 : template< class interface_type >
184 637947 : inline Reference< interface_type >::Reference( const Any & rAny, UnoReference_QueryThrow )
185 : {
186 634491 : _pInterface = iquery_throw( typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass
187 637947 : ? static_cast< XInterface * >( rAny.pReserved ) : 0 );
188 634491 : }
189 :
190 : template< class interface_type >
191 215937 : inline Reference< interface_type >::Reference( const Reference< interface_type > & rRef, UnoReference_SetThrow )
192 : {
193 215937 : _pInterface = castToXInterface( iset_throw( rRef.get() ) );
194 210641 : }
195 :
196 : template< class interface_type >
197 1068 : inline Reference< interface_type >::Reference( interface_type * pInterface, UnoReference_SetThrow )
198 : {
199 1068 : _pInterface = castToXInterface( iset_throw( pInterface ) );
200 1066 : }
201 :
202 :
203 : template< class interface_type >
204 15757305 : inline void Reference< interface_type >::clear()
205 : {
206 15757305 : if (_pInterface)
207 : {
208 12355525 : XInterface * const pOld = _pInterface;
209 12355525 : _pInterface = 0;
210 12355525 : pOld->release();
211 : }
212 15757305 : }
213 :
214 : template< class interface_type >
215 160939504 : inline bool Reference< interface_type >::set(
216 : interface_type * pInterface )
217 : {
218 160939504 : if (pInterface)
219 153107333 : castToXInterface(pInterface)->acquire();
220 160939505 : XInterface * const pOld = _pInterface;
221 160939505 : _pInterface = castToXInterface(pInterface);
222 160939505 : if (pOld)
223 4983141 : pOld->release();
224 160939505 : return (0 != pInterface);
225 : }
226 :
227 : template< class interface_type >
228 11738999 : inline bool Reference< interface_type >::set(
229 : interface_type * pInterface, __sal_NoAcquire )
230 : {
231 11738999 : XInterface * const pOld = _pInterface;
232 11738999 : _pInterface = castToXInterface(pInterface);
233 11738999 : if (pOld)
234 4363594 : pOld->release();
235 11738999 : return (0 != pInterface);
236 : }
237 :
238 : template< class interface_type >
239 4293158 : inline bool Reference< interface_type >::set(
240 : interface_type * pInterface, UnoReference_NoAcquire )
241 : {
242 4293158 : return set( pInterface, SAL_NO_ACQUIRE );
243 : }
244 :
245 :
246 : template< class interface_type >
247 9735655 : inline bool Reference< interface_type >::set(
248 : const Reference< interface_type > & rRef )
249 : {
250 9735655 : return set( castFromXInterface( rRef._pInterface ) );
251 : }
252 :
253 : template< class interface_type >
254 35212 : inline bool Reference< interface_type >::set(
255 : XInterface * pInterface, UnoReference_Query )
256 : {
257 35212 : return set( castFromXInterface(iquery( pInterface )), SAL_NO_ACQUIRE );
258 : }
259 :
260 : template< class interface_type >
261 1580150 : inline bool Reference< interface_type >::set(
262 : const BaseReference & rRef, UnoReference_Query )
263 : {
264 1580150 : return set( castFromXInterface(iquery( rRef.get() )), SAL_NO_ACQUIRE );
265 : }
266 :
267 :
268 : template< class interface_type >
269 2951940 : inline bool Reference< interface_type >::set(
270 : Any const & rAny, UnoReference_Query )
271 : {
272 : return set(
273 : castFromXInterface(
274 : iquery(
275 : rAny.pType->eTypeClass == typelib_TypeClass_INTERFACE
276 : ? static_cast< XInterface * >( rAny.pReserved ) : 0 )),
277 2951940 : SAL_NO_ACQUIRE );
278 : }
279 :
280 :
281 : template< class interface_type >
282 72 : inline void Reference< interface_type >::set(
283 : XInterface * pInterface, UnoReference_QueryThrow )
284 : {
285 72 : set( castFromXInterface(iquery_throw( pInterface )), SAL_NO_ACQUIRE );
286 72 : }
287 :
288 : template< class interface_type >
289 955956 : inline void Reference< interface_type >::set(
290 : const BaseReference & rRef, UnoReference_QueryThrow )
291 : {
292 955956 : set( castFromXInterface(iquery_throw( rRef.get() )), SAL_NO_ACQUIRE );
293 950168 : }
294 :
295 :
296 : template< class interface_type >
297 43776 : inline void Reference< interface_type >::set(
298 : Any const & rAny, UnoReference_QueryThrow )
299 : {
300 43776 : set( castFromXInterface(
301 : iquery_throw(
302 : rAny.pType->eTypeClass == typelib_TypeClass_INTERFACE
303 : ? static_cast< XInterface * >( rAny.pReserved ) : 0 )),
304 43776 : SAL_NO_ACQUIRE );
305 43776 : }
306 :
307 : template< class interface_type >
308 8338 : inline void Reference< interface_type >::set(
309 : interface_type * pInterface, UnoReference_SetThrow )
310 : {
311 8338 : set( iset_throw( pInterface ), SAL_NO_ACQUIRE );
312 8198 : }
313 :
314 : template< class interface_type >
315 8334 : inline void Reference< interface_type >::set(
316 : const Reference< interface_type > & rRef, UnoReference_SetThrow )
317 : {
318 8334 : set( rRef.get(), UNO_SET_THROW );
319 8196 : }
320 :
321 :
322 : template< class interface_type >
323 9408088 : inline Reference< interface_type > & Reference< interface_type >::operator = (
324 : interface_type * pInterface )
325 : {
326 9408088 : set( pInterface );
327 9408088 : return *this;
328 : }
329 :
330 : template< class interface_type >
331 136913486 : inline Reference< interface_type > & Reference< interface_type >::operator = (
332 : const Reference< interface_type > & rRef )
333 : {
334 136913486 : set( castFromXInterface( rRef._pInterface ) );
335 136913487 : return *this;
336 : }
337 :
338 :
339 : template< class interface_type >
340 15985215 : inline Reference< interface_type > Reference< interface_type >::query(
341 : const BaseReference & rRef )
342 : {
343 : return Reference< interface_type >(
344 15985215 : castFromXInterface(iquery( rRef.get() )), SAL_NO_ACQUIRE );
345 : }
346 :
347 : template< class interface_type >
348 41611 : inline Reference< interface_type > Reference< interface_type >::query(
349 : XInterface * pInterface )
350 : {
351 : return Reference< interface_type >(
352 41611 : castFromXInterface(iquery( pInterface )), SAL_NO_ACQUIRE );
353 : }
354 :
355 :
356 :
357 :
358 7430594 : inline bool BaseReference::operator == ( XInterface * pInterface ) const
359 : {
360 7430594 : if (_pInterface == pInterface)
361 4212974 : return true;
362 : try
363 : {
364 : // only the query to XInterface must return the same pointer if they belong to same objects
365 3217620 : Reference< XInterface > x1( _pInterface, UNO_QUERY );
366 6435240 : Reference< XInterface > x2( pInterface, UNO_QUERY );
367 6435240 : return (x1._pInterface == x2._pInterface);
368 : }
369 0 : catch (RuntimeException &)
370 : {
371 0 : return false;
372 : }
373 : }
374 :
375 :
376 364895 : inline bool BaseReference::operator < (
377 : const BaseReference & rRef ) const
378 : {
379 364895 : if (_pInterface == rRef._pInterface)
380 180294 : return false;
381 : try
382 : {
383 : // only the query to XInterface must return the same pointer:
384 184601 : Reference< XInterface > x1( _pInterface, UNO_QUERY );
385 369202 : Reference< XInterface > x2( rRef, UNO_QUERY );
386 369202 : return (x1._pInterface < x2._pInterface);
387 : }
388 0 : catch (RuntimeException &)
389 : {
390 0 : return false;
391 : }
392 : }
393 :
394 :
395 1674 : inline bool BaseReference::operator != ( XInterface * pInterface ) const
396 : {
397 1674 : return (! operator == ( pInterface ));
398 : }
399 :
400 6933026 : inline bool BaseReference::operator == ( const BaseReference & rRef ) const
401 : {
402 6933026 : return operator == ( rRef._pInterface );
403 : }
404 :
405 491918 : inline bool BaseReference::operator != ( const BaseReference & rRef ) const
406 : {
407 491918 : return (! operator == ( rRef._pInterface ));
408 : }
409 :
410 : }
411 : }
412 : }
413 : }
414 :
415 : #endif
416 :
417 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|