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