LCOV - code coverage report
Current view: top level - libreoffice/solver/unxlngi6.pro/inc/com/sun/star/uno - Reference.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 135 145 93.1 %
Date: 2012-12-27 Functions: 3973 10859 36.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 _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     2081936 : inline XInterface * BaseReference::iquery(
      38             :     XInterface * pInterface, const Type & rType )
      39             :     SAL_THROW( (RuntimeException) )
      40             : {
      41     2081936 :     if (pInterface)
      42             :     {
      43     1933519 :         Any aRet( pInterface->queryInterface( rType ) );
      44     1933519 :         if (typelib_TypeClass_INTERFACE == aRet.pType->eTypeClass)
      45             :         {
      46     1790488 :             XInterface * pRet = static_cast< XInterface * >( aRet.pReserved );
      47     1790488 :             aRet.pReserved = 0;
      48     1790488 :             return pRet;
      49     1933519 :         }
      50             :     }
      51      291448 :     return 0;
      52             : }
      53             : //__________________________________________________________________________________________________
      54             : template< class interface_type >
      55     1913221 : inline XInterface * Reference< interface_type >::iquery(
      56             :     XInterface * pInterface ) SAL_THROW( (RuntimeException) )
      57             : {
      58     1913221 :     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      168715 : inline XInterface * BaseReference::iquery_throw(
      69             :     XInterface * pInterface, const Type & rType )
      70             :     SAL_THROW( (RuntimeException) )
      71             : {
      72      168715 :     XInterface * pQueried = iquery( pInterface, rType );
      73      168715 :     if (pQueried)
      74      332648 :         return pQueried;
      75             :     throw RuntimeException(
      76             :         ::rtl::OUString( cppu_unsatisfied_iquery_msg( rType.getTypeLibType() ), SAL_NO_ACQUIRE ),
      77        2391 :         Reference< XInterface >( pInterface ) );
      78             : }
      79             : //__________________________________________________________________________________________________
      80             : template< class interface_type >
      81      168715 : inline XInterface * Reference< interface_type >::iquery_throw(
      82             :     XInterface * pInterface ) SAL_THROW( (RuntimeException) )
      83             : {
      84             :     return BaseReference::iquery_throw(
      85      168715 :         pInterface, interface_type::static_type());
      86             : }
      87             : //__________________________________________________________________________________________________
      88             : template< class interface_type >
      89        6247 : inline interface_type * Reference< interface_type >::iset_throw(
      90             :     interface_type * pInterface ) SAL_THROW( (RuntimeException) )
      91             : {
      92        6247 :     if (pInterface)
      93             :     {
      94        6222 :         castToXInterface(pInterface)->acquire();
      95       12444 :         return pInterface;
      96             :     }
      97             :     throw RuntimeException(
      98             :         ::rtl::OUString( cppu_unsatisfied_iset_msg( interface_type::static_type().getTypeLibType() ), SAL_NO_ACQUIRE ),
      99          25 :         NULL );
     100             : }
     101             : #endif
     102             : 
     103             : //__________________________________________________________________________________________________
     104             : template< class interface_type >
     105    11779459 : inline Reference< interface_type >::~Reference() SAL_THROW(())
     106             : {
     107    11779459 :     if (_pInterface)
     108     7293600 :         _pInterface->release();
     109    11779459 : }
     110             : //__________________________________________________________________________________________________
     111             : template< class interface_type >
     112     5195817 : inline Reference< interface_type >::Reference() SAL_THROW(())
     113             : {
     114     5195817 :     _pInterface = 0;
     115     5195817 : }
     116             : //__________________________________________________________________________________________________
     117             : template< class interface_type >
     118     2847222 : inline Reference< interface_type >::Reference( const Reference< interface_type > & rRef ) SAL_THROW(())
     119             : {
     120     2847222 :     _pInterface = rRef._pInterface;
     121     2847222 :     if (_pInterface)
     122     2093837 :         _pInterface->acquire();
     123     2847222 : }
     124             : //__________________________________________________________________________________________________
     125             : template< class interface_type >
     126     1902828 : inline Reference< interface_type >::Reference( interface_type * pInterface ) SAL_THROW(())
     127             : {
     128     1902828 :     _pInterface = castToXInterface(pInterface);
     129     1902828 :     if (_pInterface)
     130     1697378 :         _pInterface->acquire();
     131     1902828 : }
     132             : //__________________________________________________________________________________________________
     133             : template< class interface_type >
     134      251894 : inline Reference< interface_type >::Reference( interface_type * pInterface, __sal_NoAcquire ) SAL_THROW(())
     135             : {
     136      251894 :     _pInterface = castToXInterface(pInterface);
     137      251894 : }
     138             : //__________________________________________________________________________________________________
     139             : template< class interface_type >
     140           0 : inline Reference< interface_type >::Reference( interface_type * pInterface, UnoReference_NoAcquire ) SAL_THROW(())
     141             : {
     142           0 :     _pInterface = castToXInterface(pInterface);
     143           0 : }
     144             : //__________________________________________________________________________________________________
     145             : template< class interface_type >
     146     1282011 : inline Reference< interface_type >::Reference( const BaseReference & rRef, UnoReference_Query ) SAL_THROW( (RuntimeException) )
     147             : {
     148     1282011 :     _pInterface = iquery( rRef.get() );
     149     1282011 : }
     150             : //__________________________________________________________________________________________________
     151             : template< class interface_type >
     152      257548 : inline Reference< interface_type >::Reference( XInterface * pInterface, UnoReference_Query ) SAL_THROW( (RuntimeException) )
     153             : {
     154      257548 :     _pInterface = iquery( pInterface );
     155      257548 : }
     156             : //__________________________________________________________________________________________________
     157             : template< class interface_type >
     158        5443 : inline Reference< interface_type >::Reference( const Any & rAny, UnoReference_Query ) SAL_THROW( (RuntimeException) )
     159             : {
     160        5443 :     _pInterface = (typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass
     161             :                    ? iquery( static_cast< XInterface * >( rAny.pReserved ) ) : 0);
     162        5443 : }
     163             : #ifndef EXCEPTIONS_OFF
     164             : //__________________________________________________________________________________________________
     165             : template< class interface_type >
     166      115993 : inline Reference< interface_type >::Reference( const BaseReference & rRef, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
     167             : {
     168      115993 :     _pInterface = iquery_throw( rRef.get() );
     169      114188 : }
     170             : //__________________________________________________________________________________________________
     171             : template< class interface_type >
     172       12667 : inline Reference< interface_type >::Reference( XInterface * pInterface, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
     173             : {
     174       12667 :     _pInterface = iquery_throw( pInterface );
     175       12667 : }
     176             : //__________________________________________________________________________________________________
     177             : template< class interface_type >
     178        9746 : inline Reference< interface_type >::Reference( const Any & rAny, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
     179             : {
     180        9746 :     _pInterface = iquery_throw( typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass
     181             :                                 ? static_cast< XInterface * >( rAny.pReserved ) : 0 );
     182        9524 : }
     183             : //__________________________________________________________________________________________________
     184             : template< class interface_type >
     185        6117 : inline Reference< interface_type >::Reference( const Reference< interface_type > & rRef, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) )
     186             : {
     187        6117 :     _pInterface = castToXInterface( iset_throw( rRef.get() ) );
     188        6095 : }
     189             : //__________________________________________________________________________________________________
     190             : template< class interface_type >
     191           2 : inline Reference< interface_type >::Reference( interface_type * pInterface, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) )
     192             : {
     193           2 :     _pInterface = castToXInterface( iset_throw( pInterface ) );
     194           1 : }
     195             : #endif
     196             : 
     197             : //__________________________________________________________________________________________________
     198             : template< class interface_type >
     199      165676 : inline void Reference< interface_type >::clear() SAL_THROW(())
     200             : {
     201      165676 :     if (_pInterface)
     202             :     {
     203      143944 :         XInterface * const pOld = _pInterface;
     204      143944 :         _pInterface = 0;
     205      143944 :         pOld->release();
     206             :     }
     207      165676 : }
     208             : //__________________________________________________________________________________________________
     209             : template< class interface_type >
     210     2613992 : inline sal_Bool Reference< interface_type >::set(
     211             :     interface_type * pInterface ) SAL_THROW(())
     212             : {
     213     2613992 :     if (pInterface)
     214     2313104 :         castToXInterface(pInterface)->acquire();
     215     2613992 :     XInterface * const pOld = _pInterface;
     216     2613992 :     _pInterface = castToXInterface(pInterface);
     217     2613992 :     if (pOld)
     218      190963 :         pOld->release();
     219     2613992 :     return (0 != pInterface);
     220             : }
     221             : //__________________________________________________________________________________________________
     222             : template< class interface_type >
     223      147767 : inline sal_Bool Reference< interface_type >::set(
     224             :     interface_type * pInterface, __sal_NoAcquire ) SAL_THROW(())
     225             : {
     226      147767 :     XInterface * const pOld = _pInterface;
     227      147767 :     _pInterface = castToXInterface(pInterface);
     228      147767 :     if (pOld)
     229        6191 :         pOld->release();
     230      147767 :     return (0 != pInterface);
     231             : }
     232             : //__________________________________________________________________________________________________
     233             : template< class interface_type >
     234             : inline sal_Bool Reference< interface_type >::set(
     235             :     interface_type * pInterface, UnoReference_NoAcquire ) SAL_THROW(())
     236             : {
     237             :     return set( pInterface, SAL_NO_ACQUIRE );
     238             : }
     239             : 
     240             : //__________________________________________________________________________________________________
     241             : template< class interface_type >
     242       68544 : inline sal_Bool Reference< interface_type >::set(
     243             :     const Reference< interface_type > & rRef ) SAL_THROW(())
     244             : {
     245       68544 :     return set( castFromXInterface( rRef._pInterface ) );
     246             : }
     247             : //__________________________________________________________________________________________________
     248             : template< class interface_type >
     249           3 : inline sal_Bool Reference< interface_type >::set(
     250             :     XInterface * pInterface, UnoReference_Query ) SAL_THROW( (RuntimeException) )
     251             : {
     252           3 :     return set( castFromXInterface(iquery( pInterface )), SAL_NO_ACQUIRE );
     253             : }
     254             : //__________________________________________________________________________________________________
     255             : template< class interface_type >
     256       10446 : inline sal_Bool Reference< interface_type >::set(
     257             :     const BaseReference & rRef, UnoReference_Query ) SAL_THROW( (RuntimeException) )
     258             : {
     259       10446 :     return set( castFromXInterface(iquery( rRef.get() )), SAL_NO_ACQUIRE );
     260             : }
     261             : 
     262             : //______________________________________________________________________________
     263             : template< class interface_type >
     264      107247 : inline bool Reference< interface_type >::set(
     265             :     Any const & rAny, UnoReference_Query )
     266             : {
     267             :     return set(
     268             :         castFromXInterface(
     269             :             iquery(
     270             :                 rAny.pType->eTypeClass == typelib_TypeClass_INTERFACE
     271             :                 ? static_cast< XInterface * >( rAny.pReserved ) : 0 )),
     272      107247 :         SAL_NO_ACQUIRE );
     273             : }
     274             : 
     275             : #ifndef EXCEPTIONS_OFF
     276             : //__________________________________________________________________________________________________
     277             : template< class interface_type >
     278           0 : inline void Reference< interface_type >::set(
     279             :     XInterface * pInterface, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
     280             : {
     281           0 :     set( castFromXInterface(iquery_throw( pInterface )), SAL_NO_ACQUIRE );
     282           0 : }
     283             : //__________________________________________________________________________________________________
     284             : template< class interface_type >
     285       29225 : inline void Reference< interface_type >::set(
     286             :     const BaseReference & rRef, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
     287             : {
     288       29225 :     set( castFromXInterface(iquery_throw( rRef.get() )), SAL_NO_ACQUIRE );
     289       28861 : }
     290             : 
     291             : //______________________________________________________________________________
     292             : template< class interface_type >
     293        1084 : inline void Reference< interface_type >::set(
     294             :     Any const & rAny, UnoReference_QueryThrow )
     295             : {
     296        1084 :     set( castFromXInterface(
     297             :              iquery_throw(
     298             :                  rAny.pType->eTypeClass == typelib_TypeClass_INTERFACE
     299             :                  ? static_cast< XInterface * >( rAny.pReserved ) : 0 )),
     300             :          SAL_NO_ACQUIRE );
     301        1084 : }
     302             : //__________________________________________________________________________________________________
     303             : template< class interface_type >
     304         128 : inline void Reference< interface_type >::set(
     305             :     interface_type * pInterface, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) )
     306             : {
     307         128 :     set( iset_throw( pInterface ), SAL_NO_ACQUIRE );
     308         126 : }
     309             : //__________________________________________________________________________________________________
     310             : template< class interface_type >
     311         126 : inline void Reference< interface_type >::set(
     312             :     const Reference< interface_type > & rRef, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) )
     313             : {
     314         126 :     set( rRef.get(), UNO_SET_THROW );
     315         125 : }
     316             : 
     317             : #endif
     318             : 
     319             : //__________________________________________________________________________________________________
     320             : template< class interface_type >
     321      184003 : inline Reference< interface_type > & Reference< interface_type >::operator = (
     322             :     interface_type * pInterface ) SAL_THROW(())
     323             : {
     324      184003 :     set( pInterface );
     325      184003 :     return *this;
     326             : }
     327             : //__________________________________________________________________________________________________
     328             : template< class interface_type >
     329     2336977 : inline Reference< interface_type > & Reference< interface_type >::operator = (
     330             :     const Reference< interface_type > & rRef ) SAL_THROW(())
     331             : {
     332     2336977 :     set( castFromXInterface( rRef._pInterface ) );
     333     2336977 :     return *this;
     334             : }
     335             : 
     336             : //__________________________________________________________________________________________________
     337             : template< class interface_type >
     338      245180 : inline Reference< interface_type > Reference< interface_type >::query(
     339             :     const BaseReference & rRef ) SAL_THROW( (RuntimeException) )
     340             : {
     341             :     return Reference< interface_type >(
     342      245180 :         castFromXInterface(iquery( rRef.get() )), SAL_NO_ACQUIRE );
     343             : }
     344             : //__________________________________________________________________________________________________
     345             : template< class interface_type >
     346        5676 : inline Reference< interface_type > Reference< interface_type >::query(
     347             :     XInterface * pInterface ) SAL_THROW( (RuntimeException) )
     348             : {
     349             :     return Reference< interface_type >(
     350        5676 :         castFromXInterface(iquery( pInterface )), SAL_NO_ACQUIRE );
     351             : }
     352             : 
     353             : //##################################################################################################
     354             : 
     355             : //__________________________________________________________________________________________________
     356      162170 : inline sal_Bool BaseReference::operator == ( XInterface * pInterface ) const SAL_THROW(())
     357             : {
     358      162170 :     if (_pInterface == pInterface)
     359       84327 :         return sal_True;
     360             : #ifndef EXCEPTIONS_OFF
     361             :     try
     362             :     {
     363             : #endif
     364             :         // only the query to XInterface must return the same pointer if they belong to same objects
     365       77843 :         Reference< XInterface > x1( _pInterface, UNO_QUERY );
     366       77843 :         Reference< XInterface > x2( pInterface, UNO_QUERY );
     367       77843 :         return (x1._pInterface == x2._pInterface);
     368             : #ifndef EXCEPTIONS_OFF
     369             :     }
     370           0 :     catch (RuntimeException &)
     371             :     {
     372           0 :         return sal_False;
     373             :     }
     374             : #endif
     375             : }
     376             : 
     377             : //______________________________________________________________________________
     378        2017 : inline sal_Bool BaseReference::operator < (
     379             :     const BaseReference & rRef ) const SAL_THROW(())
     380             : {
     381        2017 :     if (_pInterface == rRef._pInterface)
     382        1200 :         return sal_False;
     383             : #if ! defined EXCEPTIONS_OFF
     384             :     try
     385             :     {
     386             : #endif
     387             :         // only the query to XInterface must return the same pointer:
     388         817 :         Reference< XInterface > x1( _pInterface, UNO_QUERY );
     389         817 :         Reference< XInterface > x2( rRef, UNO_QUERY );
     390         817 :         return (x1._pInterface < x2._pInterface);
     391             : #if ! defined EXCEPTIONS_OFF
     392             :     }
     393           0 :     catch (RuntimeException &)
     394             :     {
     395           0 :         return sal_False;
     396             :     }
     397             : #endif
     398             : }
     399             : 
     400             : //__________________________________________________________________________________________________
     401           2 : inline sal_Bool BaseReference::operator != ( XInterface * pInterface ) const SAL_THROW(())
     402             : {
     403           2 :     return (! operator == ( pInterface ));
     404             : }
     405             : //__________________________________________________________________________________________________
     406      147862 : inline sal_Bool BaseReference::operator == ( const BaseReference & rRef ) const SAL_THROW(())
     407             : {
     408      147862 :     return operator == ( rRef._pInterface );
     409             : }
     410             : //__________________________________________________________________________________________________
     411       14053 : inline sal_Bool BaseReference::operator != ( const BaseReference & rRef ) const SAL_THROW(())
     412             : {
     413       14053 :     return (! operator == ( rRef._pInterface ));
     414             : }
     415             : 
     416             : }
     417             : }
     418             : }
     419             : }
     420             : 
     421             : #endif
     422             : 
     423             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10