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 .
31 //#### assignment ##################################################################################
34 inline void _assignInterface(
35 void ** ppDest
, void * pSource
,
36 uno_AcquireFunc acquire
, uno_ReleaseFunc release
)
39 _acquire( pSource
, acquire
);
40 void * const pToBeReleased
= *ppDest
;
42 _release( pToBeReleased
, release
);
45 inline void * _queryInterface(
47 typelib_TypeDescriptionReference
* pDestType
,
48 uno_QueryInterfaceFunc queryInterface
)
52 if (nullptr == queryInterface
)
53 queryInterface
= binuno_queryInterface
;
54 pSource
= (*queryInterface
)( pSource
, pDestType
);
60 void * pDest
, void * pSource
,
61 typelib_CompoundTypeDescription
* pTypeDescr
,
62 uno_QueryInterfaceFunc queryInterface
, uno_AcquireFunc acquire
, uno_ReleaseFunc release
);
64 inline bool _assignStruct(
65 void * pDest
, void * pSource
,
66 typelib_CompoundTypeDescription
* pTypeDescr
,
67 uno_QueryInterfaceFunc queryInterface
, uno_AcquireFunc acquire
, uno_ReleaseFunc release
)
69 if (pTypeDescr
->pBaseTypeDescription
)
72 if (! assignStruct( pDest
, pSource
, pTypeDescr
->pBaseTypeDescription
,
73 queryInterface
, acquire
, release
))
79 typelib_TypeDescriptionReference
** ppTypeRefs
= pTypeDescr
->ppTypeRefs
;
80 sal_Int32
* pMemberOffsets
= pTypeDescr
->pMemberOffsets
;
81 sal_Int32 nDescr
= pTypeDescr
->nMembers
;
84 if (! ::uno_type_assignData( static_cast<char *>(pDest
) + pMemberOffsets
[nDescr
],
86 static_cast<char *>(pSource
) + pMemberOffsets
[nDescr
],
88 queryInterface
, acquire
, release
))
96 inline bool _assignData(
98 typelib_TypeDescriptionReference
* pDestType
, typelib_TypeDescription
* pDestTypeDescr
,
100 typelib_TypeDescriptionReference
* pSourceType
, typelib_TypeDescription
* pSourceTypeDescr
,
101 uno_QueryInterfaceFunc queryInterface
, uno_AcquireFunc acquire
, uno_ReleaseFunc release
)
103 if (pDest
== pSource
)
104 return _type_equals( pDestType
, pSourceType
);
108 _destructData( pDest
, pDestType
, pDestTypeDescr
, release
);
109 _defaultConstructData( pDest
, pDestType
, pDestTypeDescr
);
112 while (typelib_TypeClass_ANY
== pSourceType
->eTypeClass
)
114 pSourceTypeDescr
= nullptr;
115 pSourceType
= static_cast<uno_Any
*>(pSource
)->pType
;
116 pSource
= static_cast<uno_Any
*>(pSource
)->pData
;
117 if (pDest
== pSource
)
121 switch (pDestType
->eTypeClass
)
123 case typelib_TypeClass_VOID
:
124 return pSourceType
->eTypeClass
== typelib_TypeClass_VOID
;
125 case typelib_TypeClass_CHAR
:
126 switch (pSourceType
->eTypeClass
)
128 case typelib_TypeClass_CHAR
:
129 *static_cast<sal_Unicode
*>(pDest
) = *static_cast<sal_Unicode
*>(pSource
);
134 case typelib_TypeClass_BOOLEAN
:
135 switch (pSourceType
->eTypeClass
)
137 case typelib_TypeClass_BOOLEAN
:
138 *static_cast<sal_Bool
*>(pDest
) = bool(*static_cast<sal_Bool
*>(pSource
));
143 case typelib_TypeClass_BYTE
:
144 switch (pSourceType
->eTypeClass
)
146 case typelib_TypeClass_BYTE
:
147 *static_cast<sal_Int8
*>(pDest
) = *static_cast<sal_Int8
*>(pSource
);
152 case typelib_TypeClass_SHORT
:
153 switch (pSourceType
->eTypeClass
)
155 case typelib_TypeClass_BYTE
:
156 *static_cast<sal_Int16
*>(pDest
) = *static_cast<sal_Int8
*>(pSource
);
158 case typelib_TypeClass_SHORT
:
159 case typelib_TypeClass_UNSIGNED_SHORT
:
160 *static_cast<sal_Int16
*>(pDest
) = *static_cast<sal_Int16
*>(pSource
);
165 case typelib_TypeClass_UNSIGNED_SHORT
:
166 switch (pSourceType
->eTypeClass
)
168 case typelib_TypeClass_BYTE
:
169 *static_cast<sal_uInt16
*>(pDest
) = *static_cast<sal_Int8
*>(pSource
);
171 case typelib_TypeClass_SHORT
:
172 case typelib_TypeClass_UNSIGNED_SHORT
:
173 *static_cast<sal_uInt16
*>(pDest
) = *static_cast<sal_uInt16
*>(pSource
);
178 case typelib_TypeClass_LONG
:
179 switch (pSourceType
->eTypeClass
)
181 case typelib_TypeClass_BYTE
:
182 *static_cast<sal_Int32
*>(pDest
) = *static_cast<sal_Int8
*>(pSource
);
184 case typelib_TypeClass_SHORT
:
185 *static_cast<sal_Int32
*>(pDest
) = *static_cast<sal_Int16
*>(pSource
);
187 case typelib_TypeClass_UNSIGNED_SHORT
:
188 *static_cast<sal_Int32
*>(pDest
) = *static_cast<sal_uInt16
*>(pSource
);
190 case typelib_TypeClass_LONG
:
191 case typelib_TypeClass_UNSIGNED_LONG
:
192 *static_cast<sal_Int32
*>(pDest
) = *static_cast<sal_Int32
*>(pSource
);
197 case typelib_TypeClass_UNSIGNED_LONG
:
198 switch (pSourceType
->eTypeClass
)
200 case typelib_TypeClass_BYTE
:
201 *static_cast<sal_uInt32
*>(pDest
) = *static_cast<sal_Int8
*>(pSource
);
203 case typelib_TypeClass_SHORT
:
204 *static_cast<sal_uInt32
*>(pDest
) = *static_cast<sal_Int16
*>(pSource
);
206 case typelib_TypeClass_UNSIGNED_SHORT
:
207 *static_cast<sal_uInt32
*>(pDest
) = *static_cast<sal_uInt16
*>(pSource
);
209 case typelib_TypeClass_LONG
:
210 case typelib_TypeClass_UNSIGNED_LONG
:
211 *static_cast<sal_uInt32
*>(pDest
) = *static_cast<sal_uInt32
*>(pSource
);
216 case typelib_TypeClass_HYPER
:
217 switch (pSourceType
->eTypeClass
)
219 case typelib_TypeClass_BYTE
:
220 *static_cast<sal_Int64
*>(pDest
) = *static_cast<sal_Int8
*>(pSource
);
222 case typelib_TypeClass_SHORT
:
223 *static_cast<sal_Int64
*>(pDest
) = *static_cast<sal_Int16
*>(pSource
);
225 case typelib_TypeClass_UNSIGNED_SHORT
:
226 *static_cast<sal_Int64
*>(pDest
) = *static_cast<sal_uInt16
*>(pSource
);
228 case typelib_TypeClass_LONG
:
229 *static_cast<sal_Int64
*>(pDest
) = *static_cast<sal_Int32
*>(pSource
);
231 case typelib_TypeClass_UNSIGNED_LONG
:
232 *static_cast<sal_Int64
*>(pDest
) = *static_cast<sal_uInt32
*>(pSource
);
234 case typelib_TypeClass_HYPER
:
235 case typelib_TypeClass_UNSIGNED_HYPER
:
236 *static_cast<sal_Int64
*>(pDest
) = *static_cast<sal_Int64
*>(pSource
);
241 case typelib_TypeClass_UNSIGNED_HYPER
:
242 switch (pSourceType
->eTypeClass
)
244 case typelib_TypeClass_BYTE
:
245 *static_cast<sal_uInt64
*>(pDest
) = *static_cast<sal_Int8
*>(pSource
);
247 case typelib_TypeClass_SHORT
:
248 *static_cast<sal_uInt64
*>(pDest
) = *static_cast<sal_Int16
*>(pSource
);
250 case typelib_TypeClass_UNSIGNED_SHORT
:
251 *static_cast<sal_uInt64
*>(pDest
) = *static_cast<sal_uInt16
*>(pSource
);
253 case typelib_TypeClass_LONG
:
254 *static_cast<sal_uInt64
*>(pDest
) = *static_cast<sal_Int32
*>(pSource
);
256 case typelib_TypeClass_UNSIGNED_LONG
:
257 *static_cast<sal_uInt64
*>(pDest
) = *static_cast<sal_uInt32
*>(pSource
);
259 case typelib_TypeClass_HYPER
:
260 case typelib_TypeClass_UNSIGNED_HYPER
:
261 *static_cast<sal_uInt64
*>(pDest
) = *static_cast<sal_uInt64
*>(pSource
);
266 case typelib_TypeClass_FLOAT
:
267 switch (pSourceType
->eTypeClass
)
269 case typelib_TypeClass_BYTE
:
270 *static_cast<float *>(pDest
) = *static_cast<sal_Int8
*>(pSource
);
272 case typelib_TypeClass_SHORT
:
273 *static_cast<float *>(pDest
) = *static_cast<sal_Int16
*>(pSource
);
275 case typelib_TypeClass_UNSIGNED_SHORT
:
276 *static_cast<float *>(pDest
) = *static_cast<sal_uInt16
*>(pSource
);
278 case typelib_TypeClass_FLOAT
:
279 *static_cast<float *>(pDest
) = *static_cast<float *>(pSource
);
284 case typelib_TypeClass_DOUBLE
:
285 switch (pSourceType
->eTypeClass
)
287 case typelib_TypeClass_BYTE
:
288 *static_cast<double *>(pDest
) = *static_cast<sal_Int8
*>(pSource
);
290 case typelib_TypeClass_SHORT
:
291 *static_cast<double *>(pDest
) = *static_cast<sal_Int16
*>(pSource
);
293 case typelib_TypeClass_UNSIGNED_SHORT
:
294 *static_cast<double *>(pDest
) = *static_cast<sal_uInt16
*>(pSource
);
296 case typelib_TypeClass_LONG
:
297 *static_cast<double *>(pDest
) = *static_cast<sal_Int32
*>(pSource
);
299 case typelib_TypeClass_UNSIGNED_LONG
:
300 *static_cast<double *>(pDest
) = *static_cast<sal_uInt32
*>(pSource
);
302 case typelib_TypeClass_FLOAT
:
303 *static_cast<double *>(pDest
) = *static_cast<float *>(pSource
);
305 case typelib_TypeClass_DOUBLE
:
306 *static_cast<double *>(pDest
) = *static_cast<double *>(pSource
);
311 case typelib_TypeClass_STRING
:
312 switch (pSourceType
->eTypeClass
)
314 case typelib_TypeClass_STRING
:
315 ::rtl_uString_assign( static_cast<rtl_uString
**>(pDest
), *static_cast<rtl_uString
**>(pSource
) );
320 case typelib_TypeClass_TYPE
:
321 switch (pSourceType
->eTypeClass
)
323 case typelib_TypeClass_TYPE
:
325 typelib_TypeDescriptionReference
** pp
= static_cast<typelib_TypeDescriptionReference
**>(pDest
);
326 ::typelib_typedescriptionreference_release( *pp
);
327 *pp
= *static_cast<typelib_TypeDescriptionReference
**>(pSource
);
334 case typelib_TypeClass_ANY
:
335 _destructAny( static_cast<uno_Any
*>(pDest
), release
);
336 _copyConstructAny( static_cast<uno_Any
*>(pDest
), pSource
, pSourceType
, pSourceTypeDescr
, acquire
, nullptr );
338 case typelib_TypeClass_ENUM
:
339 if (_type_equals( pDestType
, pSourceType
))
341 *static_cast<sal_Int32
*>(pDest
) = *static_cast<sal_Int32
*>(pSource
);
345 case typelib_TypeClass_STRUCT
:
346 case typelib_TypeClass_EXCEPTION
:
347 if (typelib_TypeClass_STRUCT
== pSourceType
->eTypeClass
||
348 typelib_TypeClass_EXCEPTION
== pSourceType
->eTypeClass
)
351 if (pSourceTypeDescr
)
353 typelib_CompoundTypeDescription
* pTypeDescr
=
354 reinterpret_cast<typelib_CompoundTypeDescription
*>(pSourceTypeDescr
);
356 !_type_equals(pTypeDescr
->aBase
.pWeakRef
, pDestType
))
358 pTypeDescr
= pTypeDescr
->pBaseTypeDescription
;
362 bRet
= _assignStruct(
363 pDest
, pSource
, pTypeDescr
, queryInterface
, acquire
, release
);
368 TYPELIB_DANGER_GET( &pSourceTypeDescr
, pSourceType
);
369 typelib_CompoundTypeDescription
* pTypeDescr
=
370 reinterpret_cast<typelib_CompoundTypeDescription
*>(pSourceTypeDescr
);
372 !_type_equals(pTypeDescr
->aBase
.pWeakRef
, pDestType
))
374 pTypeDescr
= pTypeDescr
->pBaseTypeDescription
;
378 bRet
= _assignStruct(
379 pDest
, pSource
, pTypeDescr
, queryInterface
, acquire
, release
);
381 TYPELIB_DANGER_RELEASE( pSourceTypeDescr
);
386 case typelib_TypeClass_SEQUENCE
:
387 if (!_type_equals( pDestType
, pSourceType
))
389 // check self assignment (only after _type_equals, to account for shared static empty):
390 if (*static_cast<uno_Sequence
**>(pSource
) != *static_cast<uno_Sequence
**>(pDest
))
392 osl_atomic_increment( &(*static_cast<uno_Sequence
**>(pSource
))->nRefCount
);
394 *static_cast<uno_Sequence
**>(pDest
), pDestType
, pDestTypeDescr
, release
);
395 *static_cast<uno_Sequence
**>(pDest
) = *static_cast<uno_Sequence
**>(pSource
);
398 case typelib_TypeClass_INTERFACE
:
399 if (typelib_TypeClass_INTERFACE
!= pSourceType
->eTypeClass
)
401 if (_type_equals( pDestType
, pSourceType
))
403 _assignInterface( static_cast<void **>(pDest
), *static_cast<void **>(pSource
), acquire
, release
);
406 else if (*static_cast< void ** >(pSource
) == nullptr)
408 // A null reference of any interface type can be converted to a null
409 // reference of any other interface type:
410 void * const pToBeReleased
= *static_cast< void ** >(pDest
);
411 *static_cast< void ** >(pDest
) = nullptr;
412 _release( pToBeReleased
, release
);
417 if (pSourceTypeDescr
)
419 typelib_TypeDescription
* pTD
= pSourceTypeDescr
;
420 while (pTD
&& !_type_equals( pTD
->pWeakRef
, pDestType
))
422 pTD
= &reinterpret_cast<typelib_InterfaceTypeDescription
*>(pTD
)->pBaseTypeDescription
->aBase
;
424 if (pTD
) // is base of dest
426 _assignInterface( static_cast<void **>(pDest
), *static_cast<void **>(pSource
), acquire
, release
);
431 // query for interface:
432 void * pQueried
= _queryInterface( *static_cast<void **>(pSource
),
433 pDestType
, queryInterface
);
434 if (pQueried
!= nullptr) {
435 void * const pToBeReleased
= *static_cast<void **>(pDest
);
436 *static_cast<void **>(pDest
) = pQueried
;
437 _release( pToBeReleased
, release
);
439 return (pQueried
!= nullptr);
449 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */