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  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * Copyright 2000, 2010 Oracle and/or its affiliates.
7  *
8  * OpenOffice.org - a multi-platform office productivity suite
9  *
10  * This file is part of OpenOffice.org.
11  *
12  * OpenOffice.org is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License version 3
14  * only, as published by the Free Software Foundation.
15  *
16  * OpenOffice.org is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser General Public License version 3 for more details
20  * (a copy is included in the LICENSE file that accompanied this code).
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * version 3 along with OpenOffice.org. If not, see
24  * <http://www.openoffice.org/license.html>
25  * for a copy of the LGPLv3 License.
26  *
27  ************************************************************************/
28 #ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_
29 #define _COM_SUN_STAR_UNO_REFERENCE_HXX_
30 
32 #include <com/sun/star/uno/RuntimeException.hpp>
33 #include <com/sun/star/uno/XInterface.hdl>
35 
36 namespace com
37 {
38 namespace sun
39 {
40 namespace star
41 {
42 namespace uno
43 {
44 
45 //__________________________________________________________________________________________________
46 inline XInterface * BaseReference::iquery(
47  XInterface * pInterface, const Type & rType )
48  SAL_THROW( (RuntimeException) )
49 {
50  if (pInterface)
51  {
52  Any aRet( pInterface->queryInterface( rType ) );
53  if (typelib_TypeClass_INTERFACE == aRet.pType->eTypeClass)
54  {
55  XInterface * pRet = static_cast< XInterface * >( aRet.pReserved );
56  aRet.pReserved = 0;
57  return pRet;
58  }
59  }
60  return 0;
61 }
62 //__________________________________________________________________________________________________
63 template< class interface_type >
64 inline XInterface * Reference< interface_type >::iquery(
65  XInterface * pInterface ) SAL_THROW( (RuntimeException) )
66 {
67  return BaseReference::iquery(pInterface, interface_type::static_type());
68 }
69 #ifndef EXCEPTIONS_OFF
70 extern "C" rtl_uString * SAL_CALL cppu_unsatisfied_iquery_msg(
73 extern "C" rtl_uString * SAL_CALL cppu_unsatisfied_iset_msg(
76 //__________________________________________________________________________________________________
77 inline XInterface * BaseReference::iquery_throw(
78  XInterface * pInterface, const Type & rType )
79  SAL_THROW( (RuntimeException) )
80 {
81  XInterface * pQueried = iquery( pInterface, rType );
82  if (pQueried)
83  return pQueried;
84  throw RuntimeException(
85  ::rtl::OUString( cppu_unsatisfied_iquery_msg( rType.getTypeLibType() ), SAL_NO_ACQUIRE ),
86  Reference< XInterface >( pInterface ) );
87 }
88 //__________________________________________________________________________________________________
89 template< class interface_type >
91  XInterface * pInterface ) SAL_THROW( (RuntimeException) )
92 {
94  pInterface, interface_type::static_type());
95 }
96 //__________________________________________________________________________________________________
97 template< class interface_type >
98 inline interface_type * Reference< interface_type >::iset_throw(
99  interface_type * pInterface ) SAL_THROW( (RuntimeException) )
100 {
101  if (pInterface)
102  {
103  pInterface->acquire();
104  return pInterface;
105  }
106  throw RuntimeException(
107  ::rtl::OUString( cppu_unsatisfied_iset_msg( interface_type::static_type().getTypeLibType() ), SAL_NO_ACQUIRE ),
108  NULL );
109 }
110 #endif
111 
112 //__________________________________________________________________________________________________
113 template< class interface_type >
115 {
116  if (_pInterface)
117  _pInterface->release();
118 }
119 //__________________________________________________________________________________________________
120 template< class interface_type >
122 {
123  _pInterface = 0;
124 }
125 //__________________________________________________________________________________________________
126 template< class interface_type >
128 {
129  _pInterface = rRef._pInterface;
130  if (_pInterface)
131  _pInterface->acquire();
132 }
133 //__________________________________________________________________________________________________
134 template< class interface_type >
135 inline Reference< interface_type >::Reference( interface_type * pInterface ) SAL_THROW(())
136 {
137  _pInterface = castToXInterface(pInterface);
138  if (_pInterface)
139  _pInterface->acquire();
140 }
141 //__________________________________________________________________________________________________
142 template< class interface_type >
143 inline Reference< interface_type >::Reference( interface_type * pInterface, __sal_NoAcquire ) SAL_THROW(())
144 {
145  _pInterface = castToXInterface(pInterface);
146 }
147 //__________________________________________________________________________________________________
148 template< class interface_type >
150 {
151  _pInterface = castToXInterface(pInterface);
152 }
153 //__________________________________________________________________________________________________
154 template< class interface_type >
156 {
157  _pInterface = iquery( rRef.get() );
158 }
159 //__________________________________________________________________________________________________
160 template< class interface_type >
161 inline Reference< interface_type >::Reference( XInterface * pInterface, UnoReference_Query ) SAL_THROW( (RuntimeException) )
162 {
163  _pInterface = iquery( pInterface );
164 }
165 //__________________________________________________________________________________________________
166 template< class interface_type >
167 inline Reference< interface_type >::Reference( const Any & rAny, UnoReference_Query ) SAL_THROW( (RuntimeException) )
168 {
169  _pInterface = (typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass
170  ? iquery( static_cast< XInterface * >( rAny.pReserved ) ) : 0);
171 }
172 #ifndef EXCEPTIONS_OFF
173 //__________________________________________________________________________________________________
174 template< class interface_type >
176 {
177  _pInterface = iquery_throw( rRef.get() );
178 }
179 //__________________________________________________________________________________________________
180 template< class interface_type >
181 inline Reference< interface_type >::Reference( XInterface * pInterface, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
182 {
183  _pInterface = iquery_throw( pInterface );
184 }
185 //__________________________________________________________________________________________________
186 template< class interface_type >
188 {
189  _pInterface = iquery_throw( typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass
190  ? static_cast< XInterface * >( rAny.pReserved ) : 0 );
191 }
192 //__________________________________________________________________________________________________
193 template< class interface_type >
195 {
196  _pInterface = iset_throw( rRef.get() );
197 }
198 //__________________________________________________________________________________________________
199 template< class interface_type >
200 inline Reference< interface_type >::Reference( interface_type * pInterface, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) )
201 {
202  _pInterface = iset_throw( pInterface );
203 }
204 #endif
205 
206 //__________________________________________________________________________________________________
207 template< class interface_type >
209 {
210  if (_pInterface)
211  {
212  XInterface * const pOld = _pInterface;
213  _pInterface = 0;
214  pOld->release();
215  }
216 }
217 //__________________________________________________________________________________________________
218 template< class interface_type >
220  interface_type * pInterface ) SAL_THROW(())
221 {
222  if (pInterface)
223  castToXInterface(pInterface)->acquire();
224  XInterface * const pOld = _pInterface;
225  _pInterface = castToXInterface(pInterface);
226  if (pOld)
227  pOld->release();
228  return (0 != pInterface);
229 }
230 //__________________________________________________________________________________________________
231 template< class interface_type >
233  interface_type * pInterface, __sal_NoAcquire ) SAL_THROW(())
234 {
235  XInterface * const pOld = _pInterface;
236  _pInterface = castToXInterface(pInterface);
237  if (pOld)
238  pOld->release();
239  return (0 != pInterface);
240 }
241 //__________________________________________________________________________________________________
242 template< class interface_type >
244  interface_type * pInterface, UnoReference_NoAcquire ) SAL_THROW(())
245 {
246  return set( pInterface, SAL_NO_ACQUIRE );
247 }
248 
249 //__________________________________________________________________________________________________
250 template< class interface_type >
252  const Reference< interface_type > & rRef ) SAL_THROW(())
253 {
254  return set( castFromXInterface( rRef._pInterface ) );
255 }
256 //__________________________________________________________________________________________________
257 template< class interface_type >
259  XInterface * pInterface, UnoReference_Query ) SAL_THROW( (RuntimeException) )
260 {
261  return set( castFromXInterface(iquery( pInterface )), SAL_NO_ACQUIRE );
262 }
263 //__________________________________________________________________________________________________
264 template< class interface_type >
266  const BaseReference & rRef, UnoReference_Query ) SAL_THROW( (RuntimeException) )
267 {
268  return set( castFromXInterface(iquery( rRef.get() )), SAL_NO_ACQUIRE );
269 }
270 
271 //______________________________________________________________________________
272 template< class interface_type >
274  Any const & rAny, UnoReference_Query )
275 {
276  return set(
277  castFromXInterface(
278  iquery(
280  ? static_cast< XInterface * >( rAny.pReserved ) : 0 )),
281  SAL_NO_ACQUIRE );
282 }
283 
284 #ifndef EXCEPTIONS_OFF
285 //__________________________________________________________________________________________________
286 template< class interface_type >
288  XInterface * pInterface, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
289 {
290  set( castFromXInterface(iquery_throw( pInterface )), SAL_NO_ACQUIRE );
291 }
292 //__________________________________________________________________________________________________
293 template< class interface_type >
295  const BaseReference & rRef, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
296 {
297  set( castFromXInterface(iquery_throw( rRef.get() )), SAL_NO_ACQUIRE );
298 }
299 
300 //______________________________________________________________________________
301 template< class interface_type >
303  Any const & rAny, UnoReference_QueryThrow )
304 {
305  set( castFromXInterface(
306  iquery_throw(
308  ? static_cast< XInterface * >( rAny.pReserved ) : 0 )),
309  SAL_NO_ACQUIRE );
310 }
311 //__________________________________________________________________________________________________
312 template< class interface_type >
314  interface_type * pInterface, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) )
315 {
316  set( iset_throw( pInterface ), SAL_NO_ACQUIRE );
317 }
318 //__________________________________________________________________________________________________
319 template< class interface_type >
321  const Reference< interface_type > & rRef, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) )
322 {
323  set( rRef.get(), UNO_SET_THROW );
324 }
325 
326 #endif
327 
328 //__________________________________________________________________________________________________
329 template< class interface_type >
331  interface_type * pInterface ) SAL_THROW(())
332 {
333  set( pInterface );
334  return *this;
335 }
336 //__________________________________________________________________________________________________
337 template< class interface_type >
339  const Reference< interface_type > & rRef ) SAL_THROW(())
340 {
341  set( castFromXInterface( rRef._pInterface ) );
342  return *this;
343 }
344 
345 //__________________________________________________________________________________________________
346 template< class interface_type >
348  const BaseReference & rRef ) SAL_THROW( (RuntimeException) )
349 {
351  castFromXInterface(iquery( rRef.get() )), SAL_NO_ACQUIRE );
352 }
353 //__________________________________________________________________________________________________
354 template< class interface_type >
356  XInterface * pInterface ) SAL_THROW( (RuntimeException) )
357 {
359  castFromXInterface(iquery( pInterface )), SAL_NO_ACQUIRE );
360 }
361 
362 //##################################################################################################
363 
364 //__________________________________________________________________________________________________
365 inline sal_Bool BaseReference::operator == ( XInterface * pInterface ) const SAL_THROW(())
366 {
367  if (_pInterface == pInterface)
368  return sal_True;
369 #ifndef EXCEPTIONS_OFF
370  try
371  {
372 #endif
373  // only the query to XInterface must return the same pointer if they belong to same objects
374  Reference< XInterface > x1( _pInterface, UNO_QUERY );
375  Reference< XInterface > x2( pInterface, UNO_QUERY );
376  return (x1._pInterface == x2._pInterface);
377 #ifndef EXCEPTIONS_OFF
378  }
379  catch (RuntimeException &)
380  {
381  return sal_False;
382  }
383 #endif
384 }
385 
386 //______________________________________________________________________________
388  const BaseReference & rRef ) const SAL_THROW(())
389 {
390  if (_pInterface == rRef._pInterface)
391  return sal_False;
392 #if ! defined EXCEPTIONS_OFF
393  try
394  {
395 #endif
396  // only the query to XInterface must return the same pointer:
397  Reference< XInterface > x1( _pInterface, UNO_QUERY );
399  return (x1._pInterface < x2._pInterface);
400 #if ! defined EXCEPTIONS_OFF
401  }
402  catch (RuntimeException &)
403  {
404  return sal_False;
405  }
406 #endif
407 }
408 
409 //__________________________________________________________________________________________________
410 inline sal_Bool BaseReference::operator != ( XInterface * pInterface ) const SAL_THROW(())
411 {
412  return (! operator == ( pInterface ));
413 }
414 //__________________________________________________________________________________________________
416 {
417  return operator == ( rRef._pInterface );
418 }
419 //__________________________________________________________________________________________________
421 {
422  return (! operator == ( rRef._pInterface ));
423 }
424 
425 }
426 }
427 }
428 }
429 
430 #endif
431 
432 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */