LCOV - code coverage report
Current view: top level - include/uno - mapping.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 29 60 48.3 %
Date: 2014-04-14 Functions: 8 16 50.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 ) SAL_THROW(())
      57             :         { return ::rtl_allocateMemory( nSize ); }
      58             :     inline static void SAL_CALL operator delete ( void * pMem ) SAL_THROW(())
      59             :         { ::rtl_freeMemory( pMem ); }
      60             :     inline static void * SAL_CALL operator new ( size_t, void * pMem ) SAL_THROW(())
      61             :         { return pMem; }
      62             :     inline static void SAL_CALL operator delete ( void *, void * ) SAL_THROW(())
      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             :         SAL_THROW(());
      77             : 
      78             :     /** Holds a mapping from the specified source to the specified destination.
      79             : 
      80             :         @param pFrom        source environment
      81             :         @param pTo          destination environment
      82             :         @param rAddPurpose  additional purpose
      83             :     */
      84             :     inline Mapping(
      85             :         uno_Environment * pFrom, uno_Environment * pTo,
      86             :         const ::rtl::OUString & rAddPurpose = ::rtl::OUString() )
      87             :         SAL_THROW(());
      88             : 
      89             :     /** Holds a mapping from the specified source to the specified destination
      90             :         environment.
      91             : 
      92             :         @param rFrom         source environment
      93             :         @param rTo           destination environment
      94             :         @param rAddPurpose  additional purpose
      95             :     */
      96             :     inline Mapping(const Environment & rFrom, const Environment & rTo,
      97             :                    const ::rtl::OUString & rAddPurpose = ::rtl::OUString() )
      98             :         SAL_THROW(());
      99             : 
     100             :     /** Constructor.
     101             : 
     102             :         @param pMapping another mapping
     103             :     */
     104             :     inline Mapping( uno_Mapping * pMapping = 0 ) SAL_THROW(());
     105             : 
     106             :     /** Copy constructor.
     107             : 
     108             :         @param rMapping another mapping
     109             :     */
     110             :     inline Mapping( const Mapping & rMapping ) SAL_THROW(());
     111             : 
     112             :     /** Destructor.
     113             :     */
     114             :     inline ~Mapping() SAL_THROW(());
     115             : 
     116             :     /** Sets a given mapping.
     117             : 
     118             :         @param pMapping another mapping
     119             :         @return this mapping
     120             :     */
     121             :     inline Mapping & SAL_CALL operator = ( uno_Mapping * pMapping ) SAL_THROW(());
     122             :     /** Sets a given mapping.
     123             : 
     124             :         @param rMapping another mapping
     125             :         @return this mapping
     126             :     */
     127           0 :     inline Mapping & SAL_CALL operator = ( const Mapping & rMapping ) SAL_THROW(())
     128           0 :         { return operator = ( rMapping._pMapping ); }
     129             : 
     130             :     /** Provides a pointer to the C mapping. The returned mapping is NOT acquired!
     131             : 
     132             :         @return UNacquired C mapping
     133             :     */
     134          22 :     inline uno_Mapping * SAL_CALL get() const SAL_THROW(())
     135          22 :         { return _pMapping; }
     136             : 
     137             :     /** Tests if a mapping is set.
     138             : 
     139             :         @return true if a mapping is set
     140             :     */
     141           2 :     inline bool SAL_CALL is() const SAL_THROW(())
     142           2 :         { return (_pMapping != 0); }
     143             : 
     144             :     /** Releases a set mapping.
     145             :     */
     146             :     inline void SAL_CALL clear() SAL_THROW(());
     147             : 
     148             :     /** Maps an interface from one environment to another.
     149             : 
     150             :         @param pInterface       source interface
     151             :         @param pTypeDescr       type description of interface
     152             :         @return                 mapped interface
     153             :     */
     154             :     inline void * SAL_CALL mapInterface( void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const SAL_THROW(());
     155             :     /** Maps an interface from one environment to another.
     156             : 
     157             :         @param pInterface       source interface
     158             :         @param pTypeDescr       type description of interface
     159             :         @return                 mapped interface
     160             :     */
     161           0 :     inline void * SAL_CALL mapInterface( void * pInterface, typelib_TypeDescription * pTypeDescr ) const SAL_THROW(())
     162           0 :         { return mapInterface( pInterface, (typelib_InterfaceTypeDescription *)pTypeDescr ); }
     163             : 
     164             :     /** Maps an interface from one environment to another.
     165             : 
     166             :         @param pInterface       source interface
     167             :         @param rType            type of interface
     168             :         @return                 mapped interface
     169             :     */
     170             :     inline void * SAL_CALL mapInterface(
     171             :         void * pInterface, const ::com::sun::star::uno::Type & rType ) const SAL_THROW(());
     172             : 
     173             :     /** Maps an interface from one environment to another.
     174             : 
     175             :         @param ppOut            inout mapped interface
     176             :         @param pInterface       source interface
     177             :         @param pTypeDescr       type description of interface
     178             :     */
     179           2 :     inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const SAL_THROW(())
     180           2 :         { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, pTypeDescr ); }
     181             :     /** Maps an interface from one environment to another.
     182             : 
     183             :         @param ppOut            inout mapped interface
     184             :         @param pInterface       source interface
     185             :         @param pTypeDescr       type description of interface
     186             :     */
     187           0 :     inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_TypeDescription * pTypeDescr ) const SAL_THROW(())
     188           0 :         { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, (typelib_InterfaceTypeDescription *)pTypeDescr ); }
     189             : 
     190             :     /** Maps an interface from one environment to another.
     191             : 
     192             :         @param ppOut            inout mapped interface
     193             :         @param pInterface       source interface
     194             :         @param rType            type of interface to be mapped
     195             :      */
     196             :     inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, const ::com::sun::star::uno::Type & rType ) const SAL_THROW(());
     197             : };
     198             : 
     199           0 : inline Mapping::Mapping(
     200             :     const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo, const ::rtl::OUString & rAddPurpose )
     201             :     SAL_THROW(())
     202           0 :     : _pMapping( 0 )
     203             : {
     204           0 :     uno_getMappingByName( &_pMapping, rFrom.pData, rTo.pData, rAddPurpose.pData );
     205           0 : }
     206             : 
     207           2 : inline Mapping::Mapping(
     208             :     uno_Environment * pFrom, uno_Environment * pTo, const ::rtl::OUString & rAddPurpose )
     209             :     SAL_THROW(())
     210           2 :     : _pMapping( 0 )
     211             : {
     212           2 :     uno_getMapping( &_pMapping, pFrom, pTo, rAddPurpose.pData );
     213           2 : }
     214             : 
     215           4 : inline Mapping::Mapping(
     216             :     const Environment & rFrom, const Environment & rTo, const ::rtl::OUString & rAddPurpose )
     217             :     SAL_THROW(())
     218           4 :         : _pMapping(0)
     219             : {
     220           4 :     uno_getMapping( &_pMapping, rFrom.get(), rTo.get(), rAddPurpose.pData );
     221           4 : }
     222             : 
     223           0 : inline Mapping::Mapping( uno_Mapping * pMapping ) SAL_THROW(())
     224           0 :     : _pMapping( pMapping )
     225             : {
     226           0 :     if (_pMapping)
     227           0 :         (*_pMapping->acquire)( _pMapping );
     228           0 : }
     229             : 
     230           0 : inline Mapping::Mapping( const Mapping & rMapping ) SAL_THROW(())
     231           0 :     : _pMapping( rMapping._pMapping )
     232             : {
     233           0 :     if (_pMapping)
     234           0 :         (*_pMapping->acquire)( _pMapping );
     235           0 : }
     236             : 
     237           6 : inline Mapping::~Mapping() SAL_THROW(())
     238             : {
     239           6 :     if (_pMapping)
     240           6 :         (*_pMapping->release)( _pMapping );
     241           6 : }
     242             : 
     243             : inline void Mapping::clear() SAL_THROW(())
     244             : {
     245             :     if (_pMapping)
     246             :     {
     247             :         (*_pMapping->release)( _pMapping );
     248             :         _pMapping = 0;
     249             :     }
     250             : }
     251             : 
     252           0 : inline Mapping & Mapping::operator = ( uno_Mapping * pMapping ) SAL_THROW(())
     253             : {
     254           0 :     if (pMapping)
     255           0 :         (*pMapping->acquire)( pMapping );
     256           0 :     if (_pMapping)
     257           0 :         (*_pMapping->release)( _pMapping );
     258           0 :     _pMapping = pMapping;
     259           0 :     return *this;
     260             : }
     261             : 
     262           4 : inline void Mapping::mapInterface(
     263             :     void ** ppOut, void * pInterface, const ::com::sun::star::uno::Type & rType ) const
     264             :     SAL_THROW(())
     265             : {
     266           4 :     typelib_TypeDescription * pTD = 0;
     267           4 :     TYPELIB_DANGER_GET( &pTD, rType.getTypeLibType() );
     268           4 :     if (pTD)
     269             :     {
     270           4 :         (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, (typelib_InterfaceTypeDescription *)pTD );
     271           4 :         TYPELIB_DANGER_RELEASE( pTD );
     272             :     }
     273           4 : }
     274             : 
     275           0 : inline void * Mapping::mapInterface(
     276             :     void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const
     277             :     SAL_THROW(())
     278             : {
     279           0 :     void * pOut = 0;
     280           0 :     (*_pMapping->mapInterface)( _pMapping, &pOut, pInterface, pTypeDescr );
     281           0 :     return pOut;
     282             : }
     283             : 
     284           4 : inline void * Mapping::mapInterface(
     285             :     void * pInterface, const ::com::sun::star::uno::Type & rType ) const
     286             :     SAL_THROW(())
     287             : {
     288           4 :     void * pOut = 0;
     289           4 :     mapInterface( &pOut, pInterface, rType );
     290           4 :     return pOut;
     291             : }
     292             : 
     293             : /** Deprecated. This function DOES NOT WORK with Purpose Environments
     294             :     (http://wiki.openoffice.org/wiki/Uno/Binary/Spec/Purpose Environments)
     295             : 
     296             :     Maps an binary C UNO interface to be used in the currently used compiler environment.
     297             : 
     298             :     @tparam C interface type
     299             :     @param ppRet inout returned interface pointer
     300             :     @param pUnoI binary C UNO interface
     301             :     @return true if successful, false otherwise
     302             : 
     303             :     @deprecated
     304             : */
     305             : template< class C >
     306             : inline bool mapToCpp( Reference< C > * ppRet, uno_Interface * pUnoI ) SAL_THROW(())
     307             : {
     308             :     Mapping aMapping(
     309             :         ::rtl::OUString( UNO_LB_UNO ),
     310             :         ::rtl::OUString( CPPU_CURRENT_LANGUAGE_BINDING_NAME ) );
     311             :     OSL_ASSERT( aMapping.is() );
     312             :     aMapping.mapInterface(
     313             :             (void **)ppRet, pUnoI, ::cppu::getTypeFavourUnsigned( ppRet ) );
     314             :     return (0 != *ppRet);
     315             : }
     316             : /** Deprecated. This function DOES NOT WORK with Purpose Environments
     317             :     (http://wiki.openoffice.org/wiki/Uno/Binary/Spec/Purpose Environments)
     318             : 
     319             :     Maps an UNO interface of the currently used compiler environment to binary C UNO.
     320             : 
     321             :     @tparam C interface type
     322             :     @param ppRet inout returned interface pointer
     323             :     @param x interface reference
     324             :     @return true if successful, false otherwise
     325             : 
     326             :     @deprecated
     327             : */
     328             : template< class C >
     329             : inline bool mapToUno( uno_Interface ** ppRet, const Reference< C > & x ) SAL_THROW(())
     330             : {
     331             :     Mapping aMapping(
     332             :         ::rtl::OUString( CPPU_CURRENT_LANGUAGE_BINDING_NAME ),
     333             :         ::rtl::OUString( UNO_LB_UNO ) );
     334             :     OSL_ASSERT( aMapping.is() );
     335             :     aMapping.mapInterface(
     336             :             (void **)ppRet, x.get(), ::cppu::getTypeFavourUnsigned( &x ) );
     337             :     return (0 != *ppRet);
     338             : }
     339             : 
     340             : }
     341             : }
     342             : }
     343             : }
     344             : 
     345             : #endif
     346             : 
     347             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10