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 29642339 : inline XInterface * BaseReference::iquery(
38 : XInterface * pInterface, const Type & rType )
39 : SAL_THROW( (RuntimeException) )
40 : {
41 29642339 : if (pInterface)
42 : {
43 26363762 : Any aRet( pInterface->queryInterface( rType ) );
44 26363764 : if (typelib_TypeClass_INTERFACE == aRet.pType->eTypeClass)
45 : {
46 24838543 : XInterface * pRet = static_cast< XInterface * >( aRet.pReserved );
47 24838543 : aRet.pReserved = 0;
48 24838543 : return pRet;
49 1525221 : }
50 : }
51 4803798 : return 0;
52 : }
53 :
54 : template< class interface_type >
55 27298146 : inline XInterface * Reference< interface_type >::iquery(
56 : XInterface * pInterface ) SAL_THROW( (RuntimeException) )
57 : {
58 27298146 : return BaseReference::iquery(pInterface, interface_type::static_type());
59 : }
60 : extern "C" rtl_uString * SAL_CALL cppu_unsatisfied_iquery_msg(
61 : typelib_TypeDescriptionReference * pType )
62 : SAL_THROW_EXTERN_C();
63 : extern "C" rtl_uString * SAL_CALL cppu_unsatisfied_iset_msg(
64 : typelib_TypeDescriptionReference * pType )
65 : SAL_THROW_EXTERN_C();
66 :
67 2344195 : inline XInterface * BaseReference::iquery_throw(
68 : XInterface * pInterface, const Type & rType )
69 : SAL_THROW( (RuntimeException) )
70 : {
71 2344195 : XInterface * pQueried = iquery( pInterface, rType );
72 2344195 : if (pQueried)
73 4638904 : return pQueried;
74 : throw RuntimeException(
75 : ::rtl::OUString( cppu_unsatisfied_iquery_msg( rType.getTypeLibType() ), SAL_NO_ACQUIRE ),
76 24743 : Reference< XInterface >( pInterface ) );
77 : }
78 :
79 : template< class interface_type >
80 2344195 : inline XInterface * Reference< interface_type >::iquery_throw(
81 : XInterface * pInterface ) SAL_THROW( (RuntimeException) )
82 : {
83 : return BaseReference::iquery_throw(
84 2344195 : pInterface, interface_type::static_type());
85 : }
86 :
87 : template< class interface_type >
88 91435 : inline interface_type * Reference< interface_type >::iset_throw(
89 : interface_type * pInterface ) SAL_THROW( (RuntimeException) )
90 : {
91 91435 : if (pInterface)
92 : {
93 89992 : castToXInterface(pInterface)->acquire();
94 179984 : return pInterface;
95 : }
96 2886 : throw RuntimeException(
97 1443 : ::rtl::OUString( cppu_unsatisfied_iset_msg( interface_type::static_type().getTypeLibType() ), SAL_NO_ACQUIRE ),
98 1443 : NULL );
99 : }
100 :
101 :
102 : template< class interface_type >
103 197623577 : inline Reference< interface_type >::~Reference() SAL_THROW(())
104 : {
105 197623577 : if (_pInterface)
106 117243359 : _pInterface->release();
107 197623567 : }
108 :
109 : template< class interface_type >
110 102483643 : inline Reference< interface_type >::Reference() SAL_THROW(())
111 : {
112 102483986 : _pInterface = 0;
113 102483986 : }
114 :
115 : template< class interface_type >
116 31551286 : inline Reference< interface_type >::Reference( const Reference< interface_type > & rRef ) SAL_THROW(())
117 : {
118 31551286 : _pInterface = rRef._pInterface;
119 31551286 : if (_pInterface)
120 24181207 : _pInterface->acquire();
121 31551286 : }
122 :
123 : template< class interface_type > template< class derived_type >
124 316274 : inline Reference< interface_type >::Reference(
125 : const Reference< derived_type > & rRef,
126 316274 : typename detail::UpCast< interface_type, derived_type >::t )
127 : SAL_THROW(())
128 : {
129 316274 : interface_type * p = rRef.get();
130 316274 : _pInterface = p;
131 316274 : if (_pInterface)
132 316273 : _pInterface->acquire();
133 316274 : }
134 :
135 : template< class interface_type >
136 35778173 : inline Reference< interface_type >::Reference( interface_type * pInterface ) SAL_THROW(())
137 : {
138 35778234 : _pInterface = castToXInterface(pInterface);
139 35778235 : if (_pInterface)
140 33632214 : _pInterface->acquire();
141 35778234 : }
142 :
143 : template< class interface_type >
144 5890420 : inline Reference< interface_type >::Reference( interface_type * pInterface, __sal_NoAcquire ) SAL_THROW(())
145 : {
146 5890420 : _pInterface = castToXInterface(pInterface);
147 5890420 : }
148 :
149 : template< class interface_type >
150 2 : inline Reference< interface_type >::Reference( interface_type * pInterface, UnoReference_NoAcquire ) SAL_THROW(())
151 : {
152 2 : _pInterface = castToXInterface(pInterface);
153 2 : }
154 :
155 : template< class interface_type >
156 14444793 : inline Reference< interface_type >::Reference( const BaseReference & rRef, UnoReference_Query ) SAL_THROW( (RuntimeException) )
157 : {
158 14444793 : _pInterface = iquery( rRef.get() );
159 14444793 : }
160 :
161 : template< class interface_type >
162 4627851 : inline Reference< interface_type >::Reference( XInterface * pInterface, UnoReference_Query ) SAL_THROW( (RuntimeException) )
163 : {
164 4627851 : _pInterface = iquery( pInterface );
165 4627851 : }
166 :
167 : template< class interface_type >
168 806973 : inline Reference< interface_type >::Reference( const Any & rAny, UnoReference_Query ) SAL_THROW( (RuntimeException) )
169 : {
170 1609646 : _pInterface = (typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass
171 802673 : ? iquery( static_cast< XInterface * >( rAny.pReserved ) ) : 0);
172 806973 : }
173 :
174 : template< class interface_type >
175 1586203 : inline Reference< interface_type >::Reference( const BaseReference & rRef, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
176 : {
177 1586203 : _pInterface = iquery_throw( rRef.get() );
178 1564241 : }
179 :
180 : template< class interface_type >
181 128431 : inline Reference< interface_type >::Reference( XInterface * pInterface, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
182 : {
183 128431 : _pInterface = iquery_throw( pInterface );
184 128431 : }
185 :
186 : template< class interface_type >
187 271282 : inline Reference< interface_type >::Reference( const Any & rAny, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
188 : {
189 269907 : _pInterface = iquery_throw( typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass
190 271282 : ? static_cast< XInterface * >( rAny.pReserved ) : 0 );
191 269907 : }
192 :
193 : template< class interface_type >
194 87470 : inline Reference< interface_type >::Reference( const Reference< interface_type > & rRef, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) )
195 : {
196 87470 : _pInterface = castToXInterface( iset_throw( rRef.get() ) );
197 86060 : }
198 :
199 : template< class interface_type >
200 497 : inline Reference< interface_type >::Reference( interface_type * pInterface, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) )
201 : {
202 497 : _pInterface = castToXInterface( iset_throw( pInterface ) );
203 496 : }
204 :
205 :
206 : template< class interface_type >
207 5324676 : inline void Reference< interface_type >::clear() SAL_THROW(())
208 : {
209 5324676 : if (_pInterface)
210 : {
211 3917175 : XInterface * const pOld = _pInterface;
212 3917175 : _pInterface = 0;
213 3917175 : pOld->release();
214 : }
215 5324676 : }
216 :
217 : template< class interface_type >
218 56779031 : inline bool Reference< interface_type >::set(
219 : interface_type * pInterface ) SAL_THROW(())
220 : {
221 56779031 : if (pInterface)
222 53788624 : castToXInterface(pInterface)->acquire();
223 56779030 : XInterface * const pOld = _pInterface;
224 56779030 : _pInterface = castToXInterface(pInterface);
225 56779031 : if (pOld)
226 1782095 : pOld->release();
227 56779030 : return (0 != pInterface);
228 : }
229 :
230 : template< class interface_type >
231 3898587 : inline bool Reference< interface_type >::set(
232 : interface_type * pInterface, __sal_NoAcquire ) SAL_THROW(())
233 : {
234 3898587 : XInterface * const pOld = _pInterface;
235 3898587 : _pInterface = castToXInterface(pInterface);
236 3898587 : if (pOld)
237 1353328 : pOld->release();
238 3898587 : return (0 != pInterface);
239 : }
240 :
241 : template< class interface_type >
242 1311852 : inline bool Reference< interface_type >::set(
243 : interface_type * pInterface, UnoReference_NoAcquire ) SAL_THROW(())
244 : {
245 1311852 : return set( pInterface, SAL_NO_ACQUIRE );
246 : }
247 :
248 :
249 : template< class interface_type >
250 3072610 : inline bool Reference< interface_type >::set(
251 : const Reference< interface_type > & rRef ) SAL_THROW(())
252 : {
253 3072610 : return set( castFromXInterface( rRef._pInterface ) );
254 : }
255 :
256 : template< class interface_type >
257 174 : inline bool Reference< interface_type >::set(
258 : XInterface * pInterface, UnoReference_Query ) SAL_THROW( (RuntimeException) )
259 : {
260 174 : return set( castFromXInterface(iquery( pInterface )), SAL_NO_ACQUIRE );
261 : }
262 :
263 : template< class interface_type >
264 438020 : inline bool Reference< interface_type >::set(
265 : const BaseReference & rRef, UnoReference_Query ) SAL_THROW( (RuntimeException) )
266 : {
267 438020 : return set( castFromXInterface(iquery( rRef.get() )), SAL_NO_ACQUIRE );
268 : }
269 :
270 :
271 : template< class interface_type >
272 1102045 : inline bool Reference< interface_type >::set(
273 : Any const & rAny, UnoReference_Query )
274 : {
275 : return set(
276 : castFromXInterface(
277 : iquery(
278 : rAny.pType->eTypeClass == typelib_TypeClass_INTERFACE
279 : ? static_cast< XInterface * >( rAny.pReserved ) : 0 )),
280 1102045 : SAL_NO_ACQUIRE );
281 : }
282 :
283 :
284 : template< class interface_type >
285 20 : inline void Reference< interface_type >::set(
286 : XInterface * pInterface, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
287 : {
288 20 : set( castFromXInterface(iquery_throw( pInterface )), SAL_NO_ACQUIRE );
289 20 : }
290 :
291 : template< class interface_type >
292 340547 : inline void Reference< interface_type >::set(
293 : const BaseReference & rRef, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
294 : {
295 340547 : set( castFromXInterface(iquery_throw( rRef.get() )), SAL_NO_ACQUIRE );
296 339141 : }
297 :
298 :
299 : template< class interface_type >
300 17712 : inline void Reference< interface_type >::set(
301 : Any const & rAny, UnoReference_QueryThrow )
302 : {
303 17712 : set( castFromXInterface(
304 : iquery_throw(
305 : rAny.pType->eTypeClass == typelib_TypeClass_INTERFACE
306 : ? static_cast< XInterface * >( rAny.pReserved ) : 0 )),
307 17712 : SAL_NO_ACQUIRE );
308 17712 : }
309 :
310 : template< class interface_type >
311 3468 : inline void Reference< interface_type >::set(
312 : interface_type * pInterface, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) )
313 : {
314 3468 : set( iset_throw( pInterface ), SAL_NO_ACQUIRE );
315 3436 : }
316 :
317 : template< class interface_type >
318 3466 : inline void Reference< interface_type >::set(
319 : const Reference< interface_type > & rRef, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) )
320 : {
321 3466 : set( rRef.get(), UNO_SET_THROW );
322 3435 : }
323 :
324 :
325 : template< class interface_type >
326 3554772 : inline Reference< interface_type > & Reference< interface_type >::operator = (
327 : interface_type * pInterface ) SAL_THROW(())
328 : {
329 3554772 : set( pInterface );
330 3554772 : return *this;
331 : }
332 :
333 : template< class interface_type >
334 48622771 : inline Reference< interface_type > & Reference< interface_type >::operator = (
335 : const Reference< interface_type > & rRef ) SAL_THROW(())
336 : {
337 48622771 : set( castFromXInterface( rRef._pInterface ) );
338 48622775 : return *this;
339 : }
340 :
341 :
342 : template< class interface_type >
343 5868759 : inline Reference< interface_type > Reference< interface_type >::query(
344 : const BaseReference & rRef ) SAL_THROW( (RuntimeException) )
345 : {
346 : return Reference< interface_type >(
347 5868759 : castFromXInterface(iquery( rRef.get() )), SAL_NO_ACQUIRE );
348 : }
349 :
350 : template< class interface_type >
351 13831 : inline Reference< interface_type > Reference< interface_type >::query(
352 : XInterface * pInterface ) SAL_THROW( (RuntimeException) )
353 : {
354 : return Reference< interface_type >(
355 13831 : castFromXInterface(iquery( pInterface )), SAL_NO_ACQUIRE );
356 : }
357 :
358 :
359 :
360 :
361 3125818 : inline bool BaseReference::operator == ( XInterface * pInterface ) const SAL_THROW(())
362 : {
363 3125818 : if (_pInterface == pInterface)
364 1520114 : return true;
365 : try
366 : {
367 : // only the query to XInterface must return the same pointer if they belong to same objects
368 1605704 : Reference< XInterface > x1( _pInterface, UNO_QUERY );
369 3211408 : Reference< XInterface > x2( pInterface, UNO_QUERY );
370 3211408 : return (x1._pInterface == x2._pInterface);
371 : }
372 0 : catch (RuntimeException &)
373 : {
374 0 : return false;
375 : }
376 : }
377 :
378 :
379 139728 : inline bool BaseReference::operator < (
380 : const BaseReference & rRef ) const SAL_THROW(())
381 : {
382 139728 : if (_pInterface == rRef._pInterface)
383 62310 : return false;
384 : try
385 : {
386 : // only the query to XInterface must return the same pointer:
387 77418 : Reference< XInterface > x1( _pInterface, UNO_QUERY );
388 154836 : Reference< XInterface > x2( rRef, UNO_QUERY );
389 154836 : return (x1._pInterface < x2._pInterface);
390 : }
391 0 : catch (RuntimeException &)
392 : {
393 0 : return false;
394 : }
395 : }
396 :
397 :
398 880 : inline bool BaseReference::operator != ( XInterface * pInterface ) const SAL_THROW(())
399 : {
400 880 : return (! operator == ( pInterface ));
401 : }
402 :
403 2961338 : inline bool BaseReference::operator == ( const BaseReference & rRef ) const SAL_THROW(())
404 : {
405 2961338 : return operator == ( rRef._pInterface );
406 : }
407 :
408 162131 : inline bool BaseReference::operator != ( const BaseReference & rRef ) const SAL_THROW(())
409 : {
410 162131 : return (! operator == ( rRef._pInterface ));
411 : }
412 :
413 : }
414 : }
415 : }
416 : }
417 :
418 : #endif
419 :
420 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|