/src/libreoffice/include/uno/mapping.hxx
Line | Count | Source |
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 | | |
20 | | /* |
21 | | * This file is part of LibreOffice published API. |
22 | | */ |
23 | | #ifndef INCLUDED_UNO_MAPPING_HXX |
24 | | #define INCLUDED_UNO_MAPPING_HXX |
25 | | |
26 | | #include "sal/config.h" |
27 | | |
28 | | #include <cstddef> |
29 | | |
30 | | #include "uno/lbnames.h" |
31 | | #include "rtl/alloc.h" |
32 | | #include "rtl/ustring.hxx" |
33 | | #include "osl/diagnose.h" |
34 | | #include "uno/mapping.h" |
35 | | #include "com/sun/star/uno/Type.hxx" |
36 | | #include "com/sun/star/uno/Reference.hxx" |
37 | | #include "cppu/unotype.hxx" |
38 | | #include "uno/environment.hxx" |
39 | | |
40 | | typedef struct _typelib_TypeDescription typelib_TypeDescription; |
41 | | typedef struct _typelib_InterfaceTypeDescription typelib_InterfaceTypeDescription; |
42 | | typedef struct _uno_Interface uno_Interface; |
43 | | |
44 | | namespace com |
45 | | { |
46 | | namespace sun |
47 | | { |
48 | | namespace star |
49 | | { |
50 | | namespace uno |
51 | | { |
52 | | |
53 | | /** C++ wrapper for C uno_Mapping. |
54 | | |
55 | | @see uno_Mapping |
56 | | */ |
57 | | class Mapping |
58 | | { |
59 | | uno_Mapping * _pMapping; |
60 | | |
61 | | public: |
62 | | // these are here to force memory de/allocation to sal lib. |
63 | | /// @cond INTERNAL |
64 | | static void * SAL_CALL operator new ( size_t nSize ) |
65 | 0 | { return ::rtl_allocateMemory( nSize ); } |
66 | | static void SAL_CALL operator delete ( void * pMem ) |
67 | 0 | { ::rtl_freeMemory( pMem ); } |
68 | | static void * SAL_CALL operator new ( size_t, void * pMem ) |
69 | 0 | { return pMem; } |
70 | | static void SAL_CALL operator delete ( void *, void * ) |
71 | 0 | {} |
72 | | /// @endcond |
73 | | |
74 | | /** Holds a mapping from the specified source to the specified destination by environment |
75 | | type names. |
76 | | |
77 | | @param rFrom type name of source environment |
78 | | @param rTo type name of destination environment |
79 | | @param rAddPurpose additional purpose |
80 | | */ |
81 | | inline Mapping( |
82 | | const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo, |
83 | | const ::rtl::OUString & rAddPurpose = ::rtl::OUString() ); |
84 | | |
85 | | /** Holds a mapping from the specified source to the specified destination. |
86 | | |
87 | | @param pFrom source environment |
88 | | @param pTo destination environment |
89 | | @param rAddPurpose additional purpose |
90 | | */ |
91 | | inline Mapping( |
92 | | uno_Environment * pFrom, uno_Environment * pTo, |
93 | | const ::rtl::OUString & rAddPurpose = ::rtl::OUString() ); |
94 | | |
95 | | /** Holds a mapping from the specified source to the specified destination |
96 | | environment. |
97 | | |
98 | | @param rFrom source environment |
99 | | @param rTo destination environment |
100 | | @param rAddPurpose additional purpose |
101 | | */ |
102 | | inline Mapping(const Environment & rFrom, const Environment & rTo, |
103 | | const ::rtl::OUString & rAddPurpose = ::rtl::OUString() ); |
104 | | |
105 | | /** Constructor. |
106 | | |
107 | | @param pMapping another mapping |
108 | | */ |
109 | | inline Mapping( uno_Mapping * pMapping = NULL ); |
110 | | |
111 | | /** Copy constructor. |
112 | | |
113 | | @param rMapping another mapping |
114 | | */ |
115 | | inline Mapping( const Mapping & rMapping ); |
116 | | |
117 | | #if defined LIBO_INTERNAL_ONLY |
118 | | Mapping(Mapping && other) noexcept : _pMapping(other._pMapping) |
119 | 0 | { other._pMapping = nullptr; } |
120 | | #endif |
121 | | |
122 | | /** Destructor. |
123 | | */ |
124 | | inline ~Mapping(); |
125 | | |
126 | | /** Sets a given mapping. |
127 | | |
128 | | @param pMapping another mapping |
129 | | @return this mapping |
130 | | */ |
131 | | inline Mapping & SAL_CALL operator = ( uno_Mapping * pMapping ); |
132 | | /** Sets a given mapping. |
133 | | |
134 | | @param rMapping another mapping |
135 | | @return this mapping |
136 | | */ |
137 | | Mapping & SAL_CALL operator = ( const Mapping & rMapping ) |
138 | 0 | { return operator = ( rMapping._pMapping ); } |
139 | | |
140 | | #if defined LIBO_INTERNAL_ONLY |
141 | 4 | Mapping & operator =(Mapping && other) noexcept { |
142 | 4 | if (_pMapping != nullptr) { |
143 | 0 | (*_pMapping->release)(_pMapping); |
144 | 0 | } |
145 | 4 | _pMapping = other._pMapping; |
146 | 4 | other._pMapping = nullptr; |
147 | 4 | return *this; |
148 | 4 | } |
149 | | #endif |
150 | | |
151 | | /** Provides a pointer to the C mapping. The returned mapping is NOT acquired! |
152 | | |
153 | | @return UNacquired C mapping |
154 | | */ |
155 | | uno_Mapping * SAL_CALL get() const |
156 | 118k | { return _pMapping; } |
157 | | |
158 | | /** Tests if a mapping is set. |
159 | | |
160 | | @return true if a mapping is set |
161 | | */ |
162 | | bool SAL_CALL is() const |
163 | 204k | { return (_pMapping != NULL); } |
164 | | |
165 | | /** Releases a set mapping. |
166 | | */ |
167 | | inline void SAL_CALL clear(); |
168 | | |
169 | | /** Maps an interface from one environment to another. |
170 | | |
171 | | @param pInterface source interface |
172 | | @param pTypeDescr type description of interface |
173 | | @return mapped interface |
174 | | */ |
175 | | inline void * SAL_CALL mapInterface( void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const; |
176 | | /** Maps an interface from one environment to another. |
177 | | |
178 | | @param pInterface source interface |
179 | | @param pTypeDescr type description of interface |
180 | | @return mapped interface |
181 | | */ |
182 | | void * SAL_CALL mapInterface( void * pInterface, typelib_TypeDescription * pTypeDescr ) const |
183 | 0 | { return mapInterface( pInterface, reinterpret_cast<typelib_InterfaceTypeDescription *>(pTypeDescr) ); } |
184 | | |
185 | | /** Maps an interface from one environment to another. |
186 | | |
187 | | @param pInterface source interface |
188 | | @param rType type of interface |
189 | | @return mapped interface |
190 | | */ |
191 | | inline void * SAL_CALL mapInterface( |
192 | | void * pInterface, const css::uno::Type & rType ) const; |
193 | | |
194 | | /** Maps an interface from one environment to another. |
195 | | |
196 | | @param ppOut inout mapped interface |
197 | | @param pInterface source interface |
198 | | @param pTypeDescr type description of interface |
199 | | */ |
200 | | void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const |
201 | 0 | { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, pTypeDescr ); } |
202 | | /** Maps an interface from one environment to another. |
203 | | |
204 | | @param ppOut inout mapped interface |
205 | | @param pInterface source interface |
206 | | @param pTypeDescr type description of interface |
207 | | */ |
208 | | void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_TypeDescription * pTypeDescr ) const |
209 | 39.6k | { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, reinterpret_cast<typelib_InterfaceTypeDescription *>(pTypeDescr) ); } |
210 | | |
211 | | /** Maps an interface from one environment to another. |
212 | | |
213 | | @param ppOut inout mapped interface |
214 | | @param pInterface source interface |
215 | | @param rType type of interface to be mapped |
216 | | */ |
217 | | inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, const css::uno::Type & rType ) const; |
218 | | }; |
219 | | |
220 | | inline Mapping::Mapping( |
221 | | const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo, const ::rtl::OUString & rAddPurpose ) |
222 | 4 | : _pMapping( NULL ) |
223 | 4 | { |
224 | 4 | uno_getMappingByName( &_pMapping, rFrom.pData, rTo.pData, rAddPurpose.pData ); |
225 | 4 | } |
226 | | |
227 | | inline Mapping::Mapping( |
228 | | uno_Environment * pFrom, uno_Environment * pTo, const ::rtl::OUString & rAddPurpose ) |
229 | 0 | : _pMapping( NULL ) |
230 | 0 | { |
231 | 0 | uno_getMapping( &_pMapping, pFrom, pTo, rAddPurpose.pData ); |
232 | 0 | } |
233 | | |
234 | | inline Mapping::Mapping( |
235 | | const Environment & rFrom, const Environment & rTo, const ::rtl::OUString & rAddPurpose ) |
236 | 79.7k | : _pMapping(NULL) |
237 | 79.7k | { |
238 | 79.7k | uno_getMapping( &_pMapping, rFrom.get(), rTo.get(), rAddPurpose.pData ); |
239 | 79.7k | } |
240 | | |
241 | | inline Mapping::Mapping( uno_Mapping * pMapping ) |
242 | 14 | : _pMapping( pMapping ) |
243 | 14 | { |
244 | 14 | if (_pMapping) |
245 | 0 | (*_pMapping->acquire)( _pMapping ); |
246 | 14 | } |
247 | | |
248 | | inline Mapping::Mapping( const Mapping & rMapping ) |
249 | | : _pMapping( rMapping._pMapping ) |
250 | | { |
251 | | if (_pMapping) |
252 | | (*_pMapping->acquire)( _pMapping ); |
253 | | } |
254 | | |
255 | | inline Mapping::~Mapping() |
256 | 79.7k | { |
257 | 79.7k | if (_pMapping) |
258 | 79.7k | (*_pMapping->release)( _pMapping ); |
259 | 79.7k | } |
260 | | |
261 | | inline void Mapping::clear() |
262 | 0 | { |
263 | 0 | if (_pMapping) |
264 | 0 | { |
265 | 0 | (*_pMapping->release)( _pMapping ); |
266 | 0 | _pMapping = NULL; |
267 | 0 | } |
268 | 0 | } |
269 | | |
270 | | inline Mapping & Mapping::operator = ( uno_Mapping * pMapping ) |
271 | 0 | { |
272 | 0 | if (pMapping) |
273 | 0 | (*pMapping->acquire)( pMapping ); |
274 | 0 | if (_pMapping) |
275 | 0 | (*_pMapping->release)( _pMapping ); |
276 | 0 | _pMapping = pMapping; |
277 | 0 | return *this; |
278 | 0 | } |
279 | | |
280 | | inline void Mapping::mapInterface( |
281 | | void ** ppOut, void * pInterface, const css::uno::Type & rType ) const |
282 | 424 | { |
283 | 424 | typelib_TypeDescription * pTD = NULL; |
284 | 424 | TYPELIB_DANGER_GET( &pTD, rType.getTypeLibType() ); |
285 | 424 | if (pTD) |
286 | 424 | { |
287 | 424 | (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, reinterpret_cast<typelib_InterfaceTypeDescription *>(pTD) ); |
288 | 424 | TYPELIB_DANGER_RELEASE( pTD ); |
289 | 424 | } |
290 | 424 | } |
291 | | |
292 | | inline void * Mapping::mapInterface( |
293 | | void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const |
294 | 50.1k | { |
295 | 50.1k | void * pOut = NULL; |
296 | 50.1k | (*_pMapping->mapInterface)( _pMapping, &pOut, pInterface, pTypeDescr ); |
297 | 50.1k | return pOut; |
298 | 50.1k | } |
299 | | |
300 | | inline void * Mapping::mapInterface( |
301 | | void * pInterface, const css::uno::Type & rType ) const |
302 | 424 | { |
303 | | void * pOut = NULL; |
304 | 424 | mapInterface( &pOut, pInterface, rType ); |
305 | 424 | return pOut; |
306 | 424 | } |
307 | | |
308 | | /** Deprecated. This function DOES NOT WORK with Purpose Environments |
309 | | (http://wiki.openoffice.org/wiki/Uno/Binary/Spec/Purpose Environments) |
310 | | |
311 | | Maps a binary C UNO interface to be used in the currently used compiler environment. |
312 | | |
313 | | @tparam C interface type |
314 | | @param ppRet inout returned interface pointer |
315 | | @param pUnoI binary C UNO interface |
316 | | @return true if successful, false otherwise |
317 | | |
318 | | @deprecated |
319 | | */ |
320 | | template< class C > |
321 | | SAL_DEPRECATED("use uno_Mapping") |
322 | | inline bool mapToCpp( Reference< C > * ppRet, uno_Interface * pUnoI ) |
323 | | { |
324 | | Mapping aMapping( UNO_LB_UNO, CPPU_CURRENT_LANGUAGE_BINDING_NAME ); |
325 | | OSL_ASSERT( aMapping.is() ); |
326 | | aMapping.mapInterface( |
327 | | reinterpret_cast<void **>(ppRet), pUnoI, ::cppu::getTypeFavourUnsigned( ppRet ) ); |
328 | | return (0 != *ppRet); |
329 | | } |
330 | | /** Deprecated. This function DOES NOT WORK with Purpose Environments |
331 | | (http://wiki.openoffice.org/wiki/Uno/Binary/Spec/Purpose Environments) |
332 | | |
333 | | Maps a UNO interface of the currently used compiler environment to binary C UNO. |
334 | | |
335 | | @tparam C interface type |
336 | | @param ppRet inout returned interface pointer |
337 | | @param x interface reference |
338 | | @return true if successful, false otherwise |
339 | | |
340 | | @deprecated |
341 | | */ |
342 | | template< class C > |
343 | | SAL_DEPRECATED("use uno_Mapping") |
344 | | inline bool mapToUno( uno_Interface ** ppRet, const Reference< C > & x ) |
345 | | { |
346 | | Mapping aMapping( CPPU_CURRENT_LANGUAGE_BINDING_NAME, UNO_LB_UNO ); |
347 | | OSL_ASSERT( aMapping.is() ); |
348 | | aMapping.mapInterface( |
349 | | reinterpret_cast<void **>(ppRet), x.get(), ::cppu::getTypeFavourUnsigned( &x ) ); |
350 | | return (NULL != *ppRet); |
351 | | } |
352 | | |
353 | | } |
354 | | } |
355 | | } |
356 | | } |
357 | | |
358 | | #endif |
359 | | |
360 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |