AlterOffice
AlterOffice 3.4 SDK C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 #ifndef INCLUDED_UNO_MAPPING_HXX
4 #define INCLUDED_UNO_MAPPING_HXX
5 
6 #include "sal/config.h"
7 
8 #include <cstddef>
9 
10 #include "uno/lbnames.h"
11 #include "rtl/alloc.h"
12 #include "rtl/ustring.hxx"
13 #include "osl/diagnose.h"
14 #include "uno/mapping.h"
17 #include "cppu/unotype.hxx"
18 #include "uno/environment.hxx"
19 
23 
24 namespace com
25 {
26 namespace sun
27 {
28 namespace star
29 {
30 namespace uno
31 {
32 
37 class Mapping
38 {
39  uno_Mapping * _pMapping;
40 
41 public:
42  // these are here to force memory de/allocation to sal lib.
44  static void * SAL_CALL operator new ( size_t nSize )
45  { return ::rtl_allocateMemory( nSize ); }
46  static void SAL_CALL operator delete ( void * pMem )
47  { ::rtl_freeMemory( pMem ); }
48  static void * SAL_CALL operator new ( size_t, void * pMem )
49  { return pMem; }
50  static void SAL_CALL operator delete ( void *, void * )
51  {}
53 
61  inline Mapping(
62  const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo,
63  const ::rtl::OUString & rAddPurpose = ::rtl::OUString() );
64 
71  inline Mapping(
72  uno_Environment * pFrom, uno_Environment * pTo,
73  const ::rtl::OUString & rAddPurpose = ::rtl::OUString() );
74 
82  inline Mapping(const Environment & rFrom, const Environment & rTo,
83  const ::rtl::OUString & rAddPurpose = ::rtl::OUString() );
84 
89  inline Mapping( uno_Mapping * pMapping = NULL );
90 
95  inline Mapping( const Mapping & rMapping );
96 
97 #if defined LIBO_INTERNAL_ONLY
98  Mapping(Mapping && other) noexcept : _pMapping(other._pMapping)
99  { other._pMapping = nullptr; }
100 #endif
101 
104  inline ~Mapping();
105 
111  inline Mapping & SAL_CALL operator = ( uno_Mapping * pMapping );
117  Mapping & SAL_CALL operator = ( const Mapping & rMapping )
118  { return operator = ( rMapping._pMapping ); }
119 
120 #if defined LIBO_INTERNAL_ONLY
121  Mapping & operator =(Mapping && other) noexcept {
122  if (_pMapping != nullptr) {
123  (*_pMapping->release)(_pMapping);
124  }
125  _pMapping = other._pMapping;
126  other._pMapping = nullptr;
127  return *this;
128  }
129 #endif
130 
135  uno_Mapping * SAL_CALL get() const
136  { return _pMapping; }
137 
142  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  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  void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const
181  { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, pTypeDescr ); }
188  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 
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 
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 
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 
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 
251 {
252  if (pMapping)
253  (*pMapping->acquire)( pMapping );
254  if (_pMapping)
255  (*_pMapping->release)( _pMapping );
256  _pMapping = pMapping;
257  return *this;
258 }
259 
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 SAL_DEPRECATED("use uno_Mapping")
302 inline bool mapToCpp( Reference< C > * ppRet, uno_Interface * pUnoI )
303 {
304  Mapping aMapping( UNO_LB_UNO, CPPU_CURRENT_LANGUAGE_BINDING_NAME );
305  OSL_ASSERT( aMapping.is() );
306  aMapping.mapInterface(
307  reinterpret_cast<void **>(ppRet), pUnoI, ::cppu::getTypeFavourUnsigned( ppRet ) );
308  return (0 != *ppRet);
309 }
322 template< class C >
323 SAL_DEPRECATED("use uno_Mapping")
324 inline bool mapToUno( uno_Interface ** ppRet, const Reference< C > & x )
325 {
326  Mapping aMapping( CPPU_CURRENT_LANGUAGE_BINDING_NAME, UNO_LB_UNO );
327  OSL_ASSERT( aMapping.is() );
328  aMapping.mapInterface(
329  reinterpret_cast<void **>(ppRet), x.get(), ::cppu::getTypeFavourUnsigned( &x ) );
330  return (NULL != *ppRet);
331 }
332 
333 }
334 }
335 }
336 }
337 
338 #endif
339 
340 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct SAL_DLLPUBLIC_RTTI _uno_Mapping uno_Mapping
This is the binary specification of a mapping.
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
bool mapToUno(uno_Interface **ppRet, const Reference< C > &x)
Deprecated.
Definition: mapping.hxx:324
struct SAL_DLLPUBLIC_RTTI _uno_Interface uno_Interface
The binary C uno interface description.
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:182
C++ wrapper for C uno_Mapping.
Definition: mapping.hxx:37
Type description of an interface.
Definition: typedescription.h:354
void mapInterface(void **ppOut, void *pInterface, typelib_TypeDescription *pTypeDescr) const
Maps an interface from one environment to another.
Definition: mapping.hxx:188
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.
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
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 **ppOut, void *pInterface, typelib_InterfaceTypeDescription *pTypeDescr) const
Maps an interface from one environment to another.
Definition: mapping.hxx:180
uno_Environment * get() const
Provides UNacquired pointer to the set C environment.
Definition: environment.hxx:115
#define SAL_DEPRECATED(message)
Use as follows: SAL_DEPRECATED(&quot;Don&#39;t use, it&#39;s evil.&quot;) void doit(int nPara);.
Definition: types.h:454
Full type description of a type.
Definition: typedescription.h:55
struct SAL_DLLPUBLIC_RTTI _typelib_InterfaceTypeDescription typelib_InterfaceTypeDescription
Type description of an interface.
C++ wrapper for binary C uno_Environment.
Definition: environment.hxx:29
bool mapToCpp(Reference< C > *ppRet, uno_Interface *pUnoI)
Deprecated.
Definition: mapping.hxx:302
struct SAL_DLLPUBLIC_RTTI _typelib_TypeDescription typelib_TypeDescription
Full type description of a type.
bool is() const
Tests if a mapping is set.
Definition: mapping.hxx:142
The binary C uno interface description.
Definition: dispatcher.h:45
#define OSL_ASSERT(c)
If cond is false, reports an error.
Definition: diagnose.h:64
~Mapping()
Destructor.
Definition: mapping.hxx:235
void clear()
Releases a set mapping.
Definition: mapping.hxx:241
Template reference class for interface type derived from BaseReference.
Definition: unotype.hxx:23
#define UNO_LB_UNO
Environment type name for binary C UNO.
Definition: lbnames.h:29
struct SAL_DLLPUBLIC_RTTI _uno_Environment uno_Environment
The binary specification of a UNO environment.
Provides simple diagnostic support.
SAL_DLLPUBLIC void * rtl_allocateMemory(sal_Size Bytes) SAL_THROW_EXTERN_C()
Allocate memory.
css::uno::Type const & getTypeFavourUnsigned(SAL_UNUSED_PARAMETER T const *)
A working replacement for getCppuType (see there).
Definition: unotype.hxx:304
void * mapInterface(void *pInterface, typelib_TypeDescription *pTypeDescr) const
Maps an interface from one environment to another.
Definition: mapping.hxx:162
Mapping & operator=(uno_Mapping *pMapping)
Sets a given mapping.
Definition: mapping.hxx:250
void * mapInterface(void *pInterface, typelib_InterfaceTypeDescription *pTypeDescr) const
Maps an interface from one environment to another.
Definition: mapping.hxx:272