Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 : #ifndef ASSIGN_HXX
20 : #define ASSIGN_HXX
21 :
22 : #include <string.h>
23 :
24 : #include "prim.hxx"
25 : #include "destr.hxx"
26 : #include "constr.hxx"
27 : #include "copy.hxx"
28 :
29 :
30 : namespace cppu
31 : {
32 :
33 : //##################################################################################################
34 : //#### assignment ##################################################################################
35 : //##################################################################################################
36 :
37 :
38 : //--------------------------------------------------------------------------------------------------
39 88867 : inline void _assignInterface(
40 : void ** ppDest, void * pSource,
41 : uno_AcquireFunc acquire, uno_ReleaseFunc release )
42 : SAL_THROW(())
43 : {
44 88867 : _acquire( pSource, acquire );
45 88867 : void * const pToBeReleased = *ppDest;
46 88867 : *ppDest = pSource;
47 88867 : _release( pToBeReleased, release );
48 88867 : }
49 : //--------------------------------------------------------------------------------------------------
50 55231 : inline void * _queryInterface(
51 : void * pSource,
52 : typelib_TypeDescriptionReference * pDestType,
53 : uno_QueryInterfaceFunc queryInterface )
54 : SAL_THROW(())
55 : {
56 55231 : if (pSource)
57 : {
58 55231 : if (0 == queryInterface)
59 0 : queryInterface = binuno_queryInterface;
60 55231 : pSource = (*queryInterface)( pSource, pDestType );
61 : }
62 55231 : return pSource;
63 : }
64 : //==================================================================================================
65 : sal_Bool assignStruct(
66 : void * pDest, void * pSource,
67 : typelib_CompoundTypeDescription * pTypeDescr,
68 : uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release )
69 : SAL_THROW(());
70 : //--------------------------------------------------------------------------------------------------
71 62556 : inline sal_Bool _assignStruct(
72 : void * pDest, void * pSource,
73 : typelib_CompoundTypeDescription * pTypeDescr,
74 : uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release )
75 : SAL_THROW(())
76 : {
77 62556 : if (pTypeDescr->pBaseTypeDescription)
78 : {
79 : // copy base value
80 9433 : if (! assignStruct( pDest, pSource, pTypeDescr->pBaseTypeDescription,
81 9433 : queryInterface, acquire, release ))
82 : {
83 0 : return sal_False;
84 : }
85 : }
86 : // then copy members
87 62556 : typelib_TypeDescriptionReference ** ppTypeRefs = pTypeDescr->ppTypeRefs;
88 62556 : sal_Int32 * pMemberOffsets = pTypeDescr->pMemberOffsets;
89 62556 : sal_Int32 nDescr = pTypeDescr->nMembers;
90 318906 : while (nDescr--)
91 : {
92 581382 : if (! ::uno_type_assignData( (char *)pDest + pMemberOffsets[nDescr],
93 193794 : ppTypeRefs[nDescr],
94 387588 : (char *)pSource + pMemberOffsets[nDescr],
95 193794 : ppTypeRefs[nDescr],
96 968970 : queryInterface, acquire, release ))
97 : {
98 0 : return sal_False;
99 : }
100 : }
101 62556 : return sal_True;
102 : }
103 : //--------------------------------------------------------------------------------------------------
104 0 : inline sal_Bool _assignArray(
105 : void * pDest, void * pSource,
106 : typelib_ArrayTypeDescription * pTypeDescr,
107 : uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release )
108 : {
109 : typelib_TypeDescriptionReference * pElementTypeRef =
110 0 : ((typelib_IndirectTypeDescription *)pTypeDescr)->pType;
111 0 : typelib_TypeDescription * pElementTypeDescr = NULL;
112 0 : TYPELIB_DANGER_GET( &pElementTypeDescr, pElementTypeRef );
113 0 : sal_Int32 nTotalElements = pTypeDescr->nTotalElements;
114 0 : sal_Int32 nElementSize = pElementTypeDescr->nSize;
115 : sal_Int32 i;
116 0 : sal_Bool bRet = sal_False;
117 :
118 0 : switch ( pElementTypeRef->eTypeClass )
119 : {
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 0 : for (i=0; i < nTotalElements; i++)
132 : {
133 0 : memcpy((sal_Char *)pDest + i * nElementSize,
134 : (sal_Char *)pSource + i * nElementSize,
135 0 : nElementSize);
136 : }
137 0 : bRet = sal_True;
138 0 : break;
139 : case typelib_TypeClass_STRING:
140 0 : for (i=0; i < nTotalElements; i++)
141 : {
142 : ::rtl_uString_assign( (rtl_uString **)pDest + i,
143 0 : ((rtl_uString **)pSource)[i] );
144 : }
145 0 : bRet = sal_True;
146 0 : break;
147 : case typelib_TypeClass_TYPE:
148 0 : for (i=0; i < nTotalElements; i++)
149 : {
150 0 : typelib_TypeDescriptionReference ** pp = (typelib_TypeDescriptionReference **)pDest + i;
151 0 : ::typelib_typedescriptionreference_release( *pp );
152 0 : *pp = *((typelib_TypeDescriptionReference **)pSource + i);
153 0 : TYPE_ACQUIRE( *pp );
154 : }
155 0 : bRet = sal_True;
156 0 : break;
157 : case typelib_TypeClass_ANY:
158 0 : for (i=0; i < nTotalElements; i++)
159 : {
160 0 : _destructAny( (uno_Any *)pDest + i, release );
161 0 : _copyConstructAny( (uno_Any *)pDest + i, (uno_Any *)pSource + i,
162 0 : pElementTypeRef, pElementTypeDescr, acquire, 0 );
163 : }
164 0 : bRet = sal_True;
165 0 : break;
166 : case typelib_TypeClass_ENUM:
167 0 : for (i=0; i < nTotalElements; i++)
168 : {
169 0 : *((sal_Int32 *)pDest + i) = *((sal_Int32 *)pSource + i);
170 : }
171 0 : bRet = sal_True;
172 0 : break;
173 : case typelib_TypeClass_STRUCT:
174 : case typelib_TypeClass_EXCEPTION:
175 0 : for (i=0; i < nTotalElements; i++)
176 : {
177 0 : bRet = _assignStruct( (sal_Char *)pDest + i * nElementSize,
178 0 : (sal_Char *)pSource + i * nElementSize,
179 : (typelib_CompoundTypeDescription *)pElementTypeDescr,
180 0 : queryInterface, acquire, release );
181 0 : if (! bRet)
182 0 : break;
183 : }
184 0 : bRet = sal_True;
185 0 : break;
186 : case typelib_TypeClass_UNION:
187 0 : for (i=0; i < nTotalElements; i++)
188 : {
189 0 : _destructUnion( (sal_Char*)pDest + i * nElementSize, pElementTypeDescr, release );
190 0 : _copyConstructUnion( (sal_Char*)pDest + i * nElementSize,
191 0 : (sal_Char*)pSource + i * nElementSize,
192 0 : pElementTypeDescr, acquire, 0 );
193 : }
194 0 : bRet = sal_True;
195 0 : break;
196 : case typelib_TypeClass_SEQUENCE:
197 0 : for (i=0; i < nTotalElements; i++)
198 : {
199 0 : osl_atomic_increment( &(*((uno_Sequence **)pSource + i))->nRefCount );
200 : idestructSequence(
201 0 : *((uno_Sequence **)pDest + i),
202 0 : pElementTypeRef, pElementTypeDescr, release );
203 0 : *((uno_Sequence **)pDest + i) = *((uno_Sequence **)pSource + i);
204 : }
205 0 : bRet = sal_True;
206 0 : break;
207 : case typelib_TypeClass_INTERFACE:
208 0 : for (i=0; i < nTotalElements; i++)
209 : {
210 : _assignInterface(
211 : (void **)((sal_Char*)pDest + i * nElementSize),
212 : *(void **)((sal_Char*)pSource + i * nElementSize),
213 0 : acquire, release );
214 : }
215 0 : bRet = sal_True;
216 0 : break;
217 : default:
218 : OSL_ASSERT(false);
219 0 : break;
220 : }
221 :
222 0 : TYPELIB_DANGER_RELEASE( pElementTypeDescr );
223 0 : return bRet;
224 : }
225 : //--------------------------------------------------------------------------------------------------
226 503815 : inline sal_Bool _assignData(
227 : void * pDest,
228 : typelib_TypeDescriptionReference * pDestType, typelib_TypeDescription * pDestTypeDescr,
229 : void * pSource,
230 : typelib_TypeDescriptionReference * pSourceType, typelib_TypeDescription * pSourceTypeDescr,
231 : uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release )
232 : SAL_THROW(())
233 : {
234 503815 : if (pDest == pSource)
235 0 : return _type_equals( pDestType, pSourceType );
236 :
237 503815 : if (! pSource)
238 : {
239 0 : _destructData( pDest, pDestType, pDestTypeDescr, release );
240 0 : _defaultConstructData( pDest, pDestType, pDestTypeDescr );
241 0 : return sal_True;
242 : }
243 1032641 : while (typelib_TypeClass_ANY == pSourceType->eTypeClass)
244 : {
245 25011 : pSourceTypeDescr = 0;
246 25011 : pSourceType = ((uno_Any *)pSource)->pType;
247 25011 : pSource = ((uno_Any *)pSource)->pData;
248 25011 : if (pDest == pSource)
249 0 : return sal_True;
250 : }
251 :
252 503815 : switch (pDestType->eTypeClass)
253 : {
254 : case typelib_TypeClass_VOID:
255 0 : return pSourceType->eTypeClass == typelib_TypeClass_VOID;
256 : case typelib_TypeClass_CHAR:
257 6 : switch (pSourceType->eTypeClass)
258 : {
259 : case typelib_TypeClass_CHAR:
260 6 : *(sal_Unicode *)pDest = *(sal_Unicode *)pSource;
261 6 : return sal_True;
262 : default:
263 0 : return sal_False;
264 : }
265 : case typelib_TypeClass_BOOLEAN:
266 2219 : switch (pSourceType->eTypeClass)
267 : {
268 : case typelib_TypeClass_BOOLEAN:
269 2219 : *(sal_Bool *)pDest = (*(sal_Bool *)pSource != sal_False);
270 2219 : return sal_True;
271 : default:
272 0 : return sal_False;
273 : }
274 : case typelib_TypeClass_BYTE:
275 1 : switch (pSourceType->eTypeClass)
276 : {
277 : case typelib_TypeClass_BYTE:
278 1 : *(sal_Int8 *)pDest = *(sal_Int8 *)pSource;
279 1 : return sal_True;
280 : default:
281 0 : return sal_False;
282 : }
283 : case typelib_TypeClass_SHORT:
284 19403 : switch (pSourceType->eTypeClass)
285 : {
286 : case typelib_TypeClass_BYTE:
287 0 : *(sal_Int16 *)pDest = *(sal_Int8 *)pSource;
288 0 : return sal_True;
289 : case typelib_TypeClass_SHORT:
290 : case typelib_TypeClass_UNSIGNED_SHORT:
291 19403 : *(sal_Int16 *)pDest = *(sal_Int16 *)pSource;
292 19403 : return sal_True;
293 : default:
294 0 : return sal_False;
295 : }
296 : case typelib_TypeClass_UNSIGNED_SHORT:
297 491 : switch (pSourceType->eTypeClass)
298 : {
299 : case typelib_TypeClass_BYTE:
300 0 : *(sal_uInt16 *)pDest = *(sal_Int8 *)pSource;
301 0 : return sal_True;
302 : case typelib_TypeClass_SHORT:
303 : case typelib_TypeClass_UNSIGNED_SHORT:
304 491 : *(sal_uInt16 *)pDest = *(sal_uInt16 *)pSource;
305 491 : return sal_True;
306 : default:
307 0 : return sal_False;
308 : }
309 : case typelib_TypeClass_LONG:
310 49209 : switch (pSourceType->eTypeClass)
311 : {
312 : case typelib_TypeClass_BYTE:
313 0 : *(sal_Int32 *)pDest = *(sal_Int8 *)pSource;
314 0 : return sal_True;
315 : case typelib_TypeClass_SHORT:
316 0 : *(sal_Int32 *)pDest = *(sal_Int16 *)pSource;
317 0 : return sal_True;
318 : case typelib_TypeClass_UNSIGNED_SHORT:
319 0 : *(sal_Int32 *)pDest = *(sal_uInt16 *)pSource;
320 0 : return sal_True;
321 : case typelib_TypeClass_LONG:
322 : case typelib_TypeClass_UNSIGNED_LONG:
323 49209 : *(sal_Int32 *)pDest = *(sal_Int32 *)pSource;
324 49209 : return sal_True;
325 : default:
326 0 : return sal_False;
327 : }
328 : case typelib_TypeClass_UNSIGNED_LONG:
329 3510 : switch (pSourceType->eTypeClass)
330 : {
331 : case typelib_TypeClass_BYTE:
332 0 : *(sal_uInt32 *)pDest = *(sal_Int8 *)pSource;
333 0 : return sal_True;
334 : case typelib_TypeClass_SHORT:
335 0 : *(sal_uInt32 *)pDest = *(sal_Int16 *)pSource;
336 0 : return sal_True;
337 : case typelib_TypeClass_UNSIGNED_SHORT:
338 0 : *(sal_uInt32 *)pDest = *(sal_uInt16 *)pSource;
339 0 : return sal_True;
340 : case typelib_TypeClass_LONG:
341 : case typelib_TypeClass_UNSIGNED_LONG:
342 3510 : *(sal_uInt32 *)pDest = *(sal_uInt32 *)pSource;
343 3510 : return sal_True;
344 : default:
345 0 : return sal_False;
346 : }
347 : case typelib_TypeClass_HYPER:
348 1 : switch (pSourceType->eTypeClass)
349 : {
350 : case typelib_TypeClass_BYTE:
351 0 : *(sal_Int64 *)pDest = *(sal_Int8 *)pSource;
352 0 : return sal_True;
353 : case typelib_TypeClass_SHORT:
354 0 : *(sal_Int64 *)pDest = *(sal_Int16 *)pSource;
355 0 : return sal_True;
356 : case typelib_TypeClass_UNSIGNED_SHORT:
357 0 : *(sal_Int64 *)pDest = *(sal_uInt16 *)pSource;
358 0 : return sal_True;
359 : case typelib_TypeClass_LONG:
360 0 : *(sal_Int64 *)pDest = *(sal_Int32 *)pSource;
361 0 : return sal_True;
362 : case typelib_TypeClass_UNSIGNED_LONG:
363 0 : *(sal_Int64 *)pDest = *(sal_uInt32 *)pSource;
364 0 : return sal_True;
365 : case typelib_TypeClass_HYPER:
366 : case typelib_TypeClass_UNSIGNED_HYPER:
367 1 : *(sal_Int64 *)pDest = *(sal_Int64 *)pSource;
368 1 : return sal_True;
369 : default:
370 0 : return sal_False;
371 : }
372 : case typelib_TypeClass_UNSIGNED_HYPER:
373 0 : switch (pSourceType->eTypeClass)
374 : {
375 : case typelib_TypeClass_BYTE:
376 0 : *(sal_uInt64 *)pDest = *(sal_Int8 *)pSource;
377 0 : return sal_True;
378 : case typelib_TypeClass_SHORT:
379 0 : *(sal_uInt64 *)pDest = *(sal_Int16 *)pSource;
380 0 : return sal_True;
381 : case typelib_TypeClass_UNSIGNED_SHORT:
382 0 : *(sal_uInt64 *)pDest = *(sal_uInt16 *)pSource;
383 0 : return sal_True;
384 : case typelib_TypeClass_LONG:
385 0 : *(sal_uInt64 *)pDest = *(sal_Int32 *)pSource;
386 0 : return sal_True;
387 : case typelib_TypeClass_UNSIGNED_LONG:
388 0 : *(sal_uInt64 *)pDest = *(sal_uInt32 *)pSource;
389 0 : return sal_True;
390 : case typelib_TypeClass_HYPER:
391 : case typelib_TypeClass_UNSIGNED_HYPER:
392 0 : *(sal_uInt64 *)pDest = *(sal_uInt64 *)pSource;
393 0 : return sal_True;
394 : default:
395 0 : return sal_False;
396 : }
397 : case typelib_TypeClass_FLOAT:
398 274 : switch (pSourceType->eTypeClass)
399 : {
400 : case typelib_TypeClass_BYTE:
401 0 : *(float *)pDest = *(sal_Int8 *)pSource;
402 0 : return sal_True;
403 : case typelib_TypeClass_SHORT:
404 0 : *(float *)pDest = *(sal_Int16 *)pSource;
405 0 : return sal_True;
406 : case typelib_TypeClass_UNSIGNED_SHORT:
407 0 : *(float *)pDest = *(sal_uInt16 *)pSource;
408 0 : return sal_True;
409 : case typelib_TypeClass_FLOAT:
410 274 : *(float *)pDest = *(float *)pSource;
411 274 : return sal_True;
412 : default:
413 0 : return sal_False;
414 : }
415 : case typelib_TypeClass_DOUBLE:
416 13285 : switch (pSourceType->eTypeClass)
417 : {
418 : case typelib_TypeClass_BYTE:
419 0 : *(double *)pDest = *(sal_Int8 *)pSource;
420 0 : return sal_True;
421 : case typelib_TypeClass_SHORT:
422 0 : *(double *)pDest = *(sal_Int16 *)pSource;
423 0 : return sal_True;
424 : case typelib_TypeClass_UNSIGNED_SHORT:
425 0 : *(double *)pDest = *(sal_uInt16 *)pSource;
426 0 : return sal_True;
427 : case typelib_TypeClass_LONG:
428 0 : *(double *)pDest = *(sal_Int32 *)pSource;
429 0 : return sal_True;
430 : case typelib_TypeClass_UNSIGNED_LONG:
431 0 : *(double *)pDest = *(sal_uInt32 *)pSource;
432 0 : return sal_True;
433 : case typelib_TypeClass_FLOAT:
434 0 : *(double *)pDest = *(float *)pSource;
435 0 : return sal_True;
436 : case typelib_TypeClass_DOUBLE:
437 13285 : *(double *)pDest = *(double *)pSource;
438 13285 : return sal_True;
439 : default:
440 0 : return sal_False;
441 : }
442 : case typelib_TypeClass_STRING:
443 41113 : switch (pSourceType->eTypeClass)
444 : {
445 : case typelib_TypeClass_STRING:
446 41113 : ::rtl_uString_assign( (rtl_uString **)pDest, *(rtl_uString **)pSource );
447 41113 : return sal_True;
448 : default:
449 0 : return sal_False;
450 : }
451 : case typelib_TypeClass_TYPE:
452 1 : switch (pSourceType->eTypeClass)
453 : {
454 : case typelib_TypeClass_TYPE:
455 : {
456 1 : typelib_TypeDescriptionReference ** pp = (typelib_TypeDescriptionReference **)pDest;
457 1 : ::typelib_typedescriptionreference_release( *pp );
458 1 : *pp = *(typelib_TypeDescriptionReference **)pSource;
459 1 : TYPE_ACQUIRE( *pp );
460 1 : return sal_True;
461 : }
462 : default:
463 0 : return sal_False;
464 : }
465 : case typelib_TypeClass_ANY:
466 25011 : _destructAny( (uno_Any *)pDest, release );
467 25011 : _copyConstructAny( (uno_Any *)pDest, pSource, pSourceType, pSourceTypeDescr, acquire, 0 );
468 25011 : return sal_True;
469 : case typelib_TypeClass_ENUM:
470 37909 : if (_type_equals( pDestType, pSourceType ))
471 : {
472 37749 : *(sal_Int32 *)pDest = *(sal_Int32 *)pSource;
473 37749 : return sal_True;
474 : }
475 160 : return sal_False;
476 : case typelib_TypeClass_STRUCT:
477 : case typelib_TypeClass_EXCEPTION:
478 65118 : if (typelib_TypeClass_STRUCT == pSourceType->eTypeClass ||
479 : typelib_TypeClass_EXCEPTION == pSourceType->eTypeClass)
480 : {
481 60070 : sal_Bool bRet = sal_False;
482 60070 : if (pSourceTypeDescr)
483 : {
484 : typelib_CompoundTypeDescription * pTypeDescr =
485 0 : (typelib_CompoundTypeDescription *)pSourceTypeDescr;
486 0 : while (pTypeDescr &&
487 : !_type_equals(
488 0 : ((typelib_TypeDescription *)pTypeDescr)->pWeakRef, pDestType ))
489 : {
490 0 : pTypeDescr = pTypeDescr->pBaseTypeDescription;
491 : }
492 0 : if (pTypeDescr)
493 : {
494 : bRet = _assignStruct(
495 0 : pDest, pSource, pTypeDescr, queryInterface, acquire, release );
496 : }
497 : }
498 : else
499 : {
500 60070 : TYPELIB_DANGER_GET( &pSourceTypeDescr, pSourceType );
501 : typelib_CompoundTypeDescription * pTypeDescr =
502 60070 : (typelib_CompoundTypeDescription *)pSourceTypeDescr;
503 188471 : while (pTypeDescr &&
504 : !_type_equals(
505 60727 : ((typelib_TypeDescription *)pTypeDescr)->pWeakRef, pDestType ))
506 : {
507 7604 : pTypeDescr = pTypeDescr->pBaseTypeDescription;
508 : }
509 60070 : if (pTypeDescr)
510 : {
511 : bRet = _assignStruct(
512 53123 : pDest, pSource, pTypeDescr, queryInterface, acquire, release );
513 : }
514 60070 : TYPELIB_DANGER_RELEASE( pSourceTypeDescr );
515 : }
516 60070 : return bRet;
517 : }
518 5048 : return sal_False;
519 : case typelib_TypeClass_ARRAY:
520 : {
521 0 : sal_Bool bRet = sal_False;
522 0 : if (pSourceTypeDescr)
523 : {
524 : typelib_ArrayTypeDescription * pTypeDescr =
525 0 : (typelib_ArrayTypeDescription *)pSourceTypeDescr;
526 0 : bRet = _assignArray( pDest, pSource, pTypeDescr, queryInterface, acquire, release );
527 : }
528 : else
529 : {
530 0 : TYPELIB_DANGER_GET( &pSourceTypeDescr, pSourceType );
531 : typelib_ArrayTypeDescription * pTypeDescr =
532 0 : (typelib_ArrayTypeDescription *)pSourceTypeDescr;
533 0 : if ( pTypeDescr )
534 : {
535 : bRet = _assignArray(
536 0 : pDest, pSource, pTypeDescr, queryInterface, acquire, release );
537 : }
538 0 : TYPELIB_DANGER_RELEASE( pSourceTypeDescr );
539 : }
540 0 : return bRet;
541 : }
542 : case typelib_TypeClass_UNION:
543 0 : if (_type_equals( pDestType, pSourceType ))
544 : {
545 0 : if (pDestTypeDescr)
546 : {
547 0 : _destructUnion( pDest, pDestTypeDescr, release );
548 0 : _copyConstructUnion( pDest, pSource, pDestTypeDescr, acquire, 0 );
549 : }
550 : else
551 : {
552 0 : TYPELIB_DANGER_GET( &pDestTypeDescr, pDestType );
553 0 : _destructUnion( pDest, pDestTypeDescr, release );
554 0 : _copyConstructUnion( pDest, pSource, pDestTypeDescr, acquire, 0 );
555 0 : TYPELIB_DANGER_RELEASE( pDestTypeDescr );
556 : }
557 0 : return sal_True;
558 : }
559 0 : return sal_False;
560 : case typelib_TypeClass_SEQUENCE:
561 97892 : if (typelib_TypeClass_SEQUENCE != pSourceType->eTypeClass)
562 1464 : return sal_False;
563 : // self assignment:
564 96428 : if (*(uno_Sequence **)pSource == *(uno_Sequence **)pDest)
565 9470 : return sal_True;
566 86958 : if (_type_equals( pDestType, pSourceType ))
567 : {
568 84867 : osl_atomic_increment( &(*(uno_Sequence **)pSource)->nRefCount );
569 : idestructSequence(
570 84867 : *(uno_Sequence **)pDest, pDestType, pDestTypeDescr, release );
571 84867 : *(uno_Sequence **)pDest = *(uno_Sequence **)pSource;
572 84867 : return sal_True;
573 : }
574 2091 : return sal_False;
575 : case typelib_TypeClass_INTERFACE:
576 148372 : if (typelib_TypeClass_INTERFACE != pSourceType->eTypeClass)
577 4203 : return sal_False;
578 144169 : if (_type_equals( pDestType, pSourceType ))
579 : {
580 88867 : _assignInterface( (void **)pDest, *(void **)pSource, acquire, release );
581 88867 : return sal_True;
582 : }
583 55302 : else if (*static_cast< void ** >(pSource) == 0)
584 : {
585 : // A null reference of any interface type can be converted to a null
586 : // reference of any other interface type:
587 71 : void * const pToBeReleased = *static_cast< void ** >(pDest);
588 71 : *static_cast< void ** >(pDest) = 0;
589 71 : _release( pToBeReleased, release );
590 71 : return true;
591 : }
592 : else
593 : {
594 55231 : if (pSourceTypeDescr)
595 : {
596 0 : typelib_TypeDescription * pTD = pSourceTypeDescr;
597 0 : while (pTD && !_type_equals( pTD->pWeakRef, pDestType ))
598 : {
599 : pTD = (typelib_TypeDescription *)
600 0 : ((typelib_InterfaceTypeDescription *)pTD)->pBaseTypeDescription;
601 : }
602 0 : if (pTD) // is base of dest
603 : {
604 0 : _assignInterface( (void **)pDest, *(void **)pSource, acquire, release );
605 0 : return true;
606 : }
607 : }
608 :
609 : // query for interface:
610 : void * pQueried = _queryInterface( *static_cast<void **>(pSource),
611 55231 : pDestType, queryInterface );
612 55231 : if (pQueried != 0) {
613 52753 : void * const pToBeReleased = *static_cast<void **>(pDest);
614 52753 : *static_cast<void **>(pDest) = pQueried;
615 52753 : _release( pToBeReleased, release );
616 : }
617 55231 : return (pQueried != 0);
618 : }
619 : default:
620 : OSL_ASSERT(false);
621 0 : return sal_False;
622 : }
623 : }
624 :
625 : }
626 :
627 : #endif
628 :
629 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|