LCOV - code coverage report
Current view: top level - include/com/sun/star/uno - Reference.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 155 159 97.5 %
Date: 2015-06-13 12:38:46 Functions: 7487 11081 67.6 %
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 INCLUDED_COM_SUN_STAR_UNO_REFERENCE_HXX
      20             : #define INCLUDED_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/Any.hxx>
      26             : #include <cppu/cppudllapi.h>
      27             : 
      28             : extern "C" CPPU_DLLPUBLIC rtl_uString * SAL_CALL cppu_unsatisfied_iquery_msg(
      29             :     typelib_TypeDescriptionReference * pType )
      30             :     SAL_THROW_EXTERN_C();
      31             : extern "C" CPPU_DLLPUBLIC rtl_uString * SAL_CALL cppu_unsatisfied_iset_msg(
      32             :     typelib_TypeDescriptionReference * pType )
      33             :     SAL_THROW_EXTERN_C();
      34             : 
      35             : namespace com
      36             : {
      37             : namespace sun
      38             : {
      39             : namespace star
      40             : {
      41             : namespace uno
      42             : {
      43             : 
      44             : 
      45  1934009941 : inline XInterface * BaseReference::iquery(
      46             :     XInterface * pInterface, const Type & rType )
      47             : {
      48  1934009941 :     if (pInterface)
      49             :     {
      50  1928796922 :         Any aRet( pInterface->queryInterface( rType ) );
      51  1928796919 :         if (typelib_TypeClass_INTERFACE == aRet.pType->eTypeClass)
      52             :         {
      53  1926305152 :             XInterface * pRet = static_cast< XInterface * >( aRet.pReserved );
      54  1926305152 :             aRet.pReserved = 0;
      55  1926305152 :             return pRet;
      56     2491767 :         }
      57             :     }
      58     7704786 :     return 0;
      59             : }
      60             : 
      61             : template< class interface_type >
      62  1823325284 : inline XInterface * Reference< interface_type >::iquery(
      63             :     XInterface * pInterface )
      64             : {
      65  1823325284 :     return BaseReference::iquery(pInterface, interface_type::static_type());
      66             : }
      67             : 
      68   110684657 : inline XInterface * BaseReference::iquery_throw(
      69             :     XInterface * pInterface, const Type & rType )
      70             : {
      71   110684657 :     XInterface * pQueried = iquery( pInterface, rType );
      72   110684657 :     if (pQueried)
      73   221274422 :         return pQueried;
      74             :     throw RuntimeException(
      75             :         ::rtl::OUString( cppu_unsatisfied_iquery_msg( rType.getTypeLibType() ), SAL_NO_ACQUIRE ),
      76       47446 :         Reference< XInterface >( pInterface ) );
      77             : }
      78             : 
      79             : template< class interface_type >
      80   110684657 : inline XInterface * Reference< interface_type >::iquery_throw(
      81             :     XInterface * pInterface )
      82             : {
      83             :     return BaseReference::iquery_throw(
      84   110684657 :         pInterface, interface_type::static_type());
      85             : }
      86             : 
      87             : template< class interface_type >
      88      135313 : inline interface_type * Reference< interface_type >::iset_throw(
      89             :     interface_type * pInterface )
      90             : {
      91      135313 :     if (pInterface)
      92             :     {
      93      131587 :         castToXInterface(pInterface)->acquire();
      94      263174 :         return pInterface;
      95             :     }
      96        7452 :     throw RuntimeException(
      97        3726 :         ::rtl::OUString( cppu_unsatisfied_iset_msg( interface_type::static_type().getTypeLibType() ), SAL_NO_ACQUIRE ),
      98        3726 :         NULL );
      99             : }
     100             : 
     101             : 
     102             : template< class interface_type >
     103  6712885830 : inline Reference< interface_type >::~Reference()
     104             : {
     105  6712885830 :     if (_pInterface)
     106  5708029659 :         _pInterface->release();
     107  6712885839 : }
     108             : 
     109             : template< class interface_type >
     110  2152706739 : inline Reference< interface_type >::Reference()
     111             : {
     112  2152706731 :     _pInterface = 0;
     113  2152706731 : }
     114             : 
     115             : template< class interface_type >
     116  2568935381 : inline Reference< interface_type >::Reference( const Reference< interface_type > & rRef )
     117             : {
     118  2568935381 :     _pInterface = rRef._pInterface;
     119  2568935381 :     if (_pInterface)
     120  2417355513 :         _pInterface->acquire();
     121  2568935388 : }
     122             : 
     123             : template< class interface_type > template< class derived_type >
     124   171229821 : inline Reference< interface_type >::Reference(
     125             :     const Reference< derived_type > & rRef,
     126   171229821 :     typename detail::UpCast< interface_type, derived_type >::t )
     127             : {
     128   171229821 :     interface_type * p = rRef.get();
     129   171229821 :     _pInterface = p;
     130   171229821 :     if (_pInterface)
     131   171229820 :         _pInterface->acquire();
     132   171229821 : }
     133             : 
     134             : template< class interface_type >
     135   164341468 : inline Reference< interface_type >::Reference( interface_type * pInterface )
     136             : {
     137   164341468 :     _pInterface = castToXInterface(pInterface);
     138   164341469 :     if (_pInterface)
     139   137773224 :         _pInterface->acquire();
     140   164341472 : }
     141             : 
     142             : template< class interface_type >
     143    10334868 : inline Reference< interface_type >::Reference( interface_type * pInterface, __sal_NoAcquire )
     144             : {
     145    10334868 :     _pInterface = castToXInterface(pInterface);
     146    10334868 : }
     147             : 
     148             : template< class interface_type >
     149           2 : inline Reference< interface_type >::Reference( interface_type * pInterface, UnoReference_NoAcquire )
     150             : {
     151           2 :     _pInterface = castToXInterface(pInterface);
     152           2 : }
     153             : 
     154             : template< class interface_type >
     155  1581701253 : inline Reference< interface_type >::Reference( const BaseReference & rRef, UnoReference_Query )
     156             : {
     157  1581701253 :     _pInterface = iquery( rRef.get() );
     158  1581701253 : }
     159             : 
     160             : template< class interface_type >
     161     5931487 : inline Reference< interface_type >::Reference( XInterface * pInterface, UnoReference_Query )
     162             : {
     163     5931487 :     _pInterface = iquery( pInterface );
     164     5931486 : }
     165             : 
     166             : template< class interface_type >
     167     1224701 : inline Reference< interface_type >::Reference( const Any & rAny, UnoReference_Query )
     168             : {
     169     2440722 :     _pInterface = (typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass
     170     1216021 :                    ? iquery( static_cast< XInterface * >( rAny.pReserved ) ) : 0);
     171     1224701 : }
     172             : 
     173             : template< class interface_type >
     174    56057165 : inline Reference< interface_type >::Reference( const BaseReference & rRef, UnoReference_QueryThrow )
     175             : {
     176    56057165 :     _pInterface = iquery_throw( rRef.get() );
     177    56014620 : }
     178             : 
     179             : template< class interface_type >
     180      212687 : inline Reference< interface_type >::Reference( XInterface * pInterface, UnoReference_QueryThrow )
     181             : {
     182      212687 :     _pInterface = iquery_throw( pInterface );
     183      212687 : }
     184             : 
     185             : template< class interface_type >
     186      405752 : inline Reference< interface_type >::Reference( const Any & rAny, UnoReference_QueryThrow )
     187             : {
     188      403464 :     _pInterface = iquery_throw( typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass
     189      405752 :                                 ? static_cast< XInterface * >( rAny.pReserved ) : 0 );
     190      403464 : }
     191             : 
     192             : template< class interface_type >
     193      129379 : inline Reference< interface_type >::Reference( const Reference< interface_type > & rRef, UnoReference_SetThrow )
     194             : {
     195      129379 :     _pInterface = castToXInterface( iset_throw( rRef.get() ) );
     196      125664 : }
     197             : 
     198             : template< class interface_type >
     199         547 : inline Reference< interface_type >::Reference( interface_type * pInterface, UnoReference_SetThrow )
     200             : {
     201         547 :     _pInterface = castToXInterface( iset_throw( pInterface ) );
     202         546 : }
     203             : 
     204             : 
     205             : template< class interface_type >
     206     9006694 : inline void Reference< interface_type >::clear()
     207             : {
     208     9006694 :     if (_pInterface)
     209             :     {
     210     7103281 :         XInterface * const pOld = _pInterface;
     211     7103281 :         _pInterface = 0;
     212     7103281 :         pOld->release();
     213             :     }
     214     9006694 : }
     215             : 
     216             : template< class interface_type >
     217  2773051418 : inline bool Reference< interface_type >::set(
     218             :     interface_type * pInterface )
     219             : {
     220  2773051418 :     if (pInterface)
     221  2087809675 :         castToXInterface(pInterface)->acquire();
     222  2773051420 :     XInterface * const pOld = _pInterface;
     223  2773051420 :     _pInterface = castToXInterface(pInterface);
     224  2773051418 :     if (pOld)
     225     3569318 :         pOld->release();
     226  2773051418 :     return (0 != pInterface);
     227             : }
     228             : 
     229             : template< class interface_type >
     230   281925021 : inline bool Reference< interface_type >::set(
     231             :     interface_type * pInterface, __sal_NoAcquire )
     232             : {
     233   281925021 :     XInterface * const pOld = _pInterface;
     234   281925021 :     _pInterface = castToXInterface(pInterface);
     235   281925021 :     if (pOld)
     236    55816355 :         pOld->release();
     237   281925023 :     return (0 != pInterface);
     238             : }
     239             : 
     240             : template< class interface_type >
     241     2348359 : inline bool Reference< interface_type >::set(
     242             :     interface_type * pInterface, UnoReference_NoAcquire )
     243             : {
     244     2348359 :     return set( pInterface, SAL_NO_ACQUIRE );
     245             : }
     246             : 
     247             : 
     248             : template< class interface_type >
     249     5243026 : inline bool Reference< interface_type >::set(
     250             :     const Reference< interface_type > & rRef )
     251             : {
     252     5243026 :     return set( castFromXInterface( rRef._pInterface ) );
     253             : }
     254             : 
     255             : template< class interface_type >
     256       30085 : inline bool Reference< interface_type >::set(
     257             :     XInterface * pInterface, UnoReference_Query )
     258             : {
     259       30085 :     return set( castFromXInterface(iquery( pInterface )), SAL_NO_ACQUIRE );
     260             : }
     261             : 
     262             : template< class interface_type >
     263     1016139 : inline bool Reference< interface_type >::set(
     264             :     const BaseReference & rRef, UnoReference_Query )
     265             : {
     266     1016139 :     return set( castFromXInterface(iquery( rRef.get() )), SAL_NO_ACQUIRE );
     267             : }
     268             : 
     269             : 
     270             : template< class interface_type >
     271   223105664 : inline bool Reference< interface_type >::set(
     272             :     Any const & rAny, UnoReference_Query )
     273             : {
     274             :     return set(
     275             :         castFromXInterface(
     276             :             iquery(
     277             :                 rAny.pType->eTypeClass == typelib_TypeClass_INTERFACE
     278             :                 ? static_cast< XInterface * >( rAny.pReserved ) : 0 )),
     279   223105664 :         SAL_NO_ACQUIRE );
     280             : }
     281             : 
     282             : 
     283             : template< class interface_type >
     284          35 : inline void Reference< interface_type >::set(
     285             :     XInterface * pInterface, UnoReference_QueryThrow )
     286             : {
     287          35 :     set( castFromXInterface(iquery_throw( pInterface )), SAL_NO_ACQUIRE );
     288          35 : }
     289             : 
     290             : template< class interface_type >
     291      548767 : inline void Reference< interface_type >::set(
     292             :     const BaseReference & rRef, UnoReference_QueryThrow )
     293             : {
     294      548767 :     set( castFromXInterface(iquery_throw( rRef.get() )), SAL_NO_ACQUIRE );
     295      546154 : }
     296             : 
     297             : 
     298             : template< class interface_type >
     299    53460251 : inline void Reference< interface_type >::set(
     300             :     Any const & rAny, UnoReference_QueryThrow )
     301             : {
     302    53460251 :     set( castFromXInterface(
     303             :              iquery_throw(
     304             :                  rAny.pType->eTypeClass == typelib_TypeClass_INTERFACE
     305             :                  ? static_cast< XInterface * >( rAny.pReserved ) : 0 )),
     306    53460251 :          SAL_NO_ACQUIRE );
     307    53460251 : }
     308             : 
     309             : template< class interface_type >
     310        5387 : inline void Reference< interface_type >::set(
     311             :     interface_type * pInterface, UnoReference_SetThrow )
     312             : {
     313        5387 :     set( iset_throw( pInterface ), SAL_NO_ACQUIRE );
     314        5377 : }
     315             : 
     316             : template< class interface_type >
     317        5385 : inline void Reference< interface_type >::set(
     318             :     const Reference< interface_type > & rRef, UnoReference_SetThrow )
     319             : {
     320        5385 :     set( rRef.get(), UNO_SET_THROW );
     321        5376 : }
     322             : 
     323             : 
     324             : template< class interface_type >
     325   297540546 : inline Reference< interface_type > & Reference< interface_type >::operator = (
     326             :     interface_type * pInterface )
     327             : {
     328   297540546 :     set( pInterface );
     329   297540546 :     return *this;
     330             : }
     331             : 
     332             : template< class interface_type >
     333  2467592092 : inline Reference< interface_type > & Reference< interface_type >::operator = (
     334             :     const Reference< interface_type > & rRef )
     335             : {
     336  2467592092 :     set( castFromXInterface( rRef._pInterface ) );
     337  2467592091 :     return *this;
     338             : }
     339             : 
     340             : 
     341             : template< class interface_type >
     342    10299116 : inline Reference< interface_type > Reference< interface_type >::query(
     343             :     const BaseReference & rRef )
     344             : {
     345             :     return Reference< interface_type >(
     346    10299116 :         castFromXInterface(iquery( rRef.get() )), SAL_NO_ACQUIRE );
     347             : }
     348             : 
     349             : template< class interface_type >
     350       25519 : inline Reference< interface_type > Reference< interface_type >::query(
     351             :     XInterface * pInterface )
     352             : {
     353             :     return Reference< interface_type >(
     354       25519 :         castFromXInterface(iquery( pInterface )), SAL_NO_ACQUIRE );
     355             : }
     356             : 
     357             : 
     358             : 
     359             : 
     360     4544433 : inline bool BaseReference::operator == ( XInterface * pInterface ) const
     361             : {
     362     4544433 :     if (_pInterface == pInterface)
     363     2672467 :         return true;
     364             :     try
     365             :     {
     366             :         // only the query to XInterface must return the same pointer if they belong to same objects
     367     1871966 :         Reference< XInterface > x1( _pInterface, UNO_QUERY );
     368     3743932 :         Reference< XInterface > x2( pInterface, UNO_QUERY );
     369     3743932 :         return (x1._pInterface == x2._pInterface);
     370             :     }
     371           0 :     catch (RuntimeException &)
     372             :     {
     373           0 :         return false;
     374             :     }
     375             : }
     376             : 
     377             : 
     378      239309 : inline bool BaseReference::operator < (
     379             :     const BaseReference & rRef ) const
     380             : {
     381      239309 :     if (_pInterface == rRef._pInterface)
     382      123340 :         return false;
     383             :     try
     384             :     {
     385             :         // only the query to XInterface must return the same pointer:
     386      115969 :         Reference< XInterface > x1( _pInterface, UNO_QUERY );
     387      231938 :         Reference< XInterface > x2( rRef, UNO_QUERY );
     388      231938 :         return (x1._pInterface < x2._pInterface);
     389             :     }
     390           0 :     catch (RuntimeException &)
     391             :     {
     392           0 :         return false;
     393             :     }
     394             : }
     395             : 
     396             : 
     397         886 : inline bool BaseReference::operator != ( XInterface * pInterface ) const
     398             : {
     399         886 :     return (! operator == ( pInterface ));
     400             : }
     401             : 
     402     4249840 : inline bool BaseReference::operator == ( const BaseReference & rRef ) const
     403             : {
     404     4249840 :     return operator == ( rRef._pInterface );
     405             : }
     406             : 
     407      291457 : inline bool BaseReference::operator != ( const BaseReference & rRef ) const
     408             : {
     409      291457 :     return (! operator == ( rRef._pInterface ));
     410             : }
     411             : 
     412             : }
     413             : }
     414             : }
     415             : }
     416             : 
     417             : #endif
     418             : 
     419             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11