update dev300-m58
[ooovba.git] / cppu / source / uno / copy.hxx
blob26e5e8a0cef958624e48e2c7e704818e78f291cd
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: copy.hxx,v $
10 * $Revision: 1.15 $
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 ************************************************************************/
30 #ifndef COPY_HXX
31 #define COPY_HXX
33 #include "prim.hxx"
34 #include "constr.hxx"
37 namespace cppu
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 );
51 if (nSize > 0)
53 pSeq = (uno_Sequence *) rtl_allocateMemory( nSize );
54 if (pSeq != 0)
56 // header init
57 pSeq->nRefCount = 1;
58 pSeq->nElements = nElements;
61 return pSeq;
64 //--------------------------------------------------------------------------------------------------
65 void copyConstructStruct(
66 void * pDest, void * pSource,
67 typelib_CompoundTypeDescription * pTypeDescr,
68 uno_AcquireFunc acquire, uno_Mapping * mapping )
69 SAL_THROW ( () );
70 //--------------------------------------------------------------------------------------------------
71 inline void _copyConstructStruct(
72 void * pDest, void * pSource,
73 typelib_CompoundTypeDescription * pTypeDescr,
74 uno_AcquireFunc acquire, uno_Mapping * mapping )
75 SAL_THROW ( () )
77 if (pTypeDescr->pBaseTypeDescription)
79 // copy base value
80 copyConstructStruct( pDest, pSource, pTypeDescr->pBaseTypeDescription, acquire, mapping );
83 // then copy members
84 typelib_TypeDescriptionReference ** ppTypeRefs = pTypeDescr->ppTypeRefs;
85 sal_Int32 * pMemberOffsets = pTypeDescr->pMemberOffsets;
86 sal_Int32 nDescr = pTypeDescr->nMembers;
88 if (mapping)
90 while (nDescr--)
92 ::uno_type_copyAndConvertData(
93 (char *)pDest + pMemberOffsets[nDescr],
94 (char *)pSource + pMemberOffsets[nDescr],
95 ppTypeRefs[nDescr], mapping );
98 else
100 while (nDescr--)
102 ::uno_type_copyData(
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;
122 if (mapping)
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 );
132 else
134 for(sal_Int32 i = 0; i < nTotalElements; i++)
136 ::uno_type_copyData(
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 )
148 SAL_THROW ( () )
150 typelib_TypeDescriptionReference * pSetType = _unionGetSetType( pSource, pTypeDescr );
151 if (mapping)
153 ::uno_type_copyAndConvertData(
154 (char *)pDest + ((typelib_UnionTypeDescription *)pTypeDescr)->nValueOffset,
155 (char *)pSource + ((typelib_UnionTypeDescription *)pTypeDescr)->nValueOffset,
156 pSetType, mapping );
158 else
160 ::uno_type_copyData(
161 (char *)pDest + ((typelib_UnionTypeDescription *)pTypeDescr)->nValueOffset,
162 (char *)pSource + ((typelib_UnionTypeDescription *)pTypeDescr)->nValueOffset,
163 pSetType, acquire );
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 )
180 SAL_THROW ( () )
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;
190 break;
191 case typelib_TypeClass_BOOLEAN:
192 pDestAny->pData = &pDestAny->pReserved;
193 *(sal_Bool *)&pDestAny->pReserved = (*(sal_Bool *)pSource != sal_False);
194 break;
195 case typelib_TypeClass_BYTE:
196 pDestAny->pData = &pDestAny->pReserved;
197 *(sal_Int8 *)&pDestAny->pReserved = *(sal_Int8 *)pSource;
198 break;
199 case typelib_TypeClass_SHORT:
200 case typelib_TypeClass_UNSIGNED_SHORT:
201 pDestAny->pData = &pDestAny->pReserved;
202 *(sal_Int16 *)&pDestAny->pReserved = *(sal_Int16 *)pSource;
203 break;
204 case typelib_TypeClass_LONG:
205 case typelib_TypeClass_UNSIGNED_LONG:
206 pDestAny->pData = &pDestAny->pReserved;
207 *(sal_Int32 *)&pDestAny->pReserved = *(sal_Int32 *)pSource;
208 break;
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;
216 else
218 pDestAny->pData = ::rtl_allocateMemory( sizeof(sal_Int64) );
219 *(sal_Int64 *)pDestAny->pData = *(sal_Int64 *)pSource;
221 break;
222 case typelib_TypeClass_FLOAT:
223 if (sizeof(void *) >= sizeof(float))
225 pDestAny->pData = &pDestAny->pReserved;
226 *(float *)&pDestAny->pReserved = *(float *)pSource;
228 else
230 pDestAny->pData = ::rtl_allocateMemory( sizeof(float) );
231 *(float *)pDestAny->pData = *(float *)pSource;
233 break;
234 case typelib_TypeClass_DOUBLE:
235 if (sizeof(void *) >= sizeof(double))
237 pDestAny->pData = &pDestAny->pReserved;
238 *(double *)&pDestAny->pReserved = *(double *)pSource;
240 else
242 pDestAny->pData = ::rtl_allocateMemory( sizeof(double) );
243 *(double *)pDestAny->pData = *(double *)pSource;
245 break;
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;
250 break;
251 case typelib_TypeClass_TYPE:
252 TYPE_ACQUIRE( *(typelib_TypeDescriptionReference **)pSource );
253 pDestAny->pData = &pDestAny->pReserved;
254 *(typelib_TypeDescriptionReference **)&pDestAny->pReserved = *(typelib_TypeDescriptionReference **)pSource;
255 break;
256 case typelib_TypeClass_ANY:
257 OSL_ENSURE( 0, "### unexpected nested any!" );
258 break;
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;
263 break;
264 case typelib_TypeClass_STRUCT:
265 case typelib_TypeClass_EXCEPTION:
266 if (pTypeDescr)
268 pDestAny->pData = ::rtl_allocateMemory( pTypeDescr->nSize );
269 _copyConstructStruct(
270 pDestAny->pData, pSource,
271 (typelib_CompoundTypeDescription *)pTypeDescr,
272 acquire, mapping );
274 else
276 TYPELIB_DANGER_GET( &pTypeDescr, pType );
277 pDestAny->pData = ::rtl_allocateMemory( pTypeDescr->nSize );
278 _copyConstructStruct(
279 pDestAny->pData, pSource,
280 (typelib_CompoundTypeDescription *)pTypeDescr,
281 acquire, mapping );
282 TYPELIB_DANGER_RELEASE( pTypeDescr );
284 break;
285 case typelib_TypeClass_ARRAY:
286 if (pTypeDescr)
288 pDestAny->pData = ::rtl_allocateMemory( pTypeDescr->nSize );
289 _copyConstructArray(
290 pDestAny->pData, pSource,
291 (typelib_ArrayTypeDescription *)pTypeDescr,
292 acquire, mapping );
294 else
296 TYPELIB_DANGER_GET( &pTypeDescr, pType );
297 pDestAny->pData = ::rtl_allocateMemory( pTypeDescr->nSize );
298 _copyConstructArray(
299 pDestAny->pData, pSource,
300 (typelib_ArrayTypeDescription *)pTypeDescr,
301 acquire, mapping );
302 TYPELIB_DANGER_RELEASE( pTypeDescr );
304 break;
305 case typelib_TypeClass_UNION:
306 if (pTypeDescr)
308 pDestAny->pData = ::rtl_allocateMemory( pTypeDescr->nSize );
309 _copyConstructUnion( pDestAny->pData, pSource, pTypeDescr, acquire, mapping );
311 else
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 );
318 break;
319 case typelib_TypeClass_SEQUENCE:
320 pDestAny->pData = &pDestAny->pReserved;
321 if (pTypeDescr)
323 *(uno_Sequence **)&pDestAny->pReserved = copyConstructSequence(
324 *(uno_Sequence **)pSource,
325 ((typelib_IndirectTypeDescription *)pTypeDescr)->pType,
326 acquire, mapping );
328 else
330 TYPELIB_DANGER_GET( &pTypeDescr, pType );
331 *(uno_Sequence **)&pDestAny->pReserved = copyConstructSequence(
332 *(uno_Sequence **)pSource,
333 ((typelib_IndirectTypeDescription *)pTypeDescr)->pType,
334 acquire, mapping );
335 TYPELIB_DANGER_RELEASE( pTypeDescr );
337 break;
338 case typelib_TypeClass_INTERFACE:
339 pDestAny->pData = &pDestAny->pReserved;
340 if (mapping)
342 pDestAny->pReserved = _map( *(void **)pSource, pType, pTypeDescr, mapping );
344 else
346 _acquire( pDestAny->pReserved = *(void **)pSource, acquire );
348 break;
349 default:
350 OSL_ASSERT(false);
351 break;
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 )
359 SAL_THROW ( () )
361 if (typelib_TypeClass_VOID == pType->eTypeClass)
363 CONSTRUCT_EMPTY_ANY( pDestAny );
365 else
367 if (typelib_TypeClass_ANY == pType->eTypeClass)
369 if (pSource)
371 pType = ((uno_Any *)pSource)->pType;
372 if (typelib_TypeClass_VOID == pType->eTypeClass)
374 CONSTRUCT_EMPTY_ANY( pDestAny );
375 return;
377 pTypeDescr = 0;
378 pSource = ((uno_Any *)pSource)->pData;
380 else
382 CONSTRUCT_EMPTY_ANY( pDestAny );
383 return;
386 if (pSource)
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';
399 break;
400 case typelib_TypeClass_BOOLEAN:
401 pDestAny->pData = &pDestAny->pReserved;
402 *(sal_Bool *)&pDestAny->pReserved = sal_False;
403 break;
404 case typelib_TypeClass_BYTE:
405 pDestAny->pData = &pDestAny->pReserved;
406 *(sal_Int8 *)&pDestAny->pReserved = 0;
407 break;
408 case typelib_TypeClass_SHORT:
409 case typelib_TypeClass_UNSIGNED_SHORT:
410 pDestAny->pData = &pDestAny->pReserved;
411 *(sal_Int16 *)&pDestAny->pReserved = 0;
412 break;
413 case typelib_TypeClass_LONG:
414 case typelib_TypeClass_UNSIGNED_LONG:
415 pDestAny->pData = &pDestAny->pReserved;
416 *(sal_Int32 *)&pDestAny->pReserved = 0;
417 break;
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;
425 else
427 pDestAny->pData = ::rtl_allocateMemory( sizeof(sal_Int64) );
428 *(sal_Int64 *)pDestAny->pData = 0;
430 break;
431 case typelib_TypeClass_FLOAT:
432 if (sizeof(void *) >= sizeof(float))
434 pDestAny->pData = &pDestAny->pReserved;
435 *(float *)&pDestAny->pReserved = 0.0;
437 else
439 pDestAny->pData = ::rtl_allocateMemory( sizeof(float) );
440 *(float *)pDestAny->pData = 0.0;
442 break;
443 case typelib_TypeClass_DOUBLE:
444 if (sizeof(void *) >= sizeof(double))
446 pDestAny->pData = &pDestAny->pReserved;
447 *(double *)&pDestAny->pReserved = 0.0;
449 else
451 pDestAny->pData = ::rtl_allocateMemory( sizeof(double) );
452 *(double *)pDestAny->pData = 0.0;
454 break;
455 case typelib_TypeClass_STRING:
456 pDestAny->pData = &pDestAny->pReserved;
457 *(rtl_uString **)&pDestAny->pReserved = 0;
458 ::rtl_uString_new( (rtl_uString **)&pDestAny->pReserved );
459 break;
460 case typelib_TypeClass_TYPE:
461 pDestAny->pData = &pDestAny->pReserved;
462 *(typelib_TypeDescriptionReference **)&pDestAny->pReserved = _getVoidType();
463 break;
464 case typelib_TypeClass_ENUM:
465 pDestAny->pData = &pDestAny->pReserved;
466 if (pTypeDescr)
468 *(sal_Int32 *)&pDestAny->pReserved = ((typelib_EnumTypeDescription *)pTypeDescr)->nDefaultEnumValue;
470 else
472 TYPELIB_DANGER_GET( &pTypeDescr, pType );
473 *(sal_Int32 *)&pDestAny->pReserved = ((typelib_EnumTypeDescription *)pTypeDescr)->nDefaultEnumValue;
474 TYPELIB_DANGER_RELEASE( pTypeDescr );
476 break;
477 case typelib_TypeClass_STRUCT:
478 case typelib_TypeClass_EXCEPTION:
479 if (pTypeDescr)
481 pDestAny->pData = ::rtl_allocateMemory( pTypeDescr->nSize );
482 _defaultConstructStruct(
483 pDestAny->pData, (typelib_CompoundTypeDescription *)pTypeDescr );
485 else
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 );
493 break;
494 case typelib_TypeClass_ARRAY:
495 if (pTypeDescr)
497 pDestAny->pData = ::rtl_allocateMemory( pTypeDescr->nSize );
498 _defaultConstructArray(
499 pDestAny->pData, (typelib_ArrayTypeDescription *)pTypeDescr );
501 else
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 );
509 break;
510 case typelib_TypeClass_UNION:
511 if (pTypeDescr)
513 pDestAny->pData = ::rtl_allocateMemory( pTypeDescr->nSize );
514 _defaultConstructUnion( pDestAny->pData, pTypeDescr );
516 else
518 TYPELIB_DANGER_GET( &pTypeDescr, pType );
519 pDestAny->pData = ::rtl_allocateMemory( pTypeDescr->nSize );
520 _defaultConstructUnion( pDestAny->pData, pTypeDescr );
521 TYPELIB_DANGER_RELEASE( pTypeDescr );
523 break;
524 case typelib_TypeClass_SEQUENCE:
525 pDestAny->pData = &pDestAny->pReserved;
526 *(uno_Sequence **)&pDestAny->pReserved = createEmptySequence();
527 break;
528 case typelib_TypeClass_INTERFACE:
529 pDestAny->pData = &pDestAny->pReserved;
530 pDestAny->pReserved = 0; // either cpp or c-uno interface
531 break;
532 default:
533 OSL_ASSERT(false);
534 break;
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;
546 if (!mapping ||
547 (eTypeClass <= typelib_TypeClass_ENUM &&
548 eTypeClass != typelib_TypeClass_ANY))
550 ::osl_incrementInterlockedCount( &pSource->nRefCount );
551 return pSource;
553 else // create new sequence
555 uno_Sequence * pDest;
556 sal_Int32 nElements = pSource->nElements;
557 if (nElements)
559 switch (eTypeClass)
561 case typelib_TypeClass_ANY:
563 pDest = allocSeq( sizeof (uno_Any), nElements );
564 if (pDest != 0)
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] );
576 else
578 _copyConstructAnyFromData(
579 &pDestElements[nPos],
580 pSourceElements[nPos].pData,
581 pType, 0,
582 acquire, mapping );
586 break;
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 );
596 if (pDest != 0)
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 *)
605 pElementTypeDescr,
606 acquire, mapping );
609 TYPELIB_DANGER_RELEASE( pElementTypeDescr );
610 break;
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 );
619 if (pDest != 0)
621 char * pElements = pDest->elements;
622 for ( sal_Int32 nPos = nElements; nPos--; )
624 _copyConstructArray(
625 pElements + (nPos * nElementSize),
626 pSourceElements + (nPos * nElementSize),
627 (typelib_ArrayTypeDescription *)pElementTypeDescr,
628 acquire, mapping );
631 TYPELIB_DANGER_RELEASE( pElementTypeDescr );
632 break;
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 );
643 if (pDest != 0)
645 char * pElements = pDest->elements;
646 char * pSourceElements = pSource->elements;
647 for ( sal_Int32 nPos = nElements; nPos--; )
649 char * pDest2 =
650 pElements + (nPos * nElementSize);
651 char * pSource2 =
652 pSourceElements + (nPos * nElementSize);
654 typelib_TypeDescriptionReference * pSetType =
655 _unionGetSetType( pSource2, pElementTypeDescr );
656 ::uno_type_copyAndConvertData(
657 pDest2 + nValueOffset, pSource2 + nValueOffset,
658 pSetType, mapping );
659 *(sal_Int64 *)pDest2 = *(sal_Int64 *)pSource2;
660 ::typelib_typedescriptionreference_release( pSetType );
663 TYPELIB_DANGER_RELEASE( pElementTypeDescr );
664 break;
666 case typelib_TypeClass_SEQUENCE: // sequence of sequence
668 pDest = allocSeq( sizeof (uno_Sequence *), nElements );
669 if (pDest != 0)
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],
685 pSeqElementType,
686 acquire, mapping );
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 );
695 break;
697 case typelib_TypeClass_INTERFACE:
699 pDest = allocSeq( sizeof (void *), nElements );
700 if (pDest != 0)
702 char * pElements = pDest->elements;
703 void ** pSourceElements = (void **)pSource->elements;
704 if (mapping)
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 *)
717 pElementTypeDescr );
720 TYPELIB_DANGER_RELEASE( pElementTypeDescr );
722 else
724 for ( sal_Int32 nPos = nElements; nPos--; )
726 ((void **)pElements)[nPos] = pSourceElements[nPos];
727 _acquire( ((void **)pElements)[nPos], acquire );
731 break;
733 default:
734 OSL_ENSURE( 0, "### unexepcted sequence element type!" );
735 pDest = 0;
736 break;
739 else // empty sequence
741 pDest = allocSeq( 0, 0 );
744 return pDest;
748 //--------------------------------------------------------------------------------------------------
749 inline void _copyConstructData(
750 void * pDest, void * pSource,
751 typelib_TypeDescriptionReference * pType, typelib_TypeDescription * pTypeDescr,
752 uno_AcquireFunc acquire, uno_Mapping * mapping )
753 SAL_THROW ( () )
755 switch (pType->eTypeClass)
757 case typelib_TypeClass_CHAR:
758 *(sal_Unicode *)pDest = *(sal_Unicode *)pSource;
759 break;
760 case typelib_TypeClass_BOOLEAN:
761 *(sal_Bool *)pDest = (*(sal_Bool *)pSource != sal_False);
762 break;
763 case typelib_TypeClass_BYTE:
764 *(sal_Int8 *)pDest = *(sal_Int8 *)pSource;
765 break;
766 case typelib_TypeClass_SHORT:
767 case typelib_TypeClass_UNSIGNED_SHORT:
768 *(sal_Int16 *)pDest = *(sal_Int16 *)pSource;
769 break;
770 case typelib_TypeClass_LONG:
771 case typelib_TypeClass_UNSIGNED_LONG:
772 *(sal_Int32 *)pDest = *(sal_Int32 *)pSource;
773 break;
774 case typelib_TypeClass_HYPER:
775 case typelib_TypeClass_UNSIGNED_HYPER:
776 *(sal_Int64 *)pDest = *(sal_Int64 *)pSource;
777 break;
778 case typelib_TypeClass_FLOAT:
779 *(float *)pDest = *(float *)pSource;
780 break;
781 case typelib_TypeClass_DOUBLE:
782 *(double *)pDest = *(double *)pSource;
783 break;
784 case typelib_TypeClass_STRING:
785 ::rtl_uString_acquire( *(rtl_uString **)pSource );
786 *(rtl_uString **)pDest = *(rtl_uString **)pSource;
787 break;
788 case typelib_TypeClass_TYPE:
789 TYPE_ACQUIRE( *(typelib_TypeDescriptionReference **)pSource );
790 *(typelib_TypeDescriptionReference **)pDest = *(typelib_TypeDescriptionReference **)pSource;
791 break;
792 case typelib_TypeClass_ANY:
793 _copyConstructAny(
794 (uno_Any *)pDest, ((uno_Any *)pSource)->pData,
795 ((uno_Any *)pSource)->pType, 0,
796 acquire, mapping );
797 break;
798 case typelib_TypeClass_ENUM:
799 *(sal_Int32 *)pDest = *(sal_Int32 *)pSource;
800 break;
801 case typelib_TypeClass_STRUCT:
802 case typelib_TypeClass_EXCEPTION:
803 if (pTypeDescr)
805 _copyConstructStruct(
806 pDest, pSource,
807 (typelib_CompoundTypeDescription *)pTypeDescr,
808 acquire, mapping );
810 else
812 TYPELIB_DANGER_GET( &pTypeDescr, pType );
813 _copyConstructStruct(
814 pDest, pSource,
815 (typelib_CompoundTypeDescription *)pTypeDescr,
816 acquire, mapping );
817 TYPELIB_DANGER_RELEASE( pTypeDescr );
819 break;
820 case typelib_TypeClass_ARRAY:
821 if (pTypeDescr)
823 _copyConstructArray(
824 pDest, pSource,
825 (typelib_ArrayTypeDescription *)pTypeDescr,
826 acquire, mapping );
828 else
830 TYPELIB_DANGER_GET( &pTypeDescr, pType );
831 _copyConstructArray(
832 pDest, pSource,
833 (typelib_ArrayTypeDescription *)pTypeDescr,
834 acquire, mapping );
835 TYPELIB_DANGER_RELEASE( pTypeDescr );
837 break;
838 case typelib_TypeClass_UNION:
839 if (pTypeDescr)
841 _copyConstructUnion( pDest, pSource, pTypeDescr, acquire, mapping );
843 else
845 TYPELIB_DANGER_GET( &pTypeDescr, pType );
846 _copyConstructUnion( pDest, pSource, pTypeDescr, acquire, mapping );
847 TYPELIB_DANGER_RELEASE( pTypeDescr );
849 break;
850 case typelib_TypeClass_SEQUENCE:
851 if (mapping)
853 if (pTypeDescr)
855 *(uno_Sequence **)pDest = icopyConstructSequence(
856 *(uno_Sequence **)pSource,
857 ((typelib_IndirectTypeDescription *)pTypeDescr)->pType,
858 acquire, mapping );
860 else
862 TYPELIB_DANGER_GET( &pTypeDescr, pType );
863 *(uno_Sequence **)pDest = icopyConstructSequence(
864 *(uno_Sequence **)pSource,
865 ((typelib_IndirectTypeDescription *)pTypeDescr)->pType,
866 acquire, mapping );
867 TYPELIB_DANGER_RELEASE( pTypeDescr );
870 else
872 ::osl_incrementInterlockedCount( &(*(uno_Sequence **)pSource)->nRefCount );
873 *(uno_Sequence **)pDest = *(uno_Sequence **)pSource;
875 break;
876 case typelib_TypeClass_INTERFACE:
877 if (mapping)
878 *(void **)pDest = _map( *(void **)pSource, pType, pTypeDescr, mapping );
879 else
880 _acquire( *(void **)pDest = *(void **)pSource, acquire );
881 break;
882 default:
883 break;
889 #endif