1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: copy.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
40 //##################################################################################################
41 //#### copy construction ###########################################################################
42 //##################################################################################################
44 //------------------------------------------------------------------------------
45 inline uno_Sequence
* allocSeq(
46 sal_Int32 nElementSize
, sal_Int32 nElements
)
48 OSL_ASSERT( nElements
>= 0 && nElementSize
>= 0 );
49 uno_Sequence
* pSeq
= 0;
50 sal_uInt32 nSize
= calcSeqMemSize( nElementSize
, nElements
);
53 pSeq
= (uno_Sequence
*) rtl_allocateMemory( nSize
);
58 pSeq
->nElements
= nElements
;
64 //--------------------------------------------------------------------------------------------------
65 void copyConstructStruct(
66 void * pDest
, void * pSource
,
67 typelib_CompoundTypeDescription
* pTypeDescr
,
68 uno_AcquireFunc acquire
, uno_Mapping
* mapping
)
70 //--------------------------------------------------------------------------------------------------
71 inline void _copyConstructStruct(
72 void * pDest
, void * pSource
,
73 typelib_CompoundTypeDescription
* pTypeDescr
,
74 uno_AcquireFunc acquire
, uno_Mapping
* mapping
)
77 if (pTypeDescr
->pBaseTypeDescription
)
80 copyConstructStruct( pDest
, pSource
, pTypeDescr
->pBaseTypeDescription
, acquire
, mapping
);
84 typelib_TypeDescriptionReference
** ppTypeRefs
= pTypeDescr
->ppTypeRefs
;
85 sal_Int32
* pMemberOffsets
= pTypeDescr
->pMemberOffsets
;
86 sal_Int32 nDescr
= pTypeDescr
->nMembers
;
92 ::uno_type_copyAndConvertData(
93 (char *)pDest
+ pMemberOffsets
[nDescr
],
94 (char *)pSource
+ pMemberOffsets
[nDescr
],
95 ppTypeRefs
[nDescr
], mapping
);
103 (char *)pDest
+ pMemberOffsets
[nDescr
],
104 (char *)pSource
+ pMemberOffsets
[nDescr
],
105 ppTypeRefs
[nDescr
], acquire
);
109 //--------------------------------------------------------------------------------------------------
110 inline void _copyConstructArray(
111 void * pDest
, void * pSource
,
112 typelib_ArrayTypeDescription
* pTypeDescr
,
113 uno_AcquireFunc acquire
, uno_Mapping
* mapping
)
115 typelib_TypeDescriptionReference
* pElementTypeRef
= ((typelib_IndirectTypeDescription
*)pTypeDescr
)->pType
;
116 typelib_TypeDescription
* pElementTypeDescr
= NULL
;
117 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementTypeRef
);
118 sal_Int32 nElementSize
= ((typelib_TypeDescription
*)pElementTypeDescr
)->nSize
;
119 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
120 sal_Int32 nTotalElements
= pTypeDescr
->nTotalElements
;
124 for(sal_Int32 i
= 0; i
< nTotalElements
; i
++)
126 ::uno_type_copyAndConvertData(
127 (sal_Char
*)pDest
+ i
* nElementSize
,
128 (sal_Char
*)pSource
+ i
* nElementSize
,
129 pElementTypeRef
, mapping
);
134 for(sal_Int32 i
= 0; i
< nTotalElements
; i
++)
137 (sal_Char
*)pDest
+ (i
* nElementSize
),
138 (sal_Char
*)pSource
+ (i
* nElementSize
),
139 pElementTypeRef
, acquire
);
143 //--------------------------------------------------------------------------------------------------
144 inline void _copyConstructUnion(
145 void * pDest
, void * pSource
,
146 typelib_TypeDescription
* pTypeDescr
,
147 uno_AcquireFunc acquire
, uno_Mapping
* mapping
)
150 typelib_TypeDescriptionReference
* pSetType
= _unionGetSetType( pSource
, pTypeDescr
);
153 ::uno_type_copyAndConvertData(
154 (char *)pDest
+ ((typelib_UnionTypeDescription
*)pTypeDescr
)->nValueOffset
,
155 (char *)pSource
+ ((typelib_UnionTypeDescription
*)pTypeDescr
)->nValueOffset
,
161 (char *)pDest
+ ((typelib_UnionTypeDescription
*)pTypeDescr
)->nValueOffset
,
162 (char *)pSource
+ ((typelib_UnionTypeDescription
*)pTypeDescr
)->nValueOffset
,
165 *(sal_Int64
*)pDest
= *(sal_Int64
*)pSource
;
166 typelib_typedescriptionreference_release( pSetType
);
169 //------------------------------------------------------------------------------
170 uno_Sequence
* copyConstructSequence(
171 uno_Sequence
* pSource
,
172 typelib_TypeDescriptionReference
* pElementType
,
173 uno_AcquireFunc acquire
, uno_Mapping
* mapping
);
175 //--------------------------------------------------------------------------------------------------
176 inline void _copyConstructAnyFromData(
177 uno_Any
* pDestAny
, void * pSource
,
178 typelib_TypeDescriptionReference
* pType
, typelib_TypeDescription
* pTypeDescr
,
179 uno_AcquireFunc acquire
, uno_Mapping
* mapping
)
182 TYPE_ACQUIRE( pType
);
183 pDestAny
->pType
= pType
;
185 switch (pType
->eTypeClass
)
187 case typelib_TypeClass_CHAR
:
188 pDestAny
->pData
= &pDestAny
->pReserved
;
189 *(sal_Unicode
*)&pDestAny
->pReserved
= *(sal_Unicode
*)pSource
;
191 case typelib_TypeClass_BOOLEAN
:
192 pDestAny
->pData
= &pDestAny
->pReserved
;
193 *(sal_Bool
*)&pDestAny
->pReserved
= (*(sal_Bool
*)pSource
!= sal_False
);
195 case typelib_TypeClass_BYTE
:
196 pDestAny
->pData
= &pDestAny
->pReserved
;
197 *(sal_Int8
*)&pDestAny
->pReserved
= *(sal_Int8
*)pSource
;
199 case typelib_TypeClass_SHORT
:
200 case typelib_TypeClass_UNSIGNED_SHORT
:
201 pDestAny
->pData
= &pDestAny
->pReserved
;
202 *(sal_Int16
*)&pDestAny
->pReserved
= *(sal_Int16
*)pSource
;
204 case typelib_TypeClass_LONG
:
205 case typelib_TypeClass_UNSIGNED_LONG
:
206 pDestAny
->pData
= &pDestAny
->pReserved
;
207 *(sal_Int32
*)&pDestAny
->pReserved
= *(sal_Int32
*)pSource
;
209 case typelib_TypeClass_HYPER
:
210 case typelib_TypeClass_UNSIGNED_HYPER
:
211 if (sizeof(void *) >= sizeof(sal_Int64
))
213 pDestAny
->pData
= &pDestAny
->pReserved
;
214 *(sal_Int64
*)&pDestAny
->pReserved
= *(sal_Int64
*)pSource
;
218 pDestAny
->pData
= ::rtl_allocateMemory( sizeof(sal_Int64
) );
219 *(sal_Int64
*)pDestAny
->pData
= *(sal_Int64
*)pSource
;
222 case typelib_TypeClass_FLOAT
:
223 if (sizeof(void *) >= sizeof(float))
225 pDestAny
->pData
= &pDestAny
->pReserved
;
226 *(float *)&pDestAny
->pReserved
= *(float *)pSource
;
230 pDestAny
->pData
= ::rtl_allocateMemory( sizeof(float) );
231 *(float *)pDestAny
->pData
= *(float *)pSource
;
234 case typelib_TypeClass_DOUBLE
:
235 if (sizeof(void *) >= sizeof(double))
237 pDestAny
->pData
= &pDestAny
->pReserved
;
238 *(double *)&pDestAny
->pReserved
= *(double *)pSource
;
242 pDestAny
->pData
= ::rtl_allocateMemory( sizeof(double) );
243 *(double *)pDestAny
->pData
= *(double *)pSource
;
246 case typelib_TypeClass_STRING
:
247 ::rtl_uString_acquire( *(rtl_uString
**)pSource
);
248 pDestAny
->pData
= &pDestAny
->pReserved
;
249 *(rtl_uString
**)&pDestAny
->pReserved
= *(rtl_uString
**)pSource
;
251 case typelib_TypeClass_TYPE
:
252 TYPE_ACQUIRE( *(typelib_TypeDescriptionReference
**)pSource
);
253 pDestAny
->pData
= &pDestAny
->pReserved
;
254 *(typelib_TypeDescriptionReference
**)&pDestAny
->pReserved
= *(typelib_TypeDescriptionReference
**)pSource
;
256 case typelib_TypeClass_ANY
:
257 OSL_ENSURE( 0, "### unexpected nested any!" );
259 case typelib_TypeClass_ENUM
:
260 pDestAny
->pData
= &pDestAny
->pReserved
;
261 // enum is forced to 32bit long
262 *(sal_Int32
*)&pDestAny
->pReserved
= *(sal_Int32
*)pSource
;
264 case typelib_TypeClass_STRUCT
:
265 case typelib_TypeClass_EXCEPTION
:
268 pDestAny
->pData
= ::rtl_allocateMemory( pTypeDescr
->nSize
);
269 _copyConstructStruct(
270 pDestAny
->pData
, pSource
,
271 (typelib_CompoundTypeDescription
*)pTypeDescr
,
276 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
277 pDestAny
->pData
= ::rtl_allocateMemory( pTypeDescr
->nSize
);
278 _copyConstructStruct(
279 pDestAny
->pData
, pSource
,
280 (typelib_CompoundTypeDescription
*)pTypeDescr
,
282 TYPELIB_DANGER_RELEASE( pTypeDescr
);
285 case typelib_TypeClass_ARRAY
:
288 pDestAny
->pData
= ::rtl_allocateMemory( pTypeDescr
->nSize
);
290 pDestAny
->pData
, pSource
,
291 (typelib_ArrayTypeDescription
*)pTypeDescr
,
296 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
297 pDestAny
->pData
= ::rtl_allocateMemory( pTypeDescr
->nSize
);
299 pDestAny
->pData
, pSource
,
300 (typelib_ArrayTypeDescription
*)pTypeDescr
,
302 TYPELIB_DANGER_RELEASE( pTypeDescr
);
305 case typelib_TypeClass_UNION
:
308 pDestAny
->pData
= ::rtl_allocateMemory( pTypeDescr
->nSize
);
309 _copyConstructUnion( pDestAny
->pData
, pSource
, pTypeDescr
, acquire
, mapping
);
313 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
314 pDestAny
->pData
= ::rtl_allocateMemory( pTypeDescr
->nSize
);
315 _copyConstructUnion( pDestAny
->pData
, pSource
, pTypeDescr
, acquire
, mapping
);
316 TYPELIB_DANGER_RELEASE( pTypeDescr
);
319 case typelib_TypeClass_SEQUENCE
:
320 pDestAny
->pData
= &pDestAny
->pReserved
;
323 *(uno_Sequence
**)&pDestAny
->pReserved
= copyConstructSequence(
324 *(uno_Sequence
**)pSource
,
325 ((typelib_IndirectTypeDescription
*)pTypeDescr
)->pType
,
330 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
331 *(uno_Sequence
**)&pDestAny
->pReserved
= copyConstructSequence(
332 *(uno_Sequence
**)pSource
,
333 ((typelib_IndirectTypeDescription
*)pTypeDescr
)->pType
,
335 TYPELIB_DANGER_RELEASE( pTypeDescr
);
338 case typelib_TypeClass_INTERFACE
:
339 pDestAny
->pData
= &pDestAny
->pReserved
;
342 pDestAny
->pReserved
= _map( *(void **)pSource
, pType
, pTypeDescr
, mapping
);
346 _acquire( pDestAny
->pReserved
= *(void **)pSource
, acquire
);
354 //--------------------------------------------------------------------------------------------------
355 inline void _copyConstructAny(
356 uno_Any
* pDestAny
, void * pSource
,
357 typelib_TypeDescriptionReference
* pType
, typelib_TypeDescription
* pTypeDescr
,
358 uno_AcquireFunc acquire
, uno_Mapping
* mapping
)
361 if (typelib_TypeClass_VOID
== pType
->eTypeClass
)
363 CONSTRUCT_EMPTY_ANY( pDestAny
);
367 if (typelib_TypeClass_ANY
== pType
->eTypeClass
)
371 pType
= ((uno_Any
*)pSource
)->pType
;
372 if (typelib_TypeClass_VOID
== pType
->eTypeClass
)
374 CONSTRUCT_EMPTY_ANY( pDestAny
);
378 pSource
= ((uno_Any
*)pSource
)->pData
;
382 CONSTRUCT_EMPTY_ANY( pDestAny
);
388 _copyConstructAnyFromData( pDestAny
, pSource
, pType
, pTypeDescr
, acquire
, mapping
);
390 else // default construct
392 TYPE_ACQUIRE( pType
);
393 pDestAny
->pType
= pType
;
394 switch (pType
->eTypeClass
)
396 case typelib_TypeClass_CHAR
:
397 pDestAny
->pData
= &pDestAny
->pReserved
;
398 *(sal_Unicode
*)&pDestAny
->pReserved
= '\0';
400 case typelib_TypeClass_BOOLEAN
:
401 pDestAny
->pData
= &pDestAny
->pReserved
;
402 *(sal_Bool
*)&pDestAny
->pReserved
= sal_False
;
404 case typelib_TypeClass_BYTE
:
405 pDestAny
->pData
= &pDestAny
->pReserved
;
406 *(sal_Int8
*)&pDestAny
->pReserved
= 0;
408 case typelib_TypeClass_SHORT
:
409 case typelib_TypeClass_UNSIGNED_SHORT
:
410 pDestAny
->pData
= &pDestAny
->pReserved
;
411 *(sal_Int16
*)&pDestAny
->pReserved
= 0;
413 case typelib_TypeClass_LONG
:
414 case typelib_TypeClass_UNSIGNED_LONG
:
415 pDestAny
->pData
= &pDestAny
->pReserved
;
416 *(sal_Int32
*)&pDestAny
->pReserved
= 0;
418 case typelib_TypeClass_HYPER
:
419 case typelib_TypeClass_UNSIGNED_HYPER
:
420 if (sizeof(void *) >= sizeof(sal_Int64
))
422 pDestAny
->pData
= &pDestAny
->pReserved
;
423 *(sal_Int64
*)&pDestAny
->pReserved
= 0;
427 pDestAny
->pData
= ::rtl_allocateMemory( sizeof(sal_Int64
) );
428 *(sal_Int64
*)pDestAny
->pData
= 0;
431 case typelib_TypeClass_FLOAT
:
432 if (sizeof(void *) >= sizeof(float))
434 pDestAny
->pData
= &pDestAny
->pReserved
;
435 *(float *)&pDestAny
->pReserved
= 0.0;
439 pDestAny
->pData
= ::rtl_allocateMemory( sizeof(float) );
440 *(float *)pDestAny
->pData
= 0.0;
443 case typelib_TypeClass_DOUBLE
:
444 if (sizeof(void *) >= sizeof(double))
446 pDestAny
->pData
= &pDestAny
->pReserved
;
447 *(double *)&pDestAny
->pReserved
= 0.0;
451 pDestAny
->pData
= ::rtl_allocateMemory( sizeof(double) );
452 *(double *)pDestAny
->pData
= 0.0;
455 case typelib_TypeClass_STRING
:
456 pDestAny
->pData
= &pDestAny
->pReserved
;
457 *(rtl_uString
**)&pDestAny
->pReserved
= 0;
458 ::rtl_uString_new( (rtl_uString
**)&pDestAny
->pReserved
);
460 case typelib_TypeClass_TYPE
:
461 pDestAny
->pData
= &pDestAny
->pReserved
;
462 *(typelib_TypeDescriptionReference
**)&pDestAny
->pReserved
= _getVoidType();
464 case typelib_TypeClass_ENUM
:
465 pDestAny
->pData
= &pDestAny
->pReserved
;
468 *(sal_Int32
*)&pDestAny
->pReserved
= ((typelib_EnumTypeDescription
*)pTypeDescr
)->nDefaultEnumValue
;
472 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
473 *(sal_Int32
*)&pDestAny
->pReserved
= ((typelib_EnumTypeDescription
*)pTypeDescr
)->nDefaultEnumValue
;
474 TYPELIB_DANGER_RELEASE( pTypeDescr
);
477 case typelib_TypeClass_STRUCT
:
478 case typelib_TypeClass_EXCEPTION
:
481 pDestAny
->pData
= ::rtl_allocateMemory( pTypeDescr
->nSize
);
482 _defaultConstructStruct(
483 pDestAny
->pData
, (typelib_CompoundTypeDescription
*)pTypeDescr
);
487 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
488 pDestAny
->pData
= ::rtl_allocateMemory( pTypeDescr
->nSize
);
489 _defaultConstructStruct(
490 pDestAny
->pData
, (typelib_CompoundTypeDescription
*)pTypeDescr
);
491 TYPELIB_DANGER_RELEASE( pTypeDescr
);
494 case typelib_TypeClass_ARRAY
:
497 pDestAny
->pData
= ::rtl_allocateMemory( pTypeDescr
->nSize
);
498 _defaultConstructArray(
499 pDestAny
->pData
, (typelib_ArrayTypeDescription
*)pTypeDescr
);
503 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
504 pDestAny
->pData
= ::rtl_allocateMemory( pTypeDescr
->nSize
);
505 _defaultConstructArray(
506 pDestAny
->pData
, (typelib_ArrayTypeDescription
*)pTypeDescr
);
507 TYPELIB_DANGER_RELEASE( pTypeDescr
);
510 case typelib_TypeClass_UNION
:
513 pDestAny
->pData
= ::rtl_allocateMemory( pTypeDescr
->nSize
);
514 _defaultConstructUnion( pDestAny
->pData
, pTypeDescr
);
518 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
519 pDestAny
->pData
= ::rtl_allocateMemory( pTypeDescr
->nSize
);
520 _defaultConstructUnion( pDestAny
->pData
, pTypeDescr
);
521 TYPELIB_DANGER_RELEASE( pTypeDescr
);
524 case typelib_TypeClass_SEQUENCE
:
525 pDestAny
->pData
= &pDestAny
->pReserved
;
526 *(uno_Sequence
**)&pDestAny
->pReserved
= createEmptySequence();
528 case typelib_TypeClass_INTERFACE
:
529 pDestAny
->pData
= &pDestAny
->pReserved
;
530 pDestAny
->pReserved
= 0; // either cpp or c-uno interface
539 //------------------------------------------------------------------------------
540 inline uno_Sequence
* icopyConstructSequence(
541 uno_Sequence
* pSource
,
542 typelib_TypeDescriptionReference
* pElementType
,
543 uno_AcquireFunc acquire
, uno_Mapping
* mapping
)
545 typelib_TypeClass eTypeClass
= pElementType
->eTypeClass
;
547 (eTypeClass
<= typelib_TypeClass_ENUM
&&
548 eTypeClass
!= typelib_TypeClass_ANY
))
550 ::osl_incrementInterlockedCount( &pSource
->nRefCount
);
553 else // create new sequence
555 uno_Sequence
* pDest
;
556 sal_Int32 nElements
= pSource
->nElements
;
561 case typelib_TypeClass_ANY
:
563 pDest
= allocSeq( sizeof (uno_Any
), nElements
);
566 uno_Any
* pDestElements
= (uno_Any
*)pDest
->elements
;
567 uno_Any
* pSourceElements
= (uno_Any
*)pSource
->elements
;
568 for ( sal_Int32 nPos
= nElements
; nPos
--; )
570 typelib_TypeDescriptionReference
* pType
=
571 pSourceElements
[nPos
].pType
;
572 if (typelib_TypeClass_VOID
== pType
->eTypeClass
)
574 CONSTRUCT_EMPTY_ANY( &pDestElements
[nPos
] );
578 _copyConstructAnyFromData(
579 &pDestElements
[nPos
],
580 pSourceElements
[nPos
].pData
,
588 case typelib_TypeClass_STRUCT
:
589 case typelib_TypeClass_EXCEPTION
:
591 typelib_TypeDescription
* pElementTypeDescr
= 0;
592 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
593 sal_Int32 nElementSize
= pElementTypeDescr
->nSize
;
594 char * pSourceElements
= pSource
->elements
;
595 pDest
= allocSeq( nElementSize
, nElements
);
598 char * pElements
= pDest
->elements
;
599 for ( sal_Int32 nPos
= nElements
; nPos
--; )
601 _copyConstructStruct(
602 pElements
+ (nPos
* nElementSize
),
603 pSourceElements
+ (nPos
* nElementSize
),
604 (typelib_CompoundTypeDescription
*)
609 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
612 case typelib_TypeClass_ARRAY
:
614 typelib_TypeDescription
* pElementTypeDescr
= 0;
615 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
616 sal_Int32 nElementSize
= pElementTypeDescr
->nSize
;
617 char * pSourceElements
= pSource
->elements
;
618 pDest
= allocSeq( nElementSize
, nElements
);
621 char * pElements
= pDest
->elements
;
622 for ( sal_Int32 nPos
= nElements
; nPos
--; )
625 pElements
+ (nPos
* nElementSize
),
626 pSourceElements
+ (nPos
* nElementSize
),
627 (typelib_ArrayTypeDescription
*)pElementTypeDescr
,
631 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
634 case typelib_TypeClass_UNION
:
636 typelib_TypeDescription
* pElementTypeDescr
= 0;
637 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
638 sal_Int32 nElementSize
= pElementTypeDescr
->nSize
;
639 sal_Int32 nValueOffset
=
640 ((typelib_UnionTypeDescription
*)
641 pElementTypeDescr
)->nValueOffset
;
642 pDest
= allocSeq( nElementSize
, nElements
);
645 char * pElements
= pDest
->elements
;
646 char * pSourceElements
= pSource
->elements
;
647 for ( sal_Int32 nPos
= nElements
; nPos
--; )
650 pElements
+ (nPos
* nElementSize
);
652 pSourceElements
+ (nPos
* nElementSize
);
654 typelib_TypeDescriptionReference
* pSetType
=
655 _unionGetSetType( pSource2
, pElementTypeDescr
);
656 ::uno_type_copyAndConvertData(
657 pDest2
+ nValueOffset
, pSource2
+ nValueOffset
,
659 *(sal_Int64
*)pDest2
= *(sal_Int64
*)pSource2
;
660 ::typelib_typedescriptionreference_release( pSetType
);
663 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
666 case typelib_TypeClass_SEQUENCE
: // sequence of sequence
668 pDest
= allocSeq( sizeof (uno_Sequence
*), nElements
);
671 typelib_TypeDescription
* pElementTypeDescr
= 0;
672 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
673 typelib_TypeDescriptionReference
* pSeqElementType
=
674 ((typelib_IndirectTypeDescription
*)
675 pElementTypeDescr
)->pType
;
677 uno_Sequence
** pDestElements
=
678 (uno_Sequence
**) pDest
->elements
;
679 uno_Sequence
** pSourceElements
=
680 (uno_Sequence
**) pSource
->elements
;
681 for ( sal_Int32 nPos
= nElements
; nPos
--; )
683 uno_Sequence
* pNew
= copyConstructSequence(
684 pSourceElements
[nPos
],
687 OSL_ASSERT( pNew
!= 0 );
688 // ought never be a memory allocation problem,
689 // because of reference counted sequence handles
690 pDestElements
[ nPos
] = pNew
;
693 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
697 case typelib_TypeClass_INTERFACE
:
699 pDest
= allocSeq( sizeof (void *), nElements
);
702 char * pElements
= pDest
->elements
;
703 void ** pSourceElements
= (void **)pSource
->elements
;
706 typelib_TypeDescription
* pElementTypeDescr
= 0;
707 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
708 for ( sal_Int32 nPos
= nElements
; nPos
--; )
710 ((void **)pElements
)[nPos
] = 0;
711 if (((void **)pSourceElements
)[nPos
])
713 (*mapping
->mapInterface
)(
714 mapping
, (void **)pElements
+ nPos
,
715 pSourceElements
[nPos
],
716 (typelib_InterfaceTypeDescription
*)
720 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
724 for ( sal_Int32 nPos
= nElements
; nPos
--; )
726 ((void **)pElements
)[nPos
] = pSourceElements
[nPos
];
727 _acquire( ((void **)pElements
)[nPos
], acquire
);
734 OSL_ENSURE( 0, "### unexepcted sequence element type!" );
739 else // empty sequence
741 pDest
= allocSeq( 0, 0 );
748 //--------------------------------------------------------------------------------------------------
749 inline void _copyConstructData(
750 void * pDest
, void * pSource
,
751 typelib_TypeDescriptionReference
* pType
, typelib_TypeDescription
* pTypeDescr
,
752 uno_AcquireFunc acquire
, uno_Mapping
* mapping
)
755 switch (pType
->eTypeClass
)
757 case typelib_TypeClass_CHAR
:
758 *(sal_Unicode
*)pDest
= *(sal_Unicode
*)pSource
;
760 case typelib_TypeClass_BOOLEAN
:
761 *(sal_Bool
*)pDest
= (*(sal_Bool
*)pSource
!= sal_False
);
763 case typelib_TypeClass_BYTE
:
764 *(sal_Int8
*)pDest
= *(sal_Int8
*)pSource
;
766 case typelib_TypeClass_SHORT
:
767 case typelib_TypeClass_UNSIGNED_SHORT
:
768 *(sal_Int16
*)pDest
= *(sal_Int16
*)pSource
;
770 case typelib_TypeClass_LONG
:
771 case typelib_TypeClass_UNSIGNED_LONG
:
772 *(sal_Int32
*)pDest
= *(sal_Int32
*)pSource
;
774 case typelib_TypeClass_HYPER
:
775 case typelib_TypeClass_UNSIGNED_HYPER
:
776 *(sal_Int64
*)pDest
= *(sal_Int64
*)pSource
;
778 case typelib_TypeClass_FLOAT
:
779 *(float *)pDest
= *(float *)pSource
;
781 case typelib_TypeClass_DOUBLE
:
782 *(double *)pDest
= *(double *)pSource
;
784 case typelib_TypeClass_STRING
:
785 ::rtl_uString_acquire( *(rtl_uString
**)pSource
);
786 *(rtl_uString
**)pDest
= *(rtl_uString
**)pSource
;
788 case typelib_TypeClass_TYPE
:
789 TYPE_ACQUIRE( *(typelib_TypeDescriptionReference
**)pSource
);
790 *(typelib_TypeDescriptionReference
**)pDest
= *(typelib_TypeDescriptionReference
**)pSource
;
792 case typelib_TypeClass_ANY
:
794 (uno_Any
*)pDest
, ((uno_Any
*)pSource
)->pData
,
795 ((uno_Any
*)pSource
)->pType
, 0,
798 case typelib_TypeClass_ENUM
:
799 *(sal_Int32
*)pDest
= *(sal_Int32
*)pSource
;
801 case typelib_TypeClass_STRUCT
:
802 case typelib_TypeClass_EXCEPTION
:
805 _copyConstructStruct(
807 (typelib_CompoundTypeDescription
*)pTypeDescr
,
812 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
813 _copyConstructStruct(
815 (typelib_CompoundTypeDescription
*)pTypeDescr
,
817 TYPELIB_DANGER_RELEASE( pTypeDescr
);
820 case typelib_TypeClass_ARRAY
:
825 (typelib_ArrayTypeDescription
*)pTypeDescr
,
830 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
833 (typelib_ArrayTypeDescription
*)pTypeDescr
,
835 TYPELIB_DANGER_RELEASE( pTypeDescr
);
838 case typelib_TypeClass_UNION
:
841 _copyConstructUnion( pDest
, pSource
, pTypeDescr
, acquire
, mapping
);
845 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
846 _copyConstructUnion( pDest
, pSource
, pTypeDescr
, acquire
, mapping
);
847 TYPELIB_DANGER_RELEASE( pTypeDescr
);
850 case typelib_TypeClass_SEQUENCE
:
855 *(uno_Sequence
**)pDest
= icopyConstructSequence(
856 *(uno_Sequence
**)pSource
,
857 ((typelib_IndirectTypeDescription
*)pTypeDescr
)->pType
,
862 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
863 *(uno_Sequence
**)pDest
= icopyConstructSequence(
864 *(uno_Sequence
**)pSource
,
865 ((typelib_IndirectTypeDescription
*)pTypeDescr
)->pType
,
867 TYPELIB_DANGER_RELEASE( pTypeDescr
);
872 ::osl_incrementInterlockedCount( &(*(uno_Sequence
**)pSource
)->nRefCount
);
873 *(uno_Sequence
**)pDest
= *(uno_Sequence
**)pSource
;
876 case typelib_TypeClass_INTERFACE
:
878 *(void **)pDest
= _map( *(void **)pSource
, pType
, pTypeDescr
, mapping
);
880 _acquire( *(void **)pDest
= *(void **)pSource
, acquire
);