My Project
UDK 3.2.7 C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Reference.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 #ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_
20 #define _COM_SUN_STAR_UNO_REFERENCE_HXX_
21 
23 #include <com/sun/star/uno/RuntimeException.hpp>
24 #include <com/sun/star/uno/XInterface.hpp>
26 
27 namespace com
28 {
29 namespace sun
30 {
31 namespace star
32 {
33 namespace uno
34 {
35 
36 //__________________________________________________________________________________________________
37 inline XInterface * BaseReference::iquery(
38  XInterface * pInterface, const Type & rType )
39  SAL_THROW( (RuntimeException) )
40 {
41  if (pInterface)
42  {
43  Any aRet( pInterface->queryInterface( rType ) );
44  if (typelib_TypeClass_INTERFACE == aRet.pType->eTypeClass)
45  {
46  XInterface * pRet = static_cast< XInterface * >( aRet.pReserved );
47  aRet.pReserved = 0;
48  return pRet;
49  }
50  }
51  return 0;
52 }
53 //__________________________________________________________________________________________________
54 template< class interface_type >
55 inline XInterface * Reference< interface_type >::iquery(
56  XInterface * pInterface ) SAL_THROW( (RuntimeException) )
57 {
58  return BaseReference::iquery(pInterface, interface_type::static_type());
59 }
60 #ifndef EXCEPTIONS_OFF
61 extern "C" rtl_uString * SAL_CALL cppu_unsatisfied_iquery_msg(
64 extern "C" rtl_uString * SAL_CALL cppu_unsatisfied_iset_msg(
67 //__________________________________________________________________________________________________
68 inline XInterface * BaseReference::iquery_throw(
69  XInterface * pInterface, const Type & rType )
70  SAL_THROW( (RuntimeException) )
71 {
72  XInterface * pQueried = iquery( pInterface, rType );
73  if (pQueried)
74  return pQueried;
75  throw RuntimeException(
76  ::rtl::OUString( cppu_unsatisfied_iquery_msg( rType.getTypeLibType() ), SAL_NO_ACQUIRE ),
77  Reference< XInterface >( pInterface ) );
78 }
79 //__________________________________________________________________________________________________
80 template< class interface_type >
82  XInterface * pInterface ) SAL_THROW( (RuntimeException) )
83 {
85  pInterface, interface_type::static_type());
86 }
87 //__________________________________________________________________________________________________
88 template< class interface_type >
89 inline interface_type * Reference< interface_type >::iset_throw(
90  interface_type * pInterface ) SAL_THROW( (RuntimeException) )
91 {
92  if (pInterface)
93  {
94  castToXInterface(pInterface)->acquire();
95  return pInterface;
96  }
97  throw RuntimeException(
98  ::rtl::OUString( cppu_unsatisfied_iset_msg( interface_type::static_type().getTypeLibType() ), SAL_NO_ACQUIRE ),
99  NULL );
100 }
101 #endif
102 
103 //__________________________________________________________________________________________________
104 template< class interface_type >
106 {
107  if (_pInterface)
108  _pInterface->release();
109 }
110 //__________________________________________________________________________________________________
111 template< class interface_type >
113 {
114  _pInterface = 0;
115 }
116 //__________________________________________________________________________________________________
117 template< class interface_type >
119 {
120  _pInterface = rRef._pInterface;
121  if (_pInterface)
122  _pInterface->acquire();
123 }
124 //__________________________________________________________________________________________________
125 template< class interface_type >
126 inline Reference< interface_type >::Reference( interface_type * pInterface ) SAL_THROW(())
127 {
128  _pInterface = castToXInterface(pInterface);
129  if (_pInterface)
130  _pInterface->acquire();
131 }
132 //__________________________________________________________________________________________________
133 template< class interface_type >
134 inline Reference< interface_type >::Reference( interface_type * pInterface, __sal_NoAcquire ) SAL_THROW(())
135 {
136  _pInterface = castToXInterface(pInterface);
137 }
138 //__________________________________________________________________________________________________
139 template< class interface_type >
141 {
142  _pInterface = castToXInterface(pInterface);
143 }
144 //__________________________________________________________________________________________________
145 template< class interface_type >
147 {
148  _pInterface = iquery( rRef.get() );
149 }
150 //__________________________________________________________________________________________________
151 template< class interface_type >
152 inline Reference< interface_type >::Reference( XInterface * pInterface, UnoReference_Query ) SAL_THROW( (RuntimeException) )
153 {
154  _pInterface = iquery( pInterface );
155 }
156 //__________________________________________________________________________________________________
157 template< class interface_type >
158 inline Reference< interface_type >::Reference( const Any & rAny, UnoReference_Query ) SAL_THROW( (RuntimeException) )
159 {
160  _pInterface = (typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass
161  ? iquery( static_cast< XInterface * >( rAny.pReserved ) ) : 0);
162 }
163 #ifndef EXCEPTIONS_OFF
164 //__________________________________________________________________________________________________
165 template< class interface_type >
167 {
168  _pInterface = iquery_throw( rRef.get() );
169 }
170 //__________________________________________________________________________________________________
171 template< class interface_type >
172 inline Reference< interface_type >::Reference( XInterface * pInterface, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
173 {
174  _pInterface = iquery_throw( pInterface );
175 }
176 //__________________________________________________________________________________________________
177 template< class interface_type >
179 {
180  _pInterface = iquery_throw( typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass
181  ? static_cast< XInterface * >( rAny.pReserved ) : 0 );
182 }
183 //__________________________________________________________________________________________________
184 template< class interface_type >
186 {
187  _pInterface = castToXInterface( iset_throw( rRef.get() ) );
188 }
189 //__________________________________________________________________________________________________
190 template< class interface_type >
191 inline Reference< interface_type >::Reference( interface_type * pInterface, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) )
192 {
193  _pInterface = castToXInterface( iset_throw( pInterface ) );
194 }
195 #endif
196 
197 //__________________________________________________________________________________________________
198 template< class interface_type >
200 {
201  if (_pInterface)
202  {
203  XInterface * const pOld = _pInterface;
204  _pInterface = 0;
205  pOld->release();
206  }
207 }
208 //__________________________________________________________________________________________________
209 template< class interface_type >
211  interface_type * pInterface ) SAL_THROW(())
212 {
213  if (pInterface)
214  castToXInterface(pInterface)->acquire();
215  XInterface * const pOld = _pInterface;
216  _pInterface = castToXInterface(pInterface);
217  if (pOld)
218  pOld->release();
219  return (0 != pInterface);
220 }
221 //__________________________________________________________________________________________________
222 template< class interface_type >
224  interface_type * pInterface, __sal_NoAcquire ) SAL_THROW(())
225 {
226  XInterface * const pOld = _pInterface;
227  _pInterface = castToXInterface(pInterface);
228  if (pOld)
229  pOld->release();
230  return (0 != pInterface);
231 }
232 //__________________________________________________________________________________________________
233 template< class interface_type >
235  interface_type * pInterface, UnoReference_NoAcquire ) SAL_THROW(())
236 {
237  return set( pInterface, SAL_NO_ACQUIRE );
238 }
239 
240 //__________________________________________________________________________________________________
241 template< class interface_type >
243  const Reference< interface_type > & rRef ) SAL_THROW(())
244 {
245  return set( castFromXInterface( rRef._pInterface ) );
246 }
247 //__________________________________________________________________________________________________
248 template< class interface_type >
250  XInterface * pInterface, UnoReference_Query ) SAL_THROW( (RuntimeException) )
251 {
252  return set( castFromXInterface(iquery( pInterface )), SAL_NO_ACQUIRE );
253 }
254 //__________________________________________________________________________________________________
255 template< class interface_type >
257  const BaseReference & rRef, UnoReference_Query ) SAL_THROW( (RuntimeException) )
258 {
259  return set( castFromXInterface(iquery( rRef.get() )), SAL_NO_ACQUIRE );
260 }
261 
262 //______________________________________________________________________________
263 template< class interface_type >
265  Any const & rAny, UnoReference_Query )
266 {
267  return set(
268  castFromXInterface(
269  iquery(
271  ? static_cast< XInterface * >( rAny.pReserved ) : 0 )),
272  SAL_NO_ACQUIRE );
273 }
274 
275 #ifndef EXCEPTIONS_OFF
276 //__________________________________________________________________________________________________
277 template< class interface_type >
279  XInterface * pInterface, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
280 {
281  set( castFromXInterface(iquery_throw( pInterface )), SAL_NO_ACQUIRE );
282 }
283 //__________________________________________________________________________________________________
284 template< class interface_type >
286  const BaseReference & rRef, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
287 {
288  set( castFromXInterface(iquery_throw( rRef.get() )), SAL_NO_ACQUIRE );
289 }
290 
291 //______________________________________________________________________________
292 template< class interface_type >
294  Any const & rAny, UnoReference_QueryThrow )
295 {
296  set( castFromXInterface(
297  iquery_throw(
299  ? static_cast< XInterface * >( rAny.pReserved ) : 0 )),
300  SAL_NO_ACQUIRE );
301 }
302 //__________________________________________________________________________________________________
303 template< class interface_type >
305  interface_type * pInterface, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) )
306 {
307  set( iset_throw( pInterface ), SAL_NO_ACQUIRE );
308 }
309 //__________________________________________________________________________________________________
310 template< class interface_type >
312  const Reference< interface_type > & rRef, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) )
313 {
314  set( rRef.get(), UNO_SET_THROW );
315 }
316 
317 #endif
318 
319 //__________________________________________________________________________________________________
320 template< class interface_type >
322  interface_type * pInterface ) SAL_THROW(())
323 {
324  set( pInterface );
325  return *this;
326 }
327 //__________________________________________________________________________________________________
328 template< class interface_type >
330  const Reference< interface_type > & rRef ) SAL_THROW(())
331 {
332  set( castFromXInterface( rRef._pInterface ) );
333  return *this;
334 }
335 
336 //__________________________________________________________________________________________________
337 template< class interface_type >
339  const BaseReference & rRef ) SAL_THROW( (RuntimeException) )
340 {
342  castFromXInterface(iquery( rRef.get() )), SAL_NO_ACQUIRE );
343 }
344 //__________________________________________________________________________________________________
345 template< class interface_type >
347  XInterface * pInterface ) SAL_THROW( (RuntimeException) )
348 {
350  castFromXInterface(iquery( pInterface )), SAL_NO_ACQUIRE );
351 }
352 
353 //##################################################################################################
354 
355 //__________________________________________________________________________________________________
356 inline sal_Bool BaseReference::operator == ( XInterface * pInterface ) const SAL_THROW(())
357 {
358  if (_pInterface == pInterface)
359  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  Reference< XInterface > x1( _pInterface, UNO_QUERY );
366  Reference< XInterface > x2( pInterface, UNO_QUERY );
367  return (x1._pInterface == x2._pInterface);
368 #ifndef EXCEPTIONS_OFF
369  }
370  catch (RuntimeException &)
371  {
372  return sal_False;
373  }
374 #endif
375 }
376 
377 //______________________________________________________________________________
379  const BaseReference & rRef ) const SAL_THROW(())
380 {
381  if (_pInterface == rRef._pInterface)
382  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  Reference< XInterface > x1( _pInterface, UNO_QUERY );
390  return (x1._pInterface < x2._pInterface);
391 #if ! defined EXCEPTIONS_OFF
392  }
393  catch (RuntimeException &)
394  {
395  return sal_False;
396  }
397 #endif
398 }
399 
400 //__________________________________________________________________________________________________
401 inline sal_Bool BaseReference::operator != ( XInterface * pInterface ) const SAL_THROW(())
402 {
403  return (! operator == ( pInterface ));
404 }
405 //__________________________________________________________________________________________________
407 {
408  return operator == ( rRef._pInterface );
409 }
410 //__________________________________________________________________________________________________
412 {
413  return (! operator == ( rRef._pInterface ));
414 }
415 
416 }
417 }
418 }
419 }
420 
421 #endif
422 
423 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */