LCOV - code coverage report
Current view: top level - include/com/sun/star/uno - Any.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 211 218 96.8 %
Date: 2014-04-11 Functions: 1213 2011 60.3 %
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_ANY_HXX
      20             : #define INCLUDED_COM_SUN_STAR_UNO_ANY_HXX
      21             : 
      22             : #include <sal/config.h>
      23             : 
      24             : #include <cassert>
      25             : #include <iomanip>
      26             : #include <ostream>
      27             : 
      28             : #include <com/sun/star/uno/Any.h>
      29             : #include <uno/data.h>
      30             : #include <uno/sequence2.h>
      31             : #include <com/sun/star/uno/Type.hxx>
      32             : #include <com/sun/star/uno/XInterface.hpp>
      33             : #include <com/sun/star/uno/genfunc.hxx>
      34             : #include <cppu/unotype.hxx>
      35             : 
      36             : namespace com
      37             : {
      38             : namespace sun
      39             : {
      40             : namespace star
      41             : {
      42             : namespace uno
      43             : {
      44             : 
      45             : 
      46    39862280 : inline Any::Any() SAL_THROW(())
      47             : {
      48    39862281 :     ::uno_any_construct( this, 0, 0, (uno_AcquireFunc)cpp_acquire );
      49    39862281 : }
      50             : 
      51             : 
      52             : template <typename T>
      53      171177 : inline Any::Any( T const & value )
      54             : {
      55      171177 :     ::uno_type_any_construct(
      56             :         this, const_cast<T *>(&value),
      57      171177 :         ::cppu::getTypeFavourUnsigned(&value).getTypeLibType(),
      58      171177 :         (uno_AcquireFunc) cpp_acquire );
      59      171177 : }
      60             : 
      61        4424 : inline Any::Any( bool value )
      62             : {
      63        4424 :     sal_Bool b = value;
      64             :     ::uno_type_any_construct(
      65        4424 :         this, &b, ::getCppuBooleanType().getTypeLibType(),
      66        4424 :         (uno_AcquireFunc) cpp_acquire );
      67        4424 : }
      68             : 
      69             : 
      70    45014364 : inline Any::Any( const Any & rAny ) SAL_THROW(())
      71             : {
      72    45014364 :     ::uno_type_any_construct( this, rAny.pData, rAny.pType, (uno_AcquireFunc)cpp_acquire );
      73    45014364 : }
      74             : 
      75    23856205 : inline Any::Any( const void * pData_, const Type & rType ) SAL_THROW(())
      76             : {
      77             :     ::uno_type_any_construct(
      78             :         this, const_cast< void * >( pData_ ), rType.getTypeLibType(),
      79    23856205 :         (uno_AcquireFunc)cpp_acquire );
      80    23856205 : }
      81             : 
      82         253 : inline Any::Any( const void * pData_, typelib_TypeDescription * pTypeDescr ) SAL_THROW(())
      83             : {
      84             :     ::uno_any_construct(
      85         253 :         this, const_cast< void * >( pData_ ), pTypeDescr, (uno_AcquireFunc)cpp_acquire );
      86         253 : }
      87             : 
      88    13795189 : inline Any::Any( const void * pData_, typelib_TypeDescriptionReference * pType_ ) SAL_THROW(())
      89             : {
      90             :     ::uno_type_any_construct(
      91    13795191 :         this, const_cast< void * >( pData_ ), pType_, (uno_AcquireFunc)cpp_acquire );
      92    13795192 : }
      93             : 
      94   122587421 : inline Any::~Any() SAL_THROW(())
      95             : {
      96             :     ::uno_any_destruct(
      97   122587421 :         this, (uno_ReleaseFunc)cpp_release );
      98   122587423 : }
      99             : 
     100    25369657 : inline Any & Any::operator = ( const Any & rAny ) SAL_THROW(())
     101             : {
     102    25369657 :     if (this != &rAny)
     103             :     {
     104             :         ::uno_type_any_assign(
     105             :             this, rAny.pData, rAny.pType,
     106    25365284 :             (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
     107             :     }
     108    25369657 :     return *this;
     109             : }
     110             : 
     111         792 : inline ::rtl::OUString Any::getValueTypeName() const SAL_THROW(())
     112             : {
     113         792 :     return ::rtl::OUString( pType->pTypeName );
     114             : }
     115             : 
     116      383399 : inline void Any::setValue( const void * pData_, const Type & rType ) SAL_THROW(())
     117             : {
     118             :     ::uno_type_any_assign(
     119             :         this, const_cast< void * >( pData_ ), rType.getTypeLibType(),
     120      383399 :         (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
     121      383399 : }
     122             : 
     123             : inline void Any::setValue( const void * pData_, typelib_TypeDescriptionReference * pType_ ) SAL_THROW(())
     124             : {
     125             :     ::uno_type_any_assign(
     126             :         this, const_cast< void * >( pData_ ), pType_,
     127             :         (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
     128             : }
     129             : 
     130       10228 : inline void Any::setValue( const void * pData_, typelib_TypeDescription * pTypeDescr ) SAL_THROW(())
     131             : {
     132             :     ::uno_any_assign(
     133             :         this, const_cast< void * >( pData_ ), pTypeDescr,
     134       10228 :         (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
     135       10228 : }
     136             : 
     137        6717 : inline void Any::clear() SAL_THROW(())
     138             : {
     139             :     ::uno_any_clear(
     140        6717 :         this, (uno_ReleaseFunc)cpp_release );
     141        6717 : }
     142             : 
     143       68146 : inline bool Any::isExtractableTo( const Type & rType ) const SAL_THROW(())
     144             : {
     145             :     return ::uno_type_isAssignableFromData(
     146             :         rType.getTypeLibType(), pData, pType,
     147       68146 :         (uno_QueryInterfaceFunc)cpp_queryInterface, (uno_ReleaseFunc)cpp_release );
     148             : }
     149             : 
     150             : 
     151             : template <typename T>
     152        2412 : inline bool Any::has() const
     153             : {
     154        2412 :     Type const & rType = ::cppu::getTypeFavourUnsigned(static_cast< T * >(0));
     155             :     return ::uno_type_isAssignableFromData(
     156             :         rType.getTypeLibType(), pData, pType,
     157             :         (uno_QueryInterfaceFunc) cpp_queryInterface,
     158        2412 :         (uno_ReleaseFunc) cpp_release );
     159             : }
     160             : 
     161             : // not impl: forbid use with ambiguous type (sal_Unicode, sal_uInt16)
     162             : template <>
     163             : bool Any::has<sal_uInt16>() const;
     164             : 
     165             : 
     166      657242 : inline bool Any::operator == ( const Any & rAny ) const SAL_THROW(())
     167             : {
     168             :     return ::uno_type_equalData(
     169             :         pData, pType, rAny.pData, rAny.pType,
     170      657242 :         (uno_QueryInterfaceFunc)cpp_queryInterface, (uno_ReleaseFunc)cpp_release );
     171             : }
     172             : 
     173       14325 : inline bool Any::operator != ( const Any & rAny ) const SAL_THROW(())
     174             : {
     175             :     return (! ::uno_type_equalData(
     176             :         pData, pType, rAny.pData, rAny.pType,
     177       14325 :         (uno_QueryInterfaceFunc)cpp_queryInterface, (uno_ReleaseFunc)cpp_release ));
     178             : }
     179             : 
     180             : 
     181             : template< class C >
     182    11111377 : inline Any SAL_CALL makeAny( const C & value ) SAL_THROW(())
     183             : {
     184    11111377 :     return Any( &value, ::cppu::getTypeFavourUnsigned(&value) );
     185             : }
     186             : 
     187             : // additionally specialized for C++ bool
     188             : 
     189             : template<>
     190      927024 : inline Any SAL_CALL makeAny( bool const & value ) SAL_THROW(())
     191             : {
     192      927024 :     const sal_Bool b = value;
     193      927024 :     return Any( &b, ::getCppuBooleanType() );
     194             : }
     195             : 
     196             : 
     197             : #ifdef RTL_FAST_STRING
     198             : template< class C1, class C2 >
     199       16147 : inline Any SAL_CALL makeAny( const rtl::OUStringConcat< C1, C2 >& value ) SAL_THROW(())
     200             : {
     201       16147 :     const rtl::OUString str( value );
     202       16147 :     return Any( &str, ::cppu::getTypeFavourUnsigned(&str) );
     203             : }
     204             : #endif
     205             : 
     206             : template< class C >
     207     8397422 : inline void SAL_CALL operator <<= ( Any & rAny, const C & value ) SAL_THROW(())
     208             : {
     209     8397422 :     const Type & rType = ::cppu::getTypeFavourUnsigned(&value);
     210     8397422 :     ::uno_type_any_assign(
     211             :         &rAny, const_cast< C * >( &value ), rType.getTypeLibType(),
     212     8397422 :         (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
     213     8397422 : }
     214             : 
     215             : // additionally for C++ bool:
     216             : 
     217             : template<>
     218      398259 : inline void SAL_CALL operator <<= ( Any & rAny, bool const & value )
     219             :     SAL_THROW(())
     220             : {
     221      398259 :     sal_Bool b = value;
     222             :     ::uno_type_any_assign(
     223      398259 :         &rAny, &b, ::getCppuBooleanType().getTypeLibType(),
     224      398259 :         (uno_AcquireFunc) cpp_acquire, (uno_ReleaseFunc) cpp_release );
     225      398259 : }
     226             : 
     227             : 
     228             : #ifdef RTL_FAST_STRING
     229             : template< class C1, class C2 >
     230          79 : inline void SAL_CALL operator <<= ( Any & rAny, const rtl::OUStringConcat< C1, C2 >& value )
     231             :     SAL_THROW(())
     232             : {
     233          79 :     const rtl::OUString str( value );
     234          79 :     const Type & rType = ::cppu::getTypeFavourUnsigned(&str);
     235          79 :     ::uno_type_any_assign(
     236             :         &rAny, const_cast< rtl::OUString * >( &str ), rType.getTypeLibType(),
     237         158 :         (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
     238          79 : }
     239             : #endif
     240             : 
     241             : template< class C >
     242     5004477 : inline bool SAL_CALL operator >>= ( const Any & rAny, C & value ) SAL_THROW(())
     243             : {
     244     5004477 :     const Type & rType = ::cppu::getTypeFavourUnsigned(&value);
     245             :     return ::uno_type_assignData(
     246             :         &value, rType.getTypeLibType(),
     247             :         rAny.pData, rAny.pType,
     248             :         (uno_QueryInterfaceFunc)cpp_queryInterface,
     249     5004477 :         (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
     250             : }
     251             : 
     252             : // bool
     253             : 
     254             : template<>
     255      397373 : inline bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, sal_Bool & value ) SAL_THROW(())
     256             : {
     257      397373 :     if (typelib_TypeClass_BOOLEAN == rAny.pType->eTypeClass)
     258             :     {
     259      396028 :         value = (* reinterpret_cast< const sal_Bool * >( rAny.pData ) != sal_False);
     260      396028 :         return true;
     261             :     }
     262        1345 :     return false;
     263             : }
     264             : 
     265             : template<>
     266             : inline bool SAL_CALL operator == ( const Any & rAny, const sal_Bool & value ) SAL_THROW(())
     267             : {
     268             :     return (typelib_TypeClass_BOOLEAN == rAny.pType->eTypeClass &&
     269             :             (value != sal_False) == (* reinterpret_cast< const sal_Bool * >( rAny.pData ) != sal_False));
     270             : }
     271             : 
     272             : 
     273             : template<>
     274     1384525 : inline bool SAL_CALL operator >>= ( Any const & rAny, bool & value )
     275             :     SAL_THROW(())
     276             : {
     277     1384525 :     if (rAny.pType->eTypeClass == typelib_TypeClass_BOOLEAN)
     278             :     {
     279             :         value = *reinterpret_cast< sal_Bool const * >(
     280     1322768 :             rAny.pData ) != sal_False;
     281     1322768 :         return true;
     282             :     }
     283       61757 :     return false;
     284             : }
     285             : 
     286             : 
     287             : template<>
     288           0 : inline bool SAL_CALL operator == ( Any const & rAny, bool const & value )
     289             :     SAL_THROW(())
     290             : {
     291           0 :     return (rAny.pType->eTypeClass == typelib_TypeClass_BOOLEAN &&
     292           0 :             (value ==
     293             :              (*reinterpret_cast< sal_Bool const * >( rAny.pData )
     294           0 :               != sal_False)));
     295             : }
     296             : 
     297             : // byte
     298             : 
     299             : template<>
     300       12023 : inline bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, sal_Int8 & value ) SAL_THROW(())
     301             : {
     302       12023 :     if (typelib_TypeClass_BYTE == rAny.pType->eTypeClass)
     303             :     {
     304       10462 :         value = * reinterpret_cast< const sal_Int8 * >( rAny.pData );
     305       10462 :         return true;
     306             :     }
     307        1561 :     return false;
     308             : }
     309             : // short
     310             : 
     311             : template<>
     312      999553 : inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int16 & value ) SAL_THROW(())
     313             : {
     314      999553 :     switch (rAny.pType->eTypeClass)
     315             :     {
     316             :     case typelib_TypeClass_BYTE:
     317         360 :         value = * reinterpret_cast< const sal_Int8 * >( rAny.pData );
     318         360 :         return true;
     319             :     case typelib_TypeClass_SHORT:
     320             :     case typelib_TypeClass_UNSIGNED_SHORT:
     321      851580 :         value = * reinterpret_cast< const sal_Int16 * >( rAny.pData );
     322      851580 :         return true;
     323             :     default:
     324      147613 :         return false;
     325             :     }
     326             : }
     327             : 
     328             : template<>
     329      356404 : inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt16 & value ) SAL_THROW(())
     330             : {
     331      356404 :     switch (rAny.pType->eTypeClass)
     332             :     {
     333             :     case typelib_TypeClass_BYTE:
     334           5 :         value = (sal_uInt16)( * reinterpret_cast< const sal_Int8 * >( rAny.pData ) );
     335           5 :         return true;
     336             :     case typelib_TypeClass_SHORT:
     337             :     case typelib_TypeClass_UNSIGNED_SHORT:
     338      356365 :         value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData );
     339      356365 :         return true;
     340             :     default:
     341          34 :         return false;
     342             :     }
     343             : }
     344             : // long
     345             : 
     346             : template<>
     347     1059975 : inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int32 & value ) SAL_THROW(())
     348             : {
     349     1059975 :     switch (rAny.pType->eTypeClass)
     350             :     {
     351             :     case typelib_TypeClass_BYTE:
     352        1289 :         value = * reinterpret_cast< const sal_Int8 * >( rAny.pData );
     353        1289 :         return true;
     354             :     case typelib_TypeClass_SHORT:
     355      275682 :         value = * reinterpret_cast< const sal_Int16 * >( rAny.pData );
     356      275682 :         return true;
     357             :     case typelib_TypeClass_UNSIGNED_SHORT:
     358        2081 :         value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData );
     359        2081 :         return true;
     360             :     case typelib_TypeClass_LONG:
     361             :     case typelib_TypeClass_UNSIGNED_LONG:
     362      745814 :         value = * reinterpret_cast< const sal_Int32 * >( rAny.pData );
     363      745814 :         return true;
     364             :     default:
     365       35109 :         return false;
     366             :     }
     367             : }
     368             : 
     369             : template<>
     370       67927 : inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt32 & value ) SAL_THROW(())
     371             : {
     372       67927 :     switch (rAny.pType->eTypeClass)
     373             :     {
     374             :     case typelib_TypeClass_BYTE:
     375           2 :         value = (sal_uInt32)( * reinterpret_cast< const sal_Int8 * >( rAny.pData ) );
     376           2 :         return true;
     377             :     case typelib_TypeClass_SHORT:
     378           1 :         value = (sal_uInt32)( * reinterpret_cast< const sal_Int16 * >( rAny.pData ) );
     379           1 :         return true;
     380             :     case typelib_TypeClass_UNSIGNED_SHORT:
     381       42098 :         value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData );
     382       42098 :         return true;
     383             :     case typelib_TypeClass_LONG:
     384             :     case typelib_TypeClass_UNSIGNED_LONG:
     385       22694 :         value = * reinterpret_cast< const sal_uInt32 * >( rAny.pData );
     386       22694 :         return true;
     387             :     default:
     388        3132 :         return false;
     389             :     }
     390             : }
     391             : // hyper
     392             : 
     393             : template<>
     394       20813 : inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int64 & value ) SAL_THROW(())
     395             : {
     396       20813 :     switch (rAny.pType->eTypeClass)
     397             :     {
     398             :     case typelib_TypeClass_BYTE:
     399           1 :         value = * reinterpret_cast< const sal_Int8 * >( rAny.pData );
     400           1 :         return true;
     401             :     case typelib_TypeClass_SHORT:
     402           1 :         value = * reinterpret_cast< const sal_Int16 * >( rAny.pData );
     403           1 :         return true;
     404             :     case typelib_TypeClass_UNSIGNED_SHORT:
     405           1 :         value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData );
     406           1 :         return true;
     407             :     case typelib_TypeClass_LONG:
     408         207 :         value = * reinterpret_cast< const sal_Int32 * >( rAny.pData );
     409         207 :         return true;
     410             :     case typelib_TypeClass_UNSIGNED_LONG:
     411           1 :         value = * reinterpret_cast< const sal_uInt32 * >( rAny.pData );
     412           1 :         return true;
     413             :     case typelib_TypeClass_HYPER:
     414             :     case typelib_TypeClass_UNSIGNED_HYPER:
     415        3095 :         value = * reinterpret_cast< const sal_Int64 * >( rAny.pData );
     416        3095 :         return true;
     417             :     default:
     418       17507 :         return false;
     419             :     }
     420             : }
     421             : 
     422             : template<>
     423          40 : inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt64 & value ) SAL_THROW(())
     424             : {
     425          40 :     switch (rAny.pType->eTypeClass)
     426             :     {
     427             :     case typelib_TypeClass_BYTE:
     428           1 :         value = (sal_uInt64)( * reinterpret_cast< const sal_Int8 * >( rAny.pData ) );
     429           1 :         return true;
     430             :     case typelib_TypeClass_SHORT:
     431           1 :         value = (sal_uInt64)( * reinterpret_cast< const sal_Int16 * >( rAny.pData ) );
     432           1 :         return true;
     433             :     case typelib_TypeClass_UNSIGNED_SHORT:
     434           1 :         value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData );
     435           1 :         return true;
     436             :     case typelib_TypeClass_LONG:
     437           1 :         value = (sal_uInt64)( * reinterpret_cast< const sal_Int32 * >( rAny.pData ) );
     438           1 :         return true;
     439             :     case typelib_TypeClass_UNSIGNED_LONG:
     440           1 :         value = * reinterpret_cast< const sal_uInt32 * >( rAny.pData );
     441           1 :         return true;
     442             :     case typelib_TypeClass_HYPER:
     443             :     case typelib_TypeClass_UNSIGNED_HYPER:
     444          22 :         value = * reinterpret_cast< const sal_uInt64 * >( rAny.pData );
     445          22 :         return true;
     446             :     default:
     447          13 :         return false;
     448             :     }
     449             : }
     450             : // float
     451             : 
     452             : template<>
     453       27382 : inline bool SAL_CALL operator >>= ( const Any & rAny, float & value ) SAL_THROW(())
     454             : {
     455       27382 :     switch (rAny.pType->eTypeClass)
     456             :     {
     457             :     case typelib_TypeClass_BYTE:
     458           1 :         value = * reinterpret_cast< const sal_Int8 * >( rAny.pData );
     459           1 :         return true;
     460             :     case typelib_TypeClass_SHORT:
     461          42 :         value = * reinterpret_cast< const sal_Int16 * >( rAny.pData );
     462          42 :         return true;
     463             :     case typelib_TypeClass_UNSIGNED_SHORT:
     464           1 :         value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData );
     465           1 :         return true;
     466             :     case typelib_TypeClass_FLOAT:
     467       24978 :         value = * reinterpret_cast< const float * >( rAny.pData );
     468       24978 :         return true;
     469             :     default:
     470        2360 :         return false;
     471             :     }
     472             : }
     473             : // double
     474             : 
     475             : template<>
     476      293212 : inline bool SAL_CALL operator >>= ( const Any & rAny, double & value ) SAL_THROW(())
     477             : {
     478      293212 :     switch (rAny.pType->eTypeClass)
     479             :     {
     480             :     case typelib_TypeClass_BYTE:
     481        2187 :         value = * reinterpret_cast< const sal_Int8 * >( rAny.pData );
     482        2187 :         return true;
     483             :     case typelib_TypeClass_SHORT:
     484          33 :         value = * reinterpret_cast< const sal_Int16 * >( rAny.pData );
     485          33 :         return true;
     486             :     case typelib_TypeClass_UNSIGNED_SHORT:
     487           1 :         value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData );
     488           1 :         return true;
     489             :     case typelib_TypeClass_LONG:
     490         766 :         value = * reinterpret_cast< const sal_Int32 * >( rAny.pData );
     491         766 :         return true;
     492             :     case typelib_TypeClass_UNSIGNED_LONG:
     493           1 :         value = * reinterpret_cast< const sal_uInt32 * >( rAny.pData );
     494           1 :         return true;
     495             :     case typelib_TypeClass_FLOAT:
     496      135775 :         value = * reinterpret_cast< const float * >( rAny.pData );
     497      135775 :         return true;
     498             :     case typelib_TypeClass_DOUBLE:
     499      112611 :         value = * reinterpret_cast< const double * >( rAny.pData );
     500      112611 :         return true;
     501             :     default:
     502       41838 :         return false;
     503             :     }
     504             : }
     505             : // string
     506             : 
     507             : template<>
     508     7265401 : inline bool SAL_CALL operator >>= ( const Any & rAny, ::rtl::OUString & value ) SAL_THROW(())
     509             : {
     510     7265401 :     if (typelib_TypeClass_STRING == rAny.pType->eTypeClass)
     511             :     {
     512     7005382 :         value = * reinterpret_cast< const ::rtl::OUString * >( rAny.pData );
     513     7005382 :         return true;
     514             :     }
     515      260019 :     return false;
     516             : }
     517             : 
     518             : template<>
     519             : inline bool SAL_CALL operator == ( const Any & rAny, const ::rtl::OUString & value ) SAL_THROW(())
     520             : {
     521             :     return (typelib_TypeClass_STRING == rAny.pType->eTypeClass &&
     522             :             value.equals( * reinterpret_cast< const ::rtl::OUString * >( rAny.pData ) ));
     523             : }
     524             : // type
     525             : 
     526             : template<>
     527        7440 : inline bool SAL_CALL operator >>= ( const Any & rAny, Type & value ) SAL_THROW(())
     528             : {
     529        7440 :     if (typelib_TypeClass_TYPE == rAny.pType->eTypeClass)
     530             :     {
     531         229 :         value = * reinterpret_cast< const Type * >( rAny.pData );
     532         229 :         return true;
     533             :     }
     534        7211 :     return false;
     535             : }
     536             : 
     537             : template<>
     538             : inline bool SAL_CALL operator == ( const Any & rAny, const Type & value ) SAL_THROW(())
     539             : {
     540             :     return (typelib_TypeClass_TYPE == rAny.pType->eTypeClass &&
     541             :             value.equals( * reinterpret_cast< const Type * >( rAny.pData ) ));
     542             : }
     543             : // any
     544             : 
     545             : template<>
     546       29230 : inline bool SAL_CALL operator >>= ( const Any & rAny, Any & value ) SAL_THROW(())
     547             : {
     548       29230 :     if (&rAny != &value)
     549             :     {
     550             :         ::uno_type_any_assign(
     551             :             &value, rAny.pData, rAny.pType,
     552       29230 :             (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
     553             :     }
     554       29230 :     return true;
     555             : }
     556             : // interface
     557             : 
     558             : template<>
     559             : inline bool SAL_CALL operator == ( const Any & rAny, const BaseReference & value ) SAL_THROW(())
     560             : {
     561             :     if (typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass)
     562             :     {
     563             :         return reinterpret_cast< const BaseReference * >( rAny.pData )->operator == ( value );
     564             :     }
     565             :     return false;
     566             : }
     567             : 
     568             : // operator to compare to an any.
     569             : 
     570             : template< class C >
     571          97 : inline bool SAL_CALL operator == ( const Any & rAny, const C & value ) SAL_THROW(())
     572             : {
     573          97 :     const Type & rType = ::cppu::getTypeFavourUnsigned(&value);
     574             :     return ::uno_type_equalData(
     575             :         rAny.pData, rAny.pType,
     576             :         const_cast< C * >( &value ), rType.getTypeLibType(),
     577          97 :         (uno_QueryInterfaceFunc)cpp_queryInterface, (uno_ReleaseFunc)cpp_release );
     578             : }
     579             : // operator to compare to an any.  may use specialized operators ==.
     580             : 
     581             : template< class C >
     582           1 : inline bool SAL_CALL operator != ( const Any & rAny, const C & value ) SAL_THROW(())
     583             : {
     584           1 :     return (! operator == ( rAny, value ));
     585             : }
     586             : 
     587             : extern "C" rtl_uString * SAL_CALL cppu_Any_extraction_failure_msg(
     588             :     uno_Any const * pAny, typelib_TypeDescriptionReference * pType )
     589             :     SAL_THROW_EXTERN_C();
     590             : 
     591             : 
     592             : template <typename T>
     593      729155 : T Any::get() const
     594             : {
     595      729155 :     T value = T();
     596      729155 :     if (! (*this >>= value)) {
     597           0 :         throw RuntimeException(
     598             :             ::rtl::OUString(
     599             :                 cppu_Any_extraction_failure_msg(
     600             :                     this,
     601           0 :                     ::cppu::getTypeFavourUnsigned(&value).getTypeLibType() ),
     602             :                 SAL_NO_ACQUIRE ),
     603           0 :             Reference<XInterface>() );
     604             :     }
     605      729155 :     return value;
     606             : }
     607             : // not impl: forbid use with ambiguous type (sal_Unicode, sal_uInt16)
     608             : template <>
     609             : sal_uInt16 Any::get<sal_uInt16>() const;
     610             : 
     611             : /**
     612             :    Support for Any in std::ostream (and thus in CPPUNIT_ASSERT or SAL_INFO
     613             :    macros, for example).
     614             : 
     615             :    @since LibreOffice 4.2
     616             : */
     617             : template<typename charT, typename traits>
     618             : inline std::basic_ostream<charT, traits> &operator<<(std::basic_ostream<charT, traits> &o, Any const &any) {
     619             :     o << "<Any: (" << any.getValueTypeName() << ')';
     620             :     switch(any.pType->eTypeClass) {
     621             :         case typelib_TypeClass_VOID:
     622             :             break;
     623             :         case typelib_TypeClass_BOOLEAN:
     624             :             o << ' ' << any.get<bool>();
     625             :             break;
     626             :         case typelib_TypeClass_BYTE:
     627             :         case typelib_TypeClass_SHORT:
     628             :         case typelib_TypeClass_LONG:
     629             :         case typelib_TypeClass_HYPER:
     630             :             o << ' ' << any.get<sal_Int64>();
     631             :             break;
     632             :         case typelib_TypeClass_UNSIGNED_SHORT:
     633             :         case typelib_TypeClass_UNSIGNED_LONG:
     634             :         case typelib_TypeClass_UNSIGNED_HYPER:
     635             :             o << ' ' << any.get<sal_uInt64>();
     636             :             break;
     637             :         case typelib_TypeClass_FLOAT:
     638             :         case typelib_TypeClass_DOUBLE:
     639             :             o << ' ' << any.get<double>();
     640             :             break;
     641             :         case typelib_TypeClass_CHAR: {
     642             :             std::ios_base::fmtflags flgs = o.setf(
     643             :                 std::ios_base::hex, std::ios_base::basefield);
     644             :             charT fill = o.fill('0');
     645             :             o << " U+" << std::setw(4)
     646             :               << *static_cast<sal_Unicode const *>(any.getValue());
     647             :             o.setf(flgs);
     648             :             o.fill(fill);
     649             :             break;
     650             :         }
     651             :         case typelib_TypeClass_STRING:
     652             :             o << ' ' << any.get<rtl::OUString>();
     653             :             break;
     654             :         case typelib_TypeClass_TYPE:
     655             :             o << ' ' << any.get<css::uno::Type>().getTypeName();
     656             :             break;
     657             :         case typelib_TypeClass_SEQUENCE:
     658             :             o << " len "
     659             :               << ((*static_cast<uno_Sequence * const *>(any.getValue()))->
     660             :                   nElements);
     661             :             break;
     662             :         case typelib_TypeClass_ENUM:
     663             :             o << ' ' << *static_cast<sal_Int32 const *>(any.getValue());
     664             :             break;
     665             :         case typelib_TypeClass_STRUCT:
     666             :         case typelib_TypeClass_EXCEPTION:
     667             :             o << ' ' << any.getValue();
     668             :             break;
     669             :         case typelib_TypeClass_INTERFACE:
     670             :             o << ' ' << *static_cast<void * const *>(any.getValue());
     671             :             break;
     672             :         default:
     673             :             assert(false); // this cannot happen
     674             :             break;
     675             :     }
     676             :     o << '>';
     677             :     return o;
     678             : }
     679             : 
     680             : }
     681             : }
     682             : }
     683             : }
     684             : 
     685             : #endif
     686             : 
     687             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10