LibreOffice
LibreOffice 5.0 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 #include <uno/lbnames.h>
32 
36 
37 namespace com
38 {
39 namespace sun
40 {
41 namespace star
42 {
43 namespace uno
44 {
45 
50 class Mapping
51 {
52  uno_Mapping * _pMapping;
53 
54 public:
55  // these are here to force memory de/allocation to sal lib.
57  inline static void * SAL_CALL operator new ( size_t nSize )
58  { return ::rtl_allocateMemory( nSize ); }
59  inline static void SAL_CALL operator delete ( void * pMem )
60  { ::rtl_freeMemory( pMem ); }
61  inline static void * SAL_CALL operator new ( size_t, void * pMem )
62  { return pMem; }
63  inline static void SAL_CALL operator delete ( void *, void * )
64  {}
66 
74  inline Mapping(
75  const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo,
76  const ::rtl::OUString & rAddPurpose = ::rtl::OUString() );
77 
84  inline Mapping(
85  uno_Environment * pFrom, uno_Environment * pTo,
86  const ::rtl::OUString & rAddPurpose = ::rtl::OUString() );
87 
95  inline Mapping(const Environment & rFrom, const Environment & rTo,
96  const ::rtl::OUString & rAddPurpose = ::rtl::OUString() );
97 
102  inline Mapping( uno_Mapping * pMapping = 0 );
103 
108  inline Mapping( const Mapping & rMapping );
109 
112  inline ~Mapping();
113 
119  inline Mapping & SAL_CALL operator = ( uno_Mapping * pMapping );
125  inline Mapping & SAL_CALL operator = ( const Mapping & rMapping )
126  { return operator = ( rMapping._pMapping ); }
127 
132  inline uno_Mapping * SAL_CALL get() const
133  { return _pMapping; }
134 
139  inline bool SAL_CALL is() const
140  { return (_pMapping != 0); }
141 
144  inline void SAL_CALL clear();
145 
152  inline void * SAL_CALL mapInterface( void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const;
159  inline void * SAL_CALL mapInterface( void * pInterface, typelib_TypeDescription * pTypeDescr ) const
160  { return mapInterface( pInterface, reinterpret_cast<typelib_InterfaceTypeDescription *>(pTypeDescr) ); }
161 
168  inline void * SAL_CALL mapInterface(
169  void * pInterface, const ::com::sun::star::uno::Type & rType ) const;
170 
177  inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const
178  { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, pTypeDescr ); }
185  inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_TypeDescription * pTypeDescr ) const
186  { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, reinterpret_cast<typelib_InterfaceTypeDescription *>(pTypeDescr) ); }
187 
194  inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, const ::com::sun::star::uno::Type & rType ) const;
195 };
196 
198  const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo, const ::rtl::OUString & rAddPurpose )
199  : _pMapping( 0 )
200 {
201  uno_getMappingByName( &_pMapping, rFrom.pData, rTo.pData, rAddPurpose.pData );
202 }
203 
205  uno_Environment * pFrom, uno_Environment * pTo, const ::rtl::OUString & rAddPurpose )
206  : _pMapping( 0 )
207 {
208  uno_getMapping( &_pMapping, pFrom, pTo, rAddPurpose.pData );
209 }
210 
212  const Environment & rFrom, const Environment & rTo, const ::rtl::OUString & rAddPurpose )
213  : _pMapping(0)
214 {
215  uno_getMapping( &_pMapping, rFrom.get(), rTo.get(), rAddPurpose.pData );
216 }
217 
218 inline Mapping::Mapping( uno_Mapping * pMapping )
219  : _pMapping( pMapping )
220 {
221  if (_pMapping)
222  (*_pMapping->acquire)( _pMapping );
223 }
224 
225 inline Mapping::Mapping( const Mapping & rMapping )
226  : _pMapping( rMapping._pMapping )
227 {
228  if (_pMapping)
229  (*_pMapping->acquire)( _pMapping );
230 }
231 
233 {
234  if (_pMapping)
235  (*_pMapping->release)( _pMapping );
236 }
237 
238 inline void Mapping::clear()
239 {
240  if (_pMapping)
241  {
242  (*_pMapping->release)( _pMapping );
243  _pMapping = 0;
244  }
245 }
246 
248 {
249  if (pMapping)
250  (*pMapping->acquire)( pMapping );
251  if (_pMapping)
252  (*_pMapping->release)( _pMapping );
253  _pMapping = pMapping;
254  return *this;
255 }
256 
258  void ** ppOut, void * pInterface, const ::com::sun::star::uno::Type & rType ) const
259 {
260  typelib_TypeDescription * pTD = 0;
261  TYPELIB_DANGER_GET( &pTD, rType.getTypeLibType() );
262  if (pTD)
263  {
264  (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, reinterpret_cast<typelib_InterfaceTypeDescription *>(pTD) );
265  TYPELIB_DANGER_RELEASE( pTD );
266  }
267 }
268 
269 inline void * Mapping::mapInterface(
270  void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const
271 {
272  void * pOut = 0;
273  (*_pMapping->mapInterface)( _pMapping, &pOut, pInterface, pTypeDescr );
274  return pOut;
275 }
276 
277 inline void * Mapping::mapInterface(
278  void * pInterface, const ::com::sun::star::uno::Type & rType ) const
279 {
280  void * pOut = 0;
281  mapInterface( &pOut, pInterface, rType );
282  return pOut;
283 }
284 
297 template< class C >
298 inline bool mapToCpp( Reference< C > * ppRet, uno_Interface * pUnoI )
299 {
300  Mapping aMapping(
302  ::rtl::OUString( CPPU_CURRENT_LANGUAGE_BINDING_NAME ) );
303  OSL_ASSERT( aMapping.is() );
304  aMapping.mapInterface(
305  reinterpret_cast<void **>(ppRet), pUnoI, ::cppu::getTypeFavourUnsigned( ppRet ) );
306  return (0 != *ppRet);
307 }
320 template< class C >
321 inline bool mapToUno( uno_Interface ** ppRet, const Reference< C > & x )
322 {
323  Mapping aMapping(
324  ::rtl::OUString( CPPU_CURRENT_LANGUAGE_BINDING_NAME ),
325  ::rtl::OUString( UNO_LB_UNO ) );
326  OSL_ASSERT( aMapping.is() );
327  aMapping.mapInterface(
328  reinterpret_cast<void **>(ppRet), x.get(), ::cppu::getTypeFavourUnsigned( &x ) );
329  return (0 != *ppRet);
330 }
331 
332 }
333 }
334 }
335 }
336 
337 #endif
338 
339 /* 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:177
struct SAL_DLLPUBLIC_RTTI _uno_Interface uno_Interface
The binary C uno interface description.
C++ wrapper for C uno_Mapping.
Definition: mapping.hxx:50
#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:159
Mapping & operator=(uno_Mapping *pMapping)
Sets a given mapping.
Definition: mapping.hxx:247
void * mapInterface(void *pInterface, typelib_InterfaceTypeDescription *pTypeDescr) const
Maps an interface from one environment to another.
Definition: mapping.hxx:269
struct SAL_DLLPUBLIC_RTTI _uno_Environment uno_Environment
The binary specification of an UNO environment.
~Mapping()
Destructor.
Definition: mapping.hxx:232
C++ wrapper for binary C uno_Environment.
Definition: environment.hxx:45
void clear()
Releases a set mapping.
Definition: mapping.hxx:238
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:321
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:185
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:105
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:115
bool mapToCpp(Reference< C > *ppRet, uno_Interface *pUnoI)
Deprecated.
Definition: mapping.hxx:298
bool is() const
Tests if a mapping is set.
Definition: mapping.hxx:139
::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:197