LibreOffice
LibreOffice 4.2 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 <cppu/macros.hxx>
23 #include <rtl/alloc.h>
24 #include <rtl/ustring.hxx>
25 #include <uno/mapping.h>
28 #include <cppu/unotype.hxx>
29 #include <uno/environment.hxx>
30 
34 
35 namespace com
36 {
37 namespace sun
38 {
39 namespace star
40 {
41 namespace uno
42 {
43 
48 class Mapping
49 {
50  uno_Mapping * _pMapping;
51 
52 public:
53  // these are here to force memory de/allocation to sal lib.
55  inline static void * SAL_CALL operator new ( size_t nSize ) SAL_THROW(())
56  { return ::rtl_allocateMemory( nSize ); }
57  inline static void SAL_CALL operator delete ( void * pMem ) SAL_THROW(())
58  { ::rtl_freeMemory( pMem ); }
59  inline static void * SAL_CALL operator new ( size_t, void * pMem ) SAL_THROW(())
60  { return pMem; }
61  inline static void SAL_CALL operator delete ( void *, void * ) SAL_THROW(())
62  {}
64 
72  inline Mapping(
73  const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo,
74  const ::rtl::OUString & rAddPurpose = ::rtl::OUString() )
75  SAL_THROW(());
76 
83  inline Mapping(
84  uno_Environment * pFrom, uno_Environment * pTo,
85  const ::rtl::OUString & rAddPurpose = ::rtl::OUString() )
86  SAL_THROW(());
87 
95  inline Mapping(const Environment & rFrom, const Environment & rTo,
96  const ::rtl::OUString & rAddPurpose = ::rtl::OUString() )
97  SAL_THROW(());
98 
103  inline Mapping( uno_Mapping * pMapping = 0 ) SAL_THROW(());
104 
109  inline Mapping( const Mapping & rMapping ) SAL_THROW(());
110 
113  inline ~Mapping() SAL_THROW(());
114 
120  inline Mapping & SAL_CALL operator = ( uno_Mapping * pMapping ) SAL_THROW(());
126  inline Mapping & SAL_CALL operator = ( const Mapping & rMapping ) SAL_THROW(())
127  { return operator = ( rMapping._pMapping ); }
128 
133  inline uno_Mapping * SAL_CALL get() const SAL_THROW(())
134  { return _pMapping; }
135 
140  inline sal_Bool SAL_CALL is() const SAL_THROW(())
141  { return (_pMapping != 0); }
142 
145  inline void SAL_CALL clear() SAL_THROW(());
146 
153  inline void * SAL_CALL mapInterface( void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const SAL_THROW(());
160  inline void * SAL_CALL mapInterface( void * pInterface, typelib_TypeDescription * pTypeDescr ) const SAL_THROW(())
161  { return mapInterface( pInterface, (typelib_InterfaceTypeDescription *)pTypeDescr ); }
162 
169  inline void * SAL_CALL mapInterface(
170  void * pInterface, const ::com::sun::star::uno::Type & rType ) const SAL_THROW(());
171 
178  inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const SAL_THROW(())
179  { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, pTypeDescr ); }
186  inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_TypeDescription * pTypeDescr ) const SAL_THROW(())
187  { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, (typelib_InterfaceTypeDescription *)pTypeDescr ); }
188 
195  inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, const ::com::sun::star::uno::Type & rType ) const SAL_THROW(());
196 };
197 //__________________________________________________________________________________________________
199  const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo, const ::rtl::OUString & rAddPurpose )
200  SAL_THROW(())
201  : _pMapping( 0 )
202 {
203  uno_getMappingByName( &_pMapping, rFrom.pData, rTo.pData, rAddPurpose.pData );
204 }
205 //__________________________________________________________________________________________________
207  uno_Environment * pFrom, uno_Environment * pTo, const ::rtl::OUString & rAddPurpose )
208  SAL_THROW(())
209  : _pMapping( 0 )
210 {
211  uno_getMapping( &_pMapping, pFrom, pTo, rAddPurpose.pData );
212 }
213 //__________________________________________________________________________________________________
215  const Environment & rFrom, const Environment & rTo, const ::rtl::OUString & rAddPurpose )
216  SAL_THROW(())
217  : _pMapping(0)
218 {
219  uno_getMapping( &_pMapping, rFrom.get(), rTo.get(), rAddPurpose.pData );
220 }
221 //__________________________________________________________________________________________________
222 inline Mapping::Mapping( uno_Mapping * pMapping ) SAL_THROW(())
223  : _pMapping( pMapping )
224 {
225  if (_pMapping)
226  (*_pMapping->acquire)( _pMapping );
227 }
228 //__________________________________________________________________________________________________
229 inline Mapping::Mapping( const Mapping & rMapping ) SAL_THROW(())
230  : _pMapping( rMapping._pMapping )
231 {
232  if (_pMapping)
233  (*_pMapping->acquire)( _pMapping );
234 }
235 //__________________________________________________________________________________________________
236 inline Mapping::~Mapping() SAL_THROW(())
237 {
238  if (_pMapping)
239  (*_pMapping->release)( _pMapping );
240 }
241 //__________________________________________________________________________________________________
242 inline void Mapping::clear() SAL_THROW(())
243 {
244  if (_pMapping)
245  {
246  (*_pMapping->release)( _pMapping );
247  _pMapping = 0;
248  }
249 }
250 //__________________________________________________________________________________________________
252 {
253  if (pMapping)
254  (*pMapping->acquire)( pMapping );
255  if (_pMapping)
256  (*_pMapping->release)( _pMapping );
257  _pMapping = pMapping;
258  return *this;
259 }
260 //__________________________________________________________________________________________________
262  void ** ppOut, void * pInterface, const ::com::sun::star::uno::Type & rType ) const
263  SAL_THROW(())
264 {
265  typelib_TypeDescription * pTD = 0;
266  TYPELIB_DANGER_GET( &pTD, rType.getTypeLibType() );
267  if (pTD)
268  {
269  (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, (typelib_InterfaceTypeDescription *)pTD );
270  TYPELIB_DANGER_RELEASE( pTD );
271  }
272 }
273 //__________________________________________________________________________________________________
274 inline void * Mapping::mapInterface(
275  void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const
276  SAL_THROW(())
277 {
278  void * pOut = 0;
279  (*_pMapping->mapInterface)( _pMapping, &pOut, pInterface, pTypeDescr );
280  return pOut;
281 }
282 //__________________________________________________________________________________________________
283 inline void * Mapping::mapInterface(
284  void * pInterface, const ::com::sun::star::uno::Type & rType ) const
285  SAL_THROW(())
286 {
287  void * pOut = 0;
288  mapInterface( &pOut, pInterface, rType );
289  return pOut;
290 }
291 
304 template< class C >
306 {
307  Mapping aMapping(
309  ::rtl::OUString( CPPU_CURRENT_LANGUAGE_BINDING_NAME ) );
310  OSL_ASSERT( aMapping.is() );
311  aMapping.mapInterface(
312  (void **)ppRet, pUnoI, ::cppu::getTypeFavourUnsigned( ppRet ) );
313  return (0 != *ppRet);
314 }
327 template< class C >
328 inline sal_Bool mapToUno( uno_Interface ** ppRet, const Reference< C > & x ) SAL_THROW(())
329 {
330  Mapping aMapping(
331  ::rtl::OUString( CPPU_CURRENT_LANGUAGE_BINDING_NAME ),
332  ::rtl::OUString( UNO_LB_UNO ) );
333  OSL_ASSERT( aMapping.is() );
334  aMapping.mapInterface(
335  (void **)ppRet, x.get(), ::cppu::getTypeFavourUnsigned( &x ) );
336  return (0 != *ppRet);
337 }
338 
339 }
340 }
341 }
342 }
343 
344 #endif
345 
346 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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:198
uno_AcquireMappingFunc acquire
Acquires mapping.
Definition: mapping.h:68
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:82
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 ...
void * mapInterface(void *pInterface, typelib_InterfaceTypeDescription *pTypeDescr) const
Maps an interface from one environment to another.
Definition: mapping.hxx:274
sal_Bool mapToUno(uno_Interface **ppRet, const Reference< C > &x)
Deprecated.
Definition: mapping.hxx:328
SAL_DLLPUBLIC void * rtl_allocateMemory(sal_Size Bytes) SAL_THROW_EXTERN_C()
Allocate memory.
This is the binary specification of a mapping.
Definition: mapping.h:64
#define UNO_LB_UNO
Environment type name for binary C UNO.
Definition: lbnames.h:44
Type description of an interface.
Definition: typedescription.h:424
uno_MapInterfaceFunc mapInterface
mapping function
Definition: mapping.h:76
void clear()
Releases a set mapping.
Definition: mapping.hxx:242
::com::sun::star::uno::Type const & getTypeFavourUnsigned(SAL_UNUSED_PARAMETER T const *)
A working replacement for getCppuType (see there).
Definition: unotype.hxx:287
uno_ReleaseMappingFunc release
Releases mapping.
Definition: mapping.h:72
Full type description of a type.
Definition: typedescription.h:71
The binary C uno interface description.
Definition: dispatcher.h:62
The binary specification of an UNO environment.
Definition: environment.h:41
void mapInterface(void **ppOut, void *pInterface, typelib_TypeDescription *pTypeDescr) const
Maps an interface from one environment to another.
Definition: mapping.hxx:186
C++ wrapper for C uno_Mapping.
Definition: mapping.hxx:48
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.
Template reference class for interface type derived from BaseReference.
Definition: unotype.hxx:32
~Mapping()
Destructor.
Definition: mapping.hxx:236
unsigned char sal_Bool
Definition: types.h:46
#define OSL_ASSERT(c)
Definition: diagnose.h:153
sal_Bool mapToCpp(Reference< C > *ppRet, uno_Interface *pUnoI)
Deprecated.
Definition: mapping.hxx:305
Mapping & operator=(uno_Mapping *pMapping)
Sets a given mapping.
Definition: mapping.hxx:251
sal_Bool is() const
Tests if a mapping is set.
Definition: mapping.hxx:140
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
C++ wrapper for binary C uno_Environment.
Definition: environment.hxx:45
void mapInterface(void **ppOut, void *pInterface, typelib_InterfaceTypeDescription *pTypeDescr) const
Maps an interface from one environment to another.
Definition: mapping.hxx:178
#define SAL_THROW(exc)
Definition of function throw clause macros.
Definition: types.h:358