LibreOffice: uno/mapping.hxx Source File

LibreOffice LibreOffice 6.1 SDK C/C++ API Reference

mapping.hxx
Go to the documentation of this file.
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 #ifndef INCLUDED_UNO_MAPPING_HXX
20 #define INCLUDED_UNO_MAPPING_HXX
21
22 #include "sal/config.h"
23
24 #include <cstddef>
25
26 #include "uno/lbnames.h"
27 #include "rtl/alloc.h"
28 #include "rtl/ustring.hxx"
29 #include "osl/diagnose.h"
30 #include "uno/mapping.h"
31 #include "com/sun/star/uno/Type.hxx"
32 #include "com/sun/star/uno/Reference.hxx"
33 #include "cppu/unotype.hxx"
34 #include "uno/environment.hxx"
35
36 typedef struct _typelib_TypeDescription typelib_TypeDescription;
37 typedef struct _typelib_InterfaceTypeDescription typelib_InterfaceTypeDescription;
38 typedef struct _uno_Interface uno_Interface;
39
40 namespace com
41 {
42 namespace sun
43 {
44 namespace star
45 {
46 namespace uno
47 {
48
53 class Mapping
54 {
55 uno_Mapping * _pMapping;
56
57 public:
58 // these are here to force memory de/allocation to sal lib.
60 static void * SAL_CALL operator new ( size_t nSize )
61 { return ::rtl_allocateMemory( nSize ); }
62 static void SAL_CALL operator delete ( void * pMem )
63 { ::rtl_freeMemory( pMem ); }
64 static void * SAL_CALL operator new ( size_t, void * pMem )
65 { return pMem; }
66 static void SAL_CALL operator delete ( void *, void * )
67 {}
69
77 inline Mapping(
78 const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo,
79 const ::rtl::OUString & rAddPurpose = ::rtl::OUString() );
80
87 inline Mapping(
88 uno_Environment * pFrom, uno_Environment * pTo,
89 const ::rtl::OUString & rAddPurpose = ::rtl::OUString() );
90
98 inline Mapping(const Environment & rFrom, const Environment & rTo,
99 const ::rtl::OUString & rAddPurpose = ::rtl::OUString() );
100
105 inline Mapping( uno_Mapping * pMapping = NULL );
106
111 inline Mapping( const Mapping & rMapping );
112
113 #if defined LIBO_INTERNAL_ONLY
114 Mapping(Mapping && other): _pMapping(other._pMapping)
115 { other._pMapping = nullptr; }
116 #endif
117
120 inline ~Mapping();
121
127 inline Mapping & SAL_CALL operator = ( uno_Mapping * pMapping );
133 Mapping & SAL_CALL operator = ( const Mapping & rMapping )
134 { return operator = ( rMapping._pMapping ); }
135
136 #if defined LIBO_INTERNAL_ONLY
137 Mapping & operator =(Mapping && other) {
138 if (_pMapping != nullptr) {
139 (*_pMapping->release)(_pMapping);
140 }
141 _pMapping = other._pMapping;
142 other._pMapping = nullptr;
143 return *this;
144 }
145 #endif
146
151 uno_Mapping * SAL_CALL get() const
152 { return _pMapping; }
153
158 bool SAL_CALL is() const
159 { return (_pMapping != NULL); }
160
163 inline void SAL_CALL clear();
164
171 inline void * SAL_CALL mapInterface( void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const;
178 void * SAL_CALL mapInterface( void * pInterface, typelib_TypeDescription * pTypeDescr ) const
179 { return mapInterface( pInterface, reinterpret_cast<typelib_InterfaceTypeDescription *>(pTypeDescr) ); }
180
187 inline void * SAL_CALL mapInterface(
188 void * pInterface, const css::uno::Type & rType ) const;
189
196 void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const
197 { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, pTypeDescr ); }
204 void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_TypeDescription * pTypeDescr ) const
205 { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, reinterpret_cast<typelib_InterfaceTypeDescription *>(pTypeDescr) ); }
206
213 inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, const css::uno::Type & rType ) const;
214 };
215
216 inline Mapping::Mapping(
217 const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo, const ::rtl::OUString & rAddPurpose )
218 : _pMapping( NULL )
219 {
220 uno_getMappingByName( &_pMapping, rFrom.pData, rTo.pData, rAddPurpose.pData );
221 }
222
223 inline Mapping::Mapping(
224 uno_Environment * pFrom, uno_Environment * pTo, const ::rtl::OUString & rAddPurpose )
225 : _pMapping( NULL )
226 {
227 uno_getMapping( &_pMapping, pFrom, pTo, rAddPurpose.pData );
228 }
229
230 inline Mapping::Mapping(
231 const Environment & rFrom, const Environment & rTo, const ::rtl::OUString & rAddPurpose )
232 : _pMapping(NULL)
233 {
234 uno_getMapping( &_pMapping, rFrom.get(), rTo.get(), rAddPurpose.pData );
235 }
236
237 inline Mapping::Mapping( uno_Mapping * pMapping )
238 : _pMapping( pMapping )
239 {
240 if (_pMapping)
241 (*_pMapping->acquire)( _pMapping );
242 }
243
244 inline Mapping::Mapping( const Mapping & rMapping )
245 : _pMapping( rMapping._pMapping )
246 {
247 if (_pMapping)
248 (*_pMapping->acquire)( _pMapping );
249 }
250
251 inline Mapping::~Mapping()
252 {
253 if (_pMapping)
254 (*_pMapping->release)( _pMapping );
255 }
256
257 inline void Mapping::clear()
258 {
259 if (_pMapping)
260 {
261 (*_pMapping->release)( _pMapping );
262 _pMapping = NULL;
263 }
264 }
265
266 inline Mapping & Mapping::operator = ( uno_Mapping * pMapping )
267 {
268 if (pMapping)
269 (*pMapping->acquire)( pMapping );
270 if (_pMapping)
271 (*_pMapping->release)( _pMapping );
272 _pMapping = pMapping;
273 return *this;
274 }
275
276 inline void Mapping::mapInterface(
277 void ** ppOut, void * pInterface, const css::uno::Type & rType ) const
278 {
279 typelib_TypeDescription * pTD = NULL;
280 TYPELIB_DANGER_GET( &pTD, rType.getTypeLibType() );
281 if (pTD)
282 {
283 (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, reinterpret_cast<typelib_InterfaceTypeDescription *>(pTD) );
284 TYPELIB_DANGER_RELEASE( pTD );
285 }
286 }
287
288 inline void * Mapping::mapInterface(
289 void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const
290 {
291 void * pOut = NULL;
292 (*_pMapping->mapInterface)( _pMapping, &pOut, pInterface, pTypeDescr );
293 return pOut;
294 }
295
296 inline void * Mapping::mapInterface(
297 void * pInterface, const css::uno::Type & rType ) const
298 {
299 void * pOut = NULL;
300 mapInterface( &pOut, pInterface, rType );
301 return pOut;
302 }
303
316 template< class C >
317 SAL_DEPRECATED("use uno_Mapping")
318 inline bool mapToCpp( Reference< C > * ppRet, uno_Interface * pUnoI )
319 {
320 Mapping aMapping(
321 ::rtl::OUString( UNO_LB_UNO ),
322 ::rtl::OUString( CPPU_CURRENT_LANGUAGE_BINDING_NAME ) );
323 OSL_ASSERT( aMapping.is() );
324 aMapping.mapInterface(
325 reinterpret_cast<void **>(ppRet), pUnoI, ::cppu::getTypeFavourUnsigned( ppRet ) );
326 return (0 != *ppRet);
327 }
340 template< class C >
341 SAL_DEPRECATED("use uno_Mapping")
342 inline bool mapToUno( uno_Interface ** ppRet, const Reference< C > & x )
343 {
344 Mapping aMapping(
345 ::rtl::OUString( CPPU_CURRENT_LANGUAGE_BINDING_NAME ),
346 ::rtl::OUString( 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: */
lbnames.h
uno_getMappingByName
CPPU_DLLPUBLIC void uno_getMappingByName(struct _uno_Mapping **ppMapping, rtl_uString *pFrom, rtl_uString *pTo, rtl_uString *pAddPurpose) SAL_THROW_EXTERN_C()
Gets an interface mapping from one language environment to another by corresponding environment type ...
typelib_InterfaceTypeDescription
struct SAL_DLLPUBLIC_RTTI _typelib_InterfaceTypeDescription typelib_InterfaceTypeDescription
Type description of an interface.
uno_Mapping
struct SAL_DLLPUBLIC_RTTI _uno_Mapping uno_Mapping
This is the binary specification of a mapping.
com::sun::star::uno::Mapping::is
bool is() const
Tests if a mapping is set.
Definition: mapping.hxx:158
com::sun::star::uno::Reference
Template reference class for interface type derived from BaseReference.
Definition: unotype.hxx:39
uno_getMapping
CPPU_DLLPUBLIC void uno_getMapping(struct _uno_Mapping **ppMapping, struct _uno_Environment *pFrom, struct _uno_Environment *pTo, rtl_uString *pAddPurpose) SAL_THROW_EXTERN_C()
Gets an interface mapping from one environment to another.
com::sun::star::uno::Environment
C++ wrapper for binary C uno_Environment.
Definition: environment.hxx:49
mapping.h
_typelib_InterfaceTypeDescription
Type description of an interface.
Definition: typedescription.h:370
SAL_DEPRECATED
#define SAL_DEPRECATED(message)
Use as follows: SAL_DEPRECATED("Don&#39;t use, it&#39;s evil.") void doit(int nPara);.
Definition: types.h:485
Type.hxx
Reference.hxx
_uno_Interface
The binary C uno interface description.
Definition: dispatcher.h:61
rtl_allocateMemory
SAL_DLLPUBLIC void * rtl_allocateMemory(sal_Size Bytes) SAL_THROW_EXTERN_C()
Allocate memory.
rtl::OUString
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:121
ustring.hxx
com::sun::star::uno::Environment::get
uno_Environment * get() const
Provides UNacquired pointer to the set C environment.
Definition: environment.hxx:135
com::sun::star::uno::Mapping::mapInterface
void * mapInterface(void *pInterface, typelib_InterfaceTypeDescription *pTypeDescr) const
Maps an interface from one environment to another.
Definition: mapping.hxx:288
typelib_TypeDescription
struct SAL_DLLPUBLIC_RTTI _typelib_TypeDescription typelib_TypeDescription
Full type description of a type.
com
Definition: types.h:375
com::sun::star::uno::mapToCpp
bool mapToCpp(Reference< C > *ppRet, uno_Interface *pUnoI)
Deprecated.
Definition: mapping.hxx:318
unotype.hxx
cppu::getTypeFavourUnsigned
css::uno::Type const & getTypeFavourUnsigned(SAL_UNUSED_PARAMETER T const *)
A working replacement for getCppuType (see there).
Definition: unotype.hxx:320
com::sun::star::uno::Mapping::operator=
Mapping & operator=(uno_Mapping *pMapping)
Sets a given mapping.
Definition: mapping.hxx:266
com::sun::star::uno::Mapping::Mapping
Mapping(const ::rtl::OUString &rFrom, const ::rtl::OUString &rTo, const ::rtl::OUString &rAddPurpose=::rtl::OUString())
Holds a mapping from the specified source to the specified destination by environment type names...
Definition: mapping.hxx:216
UNO_LB_UNO
#define UNO_LB_UNO
Environment type name for binary C UNO.
Definition: lbnames.h:45
OSL_ASSERT
#define OSL_ASSERT(c)
If cond is false, reports an error.
Definition: diagnose.h:82
uno_Environment
struct SAL_DLLPUBLIC_RTTI _uno_Environment uno_Environment
The binary specification of an UNO environment.
com::sun::star::uno::Mapping::mapInterface
void mapInterface(void **ppOut, void *pInterface, typelib_TypeDescription *pTypeDescr) const
Maps an interface from one environment to another.
Definition: mapping.hxx:204
config.h
com::sun::star::uno::mapToUno
bool mapToUno(uno_Interface **ppRet, const Reference< C > &x)
Deprecated.
Definition: mapping.hxx:342
com::sun::star::uno::Mapping::mapInterface
void mapInterface(void **ppOut, void *pInterface, typelib_InterfaceTypeDescription *pTypeDescr) const
Maps an interface from one environment to another.
Definition: mapping.hxx:196
rtl_freeMemory
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
com::sun::star::uno::Mapping
C++ wrapper for C uno_Mapping.
Definition: mapping.hxx:53
alloc.h
com::sun::star::uno::Mapping::mapInterface
void * mapInterface(void *pInterface, typelib_TypeDescription *pTypeDescr) const
Maps an interface from one environment to another.
Definition: mapping.hxx:178
uno_Interface
struct SAL_DLLPUBLIC_RTTI _uno_Interface uno_Interface
The binary C uno interface description.
com::sun::star::uno::Mapping::clear
void clear()
Releases a set mapping.
Definition: mapping.hxx:257
environment.hxx
diagnose.h
Provides simple diagnostic support.
com::sun::star::uno::Mapping::~Mapping
~Mapping()
Destructor.
Definition: mapping.hxx:251
_typelib_TypeDescription
Full type description of a type.
Definition: typedescription.h:71