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

Generated by: LCOV version 1.10