LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/include/com/sun/star/uno - Reference.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 153 157 97.5 %
Date: 2013-07-09 Functions: 6865 11065 62.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : 
      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>
      26             : 
      27             : namespace com
      28             : {
      29             : namespace sun
      30             : {
      31             : namespace star
      32             : {
      33             : namespace uno
      34             : {
      35             : 
      36             : //__________________________________________________________________________________________________
      37    14504533 : inline XInterface * BaseReference::iquery(
      38             :     XInterface * pInterface, const Type & rType )
      39             :     SAL_THROW( (RuntimeException) )
      40             : {
      41    14504533 :     if (pInterface)
      42             :     {
      43    12327412 :         Any aRet( pInterface->queryInterface( rType ) );
      44    12327411 :         if (typelib_TypeClass_INTERFACE == aRet.pType->eTypeClass)
      45             :         {
      46    11469530 :             XInterface * pRet = static_cast< XInterface * >( aRet.pReserved );
      47    11469530 :             aRet.pReserved = 0;
      48    11469530 :             return pRet;
      49      857881 :         }
      50             :     }
      51     3035002 :     return 0;
      52             : }
      53             : //__________________________________________________________________________________________________
      54             : template< class interface_type >
      55    13507383 : inline XInterface * Reference< interface_type >::iquery(
      56             :     XInterface * pInterface ) SAL_THROW( (RuntimeException) )
      57             : {
      58    13507383 :     return BaseReference::iquery(pInterface, interface_type::static_type());
      59             : }
      60             : #ifndef EXCEPTIONS_OFF
      61             : extern "C" rtl_uString * SAL_CALL cppu_unsatisfied_iquery_msg(
      62             :     typelib_TypeDescriptionReference * pType )
      63             :     SAL_THROW_EXTERN_C();
      64             : extern "C" rtl_uString * SAL_CALL cppu_unsatisfied_iset_msg(
      65             :     typelib_TypeDescriptionReference * pType )
      66             :     SAL_THROW_EXTERN_C();
      67             : //__________________________________________________________________________________________________
      68      997150 : inline XInterface * BaseReference::iquery_throw(
      69             :     XInterface * pInterface, const Type & rType )
      70             :     SAL_THROW( (RuntimeException) )
      71             : {
      72      997150 :     XInterface * pQueried = iquery( pInterface, rType );
      73      997150 :     if (pQueried)
      74     1973930 :         return pQueried;
      75             :     throw RuntimeException(
      76             :         ::rtl::OUString( cppu_unsatisfied_iquery_msg( rType.getTypeLibType() ), SAL_NO_ACQUIRE ),
      77       10185 :         Reference< XInterface >( pInterface ) );
      78             : }
      79             : //__________________________________________________________________________________________________
      80             : template< class interface_type >
      81      997150 : inline XInterface * Reference< interface_type >::iquery_throw(
      82             :     XInterface * pInterface ) SAL_THROW( (RuntimeException) )
      83             : {
      84             :     return BaseReference::iquery_throw(
      85      997150 :         pInterface, interface_type::static_type());
      86             : }
      87             : //__________________________________________________________________________________________________
      88             : template< class interface_type >
      89       31140 : inline interface_type * Reference< interface_type >::iset_throw(
      90             :     interface_type * pInterface ) SAL_THROW( (RuntimeException) )
      91             : {
      92       31140 :     if (pInterface)
      93             :     {
      94       29921 :         castToXInterface(pInterface)->acquire();
      95       59842 :         return pInterface;
      96             :     }
      97        2438 :     throw RuntimeException(
      98        1219 :         ::rtl::OUString( cppu_unsatisfied_iset_msg( interface_type::static_type().getTypeLibType() ), SAL_NO_ACQUIRE ),
      99        1219 :         NULL );
     100             : }
     101             : #endif
     102             : 
     103             : //__________________________________________________________________________________________________
     104             : template< class interface_type >
     105    94345347 : inline Reference< interface_type >::~Reference() SAL_THROW(())
     106             : {
     107    94345347 :     if (_pInterface)
     108    46425960 :         _pInterface->release();
     109    94345347 : }
     110             : //__________________________________________________________________________________________________
     111             : template< class interface_type >
     112    51658250 : inline Reference< interface_type >::Reference() SAL_THROW(())
     113             : {
     114    51658253 :     _pInterface = 0;
     115    51658253 : }
     116             : //__________________________________________________________________________________________________
     117             : template< class interface_type >
     118    16857920 : inline Reference< interface_type >::Reference( const Reference< interface_type > & rRef ) SAL_THROW(())
     119             : {
     120    16857921 :     _pInterface = rRef._pInterface;
     121    16857921 :     if (_pInterface)
     122    12864407 :         _pInterface->acquire();
     123    16857921 : }
     124             : //__________________________________________________________________________________________________
     125             : template< class interface_type > template< class derived_type >
     126      141282 : inline Reference< interface_type >::Reference(
     127             :     const Reference< derived_type > & rRef,
     128      141282 :     typename detail::UpCast< interface_type, derived_type >::t )
     129             :     SAL_THROW(())
     130             : {
     131      141282 :     interface_type * p = rRef.get();
     132      141282 :     _pInterface = p;
     133      141282 :     if (_pInterface)
     134      141281 :         _pInterface->acquire();
     135      141282 : }
     136             : //__________________________________________________________________________________________________
     137             : template< class interface_type >
     138    12374915 : inline Reference< interface_type >::Reference( interface_type * pInterface ) SAL_THROW(())
     139             : {
     140    12374915 :     _pInterface = castToXInterface(pInterface);
     141    12374915 :     if (_pInterface)
     142    11114908 :         _pInterface->acquire();
     143    12374915 : }
     144             : //__________________________________________________________________________________________________
     145             : template< class interface_type >
     146     2075961 : inline Reference< interface_type >::Reference( interface_type * pInterface, __sal_NoAcquire ) SAL_THROW(())
     147             : {
     148     2075961 :     _pInterface = castToXInterface(pInterface);
     149     2075961 : }
     150             : //__________________________________________________________________________________________________
     151             : template< class interface_type >
     152           2 : inline Reference< interface_type >::Reference( interface_type * pInterface, UnoReference_NoAcquire ) SAL_THROW(())
     153             : {
     154           2 :     _pInterface = castToXInterface(pInterface);
     155           2 : }
     156             : //__________________________________________________________________________________________________
     157             : template< class interface_type >
     158     8276549 : inline Reference< interface_type >::Reference( const BaseReference & rRef, UnoReference_Query ) SAL_THROW( (RuntimeException) )
     159             : {
     160     8276549 :     _pInterface = iquery( rRef.get() );
     161     8276549 : }
     162             : //__________________________________________________________________________________________________
     163             : template< class interface_type >
     164     1598225 : inline Reference< interface_type >::Reference( XInterface * pInterface, UnoReference_Query ) SAL_THROW( (RuntimeException) )
     165             : {
     166     1598225 :     _pInterface = iquery( pInterface );
     167     1598225 : }
     168             : //__________________________________________________________________________________________________
     169             : template< class interface_type >
     170      612280 : inline Reference< interface_type >::Reference( const Any & rAny, UnoReference_Query ) SAL_THROW( (RuntimeException) )
     171             : {
     172     1223396 :     _pInterface = (typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass
     173      611116 :                    ? iquery( static_cast< XInterface * >( rAny.pReserved ) ) : 0);
     174      612280 : }
     175             : #ifndef EXCEPTIONS_OFF
     176             : //__________________________________________________________________________________________________
     177             : template< class interface_type >
     178      581358 : inline Reference< interface_type >::Reference( const BaseReference & rRef, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
     179             : {
     180      581358 :     _pInterface = iquery_throw( rRef.get() );
     181      572528 : }
     182             : //__________________________________________________________________________________________________
     183             : template< class interface_type >
     184       62878 : inline Reference< interface_type >::Reference( XInterface * pInterface, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
     185             : {
     186       62878 :     _pInterface = iquery_throw( pInterface );
     187       62878 : }
     188             : //__________________________________________________________________________________________________
     189             : template< class interface_type >
     190      240216 : inline Reference< interface_type >::Reference( const Any & rAny, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
     191             : {
     192      239238 :     _pInterface = iquery_throw( typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass
     193      240216 :                                 ? static_cast< XInterface * >( rAny.pReserved ) : 0 );
     194      239238 : }
     195             : //__________________________________________________________________________________________________
     196             : template< class interface_type >
     197       28888 : inline Reference< interface_type >::Reference( const Reference< interface_type > & rRef, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) )
     198             : {
     199       28888 :     _pInterface = castToXInterface( iset_throw( rRef.get() ) );
     200       27682 : }
     201             : //__________________________________________________________________________________________________
     202             : template< class interface_type >
     203         476 : inline Reference< interface_type >::Reference( interface_type * pInterface, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) )
     204             : {
     205         476 :     _pInterface = castToXInterface( iset_throw( pInterface ) );
     206         475 : }
     207             : #endif
     208             : 
     209             : //__________________________________________________________________________________________________
     210             : template< class interface_type >
     211     2024690 : inline void Reference< interface_type >::clear() SAL_THROW(())
     212             : {
     213     2024690 :     if (_pInterface)
     214             :     {
     215      883330 :         XInterface * const pOld = _pInterface;
     216      883330 :         _pInterface = 0;
     217      883330 :         pOld->release();
     218             :     }
     219     2024690 : }
     220             : //__________________________________________________________________________________________________
     221             : template< class interface_type >
     222    18850640 : inline sal_Bool Reference< interface_type >::set(
     223             :     interface_type * pInterface ) SAL_THROW(())
     224             : {
     225    18850640 :     if (pInterface)
     226    17309518 :         castToXInterface(pInterface)->acquire();
     227    18850640 :     XInterface * const pOld = _pInterface;
     228    18850640 :     _pInterface = castToXInterface(pInterface);
     229    18850640 :     if (pOld)
     230      724335 :         pOld->release();
     231    18850640 :     return (0 != pInterface);
     232             : }
     233             : //__________________________________________________________________________________________________
     234             : template< class interface_type >
     235     1061247 : inline sal_Bool Reference< interface_type >::set(
     236             :     interface_type * pInterface, __sal_NoAcquire ) SAL_THROW(())
     237             : {
     238     1061247 :     XInterface * const pOld = _pInterface;
     239     1061247 :     _pInterface = castToXInterface(pInterface);
     240     1061247 :     if (pOld)
     241       38964 :         pOld->release();
     242     1061247 :     return (0 != pInterface);
     243             : }
     244             : //__________________________________________________________________________________________________
     245             : template< class interface_type >
     246             : inline sal_Bool Reference< interface_type >::set(
     247             :     interface_type * pInterface, UnoReference_NoAcquire ) SAL_THROW(())
     248             : {
     249             :     return set( pInterface, SAL_NO_ACQUIRE );
     250             : }
     251             : 
     252             : //__________________________________________________________________________________________________
     253             : template< class interface_type >
     254      327080 : inline sal_Bool Reference< interface_type >::set(
     255             :     const Reference< interface_type > & rRef ) SAL_THROW(())
     256             : {
     257      327080 :     return set( castFromXInterface( rRef._pInterface ) );
     258             : }
     259             : //__________________________________________________________________________________________________
     260             : template< class interface_type >
     261          47 : inline sal_Bool Reference< interface_type >::set(
     262             :     XInterface * pInterface, UnoReference_Query ) SAL_THROW( (RuntimeException) )
     263             : {
     264          47 :     return set( castFromXInterface(iquery( pInterface )), SAL_NO_ACQUIRE );
     265             : }
     266             : //__________________________________________________________________________________________________
     267             : template< class interface_type >
     268      128394 : inline sal_Bool Reference< interface_type >::set(
     269             :     const BaseReference & rRef, UnoReference_Query ) SAL_THROW( (RuntimeException) )
     270             : {
     271      128394 :     return set( castFromXInterface(iquery( rRef.get() )), SAL_NO_ACQUIRE );
     272             : }
     273             : 
     274             : //______________________________________________________________________________
     275             : template< class interface_type >
     276      818721 : inline bool Reference< interface_type >::set(
     277             :     Any const & rAny, UnoReference_Query )
     278             : {
     279             :     return set(
     280             :         castFromXInterface(
     281             :             iquery(
     282             :                 rAny.pType->eTypeClass == typelib_TypeClass_INTERFACE
     283             :                 ? static_cast< XInterface * >( rAny.pReserved ) : 0 )),
     284      818721 :         SAL_NO_ACQUIRE );
     285             : }
     286             : 
     287             : #ifndef EXCEPTIONS_OFF
     288             : //__________________________________________________________________________________________________
     289             : template< class interface_type >
     290           3 : inline void Reference< interface_type >::set(
     291             :     XInterface * pInterface, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
     292             : {
     293           3 :     set( castFromXInterface(iquery_throw( pInterface )), SAL_NO_ACQUIRE );
     294           3 : }
     295             : //__________________________________________________________________________________________________
     296             : template< class interface_type >
     297      109558 : inline void Reference< interface_type >::set(
     298             :     const BaseReference & rRef, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
     299             : {
     300      109558 :     set( castFromXInterface(iquery_throw( rRef.get() )), SAL_NO_ACQUIRE );
     301      109181 : }
     302             : 
     303             : //______________________________________________________________________________
     304             : template< class interface_type >
     305        3137 : inline void Reference< interface_type >::set(
     306             :     Any const & rAny, UnoReference_QueryThrow )
     307             : {
     308        3137 :     set( castFromXInterface(
     309             :              iquery_throw(
     310             :                  rAny.pType->eTypeClass == typelib_TypeClass_INTERFACE
     311             :                  ? static_cast< XInterface * >( rAny.pReserved ) : 0 )),
     312        3137 :          SAL_NO_ACQUIRE );
     313        3137 : }
     314             : //__________________________________________________________________________________________________
     315             : template< class interface_type >
     316        1776 : inline void Reference< interface_type >::set(
     317             :     interface_type * pInterface, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) )
     318             : {
     319        1776 :     set( iset_throw( pInterface ), SAL_NO_ACQUIRE );
     320        1764 : }
     321             : //__________________________________________________________________________________________________
     322             : template< class interface_type >
     323        1774 : inline void Reference< interface_type >::set(
     324             :     const Reference< interface_type > & rRef, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) )
     325             : {
     326        1774 :     set( rRef.get(), UNO_SET_THROW );
     327        1763 : }
     328             : 
     329             : #endif
     330             : 
     331             : //__________________________________________________________________________________________________
     332             : template< class interface_type >
     333     1935684 : inline Reference< interface_type > & Reference< interface_type >::operator = (
     334             :     interface_type * pInterface ) SAL_THROW(())
     335             : {
     336     1935684 :     set( pInterface );
     337     1935684 :     return *this;
     338             : }
     339             : //__________________________________________________________________________________________________
     340             : template< class interface_type >
     341    16532880 : inline Reference< interface_type > & Reference< interface_type >::operator = (
     342             :     const Reference< interface_type > & rRef ) SAL_THROW(())
     343             : {
     344    16532880 :     set( castFromXInterface( rRef._pInterface ) );
     345    16532880 :     return *this;
     346             : }
     347             : 
     348             : //__________________________________________________________________________________________________
     349             : template< class interface_type >
     350     2056682 : inline Reference< interface_type > Reference< interface_type >::query(
     351             :     const BaseReference & rRef ) SAL_THROW( (RuntimeException) )
     352             : {
     353             :     return Reference< interface_type >(
     354     2056682 :         castFromXInterface(iquery( rRef.get() )), SAL_NO_ACQUIRE );
     355             : }
     356             : //__________________________________________________________________________________________________
     357             : template< class interface_type >
     358       17649 : inline Reference< interface_type > Reference< interface_type >::query(
     359             :     XInterface * pInterface ) SAL_THROW( (RuntimeException) )
     360             : {
     361             :     return Reference< interface_type >(
     362       17649 :         castFromXInterface(iquery( pInterface )), SAL_NO_ACQUIRE );
     363             : }
     364             : 
     365             : //##################################################################################################
     366             : 
     367             : //__________________________________________________________________________________________________
     368      925854 : inline sal_Bool BaseReference::operator == ( XInterface * pInterface ) const SAL_THROW(())
     369             : {
     370      925854 :     if (_pInterface == pInterface)
     371      605008 :         return sal_True;
     372             : #ifndef EXCEPTIONS_OFF
     373             :     try
     374             :     {
     375             : #endif
     376             :         // only the query to XInterface must return the same pointer if they belong to same objects
     377      320846 :         Reference< XInterface > x1( _pInterface, UNO_QUERY );
     378      641692 :         Reference< XInterface > x2( pInterface, UNO_QUERY );
     379      641692 :         return (x1._pInterface == x2._pInterface);
     380             : #ifndef EXCEPTIONS_OFF
     381             :     }
     382           0 :     catch (RuntimeException &)
     383             :     {
     384           0 :         return sal_False;
     385             :     }
     386             : #endif
     387             : }
     388             : 
     389             : //______________________________________________________________________________
     390       75225 : inline sal_Bool BaseReference::operator < (
     391             :     const BaseReference & rRef ) const SAL_THROW(())
     392             : {
     393       75225 :     if (_pInterface == rRef._pInterface)
     394       39320 :         return sal_False;
     395             : #if ! defined EXCEPTIONS_OFF
     396             :     try
     397             :     {
     398             : #endif
     399             :         // only the query to XInterface must return the same pointer:
     400       35905 :         Reference< XInterface > x1( _pInterface, UNO_QUERY );
     401       71810 :         Reference< XInterface > x2( rRef, UNO_QUERY );
     402       71810 :         return (x1._pInterface < x2._pInterface);
     403             : #if ! defined EXCEPTIONS_OFF
     404             :     }
     405           0 :     catch (RuntimeException &)
     406             :     {
     407           0 :         return sal_False;
     408             :     }
     409             : #endif
     410             : }
     411             : 
     412             : //__________________________________________________________________________________________________
     413         888 : inline sal_Bool BaseReference::operator != ( XInterface * pInterface ) const SAL_THROW(())
     414             : {
     415         888 :     return (! operator == ( pInterface ));
     416             : }
     417             : //__________________________________________________________________________________________________
     418      820380 : inline sal_Bool BaseReference::operator == ( const BaseReference & rRef ) const SAL_THROW(())
     419             : {
     420      820380 :     return operator == ( rRef._pInterface );
     421             : }
     422             : //__________________________________________________________________________________________________
     423      104042 : inline sal_Bool BaseReference::operator != ( const BaseReference & rRef ) const SAL_THROW(())
     424             : {
     425      104042 :     return (! operator == ( rRef._pInterface ));
     426             : }
     427             : 
     428             : }
     429             : }
     430             : }
     431             : }
     432             : 
     433             : #endif
     434             : 
     435             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10