LibreOffice
LibreOffice 5.3 SDK C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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>
33 #include <cppu/unotype.hxx>
34 #include <uno/environment.hxx>
35 
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 
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  inline 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  inline uno_Mapping * SAL_CALL get() const
152  { return _pMapping; }
153 
158  inline 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  inline 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  inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const
197  { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, pTypeDescr ); }
204  inline 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 
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 
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 
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 
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 
267 {
268  if (pMapping)
269  (*pMapping->acquire)( pMapping );
270  if (_pMapping)
271  (*_pMapping->release)( _pMapping );
272  _pMapping = pMapping;
273  return *this;
274 }
275 
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 inline bool mapToCpp( Reference< C > * ppRet, uno_Interface * pUnoI )
318 {
319  Mapping aMapping(
321  ::rtl::OUString( CPPU_CURRENT_LANGUAGE_BINDING_NAME ) );
322  OSL_ASSERT( aMapping.is() );
323  aMapping.mapInterface(
324  reinterpret_cast<void **>(ppRet), pUnoI, ::cppu::getTypeFavourUnsigned( ppRet ) );
325  return (0 != *ppRet);
326 }
339 template< class C >
340 inline bool mapToUno( uno_Interface ** ppRet, const Reference< C > & x )
341 {
342  Mapping aMapping(
343  ::rtl::OUString( CPPU_CURRENT_LANGUAGE_BINDING_NAME ),
344  ::rtl::OUString( UNO_LB_UNO ) );
345  OSL_ASSERT( aMapping.is() );
346  aMapping.mapInterface(
347  reinterpret_cast<void **>(ppRet), x.get(), ::cppu::getTypeFavourUnsigned( &x ) );
348  return (NULL != *ppRet);
349 }
350 
351 }
352 }
353 }
354 }
355 
356 #endif
357 
358 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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 ...
~Mapping()
Destructor.
Definition: mapping.hxx:251
void * mapInterface(void *pInterface, typelib_InterfaceTypeDescription *pTypeDescr) const
Maps an interface from one environment to another.
Definition: mapping.hxx:288
void mapInterface(void **ppOut, void *pInterface, typelib_InterfaceTypeDescription *pTypeDescr) const
Maps an interface from one environment to another.
Definition: mapping.hxx:196
css::uno::Type const & getTypeFavourUnsigned(SAL_UNUSED_PARAMETER T const *)
A working replacement for getCppuType (see there).
Definition: unotype.hxx:320
Type description of an interface.
Definition: typedescription.h:370
#define UNO_LB_UNO
Environment type name for binary C UNO.
Definition: lbnames.h:45
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
void clear()
Releases a set mapping.
Definition: mapping.hxx:257
uno_Environment * get() const
Provides UNacquired pointer to the set C environment.
Definition: environment.hxx:135
Full type description of a type.
Definition: typedescription.h:71
void * mapInterface(void *pInterface, typelib_TypeDescription *pTypeDescr) const
Maps an interface from one environment to another.
Definition: mapping.hxx:178
interface_type * get() const
Gets interface pointer.
Definition: Reference.h:419
C++ wrapper for binary C uno_Environment.
Definition: environment.hxx:49
struct SAL_DLLPUBLIC_RTTI _typelib_TypeDescription typelib_TypeDescription
Full type description of a type.
The binary C uno interface description.
Definition: dispatcher.h:61
Mapping & operator=(uno_Mapping *pMapping)
Sets a given mapping.
Definition: mapping.hxx:266
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:106
bool mapToUno(uno_Interface **ppRet, const Reference< C > &x)
Deprecated.
Definition: mapping.hxx:340
struct SAL_DLLPUBLIC_RTTI _typelib_InterfaceTypeDescription typelib_InterfaceTypeDescription
Type description of an interface.
Template reference class for interface type derived from BaseReference.
Definition: unotype.hxx:39
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
struct SAL_DLLPUBLIC_RTTI _uno_Mapping uno_Mapping
This is the binary specification of a mapping.
SAL_DLLPUBLIC void * rtl_allocateMemory(sal_Size Bytes) SAL_THROW_EXTERN_C()
Allocate memory.
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.
bool mapToCpp(Reference< C > *ppRet, uno_Interface *pUnoI)
Deprecated.
Definition: mapping.hxx:317
void mapInterface(void **ppOut, void *pInterface, typelib_TypeDescription *pTypeDescr) const
Maps an interface from one environment to another.
Definition: mapping.hxx:204
struct SAL_DLLPUBLIC_RTTI _uno_Environment uno_Environment
The binary specification of an UNO environment.
C++ wrapper for C uno_Mapping.
Definition: mapping.hxx:53
struct SAL_DLLPUBLIC_RTTI _uno_Interface uno_Interface
The binary C uno interface description.
#define OSL_ASSERT(c)
Definition: diagnose.h:99
bool is() const
Tests if a mapping is set.
Definition: mapping.hxx:158