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 <uno/lbnames.h>
23 #include <rtl/alloc.h>
24 #include <rtl/ustring.hxx>
25 #include <osl/diagnose.h>
26 #include <uno/mapping.h>
29 #include <cppu/unotype.hxx>
30 #include <uno/environment.hxx>
31 
35 
36 namespace com
37 {
38 namespace sun
39 {
40 namespace star
41 {
42 namespace uno
43 {
44 
49 class Mapping
50 {
51  uno_Mapping * _pMapping;
52 
53 public:
54  // these are here to force memory de/allocation to sal lib.
56  inline static void * SAL_CALL operator new ( size_t nSize )
57  { return ::rtl_allocateMemory( nSize ); }
58  inline static void SAL_CALL operator delete ( void * pMem )
59  { ::rtl_freeMemory( pMem ); }
60  inline static void * SAL_CALL operator new ( size_t, void * pMem )
61  { return pMem; }
62  inline static void SAL_CALL operator delete ( void *, void * )
63  {}
65 
73  inline Mapping(
74  const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo,
75  const ::rtl::OUString & rAddPurpose = ::rtl::OUString() );
76 
83  inline Mapping(
84  uno_Environment * pFrom, uno_Environment * pTo,
85  const ::rtl::OUString & rAddPurpose = ::rtl::OUString() );
86 
94  inline Mapping(const Environment & rFrom, const Environment & rTo,
95  const ::rtl::OUString & rAddPurpose = ::rtl::OUString() );
96 
101  inline Mapping( uno_Mapping * pMapping = 0 );
102 
107  inline Mapping( const Mapping & rMapping );
108 
111  inline ~Mapping();
112 
118  inline Mapping & SAL_CALL operator = ( uno_Mapping * pMapping );
124  inline Mapping & SAL_CALL operator = ( const Mapping & rMapping )
125  { return operator = ( rMapping._pMapping ); }
126 
131  inline uno_Mapping * SAL_CALL get() const
132  { return _pMapping; }
133 
138  inline bool SAL_CALL is() const
139  { return (_pMapping != 0); }
140 
143  inline void SAL_CALL clear();
144 
151  inline void * SAL_CALL mapInterface( void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const;
158  inline void * SAL_CALL mapInterface( void * pInterface, typelib_TypeDescription * pTypeDescr ) const
159  { return mapInterface( pInterface, reinterpret_cast<typelib_InterfaceTypeDescription *>(pTypeDescr) ); }
160 
167  inline void * SAL_CALL mapInterface(
168  void * pInterface, const ::com::sun::star::uno::Type & rType ) const;
169 
176  inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const
177  { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, pTypeDescr ); }
184  inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_TypeDescription * pTypeDescr ) const
185  { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, reinterpret_cast<typelib_InterfaceTypeDescription *>(pTypeDescr) ); }
186 
193  inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, const ::com::sun::star::uno::Type & rType ) const;
194 };
195 
197  const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo, const ::rtl::OUString & rAddPurpose )
198  : _pMapping( 0 )
199 {
200  uno_getMappingByName( &_pMapping, rFrom.pData, rTo.pData, rAddPurpose.pData );
201 }
202 
204  uno_Environment * pFrom, uno_Environment * pTo, const ::rtl::OUString & rAddPurpose )
205  : _pMapping( 0 )
206 {
207  uno_getMapping( &_pMapping, pFrom, pTo, rAddPurpose.pData );
208 }
209 
211  const Environment & rFrom, const Environment & rTo, const ::rtl::OUString & rAddPurpose )
212  : _pMapping(0)
213 {
214  uno_getMapping( &_pMapping, rFrom.get(), rTo.get(), rAddPurpose.pData );
215 }
216 
217 inline Mapping::Mapping( uno_Mapping * pMapping )
218  : _pMapping( pMapping )
219 {
220  if (_pMapping)
221  (*_pMapping->acquire)( _pMapping );
222 }
223 
224 inline Mapping::Mapping( const Mapping & rMapping )
225  : _pMapping( rMapping._pMapping )
226 {
227  if (_pMapping)
228  (*_pMapping->acquire)( _pMapping );
229 }
230 
232 {
233  if (_pMapping)
234  (*_pMapping->release)( _pMapping );
235 }
236 
237 inline void Mapping::clear()
238 {
239  if (_pMapping)
240  {
241  (*_pMapping->release)( _pMapping );
242  _pMapping = 0;
243  }
244 }
245 
247 {
248  if (pMapping)
249  (*pMapping->acquire)( pMapping );
250  if (_pMapping)
251  (*_pMapping->release)( _pMapping );
252  _pMapping = pMapping;
253  return *this;
254 }
255 
257  void ** ppOut, void * pInterface, const ::com::sun::star::uno::Type & rType ) const
258 {
259  typelib_TypeDescription * pTD = 0;
260  TYPELIB_DANGER_GET( &pTD, rType.getTypeLibType() );
261  if (pTD)
262  {
263  (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, reinterpret_cast<typelib_InterfaceTypeDescription *>(pTD) );
264  TYPELIB_DANGER_RELEASE( pTD );
265  }
266 }
267 
268 inline void * Mapping::mapInterface(
269  void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const
270 {
271  void * pOut = 0;
272  (*_pMapping->mapInterface)( _pMapping, &pOut, pInterface, pTypeDescr );
273  return pOut;
274 }
275 
276 inline void * Mapping::mapInterface(
277  void * pInterface, const ::com::sun::star::uno::Type & rType ) const
278 {
279  void * pOut = 0;
280  mapInterface( &pOut, pInterface, rType );
281  return pOut;
282 }
283 
296 template< class C >
297 inline bool mapToCpp( Reference< C > * ppRet, uno_Interface * pUnoI )
298 {
299  Mapping aMapping(
301  ::rtl::OUString( CPPU_CURRENT_LANGUAGE_BINDING_NAME ) );
302  OSL_ASSERT( aMapping.is() );
303  aMapping.mapInterface(
304  reinterpret_cast<void **>(ppRet), pUnoI, ::cppu::getTypeFavourUnsigned( ppRet ) );
305  return (0 != *ppRet);
306 }
319 template< class C >
320 inline bool mapToUno( uno_Interface ** ppRet, const Reference< C > & x )
321 {
322  Mapping aMapping(
323  ::rtl::OUString( CPPU_CURRENT_LANGUAGE_BINDING_NAME ),
324  ::rtl::OUString( UNO_LB_UNO ) );
325  OSL_ASSERT( aMapping.is() );
326  aMapping.mapInterface(
327  reinterpret_cast<void **>(ppRet), x.get(), ::cppu::getTypeFavourUnsigned( &x ) );
328  return (0 != *ppRet);
329 }
330 
331 }
332 }
333 }
334 }
335 
336 #endif
337 
338 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void mapInterface(void **ppOut, void *pInterface, typelib_InterfaceTypeDescription *pTypeDescr) const
Maps an interface from one environment to another.
Definition: mapping.hxx:176
struct SAL_DLLPUBLIC_RTTI _uno_Interface uno_Interface
The binary C uno interface description.
C++ wrapper for C uno_Mapping.
Definition: mapping.hxx:49
#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 * mapInterface(void *pInterface, typelib_TypeDescription *pTypeDescr) const
Maps an interface from one environment to another.
Definition: mapping.hxx:158
Mapping & operator=(uno_Mapping *pMapping)
Sets a given mapping.
Definition: mapping.hxx:246
void * mapInterface(void *pInterface, typelib_InterfaceTypeDescription *pTypeDescr) const
Maps an interface from one environment to another.
Definition: mapping.hxx:268
struct SAL_DLLPUBLIC_RTTI _uno_Environment uno_Environment
The binary specification of an UNO environment.
~Mapping()
Destructor.
Definition: mapping.hxx:231
C++ wrapper for binary C uno_Environment.
Definition: environment.hxx:45
void clear()
Releases a set mapping.
Definition: mapping.hxx:237
uno_Environment * get() const
Provides UNacquired pointer to the set C environment.
Definition: environment.hxx:115
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.
SAL_DLLPUBLIC void * rtl_allocateMemory(sal_Size Bytes) SAL_THROW_EXTERN_C()
Allocate memory.
struct SAL_DLLPUBLIC_RTTI _typelib_InterfaceTypeDescription typelib_InterfaceTypeDescription
Type description of an interface.
bool mapToUno(uno_Interface **ppRet, const Reference< C > &x)
Deprecated.
Definition: mapping.hxx:320
Type description of an interface.
Definition: typedescription.h:370
struct SAL_DLLPUBLIC_RTTI _uno_Mapping uno_Mapping
This is the binary specification of a mapping.
interface_type * get() const
Gets interface pointer.
Definition: Reference.h:410
void mapInterface(void **ppOut, void *pInterface, typelib_TypeDescription *pTypeDescr) const
Maps an interface from one environment to another.
Definition: mapping.hxx:184
Full type description of a type.
Definition: typedescription.h:71
Definition: types.h:385
struct SAL_DLLPUBLIC_RTTI _typelib_TypeDescription typelib_TypeDescription
Full type description of a type.
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 ...
Template reference class for interface type derived from BaseReference.
Definition: unotype.hxx:37
The binary C uno interface description.
Definition: dispatcher.h:61
#define OSL_ASSERT(c)
Definition: diagnose.h:99
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:104
bool mapToCpp(Reference< C > *ppRet, uno_Interface *pUnoI)
Deprecated.
Definition: mapping.hxx:297
bool is() const
Tests if a mapping is set.
Definition: mapping.hxx:138
::com::sun::star::uno::Type const & getTypeFavourUnsigned(SAL_UNUSED_PARAMETER T const *)
A working replacement for getCppuType (see there).
Definition: unotype.hxx:302
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:196