LCOV - code coverage report
Current view: top level - include/uno - mapping.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 59 60 98.3 %
Date: 2014-11-03 Functions: 16 16 100.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             : #ifndef INCLUDED_UNO_MAPPING_HXX
      20             : #define INCLUDED_UNO_MAPPING_HXX
      21             : 
      22             : #include <cppu/macros.hxx>
      23             : #include <rtl/alloc.h>
      24             : #include <rtl/ustring.hxx>
      25             : #include <uno/mapping.h>
      26             : #include <com/sun/star/uno/Type.hxx>
      27             : #include <com/sun/star/uno/Reference.hxx>
      28             : #include <cppu/unotype.hxx>
      29             : #include <uno/environment.hxx>
      30             : #include <uno/lbnames.h>
      31             : 
      32             : typedef struct _typelib_TypeDescription typelib_TypeDescription;
      33             : typedef struct _typelib_InterfaceTypeDescription typelib_InterfaceTypeDescription;
      34             : typedef struct _uno_Interface uno_Interface;
      35             : 
      36             : namespace com
      37             : {
      38             : namespace sun
      39             : {
      40             : namespace star
      41             : {
      42             : namespace uno
      43             : {
      44             : 
      45             : /** C++ wrapper for C uno_Mapping.
      46             : 
      47             :     @see uno_Mapping
      48             : */
      49             : class Mapping
      50             : {
      51             :     uno_Mapping * _pMapping;
      52             : 
      53             : public:
      54             :     // these are here to force memory de/allocation to sal lib.
      55             :     /// @cond INTERNAL
      56             :     inline static void * SAL_CALL operator new ( size_t nSize )
      57             :         { return ::rtl_allocateMemory( nSize ); }
      58             :     inline static void SAL_CALL operator delete ( void * pMem )
      59             :         { ::rtl_freeMemory( pMem ); }
      60             :     inline static void * SAL_CALL operator new ( size_t, void * pMem )
      61             :         { return pMem; }
      62             :     inline static void SAL_CALL operator delete ( void *, void * )
      63             :         {}
      64             :     /// @endcond
      65             : 
      66             :     /** Holds a mapping from the specified source to the specified destination by environment
      67             :         type names.
      68             : 
      69             :         @param rFrom        type name of source environment
      70             :         @param rTo          type name of destination environment
      71             :         @param rAddPurpose  additional purpose
      72             :     */
      73             :     inline Mapping(
      74             :         const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo,
      75             :         const ::rtl::OUString & rAddPurpose = ::rtl::OUString() );
      76             : 
      77             :     /** Holds a mapping from the specified source to the specified destination.
      78             : 
      79             :         @param pFrom        source environment
      80             :         @param pTo          destination environment
      81             :         @param rAddPurpose  additional purpose
      82             :     */
      83             :     inline Mapping(
      84             :         uno_Environment * pFrom, uno_Environment * pTo,
      85             :         const ::rtl::OUString & rAddPurpose = ::rtl::OUString() );
      86             : 
      87             :     /** Holds a mapping from the specified source to the specified destination
      88             :         environment.
      89             : 
      90             :         @param rFrom         source environment
      91             :         @param rTo           destination environment
      92             :         @param rAddPurpose  additional purpose
      93             :     */
      94             :     inline Mapping(const Environment & rFrom, const Environment & rTo,
      95             :                    const ::rtl::OUString & rAddPurpose = ::rtl::OUString() );
      96             : 
      97             :     /** Constructor.
      98             : 
      99             :         @param pMapping another mapping
     100             :     */
     101             :     inline Mapping( uno_Mapping * pMapping = 0 );
     102             : 
     103             :     /** Copy constructor.
     104             : 
     105             :         @param rMapping another mapping
     106             :     */
     107             :     inline Mapping( const Mapping & rMapping );
     108             : 
     109             :     /** Destructor.
     110             :     */
     111             :     inline ~Mapping();
     112             : 
     113             :     /** Sets a given mapping.
     114             : 
     115             :         @param pMapping another mapping
     116             :         @return this mapping
     117             :     */
     118             :     inline Mapping & SAL_CALL operator = ( uno_Mapping * pMapping );
     119             :     /** Sets a given mapping.
     120             : 
     121             :         @param rMapping another mapping
     122             :         @return this mapping
     123             :     */
     124         144 :     inline Mapping & SAL_CALL operator = ( const Mapping & rMapping )
     125         144 :         { return operator = ( rMapping._pMapping ); }
     126             : 
     127             :     /** Provides a pointer to the C mapping. The returned mapping is NOT acquired!
     128             : 
     129             :         @return UNacquired C mapping
     130             :     */
     131       48069 :     inline uno_Mapping * SAL_CALL get() const
     132       48069 :         { return _pMapping; }
     133             : 
     134             :     /** Tests if a mapping is set.
     135             : 
     136             :         @return true if a mapping is set
     137             :     */
     138       84000 :     inline bool SAL_CALL is() const
     139       84000 :         { return (_pMapping != 0); }
     140             : 
     141             :     /** Releases a set mapping.
     142             :     */
     143             :     inline void SAL_CALL clear();
     144             : 
     145             :     /** Maps an interface from one environment to another.
     146             : 
     147             :         @param pInterface       source interface
     148             :         @param pTypeDescr       type description of interface
     149             :         @return                 mapped interface
     150             :     */
     151             :     inline void * SAL_CALL mapInterface( void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const;
     152             :     /** Maps an interface from one environment to another.
     153             : 
     154             :         @param pInterface       source interface
     155             :         @param pTypeDescr       type description of interface
     156             :         @return                 mapped interface
     157             :     */
     158         138 :     inline void * SAL_CALL mapInterface( void * pInterface, typelib_TypeDescription * pTypeDescr ) const
     159         138 :         { return mapInterface( pInterface, (typelib_InterfaceTypeDescription *)pTypeDescr ); }
     160             : 
     161             :     /** Maps an interface from one environment to another.
     162             : 
     163             :         @param pInterface       source interface
     164             :         @param rType            type of interface
     165             :         @return                 mapped interface
     166             :     */
     167             :     inline void * SAL_CALL mapInterface(
     168             :         void * pInterface, const ::com::sun::star::uno::Type & rType ) const;
     169             : 
     170             :     /** Maps an interface from one environment to another.
     171             : 
     172             :         @param ppOut            inout mapped interface
     173             :         @param pInterface       source interface
     174             :         @param pTypeDescr       type description of interface
     175             :     */
     176        2082 :     inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const
     177        2082 :         { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, pTypeDescr ); }
     178             :     /** Maps an interface from one environment to another.
     179             : 
     180             :         @param ppOut            inout mapped interface
     181             :         @param pInterface       source interface
     182             :         @param pTypeDescr       type description of interface
     183             :     */
     184       10668 :     inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_TypeDescription * pTypeDescr ) const
     185       10668 :         { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, (typelib_InterfaceTypeDescription *)pTypeDescr ); }
     186             : 
     187             :     /** Maps an interface from one environment to another.
     188             : 
     189             :         @param ppOut            inout mapped interface
     190             :         @param pInterface       source interface
     191             :         @param rType            type of interface to be mapped
     192             :      */
     193             :     inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, const ::com::sun::star::uno::Type & rType ) const;
     194             : };
     195             : 
     196         348 : inline Mapping::Mapping(
     197             :     const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo, const ::rtl::OUString & rAddPurpose )
     198         348 :     : _pMapping( 0 )
     199             : {
     200         348 :     uno_getMappingByName( &_pMapping, rFrom.pData, rTo.pData, rAddPurpose.pData );
     201         348 : }
     202             : 
     203        2404 : inline Mapping::Mapping(
     204             :     uno_Environment * pFrom, uno_Environment * pTo, const ::rtl::OUString & rAddPurpose )
     205        2404 :     : _pMapping( 0 )
     206             : {
     207        2404 :     uno_getMapping( &_pMapping, pFrom, pTo, rAddPurpose.pData );
     208        2404 : }
     209             : 
     210       49184 : inline Mapping::Mapping(
     211             :     const Environment & rFrom, const Environment & rTo, const ::rtl::OUString & rAddPurpose )
     212       49184 :         : _pMapping(0)
     213             : {
     214       49184 :     uno_getMapping( &_pMapping, rFrom.get(), rTo.get(), rAddPurpose.pData );
     215       49184 : }
     216             : 
     217        1680 : inline Mapping::Mapping( uno_Mapping * pMapping )
     218        1680 :     : _pMapping( pMapping )
     219             : {
     220        1680 :     if (_pMapping)
     221         296 :         (*_pMapping->acquire)( _pMapping );
     222        1680 : }
     223             : 
     224         296 : inline Mapping::Mapping( const Mapping & rMapping )
     225         296 :     : _pMapping( rMapping._pMapping )
     226             : {
     227         296 :     if (_pMapping)
     228         296 :         (*_pMapping->acquire)( _pMapping );
     229         296 : }
     230             : 
     231       53626 : inline Mapping::~Mapping()
     232             : {
     233       53626 :     if (_pMapping)
     234       53380 :         (*_pMapping->release)( _pMapping );
     235       53626 : }
     236             : 
     237             : inline void Mapping::clear()
     238             : {
     239             :     if (_pMapping)
     240             :     {
     241             :         (*_pMapping->release)( _pMapping );
     242             :         _pMapping = 0;
     243             :     }
     244             : }
     245             : 
     246         144 : inline Mapping & Mapping::operator = ( uno_Mapping * pMapping )
     247             : {
     248         144 :     if (pMapping)
     249         144 :         (*pMapping->acquire)( pMapping );
     250         144 :     if (_pMapping)
     251           0 :         (*_pMapping->release)( _pMapping );
     252         144 :     _pMapping = pMapping;
     253         144 :     return *this;
     254             : }
     255             : 
     256       43834 : inline void Mapping::mapInterface(
     257             :     void ** ppOut, void * pInterface, const ::com::sun::star::uno::Type & rType ) const
     258             : {
     259       43834 :     typelib_TypeDescription * pTD = 0;
     260       43834 :     TYPELIB_DANGER_GET( &pTD, rType.getTypeLibType() );
     261       43834 :     if (pTD)
     262             :     {
     263       43834 :         (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, (typelib_InterfaceTypeDescription *)pTD );
     264       43834 :         TYPELIB_DANGER_RELEASE( pTD );
     265             :     }
     266       43834 : }
     267             : 
     268       12958 : inline void * Mapping::mapInterface(
     269             :     void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const
     270             : {
     271       12958 :     void * pOut = 0;
     272       12958 :     (*_pMapping->mapInterface)( _pMapping, &pOut, pInterface, pTypeDescr );
     273       12958 :     return pOut;
     274             : }
     275             : 
     276        3020 : inline void * Mapping::mapInterface(
     277             :     void * pInterface, const ::com::sun::star::uno::Type & rType ) const
     278             : {
     279        3020 :     void * pOut = 0;
     280        3020 :     mapInterface( &pOut, pInterface, rType );
     281        3020 :     return pOut;
     282             : }
     283             : 
     284             : /** Deprecated. This function DOES NOT WORK with Purpose Environments
     285             :     (http://wiki.openoffice.org/wiki/Uno/Binary/Spec/Purpose Environments)
     286             : 
     287             :     Maps an binary C UNO interface to be used in the currently used compiler environment.
     288             : 
     289             :     @tparam C interface type
     290             :     @param ppRet inout returned interface pointer
     291             :     @param pUnoI binary C UNO interface
     292             :     @return true if successful, false otherwise
     293             : 
     294             :     @deprecated
     295             : */
     296             : template< class C >
     297             : inline bool mapToCpp( Reference< C > * ppRet, uno_Interface * pUnoI )
     298             : {
     299             :     Mapping aMapping(
     300             :         ::rtl::OUString( UNO_LB_UNO ),
     301             :         ::rtl::OUString( CPPU_CURRENT_LANGUAGE_BINDING_NAME ) );
     302             :     OSL_ASSERT( aMapping.is() );
     303             :     aMapping.mapInterface(
     304             :             reinterpret_cast<void **>(ppRet), pUnoI, ::cppu::getTypeFavourUnsigned( ppRet ) );
     305             :     return (0 != *ppRet);
     306             : }
     307             : /** Deprecated. This function DOES NOT WORK with Purpose Environments
     308             :     (http://wiki.openoffice.org/wiki/Uno/Binary/Spec/Purpose Environments)
     309             : 
     310             :     Maps an UNO interface of the currently used compiler environment to binary C UNO.
     311             : 
     312             :     @tparam C interface type
     313             :     @param ppRet inout returned interface pointer
     314             :     @param x interface reference
     315             :     @return true if successful, false otherwise
     316             : 
     317             :     @deprecated
     318             : */
     319             : template< class C >
     320             : inline bool mapToUno( uno_Interface ** ppRet, const Reference< C > & x )
     321             : {
     322             :     Mapping aMapping(
     323             :         ::rtl::OUString( CPPU_CURRENT_LANGUAGE_BINDING_NAME ),
     324             :         ::rtl::OUString( UNO_LB_UNO ) );
     325             :     OSL_ASSERT( aMapping.is() );
     326             :     aMapping.mapInterface(
     327             :             (void **)ppRet, x.get(), ::cppu::getTypeFavourUnsigned( &x ) );
     328             :     return (0 != *ppRet);
     329             : }
     330             : 
     331             : }
     332             : }
     333             : }
     334             : }
     335             : 
     336             : #endif
     337             : 
     338             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10