fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / include / uno / mapping.hxx
blobf4340b58df9bcac5d3764d385bc3e05e7f46c577
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef _UNO_MAPPING_HXX_
20 #define _UNO_MAPPING_HXX_
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"
31 typedef struct _typelib_TypeDescription typelib_TypeDescription;
32 typedef struct _typelib_InterfaceTypeDescription typelib_InterfaceTypeDescription;
33 typedef struct _uno_Interface uno_Interface;
35 namespace com
37 namespace sun
39 namespace star
41 namespace uno
44 /** C++ wrapper for C uno_Mapping.
46 @see uno_Mapping
48 class Mapping
50 uno_Mapping * _pMapping;
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(())
63 /// @endcond
65 /** Holds a mapping from the specified source to the specified destination by environment
66 type names.
68 @param rFrom type name of source environment
69 @param rTo type name of destination environment
70 @param rAddPurpose additional purpose
72 inline Mapping(
73 const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo,
74 const ::rtl::OUString & rAddPurpose = ::rtl::OUString() )
75 SAL_THROW(());
77 /** Holds a mapping from the specified source to the specified destination.
79 @param pFrom source environment
80 @param pTo destination environment
81 @param rAddPurpose additional purpose
83 inline Mapping(
84 uno_Environment * pFrom, uno_Environment * pTo,
85 const ::rtl::OUString & rAddPurpose = ::rtl::OUString() )
86 SAL_THROW(());
88 /** Holds a mapping from the specified source to the specified destination
89 environment.
91 @param rFrom source environment
92 @param rTo destination environment
93 @param rAddPurpose additional purpose
95 inline Mapping(const Environment & rFrom, const Environment & rTo,
96 const ::rtl::OUString & rAddPurpose = ::rtl::OUString() )
97 SAL_THROW(());
99 /** Constructor.
101 @param pMapping another mapping
103 inline Mapping( uno_Mapping * pMapping = 0 ) SAL_THROW(());
105 /** Copy constructor.
107 @param rMapping another mapping
109 inline Mapping( const Mapping & rMapping ) SAL_THROW(());
111 /** Destructor.
113 inline ~Mapping() SAL_THROW(());
115 /** Sets a given mapping.
117 @param pMapping another mapping
118 @return this mapping
120 inline Mapping & SAL_CALL operator = ( uno_Mapping * pMapping ) SAL_THROW(());
121 /** Sets a given mapping.
123 @param rMapping another mapping
124 @return this mapping
126 inline Mapping & SAL_CALL operator = ( const Mapping & rMapping ) SAL_THROW(())
127 { return operator = ( rMapping._pMapping ); }
129 /** Provides a pointer to the C mapping. The returned mapping is NOT acquired!
131 @return UNacquired C mapping
133 inline uno_Mapping * SAL_CALL get() const SAL_THROW(())
134 { return _pMapping; }
136 /** Tests if a mapping is set.
138 @return true if a mapping is set
140 inline sal_Bool SAL_CALL is() const SAL_THROW(())
141 { return (_pMapping != 0); }
143 /** Releases a set mapping.
145 inline void SAL_CALL clear() SAL_THROW(());
147 /** Maps an interface from one environment to another.
149 @param pInterface source interface
150 @param pTypeDescr type description of interface
151 @return mapped interface
153 inline void * SAL_CALL mapInterface( void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const SAL_THROW(());
154 /** Maps an interface from one environment to another.
156 @param pInterface source interface
157 @param pTypeDescr type description of interface
158 @return mapped interface
160 inline void * SAL_CALL mapInterface( void * pInterface, typelib_TypeDescription * pTypeDescr ) const SAL_THROW(())
161 { return mapInterface( pInterface, (typelib_InterfaceTypeDescription *)pTypeDescr ); }
163 /** Maps an interface from one environment to another.
165 @param pInterface source interface
166 @param rType type of interface
167 @return mapped interface
169 inline void * SAL_CALL mapInterface(
170 void * pInterface, const ::com::sun::star::uno::Type & rType ) const SAL_THROW(());
172 /** Maps an interface from one environment to another.
174 @param ppOut inout mapped interface
175 @param pInterface source interface
176 @param pTypeDescr type description of interface
178 inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const SAL_THROW(())
179 { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, pTypeDescr ); }
180 /** Maps an interface from one environment to another.
182 @param ppOut inout mapped interface
183 @param pInterface source interface
184 @param pTypeDescr type description of interface
186 inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_TypeDescription * pTypeDescr ) const SAL_THROW(())
187 { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, (typelib_InterfaceTypeDescription *)pTypeDescr ); }
189 /** Maps an interface from one environment to another.
191 @param ppOut inout mapped interface
192 @param pInterface source interface
193 @param rType type of interface to be mapped
195 inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, const ::com::sun::star::uno::Type & rType ) const SAL_THROW(());
197 //__________________________________________________________________________________________________
198 inline Mapping::Mapping(
199 const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo, const ::rtl::OUString & rAddPurpose )
200 SAL_THROW(())
201 : _pMapping( 0 )
203 uno_getMappingByName( &_pMapping, rFrom.pData, rTo.pData, rAddPurpose.pData );
205 //__________________________________________________________________________________________________
206 inline Mapping::Mapping(
207 uno_Environment * pFrom, uno_Environment * pTo, const ::rtl::OUString & rAddPurpose )
208 SAL_THROW(())
209 : _pMapping( 0 )
211 uno_getMapping( &_pMapping, pFrom, pTo, rAddPurpose.pData );
213 //__________________________________________________________________________________________________
214 inline Mapping::Mapping(
215 const Environment & rFrom, const Environment & rTo, const ::rtl::OUString & rAddPurpose )
216 SAL_THROW(())
217 : _pMapping(0)
219 uno_getMapping( &_pMapping, rFrom.get(), rTo.get(), rAddPurpose.pData );
221 //__________________________________________________________________________________________________
222 inline Mapping::Mapping( uno_Mapping * pMapping ) SAL_THROW(())
223 : _pMapping( pMapping )
225 if (_pMapping)
226 (*_pMapping->acquire)( _pMapping );
228 //__________________________________________________________________________________________________
229 inline Mapping::Mapping( const Mapping & rMapping ) SAL_THROW(())
230 : _pMapping( rMapping._pMapping )
232 if (_pMapping)
233 (*_pMapping->acquire)( _pMapping );
235 //__________________________________________________________________________________________________
236 inline Mapping::~Mapping() SAL_THROW(())
238 if (_pMapping)
239 (*_pMapping->release)( _pMapping );
241 //__________________________________________________________________________________________________
242 inline void Mapping::clear() SAL_THROW(())
244 if (_pMapping)
246 (*_pMapping->release)( _pMapping );
247 _pMapping = 0;
250 //__________________________________________________________________________________________________
251 inline Mapping & Mapping::operator = ( uno_Mapping * pMapping ) SAL_THROW(())
253 if (pMapping)
254 (*pMapping->acquire)( pMapping );
255 if (_pMapping)
256 (*_pMapping->release)( _pMapping );
257 _pMapping = pMapping;
258 return *this;
260 //__________________________________________________________________________________________________
261 inline void Mapping::mapInterface(
262 void ** ppOut, void * pInterface, const ::com::sun::star::uno::Type & rType ) const
263 SAL_THROW(())
265 typelib_TypeDescription * pTD = 0;
266 TYPELIB_DANGER_GET( &pTD, rType.getTypeLibType() );
267 if (pTD)
269 (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, (typelib_InterfaceTypeDescription *)pTD );
270 TYPELIB_DANGER_RELEASE( pTD );
273 //__________________________________________________________________________________________________
274 inline void * Mapping::mapInterface(
275 void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const
276 SAL_THROW(())
278 void * pOut = 0;
279 (*_pMapping->mapInterface)( _pMapping, &pOut, pInterface, pTypeDescr );
280 return pOut;
282 //__________________________________________________________________________________________________
283 inline void * Mapping::mapInterface(
284 void * pInterface, const ::com::sun::star::uno::Type & rType ) const
285 SAL_THROW(())
287 void * pOut = 0;
288 mapInterface( &pOut, pInterface, rType );
289 return pOut;
292 /** Deprecated. This function DOES NOT WORK with Purpose Environments
293 (http://wiki.services.openoffice.org/wiki/Uno/Binary/Spec/Purpose Environments)
295 Maps an binary C UNO interface to be used in the currently used compiler environment.
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
302 @deprecated
304 template< class C >
305 inline sal_Bool mapToCpp( Reference< C > * ppRet, uno_Interface * pUnoI ) SAL_THROW(())
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);
315 /** Deprecated. This function DOES NOT WORK with Purpose Environments
316 (http://wiki.services.openoffice.org/wiki/Uno/Binary/Spec/Purpose Environments)
318 Maps an UNO interface of the currently used compiler environment to binary C UNO.
320 @tparam C interface type
321 @param ppRet inout returned interface pointer
322 @param x interface reference
323 @return true if successful, false otherwise
325 @deprecated
327 template< class C >
328 inline sal_Bool mapToUno( uno_Interface ** ppRet, const Reference< C > & x ) SAL_THROW(())
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);
344 #endif
346 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */