UDK 3.2.7 C/C++ API Reference
uno/mapping.hxx
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /*************************************************************************
00003  *
00004  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
00005  *
00006  * Copyright 2000, 2010 Oracle and/or its affiliates.
00007  *
00008  * OpenOffice.org - a multi-platform office productivity suite
00009  *
00010  * This file is part of OpenOffice.org.
00011  *
00012  * OpenOffice.org is free software: you can redistribute it and/or modify
00013  * it under the terms of the GNU Lesser General Public License version 3
00014  * only, as published by the Free Software Foundation.
00015  *
00016  * OpenOffice.org is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU Lesser General Public License version 3 for more details
00020  * (a copy is included in the LICENSE file that accompanied this code).
00021  *
00022  * You should have received a copy of the GNU Lesser General Public License
00023  * version 3 along with OpenOffice.org.  If not, see
00024  * <http://www.openoffice.org/license.html>
00025  * for a copy of the LGPLv3 License.
00026  *
00027  ************************************************************************/
00028 #ifndef _UNO_MAPPING_HXX_
00029 #define _UNO_MAPPING_HXX_
00030 
00031 #include <cppu/macros.hxx>
00032 #include <rtl/alloc.h>
00033 #include <rtl/ustring.hxx>
00034 #include <uno/mapping.h>
00035 #include <com/sun/star/uno/Type.hxx>
00036 #include <com/sun/star/uno/Reference.hxx>
00037 #include "cppu/unotype.hxx"
00038 #include "uno/environment.hxx"
00039 
00040 typedef struct _typelib_TypeDescription typelib_TypeDescription;
00041 typedef struct _typelib_InterfaceTypeDescription typelib_InterfaceTypeDescription;
00042 typedef struct _uno_Interface uno_Interface;
00043 
00044 namespace com
00045 {
00046 namespace sun
00047 {
00048 namespace star
00049 {
00050 namespace uno
00051 {
00052 
00057 class Mapping
00058 {
00059     uno_Mapping * _pMapping;
00060 
00061 public:
00062     // these are here to force memory de/allocation to sal lib.
00064     inline static void * SAL_CALL operator new ( size_t nSize ) SAL_THROW(())
00065         { return ::rtl_allocateMemory( nSize ); }
00066     inline static void SAL_CALL operator delete ( void * pMem ) SAL_THROW(())
00067         { ::rtl_freeMemory( pMem ); }
00068     inline static void * SAL_CALL operator new ( size_t, void * pMem ) SAL_THROW(())
00069         { return pMem; }
00070     inline static void SAL_CALL operator delete ( void *, void * ) SAL_THROW(())
00071         {}
00073 
00081     inline Mapping(
00082         const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo,
00083         const ::rtl::OUString & rAddPurpose = ::rtl::OUString() )
00084         SAL_THROW(());
00085 
00092     inline Mapping(
00093         uno_Environment * pFrom, uno_Environment * pTo,
00094         const ::rtl::OUString & rAddPurpose = ::rtl::OUString() )
00095         SAL_THROW(());
00096 
00104     inline Mapping(const Environment & rFrom, const Environment & rTo,
00105                    const ::rtl::OUString & rAddPurpose = ::rtl::OUString() )
00106         SAL_THROW(());
00107 
00112     inline Mapping( uno_Mapping * pMapping = 0 ) SAL_THROW(());
00113 
00118     inline Mapping( const Mapping & rMapping ) SAL_THROW(());
00119 
00122     inline ~Mapping() SAL_THROW(());
00123 
00129     inline Mapping & SAL_CALL operator = ( uno_Mapping * pMapping ) SAL_THROW(());
00135     inline Mapping & SAL_CALL operator = ( const Mapping & rMapping ) SAL_THROW(())
00136         { return operator = ( rMapping._pMapping ); }
00137 
00142     inline uno_Mapping * SAL_CALL get() const SAL_THROW(())
00143         { return _pMapping; }
00144 
00149     inline sal_Bool SAL_CALL is() const SAL_THROW(())
00150         { return (_pMapping != 0); }
00151 
00154     inline void SAL_CALL clear() SAL_THROW(());
00155 
00162     inline void * SAL_CALL mapInterface( void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const SAL_THROW(());
00169     inline void * SAL_CALL mapInterface( void * pInterface, typelib_TypeDescription * pTypeDescr ) const SAL_THROW(())
00170         { return mapInterface( pInterface, (typelib_InterfaceTypeDescription *)pTypeDescr ); }
00171 
00178     inline void * SAL_CALL mapInterface(
00179         void * pInterface, const ::com::sun::star::uno::Type & rType ) const SAL_THROW(());
00180 
00187     inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const SAL_THROW(())
00188         { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, pTypeDescr ); }
00195     inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_TypeDescription * pTypeDescr ) const SAL_THROW(())
00196         { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, (typelib_InterfaceTypeDescription *)pTypeDescr ); }
00197 
00204     inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, const ::com::sun::star::uno::Type & rType ) const SAL_THROW(());
00205 };
00206 //__________________________________________________________________________________________________
00207 inline Mapping::Mapping(
00208     const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo, const ::rtl::OUString & rAddPurpose )
00209     SAL_THROW(())
00210     : _pMapping( 0 )
00211 {
00212     uno_getMappingByName( &_pMapping, rFrom.pData, rTo.pData, rAddPurpose.pData );
00213 }
00214 //__________________________________________________________________________________________________
00215 inline Mapping::Mapping(
00216     uno_Environment * pFrom, uno_Environment * pTo, const ::rtl::OUString & rAddPurpose )
00217     SAL_THROW(())
00218     : _pMapping( 0 )
00219 {
00220     uno_getMapping( &_pMapping, pFrom, pTo, rAddPurpose.pData );
00221 }
00222 //__________________________________________________________________________________________________
00223 inline Mapping::Mapping(
00224     const Environment & rFrom, const Environment & rTo, const ::rtl::OUString & rAddPurpose )
00225     SAL_THROW(())
00226         : _pMapping(0)
00227 {
00228     uno_getMapping( &_pMapping, rFrom.get(), rTo.get(), rAddPurpose.pData );
00229 }
00230 //__________________________________________________________________________________________________
00231 inline Mapping::Mapping( uno_Mapping * pMapping ) SAL_THROW(())
00232     : _pMapping( pMapping )
00233 {
00234     if (_pMapping)
00235         (*_pMapping->acquire)( _pMapping );
00236 }
00237 //__________________________________________________________________________________________________
00238 inline Mapping::Mapping( const Mapping & rMapping ) SAL_THROW(())
00239     : _pMapping( rMapping._pMapping )
00240 {
00241     if (_pMapping)
00242         (*_pMapping->acquire)( _pMapping );
00243 }
00244 //__________________________________________________________________________________________________
00245 inline Mapping::~Mapping() SAL_THROW(())
00246 {
00247     if (_pMapping)
00248         (*_pMapping->release)( _pMapping );
00249 }
00250 //__________________________________________________________________________________________________
00251 inline void Mapping::clear() SAL_THROW(())
00252 {
00253     if (_pMapping)
00254     {
00255         (*_pMapping->release)( _pMapping );
00256         _pMapping = 0;
00257     }
00258 }
00259 //__________________________________________________________________________________________________
00260 inline Mapping & Mapping::operator = ( uno_Mapping * pMapping ) SAL_THROW(())
00261 {
00262     if (pMapping)
00263         (*pMapping->acquire)( pMapping );
00264     if (_pMapping)
00265         (*_pMapping->release)( _pMapping );
00266     _pMapping = pMapping;
00267     return *this;
00268 }
00269 //__________________________________________________________________________________________________
00270 inline void Mapping::mapInterface(
00271     void ** ppOut, void * pInterface, const ::com::sun::star::uno::Type & rType ) const
00272     SAL_THROW(())
00273 {
00274     typelib_TypeDescription * pTD = 0;
00275     TYPELIB_DANGER_GET( &pTD, rType.getTypeLibType() );
00276     if (pTD)
00277     {
00278         (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, (typelib_InterfaceTypeDescription *)pTD );
00279         TYPELIB_DANGER_RELEASE( pTD );
00280     }
00281 }
00282 //__________________________________________________________________________________________________
00283 inline void * Mapping::mapInterface(
00284     void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const
00285     SAL_THROW(())
00286 {
00287     void * pOut = 0;
00288     (*_pMapping->mapInterface)( _pMapping, &pOut, pInterface, pTypeDescr );
00289     return pOut;
00290 }
00291 //__________________________________________________________________________________________________
00292 inline void * Mapping::mapInterface(
00293     void * pInterface, const ::com::sun::star::uno::Type & rType ) const
00294     SAL_THROW(())
00295 {
00296     void * pOut = 0;
00297     mapInterface( &pOut, pInterface, rType );
00298     return pOut;
00299 }
00300 
00313 template< class C >
00314 inline sal_Bool mapToCpp( Reference< C > * ppRet, uno_Interface * pUnoI ) SAL_THROW(())
00315 {
00316     Mapping aMapping(
00317         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO) ),
00318         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ) );
00319     OSL_ASSERT( aMapping.is() );
00320     aMapping.mapInterface(
00321             (void **)ppRet, pUnoI, ::cppu::getTypeFavourUnsigned( ppRet ) );
00322     return (0 != *ppRet);
00323 }
00336 template< class C >
00337 inline sal_Bool mapToUno( uno_Interface ** ppRet, const Reference< C > & x ) SAL_THROW(())
00338 {
00339     Mapping aMapping(
00340         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ),
00341         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO) ) );
00342     OSL_ASSERT( aMapping.is() );
00343     aMapping.mapInterface(
00344             (void **)ppRet, x.get(), ::cppu::getTypeFavourUnsigned( &x ) );
00345     return (0 != *ppRet);
00346 }
00347 
00348 }
00349 }
00350 }
00351 }
00352 
00353 #endif
00354 
00355 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines