bump product version to 4.2.0.1
[LibreOffice.git] / include / com / sun / star / uno / Reference.hxx
blob9726860b2eca06e2adebcdf7458c5d35cf0a23d7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_COM_SUN_STAR_UNO_REFERENCE_HXX
20 #define INCLUDED_COM_SUN_STAR_UNO_REFERENCE_HXX
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>
27 namespace com
29 namespace sun
31 namespace star
33 namespace uno
36 //__________________________________________________________________________________________________
37 inline XInterface * BaseReference::iquery(
38 XInterface * pInterface, const Type & rType )
39 SAL_THROW( (RuntimeException) )
41 if (pInterface)
43 Any aRet( pInterface->queryInterface( rType ) );
44 if (typelib_TypeClass_INTERFACE == aRet.pType->eTypeClass)
46 XInterface * pRet = static_cast< XInterface * >( aRet.pReserved );
47 aRet.pReserved = 0;
48 return pRet;
51 return 0;
53 //__________________________________________________________________________________________________
54 template< class interface_type >
55 inline XInterface * Reference< interface_type >::iquery(
56 XInterface * pInterface ) SAL_THROW( (RuntimeException) )
58 return BaseReference::iquery(pInterface, interface_type::static_type());
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 inline XInterface * BaseReference::iquery_throw(
68 XInterface * pInterface, const Type & rType )
69 SAL_THROW( (RuntimeException) )
71 XInterface * pQueried = iquery( pInterface, rType );
72 if (pQueried)
73 return pQueried;
74 throw RuntimeException(
75 ::rtl::OUString( cppu_unsatisfied_iquery_msg( rType.getTypeLibType() ), SAL_NO_ACQUIRE ),
76 Reference< XInterface >( pInterface ) );
78 //__________________________________________________________________________________________________
79 template< class interface_type >
80 inline XInterface * Reference< interface_type >::iquery_throw(
81 XInterface * pInterface ) SAL_THROW( (RuntimeException) )
83 return BaseReference::iquery_throw(
84 pInterface, interface_type::static_type());
86 //__________________________________________________________________________________________________
87 template< class interface_type >
88 inline interface_type * Reference< interface_type >::iset_throw(
89 interface_type * pInterface ) SAL_THROW( (RuntimeException) )
91 if (pInterface)
93 castToXInterface(pInterface)->acquire();
94 return pInterface;
96 throw RuntimeException(
97 ::rtl::OUString( cppu_unsatisfied_iset_msg( interface_type::static_type().getTypeLibType() ), SAL_NO_ACQUIRE ),
98 NULL );
101 //__________________________________________________________________________________________________
102 template< class interface_type >
103 inline Reference< interface_type >::~Reference() SAL_THROW(())
105 if (_pInterface)
106 _pInterface->release();
108 //__________________________________________________________________________________________________
109 template< class interface_type >
110 inline Reference< interface_type >::Reference() SAL_THROW(())
112 _pInterface = 0;
114 //__________________________________________________________________________________________________
115 template< class interface_type >
116 inline Reference< interface_type >::Reference( const Reference< interface_type > & rRef ) SAL_THROW(())
118 _pInterface = rRef._pInterface;
119 if (_pInterface)
120 _pInterface->acquire();
122 //__________________________________________________________________________________________________
123 template< class interface_type > template< class derived_type >
124 inline Reference< interface_type >::Reference(
125 const Reference< derived_type > & rRef,
126 typename detail::UpCast< interface_type, derived_type >::t )
127 SAL_THROW(())
129 interface_type * p = rRef.get();
130 _pInterface = p;
131 if (_pInterface)
132 _pInterface->acquire();
134 //__________________________________________________________________________________________________
135 template< class interface_type >
136 inline Reference< interface_type >::Reference( interface_type * pInterface ) SAL_THROW(())
138 _pInterface = castToXInterface(pInterface);
139 if (_pInterface)
140 _pInterface->acquire();
142 //__________________________________________________________________________________________________
143 template< class interface_type >
144 inline Reference< interface_type >::Reference( interface_type * pInterface, __sal_NoAcquire ) SAL_THROW(())
146 _pInterface = castToXInterface(pInterface);
148 //__________________________________________________________________________________________________
149 template< class interface_type >
150 inline Reference< interface_type >::Reference( interface_type * pInterface, UnoReference_NoAcquire ) SAL_THROW(())
152 _pInterface = castToXInterface(pInterface);
154 //__________________________________________________________________________________________________
155 template< class interface_type >
156 inline Reference< interface_type >::Reference( const BaseReference & rRef, UnoReference_Query ) SAL_THROW( (RuntimeException) )
158 _pInterface = iquery( rRef.get() );
160 //__________________________________________________________________________________________________
161 template< class interface_type >
162 inline Reference< interface_type >::Reference( XInterface * pInterface, UnoReference_Query ) SAL_THROW( (RuntimeException) )
164 _pInterface = iquery( pInterface );
166 //__________________________________________________________________________________________________
167 template< class interface_type >
168 inline Reference< interface_type >::Reference( const Any & rAny, UnoReference_Query ) SAL_THROW( (RuntimeException) )
170 _pInterface = (typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass
171 ? iquery( static_cast< XInterface * >( rAny.pReserved ) ) : 0);
173 //__________________________________________________________________________________________________
174 template< class interface_type >
175 inline Reference< interface_type >::Reference( const BaseReference & rRef, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
177 _pInterface = iquery_throw( rRef.get() );
179 //__________________________________________________________________________________________________
180 template< class interface_type >
181 inline Reference< interface_type >::Reference( XInterface * pInterface, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
183 _pInterface = iquery_throw( pInterface );
185 //__________________________________________________________________________________________________
186 template< class interface_type >
187 inline Reference< interface_type >::Reference( const Any & rAny, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
189 _pInterface = iquery_throw( typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass
190 ? static_cast< XInterface * >( rAny.pReserved ) : 0 );
192 //__________________________________________________________________________________________________
193 template< class interface_type >
194 inline Reference< interface_type >::Reference( const Reference< interface_type > & rRef, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) )
196 _pInterface = castToXInterface( iset_throw( rRef.get() ) );
198 //__________________________________________________________________________________________________
199 template< class interface_type >
200 inline Reference< interface_type >::Reference( interface_type * pInterface, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) )
202 _pInterface = castToXInterface( iset_throw( pInterface ) );
205 //__________________________________________________________________________________________________
206 template< class interface_type >
207 inline void Reference< interface_type >::clear() SAL_THROW(())
209 if (_pInterface)
211 XInterface * const pOld = _pInterface;
212 _pInterface = 0;
213 pOld->release();
216 //__________________________________________________________________________________________________
217 template< class interface_type >
218 inline sal_Bool Reference< interface_type >::set(
219 interface_type * pInterface ) SAL_THROW(())
221 if (pInterface)
222 castToXInterface(pInterface)->acquire();
223 XInterface * const pOld = _pInterface;
224 _pInterface = castToXInterface(pInterface);
225 if (pOld)
226 pOld->release();
227 return (0 != pInterface);
229 //__________________________________________________________________________________________________
230 template< class interface_type >
231 inline sal_Bool Reference< interface_type >::set(
232 interface_type * pInterface, __sal_NoAcquire ) SAL_THROW(())
234 XInterface * const pOld = _pInterface;
235 _pInterface = castToXInterface(pInterface);
236 if (pOld)
237 pOld->release();
238 return (0 != pInterface);
240 //__________________________________________________________________________________________________
241 template< class interface_type >
242 inline sal_Bool Reference< interface_type >::set(
243 interface_type * pInterface, UnoReference_NoAcquire ) SAL_THROW(())
245 return set( pInterface, SAL_NO_ACQUIRE );
248 //__________________________________________________________________________________________________
249 template< class interface_type >
250 inline sal_Bool Reference< interface_type >::set(
251 const Reference< interface_type > & rRef ) SAL_THROW(())
253 return set( castFromXInterface( rRef._pInterface ) );
255 //__________________________________________________________________________________________________
256 template< class interface_type >
257 inline sal_Bool Reference< interface_type >::set(
258 XInterface * pInterface, UnoReference_Query ) SAL_THROW( (RuntimeException) )
260 return set( castFromXInterface(iquery( pInterface )), SAL_NO_ACQUIRE );
262 //__________________________________________________________________________________________________
263 template< class interface_type >
264 inline sal_Bool Reference< interface_type >::set(
265 const BaseReference & rRef, UnoReference_Query ) SAL_THROW( (RuntimeException) )
267 return set( castFromXInterface(iquery( rRef.get() )), SAL_NO_ACQUIRE );
270 //______________________________________________________________________________
271 template< class interface_type >
272 inline bool Reference< interface_type >::set(
273 Any const & rAny, UnoReference_Query )
275 return set(
276 castFromXInterface(
277 iquery(
278 rAny.pType->eTypeClass == typelib_TypeClass_INTERFACE
279 ? static_cast< XInterface * >( rAny.pReserved ) : 0 )),
280 SAL_NO_ACQUIRE );
283 //__________________________________________________________________________________________________
284 template< class interface_type >
285 inline void Reference< interface_type >::set(
286 XInterface * pInterface, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
288 set( castFromXInterface(iquery_throw( pInterface )), SAL_NO_ACQUIRE );
290 //__________________________________________________________________________________________________
291 template< class interface_type >
292 inline void Reference< interface_type >::set(
293 const BaseReference & rRef, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
295 set( castFromXInterface(iquery_throw( rRef.get() )), SAL_NO_ACQUIRE );
298 //______________________________________________________________________________
299 template< class interface_type >
300 inline void Reference< interface_type >::set(
301 Any const & rAny, UnoReference_QueryThrow )
303 set( castFromXInterface(
304 iquery_throw(
305 rAny.pType->eTypeClass == typelib_TypeClass_INTERFACE
306 ? static_cast< XInterface * >( rAny.pReserved ) : 0 )),
307 SAL_NO_ACQUIRE );
309 //__________________________________________________________________________________________________
310 template< class interface_type >
311 inline void Reference< interface_type >::set(
312 interface_type * pInterface, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) )
314 set( iset_throw( pInterface ), SAL_NO_ACQUIRE );
316 //__________________________________________________________________________________________________
317 template< class interface_type >
318 inline void Reference< interface_type >::set(
319 const Reference< interface_type > & rRef, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) )
321 set( rRef.get(), UNO_SET_THROW );
324 //__________________________________________________________________________________________________
325 template< class interface_type >
326 inline Reference< interface_type > & Reference< interface_type >::operator = (
327 interface_type * pInterface ) SAL_THROW(())
329 set( pInterface );
330 return *this;
332 //__________________________________________________________________________________________________
333 template< class interface_type >
334 inline Reference< interface_type > & Reference< interface_type >::operator = (
335 const Reference< interface_type > & rRef ) SAL_THROW(())
337 set( castFromXInterface( rRef._pInterface ) );
338 return *this;
341 //__________________________________________________________________________________________________
342 template< class interface_type >
343 inline Reference< interface_type > Reference< interface_type >::query(
344 const BaseReference & rRef ) SAL_THROW( (RuntimeException) )
346 return Reference< interface_type >(
347 castFromXInterface(iquery( rRef.get() )), SAL_NO_ACQUIRE );
349 //__________________________________________________________________________________________________
350 template< class interface_type >
351 inline Reference< interface_type > Reference< interface_type >::query(
352 XInterface * pInterface ) SAL_THROW( (RuntimeException) )
354 return Reference< interface_type >(
355 castFromXInterface(iquery( pInterface )), SAL_NO_ACQUIRE );
358 //##################################################################################################
360 //__________________________________________________________________________________________________
361 inline sal_Bool BaseReference::operator == ( XInterface * pInterface ) const SAL_THROW(())
363 if (_pInterface == pInterface)
364 return sal_True;
367 // only the query to XInterface must return the same pointer if they belong to same objects
368 Reference< XInterface > x1( _pInterface, UNO_QUERY );
369 Reference< XInterface > x2( pInterface, UNO_QUERY );
370 return (x1._pInterface == x2._pInterface);
372 catch (RuntimeException &)
374 return sal_False;
378 //______________________________________________________________________________
379 inline sal_Bool BaseReference::operator < (
380 const BaseReference & rRef ) const SAL_THROW(())
382 if (_pInterface == rRef._pInterface)
383 return sal_False;
386 // only the query to XInterface must return the same pointer:
387 Reference< XInterface > x1( _pInterface, UNO_QUERY );
388 Reference< XInterface > x2( rRef, UNO_QUERY );
389 return (x1._pInterface < x2._pInterface);
391 catch (RuntimeException &)
393 return sal_False;
397 //__________________________________________________________________________________________________
398 inline sal_Bool BaseReference::operator != ( XInterface * pInterface ) const SAL_THROW(())
400 return (! operator == ( pInterface ));
402 //__________________________________________________________________________________________________
403 inline sal_Bool BaseReference::operator == ( const BaseReference & rRef ) const SAL_THROW(())
405 return operator == ( rRef._pInterface );
407 //__________________________________________________________________________________________________
408 inline sal_Bool BaseReference::operator != ( const BaseReference & rRef ) const SAL_THROW(())
410 return (! operator == ( rRef._pInterface ));
418 #endif
420 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */