UDK 3.2.7 C/C++ API Reference
|
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 00002 /************************************************************************* 00003 * 00004 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 00005 * 00006 * Copyright 2000, 2010 Oracle and/or its affiliates. 00007 * 00008 * OpenOffice.org - a multi-platform office productivity suite 00009 * 00010 * This file is part of OpenOffice.org. 00011 * 00012 * OpenOffice.org is free software: you can redistribute it and/or modify 00013 * it under the terms of the GNU Lesser General Public License version 3 00014 * only, as published by the Free Software Foundation. 00015 * 00016 * OpenOffice.org is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Lesser General Public License version 3 for more details 00020 * (a copy is included in the LICENSE file that accompanied this code). 00021 * 00022 * You should have received a copy of the GNU Lesser General Public License 00023 * version 3 along with OpenOffice.org. If not, see 00024 * <http://www.openoffice.org/license.html> 00025 * for a copy of the LGPLv3 License. 00026 * 00027 ************************************************************************/ 00028 #ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_ 00029 #define _COM_SUN_STAR_UNO_REFERENCE_HXX_ 00030 00031 #include <com/sun/star/uno/Reference.h> 00032 #include <com/sun/star/uno/RuntimeException.hpp> 00033 #include <com/sun/star/uno/XInterface.hdl> 00034 #include <com/sun/star/uno/genfunc.hxx> 00035 00036 namespace com 00037 { 00038 namespace sun 00039 { 00040 namespace star 00041 { 00042 namespace uno 00043 { 00044 00045 //__________________________________________________________________________________________________ 00046 inline XInterface * BaseReference::iquery( 00047 XInterface * pInterface, const Type & rType ) 00048 SAL_THROW( (RuntimeException) ) 00049 { 00050 if (pInterface) 00051 { 00052 Any aRet( pInterface->queryInterface( rType ) ); 00053 if (typelib_TypeClass_INTERFACE == aRet.pType->eTypeClass) 00054 { 00055 XInterface * pRet = static_cast< XInterface * >( aRet.pReserved ); 00056 aRet.pReserved = 0; 00057 return pRet; 00058 } 00059 } 00060 return 0; 00061 } 00062 //__________________________________________________________________________________________________ 00063 template< class interface_type > 00064 inline XInterface * Reference< interface_type >::iquery( 00065 XInterface * pInterface ) SAL_THROW( (RuntimeException) ) 00066 { 00067 return BaseReference::iquery(pInterface, interface_type::static_type()); 00068 } 00069 #ifndef EXCEPTIONS_OFF 00070 extern "C" rtl_uString * SAL_CALL cppu_unsatisfied_iquery_msg( 00071 typelib_TypeDescriptionReference * pType ) 00072 SAL_THROW_EXTERN_C(); 00073 extern "C" rtl_uString * SAL_CALL cppu_unsatisfied_iset_msg( 00074 typelib_TypeDescriptionReference * pType ) 00075 SAL_THROW_EXTERN_C(); 00076 //__________________________________________________________________________________________________ 00077 inline XInterface * BaseReference::iquery_throw( 00078 XInterface * pInterface, const Type & rType ) 00079 SAL_THROW( (RuntimeException) ) 00080 { 00081 XInterface * pQueried = iquery( pInterface, rType ); 00082 if (pQueried) 00083 return pQueried; 00084 throw RuntimeException( 00085 ::rtl::OUString( cppu_unsatisfied_iquery_msg( rType.getTypeLibType() ), SAL_NO_ACQUIRE ), 00086 Reference< XInterface >( pInterface ) ); 00087 } 00088 //__________________________________________________________________________________________________ 00089 template< class interface_type > 00090 inline XInterface * Reference< interface_type >::iquery_throw( 00091 XInterface * pInterface ) SAL_THROW( (RuntimeException) ) 00092 { 00093 return BaseReference::iquery_throw( 00094 pInterface, interface_type::static_type()); 00095 } 00096 //__________________________________________________________________________________________________ 00097 template< class interface_type > 00098 inline interface_type * Reference< interface_type >::iset_throw( 00099 interface_type * pInterface ) SAL_THROW( (RuntimeException) ) 00100 { 00101 if (pInterface) 00102 { 00103 pInterface->acquire(); 00104 return pInterface; 00105 } 00106 throw RuntimeException( 00107 ::rtl::OUString( cppu_unsatisfied_iset_msg( interface_type::static_type().getTypeLibType() ), SAL_NO_ACQUIRE ), 00108 NULL ); 00109 } 00110 #endif 00111 00112 //__________________________________________________________________________________________________ 00113 template< class interface_type > 00114 inline Reference< interface_type >::~Reference() SAL_THROW(()) 00115 { 00116 if (_pInterface) 00117 _pInterface->release(); 00118 } 00119 //__________________________________________________________________________________________________ 00120 template< class interface_type > 00121 inline Reference< interface_type >::Reference() SAL_THROW(()) 00122 { 00123 _pInterface = 0; 00124 } 00125 //__________________________________________________________________________________________________ 00126 template< class interface_type > 00127 inline Reference< interface_type >::Reference( const Reference< interface_type > & rRef ) SAL_THROW(()) 00128 { 00129 _pInterface = rRef._pInterface; 00130 if (_pInterface) 00131 _pInterface->acquire(); 00132 } 00133 //__________________________________________________________________________________________________ 00134 template< class interface_type > 00135 inline Reference< interface_type >::Reference( interface_type * pInterface ) SAL_THROW(()) 00136 { 00137 _pInterface = castToXInterface(pInterface); 00138 if (_pInterface) 00139 _pInterface->acquire(); 00140 } 00141 //__________________________________________________________________________________________________ 00142 template< class interface_type > 00143 inline Reference< interface_type >::Reference( interface_type * pInterface, __sal_NoAcquire ) SAL_THROW(()) 00144 { 00145 _pInterface = castToXInterface(pInterface); 00146 } 00147 //__________________________________________________________________________________________________ 00148 template< class interface_type > 00149 inline Reference< interface_type >::Reference( interface_type * pInterface, UnoReference_NoAcquire ) SAL_THROW(()) 00150 { 00151 _pInterface = castToXInterface(pInterface); 00152 } 00153 //__________________________________________________________________________________________________ 00154 template< class interface_type > 00155 inline Reference< interface_type >::Reference( const BaseReference & rRef, UnoReference_Query ) SAL_THROW( (RuntimeException) ) 00156 { 00157 _pInterface = iquery( rRef.get() ); 00158 } 00159 //__________________________________________________________________________________________________ 00160 template< class interface_type > 00161 inline Reference< interface_type >::Reference( XInterface * pInterface, UnoReference_Query ) SAL_THROW( (RuntimeException) ) 00162 { 00163 _pInterface = iquery( pInterface ); 00164 } 00165 //__________________________________________________________________________________________________ 00166 template< class interface_type > 00167 inline Reference< interface_type >::Reference( const Any & rAny, UnoReference_Query ) SAL_THROW( (RuntimeException) ) 00168 { 00169 _pInterface = (typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass 00170 ? iquery( static_cast< XInterface * >( rAny.pReserved ) ) : 0); 00171 } 00172 #ifndef EXCEPTIONS_OFF 00173 //__________________________________________________________________________________________________ 00174 template< class interface_type > 00175 inline Reference< interface_type >::Reference( const BaseReference & rRef, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) ) 00176 { 00177 _pInterface = iquery_throw( rRef.get() ); 00178 } 00179 //__________________________________________________________________________________________________ 00180 template< class interface_type > 00181 inline Reference< interface_type >::Reference( XInterface * pInterface, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) ) 00182 { 00183 _pInterface = iquery_throw( pInterface ); 00184 } 00185 //__________________________________________________________________________________________________ 00186 template< class interface_type > 00187 inline Reference< interface_type >::Reference( const Any & rAny, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) ) 00188 { 00189 _pInterface = iquery_throw( typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass 00190 ? static_cast< XInterface * >( rAny.pReserved ) : 0 ); 00191 } 00192 //__________________________________________________________________________________________________ 00193 template< class interface_type > 00194 inline Reference< interface_type >::Reference( const Reference< interface_type > & rRef, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) ) 00195 { 00196 _pInterface = iset_throw( rRef.get() ); 00197 } 00198 //__________________________________________________________________________________________________ 00199 template< class interface_type > 00200 inline Reference< interface_type >::Reference( interface_type * pInterface, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) ) 00201 { 00202 _pInterface = iset_throw( pInterface ); 00203 } 00204 #endif 00205 00206 //__________________________________________________________________________________________________ 00207 template< class interface_type > 00208 inline void Reference< interface_type >::clear() SAL_THROW(()) 00209 { 00210 if (_pInterface) 00211 { 00212 XInterface * const pOld = _pInterface; 00213 _pInterface = 0; 00214 pOld->release(); 00215 } 00216 } 00217 //__________________________________________________________________________________________________ 00218 template< class interface_type > 00219 inline sal_Bool Reference< interface_type >::set( 00220 interface_type * pInterface ) SAL_THROW(()) 00221 { 00222 if (pInterface) 00223 castToXInterface(pInterface)->acquire(); 00224 XInterface * const pOld = _pInterface; 00225 _pInterface = castToXInterface(pInterface); 00226 if (pOld) 00227 pOld->release(); 00228 return (0 != pInterface); 00229 } 00230 //__________________________________________________________________________________________________ 00231 template< class interface_type > 00232 inline sal_Bool Reference< interface_type >::set( 00233 interface_type * pInterface, __sal_NoAcquire ) SAL_THROW(()) 00234 { 00235 XInterface * const pOld = _pInterface; 00236 _pInterface = castToXInterface(pInterface); 00237 if (pOld) 00238 pOld->release(); 00239 return (0 != pInterface); 00240 } 00241 //__________________________________________________________________________________________________ 00242 template< class interface_type > 00243 inline sal_Bool Reference< interface_type >::set( 00244 interface_type * pInterface, UnoReference_NoAcquire ) SAL_THROW(()) 00245 { 00246 return set( pInterface, SAL_NO_ACQUIRE ); 00247 } 00248 00249 //__________________________________________________________________________________________________ 00250 template< class interface_type > 00251 inline sal_Bool Reference< interface_type >::set( 00252 const Reference< interface_type > & rRef ) SAL_THROW(()) 00253 { 00254 return set( castFromXInterface( rRef._pInterface ) ); 00255 } 00256 //__________________________________________________________________________________________________ 00257 template< class interface_type > 00258 inline sal_Bool Reference< interface_type >::set( 00259 XInterface * pInterface, UnoReference_Query ) SAL_THROW( (RuntimeException) ) 00260 { 00261 return set( castFromXInterface(iquery( pInterface )), SAL_NO_ACQUIRE ); 00262 } 00263 //__________________________________________________________________________________________________ 00264 template< class interface_type > 00265 inline sal_Bool Reference< interface_type >::set( 00266 const BaseReference & rRef, UnoReference_Query ) SAL_THROW( (RuntimeException) ) 00267 { 00268 return set( castFromXInterface(iquery( rRef.get() )), SAL_NO_ACQUIRE ); 00269 } 00270 00271 //______________________________________________________________________________ 00272 template< class interface_type > 00273 inline bool Reference< interface_type >::set( 00274 Any const & rAny, UnoReference_Query ) 00275 { 00276 return set( 00277 castFromXInterface( 00278 iquery( 00279 rAny.pType->eTypeClass == typelib_TypeClass_INTERFACE 00280 ? static_cast< XInterface * >( rAny.pReserved ) : 0 )), 00281 SAL_NO_ACQUIRE ); 00282 } 00283 00284 #ifndef EXCEPTIONS_OFF 00285 //__________________________________________________________________________________________________ 00286 template< class interface_type > 00287 inline void Reference< interface_type >::set( 00288 XInterface * pInterface, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) ) 00289 { 00290 set( castFromXInterface(iquery_throw( pInterface )), SAL_NO_ACQUIRE ); 00291 } 00292 //__________________________________________________________________________________________________ 00293 template< class interface_type > 00294 inline void Reference< interface_type >::set( 00295 const BaseReference & rRef, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) ) 00296 { 00297 set( castFromXInterface(iquery_throw( rRef.get() )), SAL_NO_ACQUIRE ); 00298 } 00299 00300 //______________________________________________________________________________ 00301 template< class interface_type > 00302 inline void Reference< interface_type >::set( 00303 Any const & rAny, UnoReference_QueryThrow ) 00304 { 00305 set( castFromXInterface( 00306 iquery_throw( 00307 rAny.pType->eTypeClass == typelib_TypeClass_INTERFACE 00308 ? static_cast< XInterface * >( rAny.pReserved ) : 0 )), 00309 SAL_NO_ACQUIRE ); 00310 } 00311 //__________________________________________________________________________________________________ 00312 template< class interface_type > 00313 inline void Reference< interface_type >::set( 00314 interface_type * pInterface, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) ) 00315 { 00316 set( iset_throw( pInterface ), SAL_NO_ACQUIRE ); 00317 } 00318 //__________________________________________________________________________________________________ 00319 template< class interface_type > 00320 inline void Reference< interface_type >::set( 00321 const Reference< interface_type > & rRef, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) ) 00322 { 00323 set( rRef.get(), UNO_SET_THROW ); 00324 } 00325 00326 #endif 00327 00328 //__________________________________________________________________________________________________ 00329 template< class interface_type > 00330 inline Reference< interface_type > & Reference< interface_type >::operator = ( 00331 interface_type * pInterface ) SAL_THROW(()) 00332 { 00333 set( pInterface ); 00334 return *this; 00335 } 00336 //__________________________________________________________________________________________________ 00337 template< class interface_type > 00338 inline Reference< interface_type > & Reference< interface_type >::operator = ( 00339 const Reference< interface_type > & rRef ) SAL_THROW(()) 00340 { 00341 set( castFromXInterface( rRef._pInterface ) ); 00342 return *this; 00343 } 00344 00345 //__________________________________________________________________________________________________ 00346 template< class interface_type > 00347 inline Reference< interface_type > Reference< interface_type >::query( 00348 const BaseReference & rRef ) SAL_THROW( (RuntimeException) ) 00349 { 00350 return Reference< interface_type >( 00351 castFromXInterface(iquery( rRef.get() )), SAL_NO_ACQUIRE ); 00352 } 00353 //__________________________________________________________________________________________________ 00354 template< class interface_type > 00355 inline Reference< interface_type > Reference< interface_type >::query( 00356 XInterface * pInterface ) SAL_THROW( (RuntimeException) ) 00357 { 00358 return Reference< interface_type >( 00359 castFromXInterface(iquery( pInterface )), SAL_NO_ACQUIRE ); 00360 } 00361 00362 //################################################################################################## 00363 00364 //__________________________________________________________________________________________________ 00365 inline sal_Bool BaseReference::operator == ( XInterface * pInterface ) const SAL_THROW(()) 00366 { 00367 if (_pInterface == pInterface) 00368 return sal_True; 00369 #ifndef EXCEPTIONS_OFF 00370 try 00371 { 00372 #endif 00373 // only the query to XInterface must return the same pointer if they belong to same objects 00374 Reference< XInterface > x1( _pInterface, UNO_QUERY ); 00375 Reference< XInterface > x2( pInterface, UNO_QUERY ); 00376 return (x1._pInterface == x2._pInterface); 00377 #ifndef EXCEPTIONS_OFF 00378 } 00379 catch (RuntimeException &) 00380 { 00381 return sal_False; 00382 } 00383 #endif 00384 } 00385 00386 //______________________________________________________________________________ 00387 inline sal_Bool BaseReference::operator < ( 00388 const BaseReference & rRef ) const SAL_THROW(()) 00389 { 00390 if (_pInterface == rRef._pInterface) 00391 return sal_False; 00392 #if ! defined EXCEPTIONS_OFF 00393 try 00394 { 00395 #endif 00396 // only the query to XInterface must return the same pointer: 00397 Reference< XInterface > x1( _pInterface, UNO_QUERY ); 00398 Reference< XInterface > x2( rRef, UNO_QUERY ); 00399 return (x1._pInterface < x2._pInterface); 00400 #if ! defined EXCEPTIONS_OFF 00401 } 00402 catch (RuntimeException &) 00403 { 00404 return sal_False; 00405 } 00406 #endif 00407 } 00408 00409 //__________________________________________________________________________________________________ 00410 inline sal_Bool BaseReference::operator != ( XInterface * pInterface ) const SAL_THROW(()) 00411 { 00412 return (! operator == ( pInterface )); 00413 } 00414 //__________________________________________________________________________________________________ 00415 inline sal_Bool BaseReference::operator == ( const BaseReference & rRef ) const SAL_THROW(()) 00416 { 00417 return operator == ( rRef._pInterface ); 00418 } 00419 //__________________________________________________________________________________________________ 00420 inline sal_Bool BaseReference::operator != ( const BaseReference & rRef ) const SAL_THROW(()) 00421 { 00422 return (! operator == ( rRef._pInterface )); 00423 } 00424 00425 } 00426 } 00427 } 00428 } 00429 00430 #endif 00431 00432 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */