LibreOffice
LibreOffice 24.8 SDK C/C++ API Reference
Loading...
Searching...
No Matches
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
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"
37#include "cppu/unotype.hxx"
38#include "uno/environment.hxx"
39
43
44namespace com
45{
46namespace sun
47{
48namespace star
49{
50namespace uno
51{
52
58{
59 uno_Mapping * _pMapping;
60
61public:
62 // these are here to force memory de/allocation to sal lib.
64 static void * SAL_CALL operator new ( size_t nSize )
65 { return ::rtl_allocateMemory( nSize ); }
66 static void SAL_CALL operator delete ( void * pMem )
67 { ::rtl_freeMemory( pMem ); }
68 static void * SAL_CALL operator new ( size_t, void * pMem )
69 { return pMem; }
70 static void SAL_CALL operator delete ( void *, void * )
71 {}
73
81 inline Mapping(
82 const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo,
83 const ::rtl::OUString & rAddPurpose = ::rtl::OUString() );
84
91 inline Mapping(
92 uno_Environment * pFrom, uno_Environment * pTo,
93 const ::rtl::OUString & rAddPurpose = ::rtl::OUString() );
94
102 inline Mapping(const Environment & rFrom, const Environment & rTo,
103 const ::rtl::OUString & rAddPurpose = ::rtl::OUString() );
104
109 inline Mapping( uno_Mapping * pMapping = NULL );
110
115 inline Mapping( const Mapping & rMapping );
116
117#if defined LIBO_INTERNAL_ONLY
118 Mapping(Mapping && other) noexcept : _pMapping(other._pMapping)
119 { other._pMapping = nullptr; }
120#endif
121
124 inline ~Mapping();
125
131 inline Mapping & SAL_CALL operator = ( uno_Mapping * pMapping );
137 Mapping & SAL_CALL operator = ( const Mapping & rMapping )
138 { return operator = ( rMapping._pMapping ); }
139
140#if defined LIBO_INTERNAL_ONLY
141 Mapping & operator =(Mapping && other) noexcept {
142 if (_pMapping != nullptr) {
143 (*_pMapping->release)(_pMapping);
144 }
145 _pMapping = other._pMapping;
146 other._pMapping = nullptr;
147 return *this;
148 }
149#endif
150
155 uno_Mapping * SAL_CALL get() const
156 { return _pMapping; }
157
162 bool SAL_CALL is() const
163 { return (_pMapping != NULL); }
164
167 inline void SAL_CALL clear();
168
175 inline void * SAL_CALL mapInterface( void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const;
182 void * SAL_CALL mapInterface( void * pInterface, typelib_TypeDescription * pTypeDescr ) const
183 { return mapInterface( pInterface, reinterpret_cast<typelib_InterfaceTypeDescription *>(pTypeDescr) ); }
184
191 inline void * SAL_CALL mapInterface(
192 void * pInterface, const css::uno::Type & rType ) const;
193
200 void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const
201 { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, pTypeDescr ); }
208 void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_TypeDescription * pTypeDescr ) const
209 { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, reinterpret_cast<typelib_InterfaceTypeDescription *>(pTypeDescr) ); }
210
217 inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, const css::uno::Type & rType ) const;
218};
219
221 const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo, const ::rtl::OUString & rAddPurpose )
222 : _pMapping( NULL )
223{
224 uno_getMappingByName( &_pMapping, rFrom.pData, rTo.pData, rAddPurpose.pData );
225}
226
228 uno_Environment * pFrom, uno_Environment * pTo, const ::rtl::OUString & rAddPurpose )
229 : _pMapping( NULL )
230{
231 uno_getMapping( &_pMapping, pFrom, pTo, rAddPurpose.pData );
232}
233
235 const Environment & rFrom, const Environment & rTo, const ::rtl::OUString & rAddPurpose )
236 : _pMapping(NULL)
237{
238 uno_getMapping( &_pMapping, rFrom.get(), rTo.get(), rAddPurpose.pData );
239}
240
241inline Mapping::Mapping( uno_Mapping * pMapping )
242 : _pMapping( pMapping )
243{
244 if (_pMapping)
245 (*_pMapping->acquire)( _pMapping );
246}
247
248inline Mapping::Mapping( const Mapping & rMapping )
249 : _pMapping( rMapping._pMapping )
250{
251 if (_pMapping)
252 (*_pMapping->acquire)( _pMapping );
253}
254
256{
257 if (_pMapping)
258 (*_pMapping->release)( _pMapping );
259}
260
261inline void Mapping::clear()
262{
263 if (_pMapping)
264 {
265 (*_pMapping->release)( _pMapping );
266 _pMapping = NULL;
267 }
268}
269
271{
272 if (pMapping)
273 (*pMapping->acquire)( pMapping );
274 if (_pMapping)
275 (*_pMapping->release)( _pMapping );
276 _pMapping = pMapping;
277 return *this;
278}
279
281 void ** ppOut, void * pInterface, const css::uno::Type & rType ) const
282{
283 typelib_TypeDescription * pTD = NULL;
284 TYPELIB_DANGER_GET( &pTD, rType.getTypeLibType() );
285 if (pTD)
286 {
287 (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, reinterpret_cast<typelib_InterfaceTypeDescription *>(pTD) );
288 TYPELIB_DANGER_RELEASE( pTD );
289 }
290}
291
293 void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const
294{
295 void * pOut = NULL;
296 (*_pMapping->mapInterface)( _pMapping, &pOut, pInterface, pTypeDescr );
297 return pOut;
298}
299
301 void * pInterface, const css::uno::Type & rType ) const
302{
303 void * pOut = NULL;
304 mapInterface( &pOut, pInterface, rType );
305 return pOut;
306}
307
320template< class C >
321SAL_DEPRECATED("use uno_Mapping")
322inline 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}
342template< class C >
343SAL_DEPRECATED("use uno_Mapping")
344inline 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: */
#define SAL_DEPRECATED(message)
Use as follows: SAL_DEPRECATED("Don't use, it's evil.") void doit(int nPara);.
Definition types.h:492
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
Provides simple diagnostic support.
struct SAL_DLLPUBLIC_RTTI _typelib_TypeDescription typelib_TypeDescription
Full type description of a type.
struct SAL_DLLPUBLIC_RTTI _typelib_InterfaceTypeDescription typelib_InterfaceTypeDescription
Type description of an interface.
struct SAL_DLLPUBLIC_RTTI _uno_Interface uno_Interface
The binary C uno interface description.
struct SAL_DLLPUBLIC_RTTI _uno_Environment uno_Environment
The binary specification of a UNO environment.
#define UNO_LB_UNO
Environment type name for binary C UNO.
Definition lbnames.h:49
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.
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 ...
struct SAL_DLLPUBLIC_RTTI _uno_Mapping uno_Mapping
This is the binary specification of a mapping.
#define OSL_ASSERT(c)
If cond is false, reports an error.
Definition diagnose.h:84
Definition types.h:377
bool mapToCpp(Reference< C > *ppRet, uno_Interface *pUnoI)
Deprecated.
Definition mapping.hxx:322
bool mapToUno(uno_Interface **ppRet, const Reference< C > &x)
Deprecated.
Definition mapping.hxx:344
css::uno::Type const & getTypeFavourUnsigned(SAL_UNUSED_PARAMETER T const *)
A working replacement for getCppuType (see there).
Definition unotype.hxx:324
This String class provides base functionality for C++ like Unicode character array handling.
Definition ustring.hxx:172
Full type description of a type.
Definition typedescription.h:76
Type description of an interface.
Definition typedescription.h:375
The binary C uno interface description.
Definition dispatcher.h:66
C++ wrapper for binary C uno_Environment.
Definition environment.hxx:50
uno_Environment * get() const
Provides UNacquired pointer to the set C environment.
Definition environment.hxx:135
C++ wrapper for C uno_Mapping.
Definition mapping.hxx:58
~Mapping()
Destructor.
Definition mapping.hxx:255
void * mapInterface(void *pInterface, typelib_InterfaceTypeDescription *pTypeDescr) const
Maps an interface from one environment to another.
Definition mapping.hxx:292
uno_Mapping * get() const
Provides a pointer to the C mapping.
Definition mapping.hxx:155
bool is() const
Tests if a mapping is set.
Definition mapping.hxx:162
void * mapInterface(void *pInterface, typelib_TypeDescription *pTypeDescr) const
Maps an interface from one environment to another.
Definition mapping.hxx:182
void mapInterface(void **ppOut, void *pInterface, typelib_TypeDescription *pTypeDescr) const
Maps an interface from one environment to another.
Definition mapping.hxx:208
void clear()
Releases a set mapping.
Definition mapping.hxx:261
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:220
Mapping & operator=(uno_Mapping *pMapping)
Sets a given mapping.
Definition mapping.hxx:270
void mapInterface(void **ppOut, void *pInterface, typelib_InterfaceTypeDescription *pTypeDescr) const
Maps an interface from one environment to another.
Definition mapping.hxx:200
Template reference class for interface type derived from BaseReference.
Definition Reference.h:184