LCOV - code coverage report
Current view: top level - include/com/sun/star/uno - Any.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 211 253 83.4 %
Date: 2014-11-03 Functions: 1245 2019 61.7 %
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   105730717 : inline Any::Any()
      47             : {
      48   105730717 :     ::uno_any_construct( this, 0, 0, (uno_AcquireFunc)cpp_acquire );
      49   105730734 : }
      50             : 
      51             : 
      52             : template <typename T>
      53      491328 : inline Any::Any( T const & value )
      54             : {
      55      491328 :     ::uno_type_any_construct(
      56             :         this, const_cast<T *>(&value),
      57      491328 :         ::cppu::getTypeFavourUnsigned(&value).getTypeLibType(),
      58      491328 :         (uno_AcquireFunc) cpp_acquire );
      59      491328 : }
      60             : 
      61       18488 : inline Any::Any( bool value )
      62             : {
      63       18488 :     sal_Bool b = value;
      64             :     ::uno_type_any_construct(
      65       18488 :         this, &b, ::getCppuBooleanType().getTypeLibType(),
      66       18488 :         (uno_AcquireFunc) cpp_acquire );
      67       18488 : }
      68             : 
      69             : 
      70   116487956 : inline Any::Any( const Any & rAny )
      71             : {
      72   116487956 :     ::uno_type_any_construct( this, rAny.pData, rAny.pType, (uno_AcquireFunc)cpp_acquire );
      73   116487955 : }
      74             : 
      75    62556890 : inline Any::Any( const void * pData_, const Type & rType )
      76             : {
      77             :     ::uno_type_any_construct(
      78             :         this, const_cast< void * >( pData_ ), rType.getTypeLibType(),
      79    62556889 :         (uno_AcquireFunc)cpp_acquire );
      80    62556892 : }
      81             : 
      82         512 : inline Any::Any( const void * pData_, typelib_TypeDescription * pTypeDescr )
      83             : {
      84             :     ::uno_any_construct(
      85         512 :         this, const_cast< void * >( pData_ ), pTypeDescr, (uno_AcquireFunc)cpp_acquire );
      86         512 : }
      87             : 
      88    35888057 : inline Any::Any( const void * pData_, typelib_TypeDescriptionReference * pType_ )
      89             : {
      90             :     ::uno_type_any_construct(
      91    35888057 :         this, const_cast< void * >( pData_ ), pType_, (uno_AcquireFunc)cpp_acquire );
      92    35888079 : }
      93             : 
      94   320963016 : inline Any::~Any()
      95             : {
      96             :     ::uno_any_destruct(
      97   320963016 :         this, (uno_ReleaseFunc)cpp_release );
      98   320963046 : }
      99             : 
     100    69972292 : inline Any & Any::operator = ( const Any & rAny )
     101             : {
     102    69972292 :     if (this != &rAny)
     103             :     {
     104             :         ::uno_type_any_assign(
     105             :             this, rAny.pData, rAny.pType,
     106    69961674 :             (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
     107             :     }
     108    69972292 :     return *this;
     109             : }
     110             : 
     111        1256 : inline ::rtl::OUString Any::getValueTypeName() const
     112             : {
     113        1256 :     return ::rtl::OUString( pType->pTypeName );
     114             : }
     115             : 
     116      992489 : inline void Any::setValue( const void * pData_, const Type & rType )
     117             : {
     118             :     ::uno_type_any_assign(
     119             :         this, const_cast< void * >( pData_ ), rType.getTypeLibType(),
     120      992489 :         (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
     121      992489 : }
     122             : 
     123             : inline void Any::setValue( const void * pData_, typelib_TypeDescriptionReference * pType_ )
     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       20842 : inline void Any::setValue( const void * pData_, typelib_TypeDescription * pTypeDescr )
     131             : {
     132             :     ::uno_any_assign(
     133             :         this, const_cast< void * >( pData_ ), pTypeDescr,
     134       20842 :         (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
     135       20842 : }
     136             : 
     137       17812 : inline void Any::clear()
     138             : {
     139             :     ::uno_any_clear(
     140       17812 :         this, (uno_ReleaseFunc)cpp_release );
     141       17812 : }
     142             : 
     143      175469 : inline bool Any::isExtractableTo( const Type & rType ) const
     144             : {
     145             :     return ::uno_type_isAssignableFromData(
     146             :         rType.getTypeLibType(), pData, pType,
     147      175469 :         (uno_QueryInterfaceFunc)cpp_queryInterface, (uno_ReleaseFunc)cpp_release );
     148             : }
     149             : 
     150             : 
     151             : template <typename T>
     152       15890 : inline bool Any::has() const
     153             : {
     154       15890 :     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       15890 :         (uno_ReleaseFunc) cpp_release );
     159             : }
     160             : 
     161     1528250 : inline bool Any::operator == ( const Any & rAny ) const
     162             : {
     163             :     return ::uno_type_equalData(
     164             :         pData, pType, rAny.pData, rAny.pType,
     165     1528250 :         (uno_QueryInterfaceFunc)cpp_queryInterface, (uno_ReleaseFunc)cpp_release );
     166             : }
     167             : 
     168       44146 : inline bool Any::operator != ( const Any & rAny ) const
     169             : {
     170             :     return (! ::uno_type_equalData(
     171             :         pData, pType, rAny.pData, rAny.pType,
     172       44146 :         (uno_QueryInterfaceFunc)cpp_queryInterface, (uno_ReleaseFunc)cpp_release ));
     173             : }
     174             : 
     175             : 
     176             : template< class C >
     177    28254981 : inline Any SAL_CALL makeAny( const C & value )
     178             : {
     179    28254981 :     return Any( &value, ::cppu::getTypeFavourUnsigned(&value) );
     180             : }
     181             : 
     182             : // additionally specialized for C++ bool
     183             : 
     184             : template<>
     185     2948766 : inline Any SAL_CALL makeAny( bool const & value )
     186             : {
     187     2948766 :     const sal_Bool b = value;
     188     2948766 :     return Any( &b, ::getCppuBooleanType() );
     189             : }
     190             : 
     191             : 
     192             : #ifdef RTL_FAST_STRING
     193             : template< class C1, class C2 >
     194       41681 : inline Any SAL_CALL makeAny( const rtl::OUStringConcat< C1, C2 >& value )
     195             : {
     196       41681 :     const rtl::OUString str( value );
     197       41681 :     return Any( &str, ::cppu::getTypeFavourUnsigned(&str) );
     198             : }
     199             : #endif
     200             : 
     201             : template< class C >
     202    19206078 : inline void SAL_CALL operator <<= ( Any & rAny, const C & value )
     203             : {
     204    19206078 :     const Type & rType = ::cppu::getTypeFavourUnsigned(&value);
     205    19206078 :     ::uno_type_any_assign(
     206             :         &rAny, const_cast< C * >( &value ), rType.getTypeLibType(),
     207    19206078 :         (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
     208    19206078 : }
     209             : 
     210             : // additionally for C++ bool:
     211             : 
     212             : template<>
     213     1635509 : inline void SAL_CALL operator <<= ( Any & rAny, bool const & value )
     214             : {
     215     1635509 :     sal_Bool b = value;
     216             :     ::uno_type_any_assign(
     217     1635509 :         &rAny, &b, ::getCppuBooleanType().getTypeLibType(),
     218     1635509 :         (uno_AcquireFunc) cpp_acquire, (uno_ReleaseFunc) cpp_release );
     219     1635509 : }
     220             : 
     221             : 
     222             : #ifdef RTL_FAST_STRING
     223             : template< class C1, class C2 >
     224        5020 : inline void SAL_CALL operator <<= ( Any & rAny, const rtl::OUStringConcat< C1, C2 >& value )
     225             : {
     226        5020 :     const rtl::OUString str( value );
     227        5020 :     const Type & rType = ::cppu::getTypeFavourUnsigned(&str);
     228        5020 :     ::uno_type_any_assign(
     229             :         &rAny, const_cast< rtl::OUString * >( &str ), rType.getTypeLibType(),
     230       10040 :         (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
     231        5020 : }
     232             : #endif
     233             : 
     234             : template< class C >
     235    12996179 : inline bool SAL_CALL operator >>= ( const Any & rAny, C & value )
     236             : {
     237    12996179 :     const Type & rType = ::cppu::getTypeFavourUnsigned(&value);
     238             :     return ::uno_type_assignData(
     239             :         &value, rType.getTypeLibType(),
     240             :         rAny.pData, rAny.pType,
     241             :         (uno_QueryInterfaceFunc)cpp_queryInterface,
     242    12996179 :         (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
     243             : }
     244             : 
     245             : // bool
     246             : 
     247             : template<>
     248       82798 : inline bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, sal_Bool & value )
     249             : {
     250       82798 :     if (typelib_TypeClass_BOOLEAN == rAny.pType->eTypeClass)
     251             :     {
     252       82722 :         value = (* reinterpret_cast< const sal_Bool * >( rAny.pData ) != sal_False);
     253       82722 :         return true;
     254             :     }
     255          76 :     return false;
     256             : }
     257             : 
     258             : template<>
     259             : inline bool SAL_CALL operator == ( const Any & rAny, const sal_Bool & value )
     260             : {
     261             :     return (typelib_TypeClass_BOOLEAN == rAny.pType->eTypeClass &&
     262             :             (value != sal_False) == (* reinterpret_cast< const sal_Bool * >( rAny.pData ) != sal_False));
     263             : }
     264             : 
     265             : 
     266             : template<>
     267     4111315 : inline bool SAL_CALL operator >>= ( Any const & rAny, bool & value )
     268             : {
     269     4111315 :     if (rAny.pType->eTypeClass == typelib_TypeClass_BOOLEAN)
     270             :     {
     271             :         value = *reinterpret_cast< sal_Bool const * >(
     272     3969358 :             rAny.pData ) != sal_False;
     273     3969358 :         return true;
     274             :     }
     275      141957 :     return false;
     276             : }
     277             : 
     278             : 
     279             : template<>
     280           0 : inline bool SAL_CALL operator == ( Any const & rAny, bool const & value )
     281             : {
     282           0 :     return (rAny.pType->eTypeClass == typelib_TypeClass_BOOLEAN &&
     283           0 :             (value ==
     284             :              (*reinterpret_cast< sal_Bool const * >( rAny.pData )
     285           0 :               != sal_False)));
     286             : }
     287             : 
     288             : // byte
     289             : 
     290             : template<>
     291       26180 : inline bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, sal_Int8 & value )
     292             : {
     293       26180 :     if (typelib_TypeClass_BYTE == rAny.pType->eTypeClass)
     294             :     {
     295       22190 :         value = * reinterpret_cast< const sal_Int8 * >( rAny.pData );
     296       22190 :         return true;
     297             :     }
     298        3990 :     return false;
     299             : }
     300             : // short
     301             : 
     302             : template<>
     303     2193685 : inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int16 & value )
     304             : {
     305     2193685 :     switch (rAny.pType->eTypeClass)
     306             :     {
     307             :     case typelib_TypeClass_BYTE:
     308        1014 :         value = * reinterpret_cast< const sal_Int8 * >( rAny.pData );
     309        1014 :         return true;
     310             :     case typelib_TypeClass_SHORT:
     311             :     case typelib_TypeClass_UNSIGNED_SHORT:
     312     1924186 :         value = * reinterpret_cast< const sal_Int16 * >( rAny.pData );
     313     1924186 :         return true;
     314             :     default:
     315      268485 :         return false;
     316             :     }
     317             : }
     318             : 
     319             : template<>
     320      807118 : inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt16 & value )
     321             : {
     322      807118 :     switch (rAny.pType->eTypeClass)
     323             :     {
     324             :     case typelib_TypeClass_BYTE:
     325          10 :         value = (sal_uInt16)( * reinterpret_cast< const sal_Int8 * >( rAny.pData ) );
     326          10 :         return true;
     327             :     case typelib_TypeClass_SHORT:
     328             :     case typelib_TypeClass_UNSIGNED_SHORT:
     329      807020 :         value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData );
     330      807020 :         return true;
     331             :     default:
     332          88 :         return false;
     333             :     }
     334             : }
     335             : // long
     336             : 
     337             : template<>
     338     2405111 : inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int32 & value )
     339             : {
     340     2405111 :     switch (rAny.pType->eTypeClass)
     341             :     {
     342             :     case typelib_TypeClass_BYTE:
     343        3806 :         value = * reinterpret_cast< const sal_Int8 * >( rAny.pData );
     344        3806 :         return true;
     345             :     case typelib_TypeClass_SHORT:
     346      513997 :         value = * reinterpret_cast< const sal_Int16 * >( rAny.pData );
     347      513997 :         return true;
     348             :     case typelib_TypeClass_UNSIGNED_SHORT:
     349        3876 :         value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData );
     350        3876 :         return true;
     351             :     case typelib_TypeClass_LONG:
     352             :     case typelib_TypeClass_UNSIGNED_LONG:
     353     1814044 :         value = * reinterpret_cast< const sal_Int32 * >( rAny.pData );
     354     1814044 :         return true;
     355             :     default:
     356       69388 :         return false;
     357             :     }
     358             : }
     359             : 
     360             : template<>
     361      170213 : inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt32 & value )
     362             : {
     363      170213 :     switch (rAny.pType->eTypeClass)
     364             :     {
     365             :     case typelib_TypeClass_BYTE:
     366           4 :         value = (sal_uInt32)( * reinterpret_cast< const sal_Int8 * >( rAny.pData ) );
     367           4 :         return true;
     368             :     case typelib_TypeClass_SHORT:
     369           2 :         value = (sal_uInt32)( * reinterpret_cast< const sal_Int16 * >( rAny.pData ) );
     370           2 :         return true;
     371             :     case typelib_TypeClass_UNSIGNED_SHORT:
     372       96040 :         value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData );
     373       96040 :         return true;
     374             :     case typelib_TypeClass_LONG:
     375             :     case typelib_TypeClass_UNSIGNED_LONG:
     376       66817 :         value = * reinterpret_cast< const sal_uInt32 * >( rAny.pData );
     377       66817 :         return true;
     378             :     default:
     379        7350 :         return false;
     380             :     }
     381             : }
     382             : // hyper
     383             : 
     384             : template<>
     385      106009 : inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int64 & value )
     386             : {
     387      106009 :     switch (rAny.pType->eTypeClass)
     388             :     {
     389             :     case typelib_TypeClass_BYTE:
     390          10 :         value = * reinterpret_cast< const sal_Int8 * >( rAny.pData );
     391          10 :         return true;
     392             :     case typelib_TypeClass_SHORT:
     393           2 :         value = * reinterpret_cast< const sal_Int16 * >( rAny.pData );
     394           2 :         return true;
     395             :     case typelib_TypeClass_UNSIGNED_SHORT:
     396           2 :         value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData );
     397           2 :         return true;
     398             :     case typelib_TypeClass_LONG:
     399       30764 :         value = * reinterpret_cast< const sal_Int32 * >( rAny.pData );
     400       30764 :         return true;
     401             :     case typelib_TypeClass_UNSIGNED_LONG:
     402           2 :         value = * reinterpret_cast< const sal_uInt32 * >( rAny.pData );
     403           2 :         return true;
     404             :     case typelib_TypeClass_HYPER:
     405             :     case typelib_TypeClass_UNSIGNED_HYPER:
     406       26932 :         value = * reinterpret_cast< const sal_Int64 * >( rAny.pData );
     407       26932 :         return true;
     408             :     default:
     409       48297 :         return false;
     410             :     }
     411             : }
     412             : 
     413             : template<>
     414          84 : inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt64 & value )
     415             : {
     416          84 :     switch (rAny.pType->eTypeClass)
     417             :     {
     418             :     case typelib_TypeClass_BYTE:
     419           2 :         value = (sal_uInt64)( * reinterpret_cast< const sal_Int8 * >( rAny.pData ) );
     420           2 :         return true;
     421             :     case typelib_TypeClass_SHORT:
     422           2 :         value = (sal_uInt64)( * reinterpret_cast< const sal_Int16 * >( rAny.pData ) );
     423           2 :         return true;
     424             :     case typelib_TypeClass_UNSIGNED_SHORT:
     425           2 :         value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData );
     426           2 :         return true;
     427             :     case typelib_TypeClass_LONG:
     428           2 :         value = (sal_uInt64)( * reinterpret_cast< const sal_Int32 * >( rAny.pData ) );
     429           2 :         return true;
     430             :     case typelib_TypeClass_UNSIGNED_LONG:
     431           2 :         value = * reinterpret_cast< const sal_uInt32 * >( rAny.pData );
     432           2 :         return true;
     433             :     case typelib_TypeClass_HYPER:
     434             :     case typelib_TypeClass_UNSIGNED_HYPER:
     435          48 :         value = * reinterpret_cast< const sal_uInt64 * >( rAny.pData );
     436          48 :         return true;
     437             :     default:
     438          26 :         return false;
     439             :     }
     440             : }
     441             : // float
     442             : 
     443             : template<>
     444       66069 : inline bool SAL_CALL operator >>= ( const Any & rAny, float & value )
     445             : {
     446       66069 :     switch (rAny.pType->eTypeClass)
     447             :     {
     448             :     case typelib_TypeClass_BYTE:
     449           2 :         value = * reinterpret_cast< const sal_Int8 * >( rAny.pData );
     450           2 :         return true;
     451             :     case typelib_TypeClass_SHORT:
     452          92 :         value = * reinterpret_cast< const sal_Int16 * >( rAny.pData );
     453          92 :         return true;
     454             :     case typelib_TypeClass_UNSIGNED_SHORT:
     455           2 :         value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData );
     456           2 :         return true;
     457             :     case typelib_TypeClass_FLOAT:
     458       61253 :         value = * reinterpret_cast< const float * >( rAny.pData );
     459       61253 :         return true;
     460             :     default:
     461        4720 :         return false;
     462             :     }
     463             : }
     464             : // double
     465             : 
     466             : template<>
     467      587733 : inline bool SAL_CALL operator >>= ( const Any & rAny, double & value )
     468             : {
     469      587733 :     switch (rAny.pType->eTypeClass)
     470             :     {
     471             :     case typelib_TypeClass_BYTE:
     472        4374 :         value = * reinterpret_cast< const sal_Int8 * >( rAny.pData );
     473        4374 :         return true;
     474             :     case typelib_TypeClass_SHORT:
     475          66 :         value = * reinterpret_cast< const sal_Int16 * >( rAny.pData );
     476          66 :         return true;
     477             :     case typelib_TypeClass_UNSIGNED_SHORT:
     478           2 :         value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData );
     479           2 :         return true;
     480             :     case typelib_TypeClass_LONG:
     481        2646 :         value = * reinterpret_cast< const sal_Int32 * >( rAny.pData );
     482        2646 :         return true;
     483             :     case typelib_TypeClass_UNSIGNED_LONG:
     484           2 :         value = * reinterpret_cast< const sal_uInt32 * >( rAny.pData );
     485           2 :         return true;
     486             :     case typelib_TypeClass_FLOAT:
     487      244446 :         value = * reinterpret_cast< const float * >( rAny.pData );
     488      244446 :         return true;
     489             :     case typelib_TypeClass_DOUBLE:
     490      291094 :         value = * reinterpret_cast< const double * >( rAny.pData );
     491      291094 :         return true;
     492             :     default:
     493       45103 :         return false;
     494             :     }
     495             : }
     496             : // string
     497             : 
     498             : template<>
     499    17529665 : inline bool SAL_CALL operator >>= ( const Any & rAny, ::rtl::OUString & value )
     500             : {
     501    17529665 :     if (typelib_TypeClass_STRING == rAny.pType->eTypeClass)
     502             :     {
     503    16874378 :         value = * reinterpret_cast< const ::rtl::OUString * >( rAny.pData );
     504    16874378 :         return true;
     505             :     }
     506      655287 :     return false;
     507             : }
     508             : 
     509             : template<>
     510             : inline bool SAL_CALL operator == ( const Any & rAny, const ::rtl::OUString & value )
     511             : {
     512             :     return (typelib_TypeClass_STRING == rAny.pType->eTypeClass &&
     513             :             value.equals( * reinterpret_cast< const ::rtl::OUString * >( rAny.pData ) ));
     514             : }
     515             : // type
     516             : 
     517             : template<>
     518       33228 : inline bool SAL_CALL operator >>= ( const Any & rAny, Type & value )
     519             : {
     520       33228 :     if (typelib_TypeClass_TYPE == rAny.pType->eTypeClass)
     521             :     {
     522         458 :         value = * reinterpret_cast< const Type * >( rAny.pData );
     523         458 :         return true;
     524             :     }
     525       32770 :     return false;
     526             : }
     527             : 
     528             : template<>
     529             : inline bool SAL_CALL operator == ( const Any & rAny, const Type & value )
     530             : {
     531             :     return (typelib_TypeClass_TYPE == rAny.pType->eTypeClass &&
     532             :             value.equals( * reinterpret_cast< const Type * >( rAny.pData ) ));
     533             : }
     534             : // any
     535             : 
     536             : template<>
     537       74732 : inline bool SAL_CALL operator >>= ( const Any & rAny, Any & value )
     538             : {
     539       74732 :     if (&rAny != &value)
     540             :     {
     541             :         ::uno_type_any_assign(
     542             :             &value, rAny.pData, rAny.pType,
     543       74732 :             (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
     544             :     }
     545       74732 :     return true;
     546             : }
     547             : // interface
     548             : 
     549             : template<>
     550             : inline bool SAL_CALL operator == ( const Any & rAny, const BaseReference & value )
     551             : {
     552             :     if (typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass)
     553             :     {
     554             :         return reinterpret_cast< const BaseReference * >( rAny.pData )->operator == ( value );
     555             :     }
     556             :     return false;
     557             : }
     558             : 
     559             : // operator to compare to an any.
     560             : 
     561             : template< class C >
     562         288 : inline bool SAL_CALL operator == ( const Any & rAny, const C & value )
     563             : {
     564         288 :     const Type & rType = ::cppu::getTypeFavourUnsigned(&value);
     565             :     return ::uno_type_equalData(
     566             :         rAny.pData, rAny.pType,
     567             :         const_cast< C * >( &value ), rType.getTypeLibType(),
     568         288 :         (uno_QueryInterfaceFunc)cpp_queryInterface, (uno_ReleaseFunc)cpp_release );
     569             : }
     570             : // operator to compare to an any.  may use specialized operators ==.
     571             : 
     572             : template< class C >
     573           2 : inline bool SAL_CALL operator != ( const Any & rAny, const C & value )
     574             : {
     575           2 :     return (! operator == ( rAny, value ));
     576             : }
     577             : 
     578             : extern "C" rtl_uString * SAL_CALL cppu_Any_extraction_failure_msg(
     579             :     uno_Any const * pAny, typelib_TypeDescriptionReference * pType )
     580             :     SAL_THROW_EXTERN_C();
     581             : 
     582             : 
     583             : template <typename T>
     584     1405829 : T Any::get() const
     585             : {
     586     1405829 :     T value = T();
     587     1405829 :     if (! (*this >>= value)) {
     588           0 :         throw RuntimeException(
     589             :             ::rtl::OUString(
     590             :                 cppu_Any_extraction_failure_msg(
     591             :                     this,
     592           0 :                     ::cppu::getTypeFavourUnsigned(&value).getTypeLibType() ),
     593           0 :                 SAL_NO_ACQUIRE ) );
     594             :     }
     595     1405829 :     return value;
     596             : }
     597             : 
     598             : /**
     599             :    Support for Any in std::ostream (and thus in CPPUNIT_ASSERT or SAL_INFO
     600             :    macros, for example).
     601             : 
     602             :    @since LibreOffice 4.2
     603             : */
     604             : template<typename charT, typename traits>
     605           0 : inline std::basic_ostream<charT, traits> &operator<<(std::basic_ostream<charT, traits> &o, Any const &any) {
     606           0 :     o << "<Any: (" << any.getValueTypeName() << ')';
     607           0 :     switch(any.pType->eTypeClass) {
     608             :         case typelib_TypeClass_VOID:
     609           0 :             break;
     610             :         case typelib_TypeClass_BOOLEAN:
     611           0 :             o << ' ' << any.get<bool>();
     612           0 :             break;
     613             :         case typelib_TypeClass_BYTE:
     614             :         case typelib_TypeClass_SHORT:
     615             :         case typelib_TypeClass_LONG:
     616             :         case typelib_TypeClass_HYPER:
     617           0 :             o << ' ' << any.get<sal_Int64>();
     618           0 :             break;
     619             :         case typelib_TypeClass_UNSIGNED_SHORT:
     620             :         case typelib_TypeClass_UNSIGNED_LONG:
     621             :         case typelib_TypeClass_UNSIGNED_HYPER:
     622           0 :             o << ' ' << any.get<sal_uInt64>();
     623           0 :             break;
     624             :         case typelib_TypeClass_FLOAT:
     625             :         case typelib_TypeClass_DOUBLE:
     626           0 :             o << ' ' << any.get<double>();
     627           0 :             break;
     628             :         case typelib_TypeClass_CHAR: {
     629             :             std::ios_base::fmtflags flgs = o.setf(
     630           0 :                 std::ios_base::hex, std::ios_base::basefield);
     631           0 :             charT fill = o.fill('0');
     632           0 :             o << " U+" << std::setw(4)
     633           0 :               << *static_cast<sal_Unicode const *>(any.getValue());
     634           0 :             o.setf(flgs);
     635           0 :             o.fill(fill);
     636           0 :             break;
     637             :         }
     638             :         case typelib_TypeClass_STRING:
     639           0 :             o << ' ' << any.get<rtl::OUString>();
     640           0 :             break;
     641             :         case typelib_TypeClass_TYPE:
     642           0 :             o << ' ' << any.get<css::uno::Type>().getTypeName();
     643           0 :             break;
     644             :         case typelib_TypeClass_SEQUENCE:
     645           0 :             o << " len "
     646           0 :               << ((*static_cast<uno_Sequence * const *>(any.getValue()))->
     647             :                   nElements);
     648           0 :             break;
     649             :         case typelib_TypeClass_ENUM:
     650           0 :             o << ' ' << *static_cast<sal_Int32 const *>(any.getValue());
     651           0 :             break;
     652             :         case typelib_TypeClass_STRUCT:
     653             :         case typelib_TypeClass_EXCEPTION:
     654           0 :             o << ' ' << any.getValue();
     655           0 :             break;
     656             :         case typelib_TypeClass_INTERFACE:
     657           0 :             o << ' ' << *static_cast<void * const *>(any.getValue());
     658           0 :             break;
     659             :         default:
     660             :             assert(false); // this cannot happen
     661           0 :             break;
     662             :     }
     663           0 :     o << '>';
     664           0 :     return o;
     665             : }
     666             : 
     667             : }
     668             : }
     669             : }
     670             : }
     671             : 
     672             : #endif
     673             : 
     674             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10