Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / include / uno / mapping.hxx
blobdfc03ae1fdefecb7b7b2932441fb89c36241ab64
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_UNO_MAPPING_HXX
20 #define INCLUDED_UNO_MAPPING_HXX
22 #include <cppu/macros.hxx>
23 #include <rtl/alloc.h>
24 #include <rtl/ustring.hxx>
25 #include <uno/mapping.h>
26 #include <com/sun/star/uno/Type.hxx>
27 #include <com/sun/star/uno/Reference.hxx>
28 #include <cppu/unotype.hxx>
29 #include <uno/environment.hxx>
30 #include <uno/lbnames.h>
32 typedef struct _typelib_TypeDescription typelib_TypeDescription;
33 typedef struct _typelib_InterfaceTypeDescription typelib_InterfaceTypeDescription;
34 typedef struct _uno_Interface uno_Interface;
36 namespace com
38 namespace sun
40 namespace star
42 namespace uno
45 /** C++ wrapper for C uno_Mapping.
47 @see uno_Mapping
49 class Mapping
51 uno_Mapping * _pMapping;
53 public:
54 // these are here to force memory de/allocation to sal lib.
55 /// @cond INTERNAL
56 inline static void * SAL_CALL operator new ( size_t nSize ) SAL_THROW(())
57 { return ::rtl_allocateMemory( nSize ); }
58 inline static void SAL_CALL operator delete ( void * pMem ) SAL_THROW(())
59 { ::rtl_freeMemory( pMem ); }
60 inline static void * SAL_CALL operator new ( size_t, void * pMem ) SAL_THROW(())
61 { return pMem; }
62 inline static void SAL_CALL operator delete ( void *, void * ) SAL_THROW(())
64 /// @endcond
66 /** Holds a mapping from the specified source to the specified destination by environment
67 type names.
69 @param rFrom type name of source environment
70 @param rTo type name of destination environment
71 @param rAddPurpose additional purpose
73 inline Mapping(
74 const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo,
75 const ::rtl::OUString & rAddPurpose = ::rtl::OUString() )
76 SAL_THROW(());
78 /** Holds a mapping from the specified source to the specified destination.
80 @param pFrom source environment
81 @param pTo destination environment
82 @param rAddPurpose additional purpose
84 inline Mapping(
85 uno_Environment * pFrom, uno_Environment * pTo,
86 const ::rtl::OUString & rAddPurpose = ::rtl::OUString() )
87 SAL_THROW(());
89 /** Holds a mapping from the specified source to the specified destination
90 environment.
92 @param rFrom source environment
93 @param rTo destination environment
94 @param rAddPurpose additional purpose
96 inline Mapping(const Environment & rFrom, const Environment & rTo,
97 const ::rtl::OUString & rAddPurpose = ::rtl::OUString() )
98 SAL_THROW(());
100 /** Constructor.
102 @param pMapping another mapping
104 inline Mapping( uno_Mapping * pMapping = 0 ) SAL_THROW(());
106 /** Copy constructor.
108 @param rMapping another mapping
110 inline Mapping( const Mapping & rMapping ) SAL_THROW(());
112 /** Destructor.
114 inline ~Mapping() SAL_THROW(());
116 /** Sets a given mapping.
118 @param pMapping another mapping
119 @return this mapping
121 inline Mapping & SAL_CALL operator = ( uno_Mapping * pMapping ) SAL_THROW(());
122 /** Sets a given mapping.
124 @param rMapping another mapping
125 @return this mapping
127 inline Mapping & SAL_CALL operator = ( const Mapping & rMapping ) SAL_THROW(())
128 { return operator = ( rMapping._pMapping ); }
130 /** Provides a pointer to the C mapping. The returned mapping is NOT acquired!
132 @return UNacquired C mapping
134 inline uno_Mapping * SAL_CALL get() const SAL_THROW(())
135 { return _pMapping; }
137 /** Tests if a mapping is set.
139 @return true if a mapping is set
141 inline bool SAL_CALL is() const SAL_THROW(())
142 { return (_pMapping != 0); }
144 /** Releases a set mapping.
146 inline void SAL_CALL clear() SAL_THROW(());
148 /** Maps an interface from one environment to another.
150 @param pInterface source interface
151 @param pTypeDescr type description of interface
152 @return mapped interface
154 inline void * SAL_CALL mapInterface( void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const SAL_THROW(());
155 /** Maps an interface from one environment to another.
157 @param pInterface source interface
158 @param pTypeDescr type description of interface
159 @return mapped interface
161 inline void * SAL_CALL mapInterface( void * pInterface, typelib_TypeDescription * pTypeDescr ) const SAL_THROW(())
162 { return mapInterface( pInterface, (typelib_InterfaceTypeDescription *)pTypeDescr ); }
164 /** Maps an interface from one environment to another.
166 @param pInterface source interface
167 @param rType type of interface
168 @return mapped interface
170 inline void * SAL_CALL mapInterface(
171 void * pInterface, const ::com::sun::star::uno::Type & rType ) const SAL_THROW(());
173 /** Maps an interface from one environment to another.
175 @param ppOut inout mapped interface
176 @param pInterface source interface
177 @param pTypeDescr type description of interface
179 inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const SAL_THROW(())
180 { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, pTypeDescr ); }
181 /** Maps an interface from one environment to another.
183 @param ppOut inout mapped interface
184 @param pInterface source interface
185 @param pTypeDescr type description of interface
187 inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_TypeDescription * pTypeDescr ) const SAL_THROW(())
188 { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, (typelib_InterfaceTypeDescription *)pTypeDescr ); }
190 /** Maps an interface from one environment to another.
192 @param ppOut inout mapped interface
193 @param pInterface source interface
194 @param rType type of interface to be mapped
196 inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, const ::com::sun::star::uno::Type & rType ) const SAL_THROW(());
199 inline Mapping::Mapping(
200 const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo, const ::rtl::OUString & rAddPurpose )
201 SAL_THROW(())
202 : _pMapping( 0 )
204 uno_getMappingByName( &_pMapping, rFrom.pData, rTo.pData, rAddPurpose.pData );
207 inline Mapping::Mapping(
208 uno_Environment * pFrom, uno_Environment * pTo, const ::rtl::OUString & rAddPurpose )
209 SAL_THROW(())
210 : _pMapping( 0 )
212 uno_getMapping( &_pMapping, pFrom, pTo, rAddPurpose.pData );
215 inline Mapping::Mapping(
216 const Environment & rFrom, const Environment & rTo, const ::rtl::OUString & rAddPurpose )
217 SAL_THROW(())
218 : _pMapping(0)
220 uno_getMapping( &_pMapping, rFrom.get(), rTo.get(), rAddPurpose.pData );
223 inline Mapping::Mapping( uno_Mapping * pMapping ) SAL_THROW(())
224 : _pMapping( pMapping )
226 if (_pMapping)
227 (*_pMapping->acquire)( _pMapping );
230 inline Mapping::Mapping( const Mapping & rMapping ) SAL_THROW(())
231 : _pMapping( rMapping._pMapping )
233 if (_pMapping)
234 (*_pMapping->acquire)( _pMapping );
237 inline Mapping::~Mapping() SAL_THROW(())
239 if (_pMapping)
240 (*_pMapping->release)( _pMapping );
243 inline void Mapping::clear() SAL_THROW(())
245 if (_pMapping)
247 (*_pMapping->release)( _pMapping );
248 _pMapping = 0;
252 inline Mapping & Mapping::operator = ( uno_Mapping * pMapping ) SAL_THROW(())
254 if (pMapping)
255 (*pMapping->acquire)( pMapping );
256 if (_pMapping)
257 (*_pMapping->release)( _pMapping );
258 _pMapping = pMapping;
259 return *this;
262 inline void Mapping::mapInterface(
263 void ** ppOut, void * pInterface, const ::com::sun::star::uno::Type & rType ) const
264 SAL_THROW(())
266 typelib_TypeDescription * pTD = 0;
267 TYPELIB_DANGER_GET( &pTD, rType.getTypeLibType() );
268 if (pTD)
270 (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, (typelib_InterfaceTypeDescription *)pTD );
271 TYPELIB_DANGER_RELEASE( pTD );
275 inline void * Mapping::mapInterface(
276 void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const
277 SAL_THROW(())
279 void * pOut = 0;
280 (*_pMapping->mapInterface)( _pMapping, &pOut, pInterface, pTypeDescr );
281 return pOut;
284 inline void * Mapping::mapInterface(
285 void * pInterface, const ::com::sun::star::uno::Type & rType ) const
286 SAL_THROW(())
288 void * pOut = 0;
289 mapInterface( &pOut, pInterface, rType );
290 return pOut;
293 /** Deprecated. This function DOES NOT WORK with Purpose Environments
294 (http://wiki.openoffice.org/wiki/Uno/Binary/Spec/Purpose Environments)
296 Maps an binary C UNO interface to be used in the currently used compiler environment.
298 @tparam C interface type
299 @param ppRet inout returned interface pointer
300 @param pUnoI binary C UNO interface
301 @return true if successful, false otherwise
303 @deprecated
305 template< class C >
306 inline bool mapToCpp( Reference< C > * ppRet, uno_Interface * pUnoI ) SAL_THROW(())
308 Mapping aMapping(
309 ::rtl::OUString( UNO_LB_UNO ),
310 ::rtl::OUString( CPPU_CURRENT_LANGUAGE_BINDING_NAME ) );
311 OSL_ASSERT( aMapping.is() );
312 aMapping.mapInterface(
313 (void **)ppRet, pUnoI, ::cppu::getTypeFavourUnsigned( ppRet ) );
314 return (0 != *ppRet);
316 /** Deprecated. This function DOES NOT WORK with Purpose Environments
317 (http://wiki.openoffice.org/wiki/Uno/Binary/Spec/Purpose Environments)
319 Maps an UNO interface of the currently used compiler environment to binary C UNO.
321 @tparam C interface type
322 @param ppRet inout returned interface pointer
323 @param x interface reference
324 @return true if successful, false otherwise
326 @deprecated
328 template< class C >
329 inline bool mapToUno( uno_Interface ** ppRet, const Reference< C > & x ) SAL_THROW(())
331 Mapping aMapping(
332 ::rtl::OUString( CPPU_CURRENT_LANGUAGE_BINDING_NAME ),
333 ::rtl::OUString( UNO_LB_UNO ) );
334 OSL_ASSERT( aMapping.is() );
335 aMapping.mapInterface(
336 (void **)ppRet, x.get(), ::cppu::getTypeFavourUnsigned( &x ) );
337 return (0 != *ppRet);
345 #endif
347 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */