1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <uno/lbnames.h>
23 #include <rtl/alloc.h>
24 #include <rtl/ustring.hxx>
25 #include <osl/diagnose.h>
26 #include <uno/mapping.h>
27 #include <com/sun/star/uno/Type.hxx>
28 #include <com/sun/star/uno/Reference.hxx>
29 #include <cppu/unotype.hxx>
30 #include <uno/environment.hxx>
31 #include <uno/lbnames.h>
33 typedef struct _typelib_TypeDescription typelib_TypeDescription
;
34 typedef struct _typelib_InterfaceTypeDescription typelib_InterfaceTypeDescription
;
35 typedef struct _uno_Interface uno_Interface
;
46 /** C++ wrapper for C uno_Mapping.
52 uno_Mapping
* _pMapping
;
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
)
63 inline static void SAL_CALL
operator delete ( void *, void * )
67 /** Holds a mapping from the specified source to the specified destination by environment
70 @param rFrom type name of source environment
71 @param rTo type name of destination environment
72 @param rAddPurpose additional purpose
75 const ::rtl::OUString
& rFrom
, const ::rtl::OUString
& rTo
,
76 const ::rtl::OUString
& rAddPurpose
= ::rtl::OUString() );
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
85 uno_Environment
* pFrom
, uno_Environment
* pTo
,
86 const ::rtl::OUString
& rAddPurpose
= ::rtl::OUString() );
88 /** Holds a mapping from the specified source to the specified destination
91 @param rFrom source environment
92 @param rTo destination environment
93 @param rAddPurpose additional purpose
95 inline Mapping(const Environment
& rFrom
, const Environment
& rTo
,
96 const ::rtl::OUString
& rAddPurpose
= ::rtl::OUString() );
100 @param pMapping another mapping
102 inline Mapping( uno_Mapping
* pMapping
= 0 );
104 /** Copy constructor.
106 @param rMapping another mapping
108 inline Mapping( const Mapping
& rMapping
);
114 /** Sets a given mapping.
116 @param pMapping another mapping
119 inline Mapping
& SAL_CALL
operator = ( uno_Mapping
* pMapping
);
120 /** Sets a given mapping.
122 @param rMapping another mapping
125 inline Mapping
& SAL_CALL
operator = ( const Mapping
& rMapping
)
126 { return operator = ( rMapping
._pMapping
); }
128 /** Provides a pointer to the C mapping. The returned mapping is NOT acquired!
130 @return UNacquired C mapping
132 inline uno_Mapping
* SAL_CALL
get() const
133 { return _pMapping
; }
135 /** Tests if a mapping is set.
137 @return true if a mapping is set
139 inline bool SAL_CALL
is() const
140 { return (_pMapping
!= 0); }
142 /** Releases a set mapping.
144 inline void SAL_CALL
clear();
146 /** Maps an interface from one environment to another.
148 @param pInterface source interface
149 @param pTypeDescr type description of interface
150 @return mapped interface
152 inline void * SAL_CALL
mapInterface( void * pInterface
, typelib_InterfaceTypeDescription
* pTypeDescr
) const;
153 /** Maps an interface from one environment to another.
155 @param pInterface source interface
156 @param pTypeDescr type description of interface
157 @return mapped interface
159 inline void * SAL_CALL
mapInterface( void * pInterface
, typelib_TypeDescription
* pTypeDescr
) const
160 { return mapInterface( pInterface
, reinterpret_cast<typelib_InterfaceTypeDescription
*>(pTypeDescr
) ); }
162 /** Maps an interface from one environment to another.
164 @param pInterface source interface
165 @param rType type of interface
166 @return mapped interface
168 inline void * SAL_CALL
mapInterface(
169 void * pInterface
, const ::com::sun::star::uno::Type
& rType
) const;
171 /** Maps an interface from one environment to another.
173 @param ppOut inout mapped interface
174 @param pInterface source interface
175 @param pTypeDescr type description of interface
177 inline void SAL_CALL
mapInterface( void ** ppOut
, void * pInterface
, typelib_InterfaceTypeDescription
* pTypeDescr
) const
178 { (*_pMapping
->mapInterface
)( _pMapping
, ppOut
, pInterface
, pTypeDescr
); }
179 /** Maps an interface from one environment to another.
181 @param ppOut inout mapped interface
182 @param pInterface source interface
183 @param pTypeDescr type description of interface
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
) ); }
188 /** Maps an interface from one environment to another.
190 @param ppOut inout mapped interface
191 @param pInterface source interface
192 @param rType type of interface to be mapped
194 inline void SAL_CALL
mapInterface( void ** ppOut
, void * pInterface
, const ::com::sun::star::uno::Type
& rType
) const;
197 inline Mapping::Mapping(
198 const ::rtl::OUString
& rFrom
, const ::rtl::OUString
& rTo
, const ::rtl::OUString
& rAddPurpose
)
201 uno_getMappingByName( &_pMapping
, rFrom
.pData
, rTo
.pData
, rAddPurpose
.pData
);
204 inline Mapping::Mapping(
205 uno_Environment
* pFrom
, uno_Environment
* pTo
, const ::rtl::OUString
& rAddPurpose
)
208 uno_getMapping( &_pMapping
, pFrom
, pTo
, rAddPurpose
.pData
);
211 inline Mapping::Mapping(
212 const Environment
& rFrom
, const Environment
& rTo
, const ::rtl::OUString
& rAddPurpose
)
215 uno_getMapping( &_pMapping
, rFrom
.get(), rTo
.get(), rAddPurpose
.pData
);
218 inline Mapping::Mapping( uno_Mapping
* pMapping
)
219 : _pMapping( pMapping
)
222 (*_pMapping
->acquire
)( _pMapping
);
225 inline Mapping::Mapping( const Mapping
& rMapping
)
226 : _pMapping( rMapping
._pMapping
)
229 (*_pMapping
->acquire
)( _pMapping
);
232 inline Mapping::~Mapping()
235 (*_pMapping
->release
)( _pMapping
);
238 inline void Mapping::clear()
242 (*_pMapping
->release
)( _pMapping
);
247 inline Mapping
& Mapping::operator = ( uno_Mapping
* pMapping
)
250 (*pMapping
->acquire
)( pMapping
);
252 (*_pMapping
->release
)( _pMapping
);
253 _pMapping
= pMapping
;
257 inline void Mapping::mapInterface(
258 void ** ppOut
, void * pInterface
, const ::com::sun::star::uno::Type
& rType
) const
260 typelib_TypeDescription
* pTD
= 0;
261 TYPELIB_DANGER_GET( &pTD
, rType
.getTypeLibType() );
264 (*_pMapping
->mapInterface
)( _pMapping
, ppOut
, pInterface
, reinterpret_cast<typelib_InterfaceTypeDescription
*>(pTD
) );
265 TYPELIB_DANGER_RELEASE( pTD
);
269 inline void * Mapping::mapInterface(
270 void * pInterface
, typelib_InterfaceTypeDescription
* pTypeDescr
) const
273 (*_pMapping
->mapInterface
)( _pMapping
, &pOut
, pInterface
, pTypeDescr
);
277 inline void * Mapping::mapInterface(
278 void * pInterface
, const ::com::sun::star::uno::Type
& rType
) const
281 mapInterface( &pOut
, pInterface
, rType
);
285 /** Deprecated. This function DOES NOT WORK with Purpose Environments
286 (http://wiki.openoffice.org/wiki/Uno/Binary/Spec/Purpose Environments)
288 Maps an binary C UNO interface to be used in the currently used compiler environment.
290 @tparam C interface type
291 @param ppRet inout returned interface pointer
292 @param pUnoI binary C UNO interface
293 @return true if successful, false otherwise
298 inline bool mapToCpp( Reference
< C
> * ppRet
, uno_Interface
* pUnoI
)
301 ::rtl::OUString( UNO_LB_UNO
),
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
);
308 /** Deprecated. This function DOES NOT WORK with Purpose Environments
309 (http://wiki.openoffice.org/wiki/Uno/Binary/Spec/Purpose Environments)
311 Maps an UNO interface of the currently used compiler environment to binary C UNO.
313 @tparam C interface type
314 @param ppRet inout returned interface pointer
315 @param x interface reference
316 @return true if successful, false otherwise
321 inline bool mapToUno( uno_Interface
** ppRet
, const Reference
< C
> & x
)
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
);
339 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */