1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: mapping.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef _UNO_MAPPING_HXX_
31 #define _UNO_MAPPING_HXX_
33 #include <cppu/macros.hxx>
34 #include <rtl/alloc.h>
35 #include <rtl/ustring.hxx>
36 #include <uno/mapping.h>
37 #include <com/sun/star/uno/Type.hxx>
38 #include <com/sun/star/uno/Reference.hxx>
39 #include "cppu/unotype.hxx"
40 #include "uno/environment.hxx"
42 typedef struct _typelib_TypeDescription typelib_TypeDescription
;
43 typedef struct _typelib_InterfaceTypeDescription typelib_InterfaceTypeDescription
;
44 typedef struct _uno_Interface uno_Interface
;
55 /** C++ wrapper for C uno_Mapping.
61 uno_Mapping
* _pMapping
;
64 // these are here to force memory de/allocation to sal lib.
66 inline static void * SAL_CALL
operator new ( size_t nSize
) SAL_THROW( () )
67 { return ::rtl_allocateMemory( nSize
); }
69 inline static void SAL_CALL
operator delete ( void * pMem
) SAL_THROW( () )
70 { ::rtl_freeMemory( pMem
); }
72 inline static void * SAL_CALL
operator new ( size_t, void * pMem
) SAL_THROW( () )
75 inline static void SAL_CALL
operator delete ( void *, void * ) SAL_THROW( () )
78 /** Holds a mapping from the specified source to the specified destination by environment
81 @param rFrom type name of source environment
82 @param rTo type name of destination environment
83 @param rAddPurpose additional purpose
86 const ::rtl::OUString
& rFrom
, const ::rtl::OUString
& rTo
,
87 const ::rtl::OUString
& rAddPurpose
= ::rtl::OUString() )
90 /** Holds a mapping from the specified source to the specified destination.
92 @param pFrom source environment
93 @param pTo destination environment
94 @param rAddPurpose additional purpose
97 uno_Environment
* pFrom
, uno_Environment
* pTo
,
98 const ::rtl::OUString
& rAddPurpose
= ::rtl::OUString() )
101 /** Holds a mapping from the specified source to the specified destination
104 @param from source environment
105 @param to destination environment
106 @param rAddPurpose additional purpose
108 inline Mapping(const Environment
& rFrom
, const Environment
& rTo
,
109 const ::rtl::OUString
& rAddPurpose
= ::rtl::OUString() )
114 @param pMapping another mapping
116 inline Mapping( uno_Mapping
* pMapping
= 0 ) SAL_THROW( () );
118 /** Copy constructor.
120 @param rMapping another mapping
122 inline Mapping( const Mapping
& rMapping
) SAL_THROW( () );
126 inline ~Mapping() SAL_THROW( () );
128 /** Sets a given mapping.
130 @param pMapping another mapping
133 inline Mapping
& SAL_CALL
operator = ( uno_Mapping
* pMapping
) SAL_THROW( () );
134 /** Sets a given mapping.
136 @param rMapping another mapping
139 inline Mapping
& SAL_CALL
operator = ( const Mapping
& rMapping
) SAL_THROW( () )
140 { return operator = ( rMapping
._pMapping
); }
142 /** Provides a pointer to the C mapping. The returned mapping is NOT acquired!
144 @return UNacquired C mapping
146 inline uno_Mapping
* SAL_CALL
get() const SAL_THROW( () )
147 { return _pMapping
; }
149 /** Tests if a mapping is set.
151 @return true if a mapping is set
153 inline sal_Bool SAL_CALL
is() const SAL_THROW( () )
154 { return (_pMapping
!= 0); }
156 /** Releases a set mapping.
158 inline void SAL_CALL
clear() SAL_THROW( () );
160 /** Maps an interface from one environment to another.
162 @param pInterface source interface
163 @param pTypeDescr type description of interface
164 @return mapped interface
166 inline void * SAL_CALL
mapInterface( void * pInterface
, typelib_InterfaceTypeDescription
* pTypeDescr
) const SAL_THROW( () );
167 /** Maps an interface from one environment to another.
169 @param pInterface source interface
170 @param pTypeDescr type description of interface
171 @return mapped interface
173 inline void * SAL_CALL
mapInterface( void * pInterface
, typelib_TypeDescription
* pTypeDescr
) const SAL_THROW( () )
174 { return mapInterface( pInterface
, (typelib_InterfaceTypeDescription
*)pTypeDescr
); }
176 /** Maps an interface from one environment to another.
178 @param pInterface source interface
179 @param rType type of interface
180 @return mapped interface
182 inline void * SAL_CALL
mapInterface(
183 void * pInterface
, const ::com::sun::star::uno::Type
& rType
) const SAL_THROW( () );
185 /** Maps an interface from one environment to another.
187 @param ppOut inout mapped interface
188 @param pInterface source interface
189 @param pTypeDescr type description of interface
191 inline void SAL_CALL
mapInterface( void ** ppOut
, void * pInterface
, typelib_InterfaceTypeDescription
* pTypeDescr
) const SAL_THROW( () )
192 { (*_pMapping
->mapInterface
)( _pMapping
, ppOut
, pInterface
, pTypeDescr
); }
193 /** Maps an interface from one environment to another.
195 @param ppOut inout mapped interface
196 @param pInterface source interface
197 @param pTypeDescr type description of interface
199 inline void SAL_CALL
mapInterface( void ** ppOut
, void * pInterface
, typelib_TypeDescription
* pTypeDescr
) const SAL_THROW( () )
200 { (*_pMapping
->mapInterface
)( _pMapping
, ppOut
, pInterface
, (typelib_InterfaceTypeDescription
*)pTypeDescr
); }
202 /** Maps an interface from one environment to another.
204 @param ppOut inout mapped interface
205 @param pInterface source interface
206 @param rType type of interface to be mapped
208 inline void SAL_CALL
mapInterface( void ** ppOut
, void * pInterface
, const ::com::sun::star::uno::Type
& rType
) const SAL_THROW( () );
210 //__________________________________________________________________________________________________
211 inline Mapping::Mapping(
212 const ::rtl::OUString
& rFrom
, const ::rtl::OUString
& rTo
, const ::rtl::OUString
& rAddPurpose
)
216 uno_getMappingByName( &_pMapping
, rFrom
.pData
, rTo
.pData
, rAddPurpose
.pData
);
218 //__________________________________________________________________________________________________
219 inline Mapping::Mapping(
220 uno_Environment
* pFrom
, uno_Environment
* pTo
, const ::rtl::OUString
& rAddPurpose
)
224 uno_getMapping( &_pMapping
, pFrom
, pTo
, rAddPurpose
.pData
);
226 //__________________________________________________________________________________________________
227 inline Mapping::Mapping(
228 const Environment
& rFrom
, const Environment
& rTo
, const ::rtl::OUString
& rAddPurpose
)
232 uno_getMapping( &_pMapping
, rFrom
.get(), rTo
.get(), rAddPurpose
.pData
);
234 //__________________________________________________________________________________________________
235 inline Mapping::Mapping( uno_Mapping
* pMapping
) SAL_THROW( () )
236 : _pMapping( pMapping
)
239 (*_pMapping
->acquire
)( _pMapping
);
241 //__________________________________________________________________________________________________
242 inline Mapping::Mapping( const Mapping
& rMapping
) SAL_THROW( () )
243 : _pMapping( rMapping
._pMapping
)
246 (*_pMapping
->acquire
)( _pMapping
);
248 //__________________________________________________________________________________________________
249 inline Mapping::~Mapping() SAL_THROW( () )
252 (*_pMapping
->release
)( _pMapping
);
254 //__________________________________________________________________________________________________
255 inline void Mapping::clear() SAL_THROW( () )
259 (*_pMapping
->release
)( _pMapping
);
263 //__________________________________________________________________________________________________
264 inline Mapping
& Mapping::operator = ( uno_Mapping
* pMapping
) SAL_THROW( () )
267 (*pMapping
->acquire
)( pMapping
);
269 (*_pMapping
->release
)( _pMapping
);
270 _pMapping
= pMapping
;
273 //__________________________________________________________________________________________________
274 inline void Mapping::mapInterface(
275 void ** ppOut
, void * pInterface
, const ::com::sun::star::uno::Type
& rType
) const
278 typelib_TypeDescription
* pTD
= 0;
279 TYPELIB_DANGER_GET( &pTD
, rType
.getTypeLibType() );
282 (*_pMapping
->mapInterface
)( _pMapping
, ppOut
, pInterface
, (typelib_InterfaceTypeDescription
*)pTD
);
283 TYPELIB_DANGER_RELEASE( pTD
);
286 //__________________________________________________________________________________________________
287 inline void * Mapping::mapInterface(
288 void * pInterface
, typelib_InterfaceTypeDescription
* pTypeDescr
) const
292 (*_pMapping
->mapInterface
)( _pMapping
, &pOut
, pInterface
, pTypeDescr
);
295 //__________________________________________________________________________________________________
296 inline void * Mapping::mapInterface(
297 void * pInterface
, const ::com::sun::star::uno::Type
& rType
) const
301 mapInterface( &pOut
, pInterface
, rType
);
305 /** Deprecated. This function DOES NOT WORK with Purpose Environments
306 (http://wiki.services.openoffice.org/wiki/Uno/Binary/Spec/Purpose Environments)
308 Maps an binary C UNO interface to be used in the currently used compiler environment.
310 @tplparam C interface type
311 @param ppRet inout returned interface pointer
312 @param pUnoI binary C UNO interface
313 @return true if successful, false otherwise
318 inline sal_Bool
mapToCpp( Reference
< C
> * ppRet
, uno_Interface
* pUnoI
) SAL_THROW( () )
321 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO
) ),
322 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME
) ) );
323 OSL_ASSERT( aMapping
.is() );
324 aMapping
.mapInterface(
325 (void **)ppRet
, pUnoI
, ::cppu::getTypeFavourUnsigned( ppRet
) );
326 return (0 != *ppRet
);
328 /** Deprecated. This function DOES NOT WORK with Purpose Environments
329 (http://wiki.services.openoffice.org/wiki/Uno/Binary/Spec/Purpose Environments)
331 Maps an UNO interface of the currently used compiler environment to binary C UNO.
333 @tplparam C interface type
334 @param ppRet inout returned interface pointer
335 @param x interface reference
336 @return true if successful, false otherwise
341 inline sal_Bool
mapToUno( uno_Interface
** ppRet
, const Reference
< C
> & x
) SAL_THROW( () )
344 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME
) ),
345 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO
) ) );
346 OSL_ASSERT( aMapping
.is() );
347 aMapping
.mapInterface(
348 (void **)ppRet
, x
.get(), ::cppu::getTypeFavourUnsigned( &x
) );
349 return (0 != *ppRet
);