00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef _UNO_MAPPING_HXX_
00020 #define _UNO_MAPPING_HXX_
00021
00022 #include <cppu/macros.hxx>
00023 #include <rtl/alloc.h>
00024 #include <rtl/ustring.hxx>
00025 #include <uno/mapping.h>
00026 #include <com/sun/star/uno/Type.hxx>
00027 #include <com/sun/star/uno/Reference.hxx>
00028 #include "cppu/unotype.hxx"
00029 #include "uno/environment.hxx"
00030
00031 typedef struct _typelib_TypeDescription typelib_TypeDescription;
00032 typedef struct _typelib_InterfaceTypeDescription typelib_InterfaceTypeDescription;
00033 typedef struct _uno_Interface uno_Interface;
00034
00035 namespace com
00036 {
00037 namespace sun
00038 {
00039 namespace star
00040 {
00041 namespace uno
00042 {
00043
00048 class Mapping
00049 {
00050 uno_Mapping * _pMapping;
00051
00052 public:
00053
00055 inline static void * SAL_CALL operator new ( size_t nSize ) SAL_THROW(())
00056 { return ::rtl_allocateMemory( nSize ); }
00057 inline static void SAL_CALL operator delete ( void * pMem ) SAL_THROW(())
00058 { ::rtl_freeMemory( pMem ); }
00059 inline static void * SAL_CALL operator new ( size_t, void * pMem ) SAL_THROW(())
00060 { return pMem; }
00061 inline static void SAL_CALL operator delete ( void *, void * ) SAL_THROW(())
00062 {}
00064
00072 inline Mapping(
00073 const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo,
00074 const ::rtl::OUString & rAddPurpose = ::rtl::OUString() )
00075 SAL_THROW(());
00076
00083 inline Mapping(
00084 uno_Environment * pFrom, uno_Environment * pTo,
00085 const ::rtl::OUString & rAddPurpose = ::rtl::OUString() )
00086 SAL_THROW(());
00087
00095 inline Mapping(const Environment & rFrom, const Environment & rTo,
00096 const ::rtl::OUString & rAddPurpose = ::rtl::OUString() )
00097 SAL_THROW(());
00098
00103 inline Mapping( uno_Mapping * pMapping = 0 ) SAL_THROW(());
00104
00109 inline Mapping( const Mapping & rMapping ) SAL_THROW(());
00110
00113 inline ~Mapping() SAL_THROW(());
00114
00120 inline Mapping & SAL_CALL operator = ( uno_Mapping * pMapping ) SAL_THROW(());
00126 inline Mapping & SAL_CALL operator = ( const Mapping & rMapping ) SAL_THROW(())
00127 { return operator = ( rMapping._pMapping ); }
00128
00133 inline uno_Mapping * SAL_CALL get() const SAL_THROW(())
00134 { return _pMapping; }
00135
00140 inline sal_Bool SAL_CALL is() const SAL_THROW(())
00141 { return (_pMapping != 0); }
00142
00145 inline void SAL_CALL clear() SAL_THROW(());
00146
00153 inline void * SAL_CALL mapInterface( void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const SAL_THROW(());
00160 inline void * SAL_CALL mapInterface( void * pInterface, typelib_TypeDescription * pTypeDescr ) const SAL_THROW(())
00161 { return mapInterface( pInterface, (typelib_InterfaceTypeDescription *)pTypeDescr ); }
00162
00169 inline void * SAL_CALL mapInterface(
00170 void * pInterface, const ::com::sun::star::uno::Type & rType ) const SAL_THROW(());
00171
00178 inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const SAL_THROW(())
00179 { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, pTypeDescr ); }
00186 inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_TypeDescription * pTypeDescr ) const SAL_THROW(())
00187 { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, (typelib_InterfaceTypeDescription *)pTypeDescr ); }
00188
00195 inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, const ::com::sun::star::uno::Type & rType ) const SAL_THROW(());
00196 };
00197
00198 inline Mapping::Mapping(
00199 const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo, const ::rtl::OUString & rAddPurpose )
00200 SAL_THROW(())
00201 : _pMapping( 0 )
00202 {
00203 uno_getMappingByName( &_pMapping, rFrom.pData, rTo.pData, rAddPurpose.pData );
00204 }
00205
00206 inline Mapping::Mapping(
00207 uno_Environment * pFrom, uno_Environment * pTo, const ::rtl::OUString & rAddPurpose )
00208 SAL_THROW(())
00209 : _pMapping( 0 )
00210 {
00211 uno_getMapping( &_pMapping, pFrom, pTo, rAddPurpose.pData );
00212 }
00213
00214 inline Mapping::Mapping(
00215 const Environment & rFrom, const Environment & rTo, const ::rtl::OUString & rAddPurpose )
00216 SAL_THROW(())
00217 : _pMapping(0)
00218 {
00219 uno_getMapping( &_pMapping, rFrom.get(), rTo.get(), rAddPurpose.pData );
00220 }
00221
00222 inline Mapping::Mapping( uno_Mapping * pMapping ) SAL_THROW(())
00223 : _pMapping( pMapping )
00224 {
00225 if (_pMapping)
00226 (*_pMapping->acquire)( _pMapping );
00227 }
00228
00229 inline Mapping::Mapping( const Mapping & rMapping ) SAL_THROW(())
00230 : _pMapping( rMapping._pMapping )
00231 {
00232 if (_pMapping)
00233 (*_pMapping->acquire)( _pMapping );
00234 }
00235
00236 inline Mapping::~Mapping() SAL_THROW(())
00237 {
00238 if (_pMapping)
00239 (*_pMapping->release)( _pMapping );
00240 }
00241
00242 inline void Mapping::clear() SAL_THROW(())
00243 {
00244 if (_pMapping)
00245 {
00246 (*_pMapping->release)( _pMapping );
00247 _pMapping = 0;
00248 }
00249 }
00250
00251 inline Mapping & Mapping::operator = ( uno_Mapping * pMapping ) SAL_THROW(())
00252 {
00253 if (pMapping)
00254 (*pMapping->acquire)( pMapping );
00255 if (_pMapping)
00256 (*_pMapping->release)( _pMapping );
00257 _pMapping = pMapping;
00258 return *this;
00259 }
00260
00261 inline void Mapping::mapInterface(
00262 void ** ppOut, void * pInterface, const ::com::sun::star::uno::Type & rType ) const
00263 SAL_THROW(())
00264 {
00265 typelib_TypeDescription * pTD = 0;
00266 TYPELIB_DANGER_GET( &pTD, rType.getTypeLibType() );
00267 if (pTD)
00268 {
00269 (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, (typelib_InterfaceTypeDescription *)pTD );
00270 TYPELIB_DANGER_RELEASE( pTD );
00271 }
00272 }
00273
00274 inline void * Mapping::mapInterface(
00275 void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const
00276 SAL_THROW(())
00277 {
00278 void * pOut = 0;
00279 (*_pMapping->mapInterface)( _pMapping, &pOut, pInterface, pTypeDescr );
00280 return pOut;
00281 }
00282
00283 inline void * Mapping::mapInterface(
00284 void * pInterface, const ::com::sun::star::uno::Type & rType ) const
00285 SAL_THROW(())
00286 {
00287 void * pOut = 0;
00288 mapInterface( &pOut, pInterface, rType );
00289 return pOut;
00290 }
00291
00304 template< class C >
00305 inline sal_Bool mapToCpp( Reference< C > * ppRet, uno_Interface * pUnoI ) SAL_THROW(())
00306 {
00307 Mapping aMapping(
00308 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO) ),
00309 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ) );
00310 OSL_ASSERT( aMapping.is() );
00311 aMapping.mapInterface(
00312 (void **)ppRet, pUnoI, ::cppu::getTypeFavourUnsigned( ppRet ) );
00313 return (0 != *ppRet);
00314 }
00327 template< class C >
00328 inline sal_Bool mapToUno( uno_Interface ** ppRet, const Reference< C > & x ) SAL_THROW(())
00329 {
00330 Mapping aMapping(
00331 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ),
00332 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO) ) );
00333 OSL_ASSERT( aMapping.is() );
00334 aMapping.mapInterface(
00335 (void **)ppRet, x.get(), ::cppu::getTypeFavourUnsigned( &x ) );
00336 return (0 != *ppRet);
00337 }
00338
00339 }
00340 }
00341 }
00342 }
00343
00344 #endif
00345
00346