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 <sal/config.h>
26 #include <uno/lbnames.h>
27 #include <rtl/alloc.h>
28 #include <rtl/ustring.hxx>
29 #include <osl/diagnose.h>
30 #include <uno/mapping.h>
31 #include <com/sun/star/uno/Type.hxx>
32 #include <com/sun/star/uno/Reference.hxx>
33 #include <cppu/unotype.hxx>
34 #include <uno/environment.hxx>
36 typedef struct _typelib_TypeDescription typelib_TypeDescription
;
37 typedef struct _typelib_InterfaceTypeDescription typelib_InterfaceTypeDescription
;
38 typedef struct _uno_Interface uno_Interface
;
49 /** C++ wrapper for C uno_Mapping.
55 uno_Mapping
* _pMapping
;
58 // these are here to force memory de/allocation to sal lib.
60 inline static void * SAL_CALL
operator new ( size_t nSize
)
61 { return ::rtl_allocateMemory( nSize
); }
62 inline static void SAL_CALL
operator delete ( void * pMem
)
63 { ::rtl_freeMemory( pMem
); }
64 inline static void * SAL_CALL
operator new ( size_t, void * pMem
)
66 inline static void SAL_CALL
operator delete ( void *, void * )
70 /** Holds a mapping from the specified source to the specified destination by environment
73 @param rFrom type name of source environment
74 @param rTo type name of destination environment
75 @param rAddPurpose additional purpose
78 const ::rtl::OUString
& rFrom
, const ::rtl::OUString
& rTo
,
79 const ::rtl::OUString
& rAddPurpose
= ::rtl::OUString() );
81 /** Holds a mapping from the specified source to the specified destination.
83 @param pFrom source environment
84 @param pTo destination environment
85 @param rAddPurpose additional purpose
88 uno_Environment
* pFrom
, uno_Environment
* pTo
,
89 const ::rtl::OUString
& rAddPurpose
= ::rtl::OUString() );
91 /** Holds a mapping from the specified source to the specified destination
94 @param rFrom source environment
95 @param rTo destination environment
96 @param rAddPurpose additional purpose
98 inline Mapping(const Environment
& rFrom
, const Environment
& rTo
,
99 const ::rtl::OUString
& rAddPurpose
= ::rtl::OUString() );
103 @param pMapping another mapping
105 inline Mapping( uno_Mapping
* pMapping
= NULL
);
107 /** Copy constructor.
109 @param rMapping another mapping
111 inline Mapping( const Mapping
& rMapping
);
117 /** Sets a given mapping.
119 @param pMapping another mapping
122 inline Mapping
& SAL_CALL
operator = ( uno_Mapping
* pMapping
);
123 /** Sets a given mapping.
125 @param rMapping another mapping
128 inline Mapping
& SAL_CALL
operator = ( const Mapping
& rMapping
)
129 { return operator = ( rMapping
._pMapping
); }
131 /** Provides a pointer to the C mapping. The returned mapping is NOT acquired!
133 @return UNacquired C mapping
135 inline uno_Mapping
* SAL_CALL
get() const
136 { return _pMapping
; }
138 /** Tests if a mapping is set.
140 @return true if a mapping is set
142 inline bool SAL_CALL
is() const
143 { return (_pMapping
!= NULL
); }
145 /** Releases a set mapping.
147 inline void SAL_CALL
clear();
149 /** Maps an interface from one environment to another.
151 @param pInterface source interface
152 @param pTypeDescr type description of interface
153 @return mapped interface
155 inline void * SAL_CALL
mapInterface( void * pInterface
, typelib_InterfaceTypeDescription
* pTypeDescr
) const;
156 /** Maps an interface from one environment to another.
158 @param pInterface source interface
159 @param pTypeDescr type description of interface
160 @return mapped interface
162 inline void * SAL_CALL
mapInterface( void * pInterface
, typelib_TypeDescription
* pTypeDescr
) const
163 { return mapInterface( pInterface
, reinterpret_cast<typelib_InterfaceTypeDescription
*>(pTypeDescr
) ); }
165 /** Maps an interface from one environment to another.
167 @param pInterface source interface
168 @param rType type of interface
169 @return mapped interface
171 inline void * SAL_CALL
mapInterface(
172 void * pInterface
, const css::uno::Type
& rType
) const;
174 /** Maps an interface from one environment to another.
176 @param ppOut inout mapped interface
177 @param pInterface source interface
178 @param pTypeDescr type description of interface
180 inline void SAL_CALL
mapInterface( void ** ppOut
, void * pInterface
, typelib_InterfaceTypeDescription
* pTypeDescr
) const
181 { (*_pMapping
->mapInterface
)( _pMapping
, ppOut
, pInterface
, pTypeDescr
); }
182 /** Maps an interface from one environment to another.
184 @param ppOut inout mapped interface
185 @param pInterface source interface
186 @param pTypeDescr type description of interface
188 inline void SAL_CALL
mapInterface( void ** ppOut
, void * pInterface
, typelib_TypeDescription
* pTypeDescr
) const
189 { (*_pMapping
->mapInterface
)( _pMapping
, ppOut
, pInterface
, reinterpret_cast<typelib_InterfaceTypeDescription
*>(pTypeDescr
) ); }
191 /** Maps an interface from one environment to another.
193 @param ppOut inout mapped interface
194 @param pInterface source interface
195 @param rType type of interface to be mapped
197 inline void SAL_CALL
mapInterface( void ** ppOut
, void * pInterface
, const css::uno::Type
& rType
) const;
200 inline Mapping::Mapping(
201 const ::rtl::OUString
& rFrom
, const ::rtl::OUString
& rTo
, const ::rtl::OUString
& rAddPurpose
)
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
)
211 uno_getMapping( &_pMapping
, pFrom
, pTo
, rAddPurpose
.pData
);
214 inline Mapping::Mapping(
215 const Environment
& rFrom
, const Environment
& rTo
, const ::rtl::OUString
& rAddPurpose
)
218 uno_getMapping( &_pMapping
, rFrom
.get(), rTo
.get(), rAddPurpose
.pData
);
221 inline Mapping::Mapping( uno_Mapping
* pMapping
)
222 : _pMapping( pMapping
)
225 (*_pMapping
->acquire
)( _pMapping
);
228 inline Mapping::Mapping( const Mapping
& rMapping
)
229 : _pMapping( rMapping
._pMapping
)
232 (*_pMapping
->acquire
)( _pMapping
);
235 inline Mapping::~Mapping()
238 (*_pMapping
->release
)( _pMapping
);
241 inline void Mapping::clear()
245 (*_pMapping
->release
)( _pMapping
);
250 inline Mapping
& Mapping::operator = ( uno_Mapping
* pMapping
)
253 (*pMapping
->acquire
)( pMapping
);
255 (*_pMapping
->release
)( _pMapping
);
256 _pMapping
= pMapping
;
260 inline void Mapping::mapInterface(
261 void ** ppOut
, void * pInterface
, const css::uno::Type
& rType
) const
263 typelib_TypeDescription
* pTD
= NULL
;
264 TYPELIB_DANGER_GET( &pTD
, rType
.getTypeLibType() );
267 (*_pMapping
->mapInterface
)( _pMapping
, ppOut
, pInterface
, reinterpret_cast<typelib_InterfaceTypeDescription
*>(pTD
) );
268 TYPELIB_DANGER_RELEASE( pTD
);
272 inline void * Mapping::mapInterface(
273 void * pInterface
, typelib_InterfaceTypeDescription
* pTypeDescr
) const
276 (*_pMapping
->mapInterface
)( _pMapping
, &pOut
, pInterface
, pTypeDescr
);
280 inline void * Mapping::mapInterface(
281 void * pInterface
, const css::uno::Type
& rType
) const
284 mapInterface( &pOut
, pInterface
, rType
);
288 /** Deprecated. This function DOES NOT WORK with Purpose Environments
289 (http://wiki.openoffice.org/wiki/Uno/Binary/Spec/Purpose Environments)
291 Maps an binary C UNO interface to be used in the currently used compiler environment.
293 @tparam C interface type
294 @param ppRet inout returned interface pointer
295 @param pUnoI binary C UNO interface
296 @return true if successful, false otherwise
301 inline bool mapToCpp( Reference
< C
> * ppRet
, uno_Interface
* pUnoI
)
304 ::rtl::OUString( UNO_LB_UNO
),
305 ::rtl::OUString( CPPU_CURRENT_LANGUAGE_BINDING_NAME
) );
306 OSL_ASSERT( aMapping
.is() );
307 aMapping
.mapInterface(
308 reinterpret_cast<void **>(ppRet
), pUnoI
, ::cppu::getTypeFavourUnsigned( ppRet
) );
309 return (0 != *ppRet
);
311 /** Deprecated. This function DOES NOT WORK with Purpose Environments
312 (http://wiki.openoffice.org/wiki/Uno/Binary/Spec/Purpose Environments)
314 Maps an UNO interface of the currently used compiler environment to binary C UNO.
316 @tparam C interface type
317 @param ppRet inout returned interface pointer
318 @param x interface reference
319 @return true if successful, false otherwise
324 inline bool mapToUno( uno_Interface
** ppRet
, const Reference
< C
> & x
)
327 ::rtl::OUString( CPPU_CURRENT_LANGUAGE_BINDING_NAME
),
328 ::rtl::OUString( UNO_LB_UNO
) );
329 OSL_ASSERT( aMapping
.is() );
330 aMapping
.mapInterface(
331 reinterpret_cast<void **>(ppRet
), x
.get(), ::cppu::getTypeFavourUnsigned( &x
) );
332 return (NULL
!= *ppRet
);
342 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */