My Project
UDK 3.2.7 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  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * Copyright 2000, 2010 Oracle and/or its affiliates.
7  *
8  * OpenOffice.org - a multi-platform office productivity suite
9  *
10  * This file is part of OpenOffice.org.
11  *
12  * OpenOffice.org is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License version 3
14  * only, as published by the Free Software Foundation.
15  *
16  * OpenOffice.org is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser General Public License version 3 for more details
20  * (a copy is included in the LICENSE file that accompanied this code).
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * version 3 along with OpenOffice.org. If not, see
24  * <http://www.openoffice.org/license.html>
25  * for a copy of the LGPLv3 License.
26  *
27  ************************************************************************/
28 #ifndef _UNO_MAPPING_HXX_
29 #define _UNO_MAPPING_HXX_
30 
31 #include <cppu/macros.hxx>
32 #include <rtl/alloc.h>
33 #include <rtl/ustring.hxx>
34 #include <uno/mapping.h>
37 #include "cppu/unotype.hxx"
38 #include "uno/environment.hxx"
39 
43 
44 namespace com
45 {
46 namespace sun
47 {
48 namespace star
49 {
50 namespace uno
51 {
52 
57 class Mapping
58 {
59  uno_Mapping * _pMapping;
60 
61 public:
62  // these are here to force memory de/allocation to sal lib.
64  inline static void * SAL_CALL operator new ( size_t nSize ) SAL_THROW(())
65  { return ::rtl_allocateMemory( nSize ); }
66  inline static void SAL_CALL operator delete ( void * pMem ) SAL_THROW(())
67  { ::rtl_freeMemory( pMem ); }
68  inline static void * SAL_CALL operator new ( size_t, void * pMem ) SAL_THROW(())
69  { return pMem; }
70  inline static void SAL_CALL operator delete ( void *, void * ) SAL_THROW(())
71  {}
73 
81  inline Mapping(
82  const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo,
83  const ::rtl::OUString & rAddPurpose = ::rtl::OUString() )
84  SAL_THROW(());
85 
92  inline Mapping(
93  uno_Environment * pFrom, uno_Environment * pTo,
94  const ::rtl::OUString & rAddPurpose = ::rtl::OUString() )
95  SAL_THROW(());
96 
104  inline Mapping(const Environment & rFrom, const Environment & rTo,
105  const ::rtl::OUString & rAddPurpose = ::rtl::OUString() )
106  SAL_THROW(());
107 
112  inline Mapping( uno_Mapping * pMapping = 0 ) SAL_THROW(());
113 
118  inline Mapping( const Mapping & rMapping ) SAL_THROW(());
119 
122  inline ~Mapping() SAL_THROW(());
123 
129  inline Mapping & SAL_CALL operator = ( uno_Mapping * pMapping ) SAL_THROW(());
135  inline Mapping & SAL_CALL operator = ( const Mapping & rMapping ) SAL_THROW(())
136  { return operator = ( rMapping._pMapping ); }
137 
142  inline uno_Mapping * SAL_CALL get() const SAL_THROW(())
143  { return _pMapping; }
144 
149  inline sal_Bool SAL_CALL is() const SAL_THROW(())
150  { return (_pMapping != 0); }
151 
154  inline void SAL_CALL clear() SAL_THROW(());
155 
162  inline void * SAL_CALL mapInterface( void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const SAL_THROW(());
169  inline void * SAL_CALL mapInterface( void * pInterface, typelib_TypeDescription * pTypeDescr ) const SAL_THROW(())
170  { return mapInterface( pInterface, (typelib_InterfaceTypeDescription *)pTypeDescr ); }
171 
178  inline void * SAL_CALL mapInterface(
179  void * pInterface, const ::com::sun::star::uno::Type & rType ) const SAL_THROW(());
180 
187  inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const SAL_THROW(())
188  { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, pTypeDescr ); }
195  inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_TypeDescription * pTypeDescr ) const SAL_THROW(())
196  { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, (typelib_InterfaceTypeDescription *)pTypeDescr ); }
197 
204  inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, const ::com::sun::star::uno::Type & rType ) const SAL_THROW(());
205 };
206 //__________________________________________________________________________________________________
208  const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo, const ::rtl::OUString & rAddPurpose )
209  SAL_THROW(())
210  : _pMapping( 0 )
211 {
212  uno_getMappingByName( &_pMapping, rFrom.pData, rTo.pData, rAddPurpose.pData );
213 }
214 //__________________________________________________________________________________________________
216  uno_Environment * pFrom, uno_Environment * pTo, const ::rtl::OUString & rAddPurpose )
217  SAL_THROW(())
218  : _pMapping( 0 )
219 {
220  uno_getMapping( &_pMapping, pFrom, pTo, rAddPurpose.pData );
221 }
222 //__________________________________________________________________________________________________
224  const Environment & rFrom, const Environment & rTo, const ::rtl::OUString & rAddPurpose )
225  SAL_THROW(())
226  : _pMapping(0)
227 {
228  uno_getMapping( &_pMapping, rFrom.get(), rTo.get(), rAddPurpose.pData );
229 }
230 //__________________________________________________________________________________________________
231 inline Mapping::Mapping( uno_Mapping * pMapping ) SAL_THROW(())
232  : _pMapping( pMapping )
233 {
234  if (_pMapping)
235  (*_pMapping->acquire)( _pMapping );
236 }
237 //__________________________________________________________________________________________________
238 inline Mapping::Mapping( const Mapping & rMapping ) SAL_THROW(())
239  : _pMapping( rMapping._pMapping )
240 {
241  if (_pMapping)
242  (*_pMapping->acquire)( _pMapping );
243 }
244 //__________________________________________________________________________________________________
245 inline Mapping::~Mapping() SAL_THROW(())
246 {
247  if (_pMapping)
248  (*_pMapping->release)( _pMapping );
249 }
250 //__________________________________________________________________________________________________
251 inline void Mapping::clear() SAL_THROW(())
252 {
253  if (_pMapping)
254  {
255  (*_pMapping->release)( _pMapping );
256  _pMapping = 0;
257  }
258 }
259 //__________________________________________________________________________________________________
261 {
262  if (pMapping)
263  (*pMapping->acquire)( pMapping );
264  if (_pMapping)
265  (*_pMapping->release)( _pMapping );
266  _pMapping = pMapping;
267  return *this;
268 }
269 //__________________________________________________________________________________________________
271  void ** ppOut, void * pInterface, const ::com::sun::star::uno::Type & rType ) const
272  SAL_THROW(())
273 {
274  typelib_TypeDescription * pTD = 0;
275  TYPELIB_DANGER_GET( &pTD, rType.getTypeLibType() );
276  if (pTD)
277  {
278  (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, (typelib_InterfaceTypeDescription *)pTD );
279  TYPELIB_DANGER_RELEASE( pTD );
280  }
281 }
282 //__________________________________________________________________________________________________
283 inline void * Mapping::mapInterface(
284  void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const
285  SAL_THROW(())
286 {
287  void * pOut = 0;
288  (*_pMapping->mapInterface)( _pMapping, &pOut, pInterface, pTypeDescr );
289  return pOut;
290 }
291 //__________________________________________________________________________________________________
292 inline void * Mapping::mapInterface(
293  void * pInterface, const ::com::sun::star::uno::Type & rType ) const
294  SAL_THROW(())
295 {
296  void * pOut = 0;
297  mapInterface( &pOut, pInterface, rType );
298  return pOut;
299 }
300 
313 template< class C >
315 {
316  Mapping aMapping(
318  ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ) );
319  OSL_ASSERT( aMapping.is() );
320  aMapping.mapInterface(
321  (void **)ppRet, pUnoI, ::cppu::getTypeFavourUnsigned( ppRet ) );
322  return (0 != *ppRet);
323 }
336 template< class C >
337 inline sal_Bool mapToUno( uno_Interface ** ppRet, const Reference< C > & x ) SAL_THROW(())
338 {
339  Mapping aMapping(
340  ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ),
342  OSL_ASSERT( aMapping.is() );
343  aMapping.mapInterface(
344  (void **)ppRet, x.get(), ::cppu::getTypeFavourUnsigned( &x ) );
345  return (0 != *ppRet);
346 }
347 
348 }
349 }
350 }
351 }
352 
353 #endif
354 
355 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */