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 .
33 //##################################################################################################
34 //#### assignment ##################################################################################
35 //##################################################################################################
38 //--------------------------------------------------------------------------------------------------
39 inline void _assignInterface(
40 void ** ppDest
, void * pSource
,
41 uno_AcquireFunc acquire
, uno_ReleaseFunc release
)
44 _acquire( pSource
, acquire
);
45 void * const pToBeReleased
= *ppDest
;
47 _release( pToBeReleased
, release
);
49 //--------------------------------------------------------------------------------------------------
50 inline void * _queryInterface(
52 typelib_TypeDescriptionReference
* pDestType
,
53 uno_QueryInterfaceFunc queryInterface
)
58 if (0 == queryInterface
)
59 queryInterface
= binuno_queryInterface
;
60 pSource
= (*queryInterface
)( pSource
, pDestType
);
64 //==================================================================================================
65 sal_Bool
assignStruct(
66 void * pDest
, void * pSource
,
67 typelib_CompoundTypeDescription
* pTypeDescr
,
68 uno_QueryInterfaceFunc queryInterface
, uno_AcquireFunc acquire
, uno_ReleaseFunc release
)
70 //--------------------------------------------------------------------------------------------------
71 inline sal_Bool
_assignStruct(
72 void * pDest
, void * pSource
,
73 typelib_CompoundTypeDescription
* pTypeDescr
,
74 uno_QueryInterfaceFunc queryInterface
, uno_AcquireFunc acquire
, uno_ReleaseFunc release
)
77 if (pTypeDescr
->pBaseTypeDescription
)
80 if (! assignStruct( pDest
, pSource
, pTypeDescr
->pBaseTypeDescription
,
81 queryInterface
, acquire
, release
))
87 typelib_TypeDescriptionReference
** ppTypeRefs
= pTypeDescr
->ppTypeRefs
;
88 sal_Int32
* pMemberOffsets
= pTypeDescr
->pMemberOffsets
;
89 sal_Int32 nDescr
= pTypeDescr
->nMembers
;
92 if (! ::uno_type_assignData( (char *)pDest
+ pMemberOffsets
[nDescr
],
94 (char *)pSource
+ pMemberOffsets
[nDescr
],
96 queryInterface
, acquire
, release
))
103 //--------------------------------------------------------------------------------------------------
104 inline sal_Bool
_assignArray(
105 void * pDest
, void * pSource
,
106 typelib_ArrayTypeDescription
* pTypeDescr
,
107 uno_QueryInterfaceFunc queryInterface
, uno_AcquireFunc acquire
, uno_ReleaseFunc release
)
109 typelib_TypeDescriptionReference
* pElementTypeRef
=
110 ((typelib_IndirectTypeDescription
*)pTypeDescr
)->pType
;
111 typelib_TypeDescription
* pElementTypeDescr
= NULL
;
112 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementTypeRef
);
113 sal_Int32 nTotalElements
= pTypeDescr
->nTotalElements
;
114 sal_Int32 nElementSize
= pElementTypeDescr
->nSize
;
116 sal_Bool bRet
= sal_False
;
118 switch ( pElementTypeRef
->eTypeClass
)
120 case typelib_TypeClass_CHAR
:
121 case typelib_TypeClass_BOOLEAN
:
122 case typelib_TypeClass_BYTE
:
123 case typelib_TypeClass_SHORT
:
124 case typelib_TypeClass_UNSIGNED_SHORT
:
125 case typelib_TypeClass_LONG
:
126 case typelib_TypeClass_UNSIGNED_LONG
:
127 case typelib_TypeClass_HYPER
:
128 case typelib_TypeClass_UNSIGNED_HYPER
:
129 case typelib_TypeClass_FLOAT
:
130 case typelib_TypeClass_DOUBLE
:
131 for (i
=0; i
< nTotalElements
; i
++)
133 memcpy((sal_Char
*)pDest
+ i
* nElementSize
,
134 (sal_Char
*)pSource
+ i
* nElementSize
,
139 case typelib_TypeClass_STRING
:
140 for (i
=0; i
< nTotalElements
; i
++)
142 ::rtl_uString_assign( (rtl_uString
**)pDest
+ i
,
143 ((rtl_uString
**)pSource
)[i
] );
147 case typelib_TypeClass_TYPE
:
148 for (i
=0; i
< nTotalElements
; i
++)
150 typelib_TypeDescriptionReference
** pp
= (typelib_TypeDescriptionReference
**)pDest
+ i
;
151 ::typelib_typedescriptionreference_release( *pp
);
152 *pp
= *((typelib_TypeDescriptionReference
**)pSource
+ i
);
157 case typelib_TypeClass_ANY
:
158 for (i
=0; i
< nTotalElements
; i
++)
160 _destructAny( (uno_Any
*)pDest
+ i
, release
);
161 _copyConstructAny( (uno_Any
*)pDest
+ i
, (uno_Any
*)pSource
+ i
,
162 pElementTypeRef
, pElementTypeDescr
, acquire
, 0 );
166 case typelib_TypeClass_ENUM
:
167 for (i
=0; i
< nTotalElements
; i
++)
169 *((sal_Int32
*)pDest
+ i
) = *((sal_Int32
*)pSource
+ i
);
173 case typelib_TypeClass_STRUCT
:
174 case typelib_TypeClass_EXCEPTION
:
175 for (i
=0; i
< nTotalElements
; i
++)
177 bRet
= _assignStruct( (sal_Char
*)pDest
+ i
* nElementSize
,
178 (sal_Char
*)pSource
+ i
* nElementSize
,
179 (typelib_CompoundTypeDescription
*)pElementTypeDescr
,
180 queryInterface
, acquire
, release
);
186 case typelib_TypeClass_UNION
:
187 for (i
=0; i
< nTotalElements
; i
++)
189 _destructUnion( (sal_Char
*)pDest
+ i
* nElementSize
, pElementTypeDescr
, release
);
190 _copyConstructUnion( (sal_Char
*)pDest
+ i
* nElementSize
,
191 (sal_Char
*)pSource
+ i
* nElementSize
,
192 pElementTypeDescr
, acquire
, 0 );
196 case typelib_TypeClass_SEQUENCE
:
197 for (i
=0; i
< nTotalElements
; i
++)
199 osl_atomic_increment( &(*((uno_Sequence
**)pSource
+ i
))->nRefCount
);
201 *((uno_Sequence
**)pDest
+ i
),
202 pElementTypeRef
, pElementTypeDescr
, release
);
203 *((uno_Sequence
**)pDest
+ i
) = *((uno_Sequence
**)pSource
+ i
);
207 case typelib_TypeClass_INTERFACE
:
208 for (i
=0; i
< nTotalElements
; i
++)
211 (void **)((sal_Char
*)pDest
+ i
* nElementSize
),
212 *(void **)((sal_Char
*)pSource
+ i
* nElementSize
),
222 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
225 //--------------------------------------------------------------------------------------------------
226 inline sal_Bool
_assignData(
228 typelib_TypeDescriptionReference
* pDestType
, typelib_TypeDescription
* pDestTypeDescr
,
230 typelib_TypeDescriptionReference
* pSourceType
, typelib_TypeDescription
* pSourceTypeDescr
,
231 uno_QueryInterfaceFunc queryInterface
, uno_AcquireFunc acquire
, uno_ReleaseFunc release
)
234 if (pDest
== pSource
)
235 return _type_equals( pDestType
, pSourceType
);
239 _destructData( pDest
, pDestType
, pDestTypeDescr
, release
);
240 _defaultConstructData( pDest
, pDestType
, pDestTypeDescr
);
243 while (typelib_TypeClass_ANY
== pSourceType
->eTypeClass
)
245 pSourceTypeDescr
= 0;
246 pSourceType
= ((uno_Any
*)pSource
)->pType
;
247 pSource
= ((uno_Any
*)pSource
)->pData
;
248 if (pDest
== pSource
)
252 switch (pDestType
->eTypeClass
)
254 case typelib_TypeClass_VOID
:
255 return pSourceType
->eTypeClass
== typelib_TypeClass_VOID
;
256 case typelib_TypeClass_CHAR
:
257 switch (pSourceType
->eTypeClass
)
259 case typelib_TypeClass_CHAR
:
260 *(sal_Unicode
*)pDest
= *(sal_Unicode
*)pSource
;
265 case typelib_TypeClass_BOOLEAN
:
266 switch (pSourceType
->eTypeClass
)
268 case typelib_TypeClass_BOOLEAN
:
269 *(sal_Bool
*)pDest
= (*(sal_Bool
*)pSource
!= sal_False
);
274 case typelib_TypeClass_BYTE
:
275 switch (pSourceType
->eTypeClass
)
277 case typelib_TypeClass_BYTE
:
278 *(sal_Int8
*)pDest
= *(sal_Int8
*)pSource
;
283 case typelib_TypeClass_SHORT
:
284 switch (pSourceType
->eTypeClass
)
286 case typelib_TypeClass_BYTE
:
287 *(sal_Int16
*)pDest
= *(sal_Int8
*)pSource
;
289 case typelib_TypeClass_SHORT
:
290 case typelib_TypeClass_UNSIGNED_SHORT
:
291 *(sal_Int16
*)pDest
= *(sal_Int16
*)pSource
;
296 case typelib_TypeClass_UNSIGNED_SHORT
:
297 switch (pSourceType
->eTypeClass
)
299 case typelib_TypeClass_BYTE
:
300 *(sal_uInt16
*)pDest
= *(sal_Int8
*)pSource
;
302 case typelib_TypeClass_SHORT
:
303 case typelib_TypeClass_UNSIGNED_SHORT
:
304 *(sal_uInt16
*)pDest
= *(sal_uInt16
*)pSource
;
309 case typelib_TypeClass_LONG
:
310 switch (pSourceType
->eTypeClass
)
312 case typelib_TypeClass_BYTE
:
313 *(sal_Int32
*)pDest
= *(sal_Int8
*)pSource
;
315 case typelib_TypeClass_SHORT
:
316 *(sal_Int32
*)pDest
= *(sal_Int16
*)pSource
;
318 case typelib_TypeClass_UNSIGNED_SHORT
:
319 *(sal_Int32
*)pDest
= *(sal_uInt16
*)pSource
;
321 case typelib_TypeClass_LONG
:
322 case typelib_TypeClass_UNSIGNED_LONG
:
323 *(sal_Int32
*)pDest
= *(sal_Int32
*)pSource
;
328 case typelib_TypeClass_UNSIGNED_LONG
:
329 switch (pSourceType
->eTypeClass
)
331 case typelib_TypeClass_BYTE
:
332 *(sal_uInt32
*)pDest
= *(sal_Int8
*)pSource
;
334 case typelib_TypeClass_SHORT
:
335 *(sal_uInt32
*)pDest
= *(sal_Int16
*)pSource
;
337 case typelib_TypeClass_UNSIGNED_SHORT
:
338 *(sal_uInt32
*)pDest
= *(sal_uInt16
*)pSource
;
340 case typelib_TypeClass_LONG
:
341 case typelib_TypeClass_UNSIGNED_LONG
:
342 *(sal_uInt32
*)pDest
= *(sal_uInt32
*)pSource
;
347 case typelib_TypeClass_HYPER
:
348 switch (pSourceType
->eTypeClass
)
350 case typelib_TypeClass_BYTE
:
351 *(sal_Int64
*)pDest
= *(sal_Int8
*)pSource
;
353 case typelib_TypeClass_SHORT
:
354 *(sal_Int64
*)pDest
= *(sal_Int16
*)pSource
;
356 case typelib_TypeClass_UNSIGNED_SHORT
:
357 *(sal_Int64
*)pDest
= *(sal_uInt16
*)pSource
;
359 case typelib_TypeClass_LONG
:
360 *(sal_Int64
*)pDest
= *(sal_Int32
*)pSource
;
362 case typelib_TypeClass_UNSIGNED_LONG
:
363 *(sal_Int64
*)pDest
= *(sal_uInt32
*)pSource
;
365 case typelib_TypeClass_HYPER
:
366 case typelib_TypeClass_UNSIGNED_HYPER
:
367 *(sal_Int64
*)pDest
= *(sal_Int64
*)pSource
;
372 case typelib_TypeClass_UNSIGNED_HYPER
:
373 switch (pSourceType
->eTypeClass
)
375 case typelib_TypeClass_BYTE
:
376 *(sal_uInt64
*)pDest
= *(sal_Int8
*)pSource
;
378 case typelib_TypeClass_SHORT
:
379 *(sal_uInt64
*)pDest
= *(sal_Int16
*)pSource
;
381 case typelib_TypeClass_UNSIGNED_SHORT
:
382 *(sal_uInt64
*)pDest
= *(sal_uInt16
*)pSource
;
384 case typelib_TypeClass_LONG
:
385 *(sal_uInt64
*)pDest
= *(sal_Int32
*)pSource
;
387 case typelib_TypeClass_UNSIGNED_LONG
:
388 *(sal_uInt64
*)pDest
= *(sal_uInt32
*)pSource
;
390 case typelib_TypeClass_HYPER
:
391 case typelib_TypeClass_UNSIGNED_HYPER
:
392 *(sal_uInt64
*)pDest
= *(sal_uInt64
*)pSource
;
397 case typelib_TypeClass_FLOAT
:
398 switch (pSourceType
->eTypeClass
)
400 case typelib_TypeClass_BYTE
:
401 *(float *)pDest
= *(sal_Int8
*)pSource
;
403 case typelib_TypeClass_SHORT
:
404 *(float *)pDest
= *(sal_Int16
*)pSource
;
406 case typelib_TypeClass_UNSIGNED_SHORT
:
407 *(float *)pDest
= *(sal_uInt16
*)pSource
;
409 case typelib_TypeClass_FLOAT
:
410 *(float *)pDest
= *(float *)pSource
;
415 case typelib_TypeClass_DOUBLE
:
416 switch (pSourceType
->eTypeClass
)
418 case typelib_TypeClass_BYTE
:
419 *(double *)pDest
= *(sal_Int8
*)pSource
;
421 case typelib_TypeClass_SHORT
:
422 *(double *)pDest
= *(sal_Int16
*)pSource
;
424 case typelib_TypeClass_UNSIGNED_SHORT
:
425 *(double *)pDest
= *(sal_uInt16
*)pSource
;
427 case typelib_TypeClass_LONG
:
428 *(double *)pDest
= *(sal_Int32
*)pSource
;
430 case typelib_TypeClass_UNSIGNED_LONG
:
431 *(double *)pDest
= *(sal_uInt32
*)pSource
;
433 case typelib_TypeClass_FLOAT
:
434 *(double *)pDest
= *(float *)pSource
;
436 case typelib_TypeClass_DOUBLE
:
437 *(double *)pDest
= *(double *)pSource
;
442 case typelib_TypeClass_STRING
:
443 switch (pSourceType
->eTypeClass
)
445 case typelib_TypeClass_STRING
:
446 ::rtl_uString_assign( (rtl_uString
**)pDest
, *(rtl_uString
**)pSource
);
451 case typelib_TypeClass_TYPE
:
452 switch (pSourceType
->eTypeClass
)
454 case typelib_TypeClass_TYPE
:
456 typelib_TypeDescriptionReference
** pp
= (typelib_TypeDescriptionReference
**)pDest
;
457 ::typelib_typedescriptionreference_release( *pp
);
458 *pp
= *(typelib_TypeDescriptionReference
**)pSource
;
465 case typelib_TypeClass_ANY
:
466 _destructAny( (uno_Any
*)pDest
, release
);
467 _copyConstructAny( (uno_Any
*)pDest
, pSource
, pSourceType
, pSourceTypeDescr
, acquire
, 0 );
469 case typelib_TypeClass_ENUM
:
470 if (_type_equals( pDestType
, pSourceType
))
472 *(sal_Int32
*)pDest
= *(sal_Int32
*)pSource
;
476 case typelib_TypeClass_STRUCT
:
477 case typelib_TypeClass_EXCEPTION
:
478 if (typelib_TypeClass_STRUCT
== pSourceType
->eTypeClass
||
479 typelib_TypeClass_EXCEPTION
== pSourceType
->eTypeClass
)
481 sal_Bool bRet
= sal_False
;
482 if (pSourceTypeDescr
)
484 typelib_CompoundTypeDescription
* pTypeDescr
=
485 (typelib_CompoundTypeDescription
*)pSourceTypeDescr
;
488 ((typelib_TypeDescription
*)pTypeDescr
)->pWeakRef
, pDestType
))
490 pTypeDescr
= pTypeDescr
->pBaseTypeDescription
;
494 bRet
= _assignStruct(
495 pDest
, pSource
, pTypeDescr
, queryInterface
, acquire
, release
);
500 TYPELIB_DANGER_GET( &pSourceTypeDescr
, pSourceType
);
501 typelib_CompoundTypeDescription
* pTypeDescr
=
502 (typelib_CompoundTypeDescription
*)pSourceTypeDescr
;
505 ((typelib_TypeDescription
*)pTypeDescr
)->pWeakRef
, pDestType
))
507 pTypeDescr
= pTypeDescr
->pBaseTypeDescription
;
511 bRet
= _assignStruct(
512 pDest
, pSource
, pTypeDescr
, queryInterface
, acquire
, release
);
514 TYPELIB_DANGER_RELEASE( pSourceTypeDescr
);
519 case typelib_TypeClass_ARRAY
:
521 sal_Bool bRet
= sal_False
;
522 if (pSourceTypeDescr
)
524 typelib_ArrayTypeDescription
* pTypeDescr
=
525 (typelib_ArrayTypeDescription
*)pSourceTypeDescr
;
526 bRet
= _assignArray( pDest
, pSource
, pTypeDescr
, queryInterface
, acquire
, release
);
530 TYPELIB_DANGER_GET( &pSourceTypeDescr
, pSourceType
);
531 typelib_ArrayTypeDescription
* pTypeDescr
=
532 (typelib_ArrayTypeDescription
*)pSourceTypeDescr
;
536 pDest
, pSource
, pTypeDescr
, queryInterface
, acquire
, release
);
538 TYPELIB_DANGER_RELEASE( pSourceTypeDescr
);
542 case typelib_TypeClass_UNION
:
543 if (_type_equals( pDestType
, pSourceType
))
547 _destructUnion( pDest
, pDestTypeDescr
, release
);
548 _copyConstructUnion( pDest
, pSource
, pDestTypeDescr
, acquire
, 0 );
552 TYPELIB_DANGER_GET( &pDestTypeDescr
, pDestType
);
553 _destructUnion( pDest
, pDestTypeDescr
, release
);
554 _copyConstructUnion( pDest
, pSource
, pDestTypeDescr
, acquire
, 0 );
555 TYPELIB_DANGER_RELEASE( pDestTypeDescr
);
560 case typelib_TypeClass_SEQUENCE
:
561 if (typelib_TypeClass_SEQUENCE
!= pSourceType
->eTypeClass
)
564 if (*(uno_Sequence
**)pSource
== *(uno_Sequence
**)pDest
)
566 if (_type_equals( pDestType
, pSourceType
))
568 osl_atomic_increment( &(*(uno_Sequence
**)pSource
)->nRefCount
);
570 *(uno_Sequence
**)pDest
, pDestType
, pDestTypeDescr
, release
);
571 *(uno_Sequence
**)pDest
= *(uno_Sequence
**)pSource
;
575 case typelib_TypeClass_INTERFACE
:
576 if (typelib_TypeClass_INTERFACE
!= pSourceType
->eTypeClass
)
578 if (_type_equals( pDestType
, pSourceType
))
580 _assignInterface( (void **)pDest
, *(void **)pSource
, acquire
, release
);
583 else if (*static_cast< void ** >(pSource
) == 0)
585 // A null reference of any interface type can be converted to a null
586 // reference of any other interface type:
587 void * const pToBeReleased
= *static_cast< void ** >(pDest
);
588 *static_cast< void ** >(pDest
) = 0;
589 _release( pToBeReleased
, release
);
594 if (pSourceTypeDescr
)
596 typelib_TypeDescription
* pTD
= pSourceTypeDescr
;
597 while (pTD
&& !_type_equals( pTD
->pWeakRef
, pDestType
))
599 pTD
= (typelib_TypeDescription
*)
600 ((typelib_InterfaceTypeDescription
*)pTD
)->pBaseTypeDescription
;
602 if (pTD
) // is base of dest
604 _assignInterface( (void **)pDest
, *(void **)pSource
, acquire
, release
);
609 // query for interface:
610 void * pQueried
= _queryInterface( *static_cast<void **>(pSource
),
611 pDestType
, queryInterface
);
613 void * const pToBeReleased
= *static_cast<void **>(pDest
);
614 *static_cast<void **>(pDest
) = pQueried
;
615 _release( pToBeReleased
, release
);
617 return (pQueried
!= 0);
629 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */