LCOV - code coverage report
Current view: top level - include/cppu - unotype.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 18 59 30.5 %
Date: 2014-04-14 Functions: 133 6522 2.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_CPPU_UNOTYPE_HXX
      21             : #define INCLUDED_CPPU_UNOTYPE_HXX
      22             : 
      23             : #include <sal/config.h>
      24             : #include <com/sun/star/uno/Type.h>
      25             : #include <sal/types.h>
      26             : #include <typelib/typeclass.h>
      27             : #include <typelib/typedescription.h>
      28             : 
      29             : namespace com { namespace sun { namespace star { namespace uno {
      30             :     class Any;
      31             :     class Exception;
      32             :     template< typename > class Reference;
      33             :     template< typename > class Sequence;
      34             :     class XInterface;
      35             : } } } }
      36             : namespace rtl { class OUString; }
      37             : 
      38             : namespace cppu {
      39             : 
      40             : template< typename > class UnoType;
      41             : 
      42             : /**
      43             :    A unique C++ type representing the UNO type VOID in cppu::UnoType.
      44             : 
      45             :    This type is declared but not defined.  Its only use is as a template
      46             :    argument to cppu::UnoType.
      47             : 
      48             :    @since UDK 3.2.2
      49             : */
      50             : struct UnoVoidType;
      51             : 
      52             : /**
      53             :    A unique C++ type representing the UNO type UNSIGNED SHORT in cppu::UnoType.
      54             : 
      55             :    The UNO types UNSIGNED SHORT and CHAR map to the same C++ type, so this C++
      56             :    type is needed to unambiguously specify UNO types in cppu::UnoType.
      57             : 
      58             :    This type is declared but not defined.  Its only use is as a template
      59             :    argument to cppu::UnoType.
      60             : 
      61             :    @since UDK 3.2.2
      62             : */
      63             : struct UnoUnsignedShortType;
      64             : 
      65             : /**
      66             :    A unique C++ type representing the UNO type UNSIGNED SHORT in cppu::UnoType.
      67             : 
      68             :    The UNO types UNSIGNED SHORT and CHAR map to the same C++ type, so this C++
      69             :    type is needed to unambiguously specify UNO types in cppu::UnoType.
      70             : 
      71             :    This type is declared but not defined.  Its only use is as a template
      72             :    argument to cppu::UnoType.
      73             : 
      74             :    @since UDK 3.2.2
      75             : */
      76             : struct UnoCharType;
      77             : 
      78             : /**
      79             :    A unique C++ type template representing the UNO sequence types in
      80             :    cppu::UnoType.
      81             : 
      82             :    The UNO types UNSIGNED SHORT and CHAR map to the same C++ type, so this C++
      83             :    type is needed to unambiguously specify UNO types in cppu::UnoType.
      84             : 
      85             :    This type is declared but not defined.  Its only use is as a template
      86             :    argument to cppu::UnoType.
      87             : 
      88             :    @since UDK 3.2.2
      89             : */
      90             : template< typename > struct UnoSequenceType;
      91             : 
      92             : namespace detail {
      93             : 
      94         241 : inline ::com::sun::star::uno::Type const & getTypeFromTypeDescriptionReference(
      95             :     ::typelib_TypeDescriptionReference * const * tdr)
      96             : {
      97         241 :     return *reinterpret_cast< ::com::sun::star::uno::Type const * >(tdr);
      98             : }
      99             : 
     100             : inline ::com::sun::star::uno::Type const &
     101          95 : getTypeFromTypeClass(::typelib_TypeClass tc) {
     102             :     return getTypeFromTypeDescriptionReference(
     103          95 :         ::typelib_static_type_getByTypeClass(tc));
     104             : }
     105             : 
     106             : }
     107             : 
     108             : }
     109             : 
     110             : namespace cppu { namespace detail {
     111             : 
     112             : inline ::com::sun::star::uno::Type const &
     113           0 : cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::cppu::UnoVoidType const *) {
     114           0 :     return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_VOID);
     115             : }
     116             : 
     117             : inline ::com::sun::star::uno::Type const &
     118           0 : cppu_detail_getUnoType(SAL_UNUSED_PARAMETER bool const *) {
     119           0 :     return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_BOOLEAN);
     120             : }
     121             : 
     122             : inline ::com::sun::star::uno::Type const &
     123           0 : cppu_detail_getUnoType(SAL_UNUSED_PARAMETER sal_Bool const *) {
     124           0 :     return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_BOOLEAN);
     125             : }
     126             : 
     127             : inline ::com::sun::star::uno::Type const &
     128           0 : cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_Int8 const *) {
     129           0 :     return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_BYTE);
     130             : }
     131             : 
     132             : inline ::com::sun::star::uno::Type const &
     133           0 : cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_Int16 const *) {
     134           0 :     return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_SHORT);
     135             : }
     136             : 
     137             : inline ::com::sun::star::uno::Type const &
     138           0 : cppu_detail_getUnoType(
     139             :     SAL_UNUSED_PARAMETER ::cppu::UnoUnsignedShortType const *)
     140             : {
     141             :     return ::cppu::detail::getTypeFromTypeClass(
     142           0 :         ::typelib_TypeClass_UNSIGNED_SHORT);
     143             : }
     144             : 
     145             : inline ::com::sun::star::uno::Type const &
     146           0 : cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_Int32 const *) {
     147           0 :     return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_LONG);
     148             : }
     149             : 
     150             : inline ::com::sun::star::uno::Type const &
     151           0 : cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_uInt32 const *) {
     152             :     return ::cppu::detail::getTypeFromTypeClass(
     153           0 :         ::typelib_TypeClass_UNSIGNED_LONG);
     154             : }
     155             : 
     156             : inline ::com::sun::star::uno::Type const &
     157           0 : cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_Int64 const *) {
     158           0 :     return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_HYPER);
     159             : }
     160             : 
     161             : inline ::com::sun::star::uno::Type const &
     162           0 : cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_uInt64 const *) {
     163             :     return ::cppu::detail::getTypeFromTypeClass(
     164           0 :         ::typelib_TypeClass_UNSIGNED_HYPER);
     165             : }
     166             : 
     167             : inline ::com::sun::star::uno::Type const &
     168           0 : cppu_detail_getUnoType(SAL_UNUSED_PARAMETER float const *) {
     169           0 :     return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_FLOAT);
     170             : }
     171             : 
     172             : inline ::com::sun::star::uno::Type const &
     173           0 : cppu_detail_getUnoType(SAL_UNUSED_PARAMETER double const *) {
     174           0 :     return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_DOUBLE);
     175             : }
     176             : 
     177             : inline ::com::sun::star::uno::Type const &
     178           0 : cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::cppu::UnoCharType const *) {
     179           0 :     return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_CHAR);
     180             : }
     181             : 
     182             : inline ::com::sun::star::uno::Type const &
     183           8 : cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::rtl::OUString const *) {
     184           8 :     return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_STRING);
     185             : }
     186             : 
     187             : inline ::com::sun::star::uno::Type const &
     188           0 : cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::com::sun::star::uno::Type const *)
     189             : {
     190           0 :     return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_TYPE);
     191             : }
     192             : 
     193             : inline ::com::sun::star::uno::Type const &
     194           2 : cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::com::sun::star::uno::Any const *)
     195             : {
     196           2 :     return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_ANY);
     197             : }
     198             : 
     199             : template< typename T > inline ::com::sun::star::uno::Type const &
     200           0 : cppu_detail_getUnoType(
     201             :     SAL_UNUSED_PARAMETER ::cppu::UnoSequenceType< T > const *)
     202             : {
     203             :     //TODO: depending on memory model, the following might not work reliably
     204             :     static typelib_TypeDescriptionReference * p = 0;
     205           0 :     if (p == 0) {
     206           0 :         ::typelib_static_sequence_type_init(
     207           0 :             &p, ::cppu::UnoType< T >::get().getTypeLibType());
     208             :     }
     209           0 :     return ::cppu::detail::getTypeFromTypeDescriptionReference(&p);
     210             : }
     211             : 
     212             : template< typename T > inline ::com::sun::star::uno::Type const &
     213           0 : cppu_detail_getUnoType(
     214             :     SAL_UNUSED_PARAMETER ::com::sun::star::uno::Sequence< T > const *)
     215             : {
     216             :     return cppu_detail_getUnoType(
     217           0 :         static_cast< ::cppu::UnoSequenceType< T > * >(0));
     218             : }
     219             : 
     220          16 : inline ::com::sun::star::uno::Type const & cppu_detail_getUnoType(
     221             :     SAL_UNUSED_PARAMETER ::com::sun::star::uno::Exception const *)
     222             : {
     223          16 :     return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_EXCEPTION);
     224             : }
     225             : 
     226          69 : inline ::com::sun::star::uno::Type const & cppu_detail_getUnoType(
     227             :     SAL_UNUSED_PARAMETER ::com::sun::star::uno::XInterface const *)
     228             : {
     229          69 :     return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_INTERFACE);
     230             : }
     231             : 
     232             : template< typename T > inline ::com::sun::star::uno::Type const &
     233         300 : cppu_detail_getUnoType(
     234             :     SAL_UNUSED_PARAMETER ::com::sun::star::uno::Reference< T > const *)
     235             : {
     236         300 :     return ::cppu::UnoType< T >::get();
     237             : }
     238             : 
     239             : } }
     240             : 
     241             : namespace cppu {
     242             : 
     243             : /**
     244             :    Get the com::sun::star::uno::Type instance representing a certain UNO type.
     245             : 
     246             :    For each C++ type representing a UNO type, the corresponding instantiation of
     247             :    this template has a public static member function get().  (The template is
     248             :    specialized for C++ templates representing polymorphic struct type templates
     249             :    of UNO.  In those cases, it does not work to instantiate UnoType with a C++
     250             :    type that is derived from a C++ type that represents a UNO type, but does not
     251             :    itself represent a UNO type.  In all other cases, UnoType even works for such
     252             :    C++ types that are unambiguously derived from one C++ type that represents a
     253             :    UNO type.)  In addition to those C++ types that are mappings of UNO types
     254             :    (except for sal_uInt16 and sal_Unicode, see below), the following C++ types
     255             :    are appropriate as template arguments: cppu::UnoVoidType, bool,
     256             :    cppu::UnoUnsignedShortType, cppu::UnoCharType, cppu::UnoSequenceType with any
     257             :    appropriate template argument (the latter three to unambiguously specify UNO
     258             :    types, as the UNO types UNSIGNED SHORT and CHAR map to the same C++ type),
     259             :    and com::sun::star::uno::Reference with any appropriate template argument.
     260             : 
     261             :    @since UDK 3.2.2
     262             : */
     263             : template< typename T > class UnoType {
     264             : public:
     265         732 :     static inline ::com::sun::star::uno::Type const & get() {
     266             :         using namespace ::cppu::detail;
     267         732 :         return cppu_detail_getUnoType(static_cast< T * >(0));
     268             :     }
     269             : 
     270             : private:
     271             :     UnoType(UnoType &); // not defined
     272             :     ~UnoType(); // not defined
     273             :     void operator =(UnoType &); // not defined
     274             : };
     275             : 
     276             : /**
     277             :    A working replacement for getCppuType (see there).
     278             : 
     279             :    There are three overloads of this function that together form the replacement
     280             :    of getCppuType.  The replacement has exactly the same semantics as
     281             :    getCppuType, in that it returns correct results for the UNO type UNSIGNED
     282             :    SHORT but not for the UNO type CHAR.
     283             : 
     284             :    @since UDK 3.2.2
     285             : */
     286             : template< typename T > inline ::com::sun::star::uno::Type const &
     287          93 : getTypeFavourUnsigned(SAL_UNUSED_PARAMETER T const *) {
     288          93 :     return ::cppu::UnoType< T >::get();
     289             : }
     290             : 
     291             : /**
     292             :    A working replacement for getCppuType (see there).
     293             : 
     294             :    There are three overloads of this function that together form the replacement
     295             :    of getCppuType.  The replacement has exactly the same semantics as
     296             :    getCppuType, in that it returns correct results for the UNO type UNSIGNED
     297             :    SHORT but not for the UNO type CHAR.
     298             : 
     299             :    @since UDK 3.2.2
     300             : */
     301             : inline ::com::sun::star::uno::Type const &
     302           0 : getTypeFavourUnsigned(SAL_UNUSED_PARAMETER ::sal_uInt16 const *) {
     303           0 :     return ::cppu::UnoType< ::cppu::UnoUnsignedShortType >::get();
     304             : }
     305             : 
     306             : /**
     307             :    A working replacement for getCppuType (see there).
     308             : 
     309             :    There are three overloads of this function that together form the replacement
     310             :    of getCppuType.  The replacement has exactly the same semantics as
     311             :    getCppuType, in that it returns correct results for the UNO type UNSIGNED
     312             :    SHORT but not for the UNO type CHAR.
     313             : 
     314             :    @since UDK 3.2.2
     315             : */
     316             : template< typename T > inline ::com::sun::star::uno::Type const &
     317             : getTypeFavourUnsigned(::com::sun::star::uno::Sequence< T > const *);
     318             :     // defined in com/sun/star/uno/Sequence.hxx
     319             : 
     320             : /// @cond INTERNAL
     321             : 
     322             : /**
     323             :    A working replacement for getCppuType (see there).
     324             : 
     325             :    There are three overloads of this function that together form the replacement
     326             :    of the getCppuType template.  The replacement has exactly the same semantics
     327             :    as the getCppuType template, in that it returns correct results for the UNO
     328             :    type CHAR but not for the UNO type UNSIGNED SHORT.  Additionally, it also
     329             :    returns the intended results for sequence types.
     330             : 
     331             :    @since UDK 3.2.3
     332             : */
     333             : template< typename T > inline ::com::sun::star::uno::Type const &
     334           0 : getTypeFavourChar(SAL_UNUSED_PARAMETER T const *) {
     335           0 :     return ::cppu::UnoType< T >::get();
     336             : }
     337             : 
     338             : /**
     339             :    A working replacement for getCppuType (see there).
     340             : 
     341             :    There are three overloads of this function that together form the replacement
     342             :    of the getCppuType template.  The replacement has exactly the same semantics
     343             :    as the getCppuType template, in that it returns correct results for the UNO
     344             :    type CHAR but not for the UNO type UNSIGNED SHORT.  Additionally, it also
     345             :    returns the intended results for sequence types.
     346             : 
     347             :    @since UDK 3.2.3
     348             : */
     349             : inline ::com::sun::star::uno::Type const &
     350           0 : getTypeFavourChar(SAL_UNUSED_PARAMETER ::sal_Unicode const *) {
     351           0 :     return ::cppu::UnoType< ::cppu::UnoCharType >::get();
     352             : }
     353             : 
     354             : /**
     355             :    A working replacement for getCppuType (see there).
     356             : 
     357             :    There are three overloads of this function that together form the replacement
     358             :    of the getCppuType template.  The replacement has exactly the same semantics
     359             :    as the getCppuType template, in that it returns correct results for the UNO
     360             :    type CHAR but not for the UNO type UNSIGNED SHORT.  Additionally, it also
     361             :    returns the intended results for sequence types.
     362             : 
     363             :    @since UDK 3.2.3
     364             : */
     365             : template< typename T > inline ::com::sun::star::uno::Type const &
     366             : getTypeFavourChar(::com::sun::star::uno::Sequence< T > const *);
     367             :     // defined in com/sun/star/uno/Sequence.hxx
     368             : 
     369             : /// @endcond
     370             : 
     371             : }
     372             : 
     373             : #endif
     374             : 
     375             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10