LibreOffice: uno/mapping.hxx Source File

LibreOffice LibreOffice 5.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 inline static void * SAL_CALL operator new ( size_t nSize )
61 { return ::rtl_allocateMemory( nSize ); }
62 inline static void SAL_CALL operator delete ( void * pMem )
63 { ::rtl_freeMemory( pMem ); }
64 inline static void * SAL_CALL operator new ( size_t, void * pMem )
65 { return pMem; }
66 inline 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
115 inline ~Mapping();
116
122 inline Mapping & SAL_CALL operator = ( uno_Mapping * pMapping );
128 inline Mapping & SAL_CALL operator = ( const Mapping & rMapping )
129 { return operator = ( rMapping._pMapping ); }
130
135 inline uno_Mapping * SAL_CALL get() const
136 { return _pMapping; }
137
142 inline bool SAL_CALL is() const
143 { return (_pMapping != NULL); }
144
147 inline void SAL_CALL clear();
148
155 inline void * SAL_CALL mapInterface( void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const;
162 inline void * SAL_CALL mapInterface( void * pInterface, typelib_TypeDescription * pTypeDescr ) const
163 { return mapInterface( pInterface, reinterpret_cast<typelib_InterfaceTypeDescription *>(pTypeDescr) ); }
164
171 inline void * SAL_CALL mapInterface(
172 void * pInterface, const css::uno::Type & rType ) const;
173
180 inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const
181 { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, pTypeDescr ); }
188 inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_TypeDescription * pTypeDescr ) const
189 { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, reinterpret_cast<typelib_InterfaceTypeDescription *>(pTypeDescr) ); }
190
197 inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, const css::uno::Type & rType ) const;
198 };
199
200 inline Mapping::Mapping(
201 const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo, const ::rtl::OUString & rAddPurpose )
202 : _pMapping( NULL )
203 {
204 uno_getMappingByName( &_pMapping, rFrom.pData, rTo.pData, rAddPurpose.pData );
205 }
206
207 inline Mapping::Mapping(
208 uno_Environment * pFrom, uno_Environment * pTo, const ::rtl::OUString & rAddPurpose )
209 : _pMapping( NULL )
210 {
211 uno_getMapping( &_pMapping, pFrom, pTo, rAddPurpose.pData );
212 }
213
214 inline Mapping::Mapping(
215 const Environment & rFrom, const Environment & rTo, const ::rtl::OUString & rAddPurpose )
216 : _pMapping(NULL)
217 {
218 uno_getMapping( &_pMapping, rFrom.get(), rTo.get(), rAddPurpose.pData );
219 }
220
221 inline Mapping::Mapping( uno_Mapping * pMapping )
222 : _pMapping( pMapping )
223 {
224 if (_pMapping)
225 (*_pMapping->acquire)( _pMapping );
226 }
227
228 inline Mapping::Mapping( const Mapping & rMapping )
229 : _pMapping( rMapping._pMapping )
230 {
231 if (_pMapping)
232 (*_pMapping->acquire)( _pMapping );
233 }
234
235 inline Mapping::~Mapping()
236 {
237 if (_pMapping)
238 (*_pMapping->release)( _pMapping );
239 }
240
241 inline void Mapping::clear()
242 {
243 if (_pMapping)
244 {
245 (*_pMapping->release)( _pMapping );
246 _pMapping = NULL;
247 }
248 }
249
250 inline Mapping & Mapping::operator = ( uno_Mapping * pMapping )
251 {
252 if (pMapping)
253 (*pMapping->acquire)( pMapping );
254 if (_pMapping)
255 (*_pMapping->release)( _pMapping );
256 _pMapping = pMapping;
257 return *this;
258 }
259
260 inline void Mapping::mapInterface(
261 void ** ppOut, void * pInterface, const css::uno::Type & rType ) const
262 {
263 typelib_TypeDescription * pTD = NULL;
264 TYPELIB_DANGER_GET( &pTD, rType.getTypeLibType() );
265 if (pTD)
266 {
267 (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, reinterpret_cast<typelib_InterfaceTypeDescription *>(pTD) );
268 TYPELIB_DANGER_RELEASE( pTD );
269 }
270 }
271
272 inline void * Mapping::mapInterface(
273 void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const
274 {
275 void * pOut = NULL;
276 (*_pMapping->mapInterface)( _pMapping, &pOut, pInterface, pTypeDescr );
277 return pOut;
278 }
279
280 inline void * Mapping::mapInterface(
281 void * pInterface, const css::uno::Type & rType ) const
282 {
283 void * pOut = NULL;
284 mapInterface( &pOut, pInterface, rType );
285 return pOut;
286 }
287
300 template< class C >
301 inline bool mapToCpp( Reference< C > * ppRet, uno_Interface * pUnoI )
302 {
303 Mapping aMapping(
304 ::rtl::OUString( UNO_LB_UNO ),
305 ::rtl::OUString( CPPU_CURRENT_LANGUAGE_BINDING_NAME ) );
306 OSL_ASSERT( aMapping.is() );
307 aMapping.mapInterface(
308 reinterpret_cast<void **>(ppRet), pUnoI, ::cppu::getTypeFavourUnsigned( ppRet ) );
309 return (0 != *ppRet);
310 }
323 template< class C >
324 inline bool mapToUno( uno_Interface ** ppRet, const Reference< C > & x )
325 {
326 Mapping aMapping(
327 ::rtl::OUString( CPPU_CURRENT_LANGUAGE_BINDING_NAME ),
328 ::rtl::OUString( UNO_LB_UNO ) );
329 OSL_ASSERT( aMapping.is() );
330 aMapping.mapInterface(
331 reinterpret_cast<void **>(ppRet), x.get(), ::cppu::getTypeFavourUnsigned( &x ) );
332 return (NULL != *ppRet);
333 }
334
335 }
336 }
337 }
338 }
339
340 #endif
341
342 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
lbnames.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:162
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.
com::sun::star::uno::Reference::get
interface_type * get() const
Gets interface pointer.
Definition: Reference.h:411
uno_Mapping
struct SAL_DLLPUBLIC_RTTI _uno_Mapping uno_Mapping
This is the binary specification of a mapping.
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:180
com::sun::star::uno::Mapping::operator=
Mapping & operator=(uno_Mapping *pMapping)
Sets a given mapping.
Definition: mapping.hxx:250
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.
cppu::getTypeFavourUnsigned
css::uno::Type const & getTypeFavourUnsigned(SAL_UNUSED_PARAMETER T const *)
A working replacement for getCppuType (see there).
Definition: unotype.hxx:320
com
Definition: types.h:389
environment.hxx
com::sun::star::uno::Environment::get
uno_Environment * get() const
Provides UNacquired pointer to the set C environment.
Definition: environment.hxx:119
mapping.h
OSL_ASSERT
#define OSL_ASSERT(c)
Definition: diagnose.h:99
Type.hxx
Reference.hxx
com::sun::star::uno::Mapping::~Mapping
~Mapping()
Destructor.
Definition: mapping.hxx:235
com::sun::star::uno::Reference
Template reference class for interface type derived from BaseReference.
Definition: unotype.hxx:39
rtl_allocateMemory
SAL_DLLPUBLIC void * rtl_allocateMemory(sal_Size Bytes) SAL_THROW_EXTERN_C()
Allocate memory.
ustring.hxx
typelib_TypeDescription
struct SAL_DLLPUBLIC_RTTI _typelib_TypeDescription typelib_TypeDescription
Full type description of a type.
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:200
_uno_Interface
The binary C uno interface description.
Definition: dispatcher.h:61
unotype.hxx
UNO_LB_UNO
#define UNO_LB_UNO
Environment type name for binary C UNO.
Definition: lbnames.h:45
_typelib_InterfaceTypeDescription
Type description of an interface.
Definition: typedescription.h:370
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:272
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:188
com::sun::star::uno::Mapping
C++ wrapper for C uno_Mapping.
Definition: mapping.hxx:53
config.h
_typelib_TypeDescription
Full type description of a type.
Definition: typedescription.h:71
rtl::OUString
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:106
com::sun::star::uno::mapToCpp
bool mapToCpp(Reference< C > *ppRet, uno_Interface *pUnoI)
Deprecated.
Definition: mapping.hxx:301
com::sun::star::uno::Mapping::clear
void clear()
Releases a set mapping.
Definition: mapping.hxx:241
com::sun::star::uno::Mapping::is
bool is() const
Tests if a mapping is set.
Definition: mapping.hxx:142
rtl_freeMemory
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
alloc.h
com::sun::star::uno::mapToUno
bool mapToUno(uno_Interface **ppRet, const Reference< C > &x)
Deprecated.
Definition: mapping.hxx:324
uno_Interface
struct SAL_DLLPUBLIC_RTTI _uno_Interface uno_Interface
The binary C uno interface description.
com::sun::star::uno::Environment
C++ wrapper for binary C uno_Environment.
Definition: environment.hxx:49
diagnose.h