LCOV - code coverage report
Current view: top level - libreoffice/cppu/source/uno - copy.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 211 374 56.4 %
Date: 2012-12-27 Functions: 6 8 75.0 %
Legend: Lines: hit not hit

          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 COPY_HXX
      20             : #define COPY_HXX
      21             : 
      22             : #include "prim.hxx"
      23             : #include "constr.hxx"
      24             : 
      25             : 
      26             : namespace cppu
      27             : {
      28             : 
      29             : //##################################################################################################
      30             : //#### copy construction ###########################################################################
      31             : //##################################################################################################
      32             : 
      33             : //------------------------------------------------------------------------------
      34       29411 : inline uno_Sequence * allocSeq(
      35             :     sal_Int32 nElementSize, sal_Int32 nElements )
      36             : {
      37             :     OSL_ASSERT( nElements >= 0 && nElementSize >= 0 );
      38       29411 :     uno_Sequence * pSeq = 0;
      39       29411 :     sal_uInt32 nSize = calcSeqMemSize( nElementSize, nElements );
      40       29411 :     if (nSize > 0)
      41             :     {
      42       29411 :         pSeq = (uno_Sequence *) rtl_allocateMemory( nSize );
      43       29411 :         if (pSeq != 0)
      44             :         {
      45             :             // header init
      46       29411 :             pSeq->nRefCount = 1;
      47       29411 :             pSeq->nElements = nElements;
      48             :         }
      49             :     }
      50       29411 :     return pSeq;
      51             : }
      52             : 
      53             : //--------------------------------------------------------------------------------------------------
      54             : void copyConstructStruct(
      55             :     void * pDest, void * pSource,
      56             :     typelib_CompoundTypeDescription * pTypeDescr,
      57             :     uno_AcquireFunc acquire, uno_Mapping * mapping )
      58             :     SAL_THROW (());
      59             : //--------------------------------------------------------------------------------------------------
      60      215815 : inline void _copyConstructStruct(
      61             :     void * pDest, void * pSource,
      62             :     typelib_CompoundTypeDescription * pTypeDescr,
      63             :     uno_AcquireFunc acquire, uno_Mapping * mapping )
      64             :     SAL_THROW (())
      65             : {
      66      215815 :     if (pTypeDescr->pBaseTypeDescription)
      67             :     {
      68             :         // copy base value
      69       59120 :         copyConstructStruct( pDest, pSource, pTypeDescr->pBaseTypeDescription, acquire, mapping );
      70             :     }
      71             : 
      72             :     // then copy members
      73      215815 :     typelib_TypeDescriptionReference ** ppTypeRefs = pTypeDescr->ppTypeRefs;
      74      215815 :     sal_Int32 * pMemberOffsets = pTypeDescr->pMemberOffsets;
      75      215815 :     sal_Int32 nDescr = pTypeDescr->nMembers;
      76             : 
      77      215815 :     if (mapping)
      78             :     {
      79       87778 :         while (nDescr--)
      80             :         {
      81             :             ::uno_type_copyAndConvertData(
      82       91900 :                 (char *)pDest + pMemberOffsets[nDescr],
      83       91900 :                 (char *)pSource + pMemberOffsets[nDescr],
      84      183800 :                 ppTypeRefs[nDescr], mapping );
      85             :         }
      86             :     }
      87             :     else
      88             :     {
      89      932223 :         while (nDescr--)
      90             :         {
      91             :             ::uno_type_copyData(
      92     1084842 :                 (char *)pDest + pMemberOffsets[nDescr],
      93     1084842 :                 (char *)pSource + pMemberOffsets[nDescr],
      94     2169684 :                 ppTypeRefs[nDescr], acquire );
      95             :         }
      96             :     }
      97      215815 : }
      98             : //--------------------------------------------------------------------------------------------------
      99           0 : inline void _copyConstructArray(
     100             :     void * pDest, void * pSource,
     101             :     typelib_ArrayTypeDescription * pTypeDescr,
     102             :     uno_AcquireFunc acquire, uno_Mapping * mapping )
     103             : {
     104           0 :     typelib_TypeDescriptionReference * pElementTypeRef = ((typelib_IndirectTypeDescription *)pTypeDescr)->pType;
     105           0 :     typelib_TypeDescription * pElementTypeDescr = NULL;
     106           0 :     TYPELIB_DANGER_GET( &pElementTypeDescr, pElementTypeRef );
     107           0 :     sal_Int32 nElementSize = ((typelib_TypeDescription*)pElementTypeDescr)->nSize;
     108           0 :     TYPELIB_DANGER_RELEASE( pElementTypeDescr );
     109           0 :     sal_Int32 nTotalElements = pTypeDescr->nTotalElements;
     110             : 
     111           0 :     if (mapping)
     112             :     {
     113           0 :         for(sal_Int32 i = 0; i < nTotalElements; i++)
     114             :         {
     115             :             ::uno_type_copyAndConvertData(
     116           0 :                 (sal_Char *)pDest + i * nElementSize,
     117           0 :                 (sal_Char *)pSource + i * nElementSize,
     118           0 :                 pElementTypeRef, mapping );
     119             :         }
     120             :     }
     121             :     else
     122             :     {
     123           0 :         for(sal_Int32 i = 0; i < nTotalElements; i++)
     124             :         {
     125             :             ::uno_type_copyData(
     126           0 :                 (sal_Char *)pDest + (i * nElementSize),
     127           0 :                 (sal_Char *)pSource + (i * nElementSize),
     128           0 :                 pElementTypeRef, acquire );
     129             :         }
     130             :     }
     131           0 : }
     132             : //--------------------------------------------------------------------------------------------------
     133           0 : inline void _copyConstructUnion(
     134             :     void * pDest, void * pSource,
     135             :     typelib_TypeDescription * pTypeDescr,
     136             :     uno_AcquireFunc acquire, uno_Mapping * mapping )
     137             :     SAL_THROW (())
     138             : {
     139           0 :     typelib_TypeDescriptionReference * pSetType = _unionGetSetType( pSource, pTypeDescr );
     140           0 :     if (mapping)
     141             :     {
     142             :         ::uno_type_copyAndConvertData(
     143           0 :             (char *)pDest + ((typelib_UnionTypeDescription *)pTypeDescr)->nValueOffset,
     144           0 :             (char *)pSource + ((typelib_UnionTypeDescription *)pTypeDescr)->nValueOffset,
     145           0 :             pSetType, mapping );
     146             :     }
     147             :     else
     148             :     {
     149             :         ::uno_type_copyData(
     150           0 :             (char *)pDest + ((typelib_UnionTypeDescription *)pTypeDescr)->nValueOffset,
     151           0 :             (char *)pSource + ((typelib_UnionTypeDescription *)pTypeDescr)->nValueOffset,
     152           0 :             pSetType, acquire );
     153             :     }
     154           0 :     *(sal_Int64 *)pDest = *(sal_Int64 *)pSource;
     155           0 :     typelib_typedescriptionreference_release( pSetType );
     156           0 : }
     157             : 
     158             : //------------------------------------------------------------------------------
     159             : uno_Sequence * copyConstructSequence(
     160             :     uno_Sequence * pSource,
     161             :     typelib_TypeDescriptionReference * pElementType,
     162             :     uno_AcquireFunc acquire, uno_Mapping * mapping );
     163             : 
     164             : //--------------------------------------------------------------------------------------------------
     165     7172170 : inline void _copyConstructAnyFromData(
     166             :     uno_Any * pDestAny, void * pSource,
     167             :     typelib_TypeDescriptionReference * pType, typelib_TypeDescription * pTypeDescr,
     168             :     uno_AcquireFunc acquire, uno_Mapping * mapping )
     169             :     SAL_THROW (())
     170             : {
     171     7172170 :     TYPE_ACQUIRE( pType );
     172     7172170 :     pDestAny->pType = pType;
     173             : 
     174     7172170 :     switch (pType->eTypeClass)
     175             :     {
     176             :     case typelib_TypeClass_CHAR:
     177          15 :         pDestAny->pData = &pDestAny->pReserved;
     178          15 :         *(sal_Unicode *)pDestAny->pData = *(sal_Unicode *)pSource;
     179          15 :         break;
     180             :     case typelib_TypeClass_BOOLEAN:
     181     1159726 :         pDestAny->pData = &pDestAny->pReserved;
     182     1159726 :         *(sal_Bool *)pDestAny->pData = (*(sal_Bool *)pSource != sal_False);
     183     1159726 :         break;
     184             :     case typelib_TypeClass_BYTE:
     185        3562 :         pDestAny->pData = &pDestAny->pReserved;
     186        3562 :         *(sal_Int8 *)pDestAny->pData = *(sal_Int8 *)pSource;
     187        3562 :         break;
     188             :     case typelib_TypeClass_SHORT:
     189             :     case typelib_TypeClass_UNSIGNED_SHORT:
     190      232837 :         pDestAny->pData = &pDestAny->pReserved;
     191      232837 :         *(sal_Int16 *)pDestAny->pData = *(sal_Int16 *)pSource;
     192      232837 :         break;
     193             :     case typelib_TypeClass_LONG:
     194             :     case typelib_TypeClass_UNSIGNED_LONG:
     195      622654 :         pDestAny->pData = &pDestAny->pReserved;
     196      622654 :         *(sal_Int32 *)pDestAny->pData = *(sal_Int32 *)pSource;
     197      622654 :         break;
     198             :     case typelib_TypeClass_HYPER:
     199             :     case typelib_TypeClass_UNSIGNED_HYPER:
     200             :         if (sizeof(void *) >= sizeof(sal_Int64))
     201             :             pDestAny->pData = &pDestAny->pReserved;
     202             :         else
     203       18177 :             pDestAny->pData = ::rtl_allocateMemory( sizeof(sal_Int64) );
     204       18177 :         *(sal_Int64 *)pDestAny->pData = *(sal_Int64 *)pSource;
     205       18177 :         break;
     206             :     case typelib_TypeClass_FLOAT:
     207             :         if (sizeof(void *) >= sizeof(float))
     208       38864 :             pDestAny->pData = &pDestAny->pReserved;
     209             :         else
     210             :             pDestAny->pData = ::rtl_allocateMemory( sizeof(float) );
     211       38864 :         *(float *)pDestAny->pData = *(float *)pSource;
     212       38864 :         break;
     213             :     case typelib_TypeClass_DOUBLE:
     214             :         if (sizeof(void *) >= sizeof(double))
     215             :             pDestAny->pData = &pDestAny->pReserved;
     216             :         else
     217       43195 :             pDestAny->pData = ::rtl_allocateMemory( sizeof(double) );
     218       43195 :         *(double *)pDestAny->pData = *(double *)pSource;
     219       43195 :         break;
     220             :     case typelib_TypeClass_STRING:
     221     1977823 :         ::rtl_uString_acquire( *(rtl_uString **)pSource );
     222     1977823 :         pDestAny->pData = &pDestAny->pReserved;
     223     1977823 :         *(rtl_uString **)pDestAny->pData = *(rtl_uString **)pSource;
     224     1977823 :         break;
     225             :     case typelib_TypeClass_TYPE:
     226           8 :         TYPE_ACQUIRE( *(typelib_TypeDescriptionReference **)pSource );
     227           8 :         pDestAny->pData = &pDestAny->pReserved;
     228           8 :         *(typelib_TypeDescriptionReference **)pDestAny->pData = *(typelib_TypeDescriptionReference **)pSource;
     229           8 :         break;
     230             :     case typelib_TypeClass_ANY:
     231             :         OSL_FAIL( "### unexpected nested any!" );
     232           0 :         break;
     233             :     case typelib_TypeClass_ENUM:
     234      103057 :         pDestAny->pData = &pDestAny->pReserved;
     235             :         // enum is forced to 32bit long
     236      103057 :         *(sal_Int32 *)pDestAny->pData = *(sal_Int32 *)pSource;
     237      103057 :         break;
     238             :     case typelib_TypeClass_STRUCT:
     239             :     case typelib_TypeClass_EXCEPTION:
     240      135733 :         if (pTypeDescr)
     241             :         {
     242          86 :             pDestAny->pData = ::rtl_allocateMemory( pTypeDescr->nSize );
     243             :             _copyConstructStruct(
     244             :                 pDestAny->pData, pSource,
     245             :                 (typelib_CompoundTypeDescription *)pTypeDescr,
     246          86 :                 acquire, mapping );
     247             :         }
     248             :         else
     249             :         {
     250      135647 :             TYPELIB_DANGER_GET( &pTypeDescr, pType );
     251      135647 :             pDestAny->pData = ::rtl_allocateMemory( pTypeDescr->nSize );
     252             :             _copyConstructStruct(
     253             :                 pDestAny->pData, pSource,
     254             :                 (typelib_CompoundTypeDescription *)pTypeDescr,
     255      135647 :                 acquire, mapping );
     256      135647 :             TYPELIB_DANGER_RELEASE( pTypeDescr );
     257             :         }
     258      135733 :         break;
     259             :     case typelib_TypeClass_ARRAY:
     260           0 :         if (pTypeDescr)
     261             :         {
     262           0 :             pDestAny->pData = ::rtl_allocateMemory( pTypeDescr->nSize );
     263             :             _copyConstructArray(
     264             :                 pDestAny->pData, pSource,
     265             :                 (typelib_ArrayTypeDescription *)pTypeDescr,
     266           0 :                 acquire, mapping );
     267             :         }
     268             :         else
     269             :         {
     270           0 :             TYPELIB_DANGER_GET( &pTypeDescr, pType );
     271           0 :             pDestAny->pData = ::rtl_allocateMemory( pTypeDescr->nSize );
     272             :             _copyConstructArray(
     273             :                 pDestAny->pData, pSource,
     274             :                 (typelib_ArrayTypeDescription *)pTypeDescr,
     275           0 :                 acquire, mapping );
     276           0 :             TYPELIB_DANGER_RELEASE( pTypeDescr );
     277             :         }
     278           0 :         break;
     279             :     case typelib_TypeClass_UNION:
     280           0 :         if (pTypeDescr)
     281             :         {
     282           0 :             pDestAny->pData = ::rtl_allocateMemory( pTypeDescr->nSize );
     283           0 :             _copyConstructUnion( pDestAny->pData, pSource, pTypeDescr, acquire, mapping );
     284             :         }
     285             :         else
     286             :         {
     287           0 :             TYPELIB_DANGER_GET( &pTypeDescr, pType );
     288           0 :             pDestAny->pData = ::rtl_allocateMemory( pTypeDescr->nSize );
     289           0 :             _copyConstructUnion( pDestAny->pData, pSource, pTypeDescr, acquire, mapping );
     290           0 :             TYPELIB_DANGER_RELEASE( pTypeDescr );
     291             :         }
     292           0 :         break;
     293             :     case typelib_TypeClass_SEQUENCE:
     294      213543 :         pDestAny->pData = &pDestAny->pReserved;
     295      213543 :         if (pTypeDescr)
     296             :         {
     297             :             *(uno_Sequence **)pDestAny->pData = copyConstructSequence(
     298             :                 *(uno_Sequence **)pSource,
     299             :                 ((typelib_IndirectTypeDescription *)pTypeDescr)->pType,
     300           0 :                 acquire, mapping );
     301             :         }
     302             :         else
     303             :         {
     304      213543 :             TYPELIB_DANGER_GET( &pTypeDescr, pType );
     305             :             *(uno_Sequence **)pDestAny->pData = copyConstructSequence(
     306             :                 *(uno_Sequence **)pSource,
     307             :                 ((typelib_IndirectTypeDescription *)pTypeDescr)->pType,
     308      213543 :                 acquire, mapping );
     309      213543 :             TYPELIB_DANGER_RELEASE( pTypeDescr );
     310             :         }
     311      213543 :         break;
     312             :     case typelib_TypeClass_INTERFACE:
     313     2622976 :         pDestAny->pData = &pDestAny->pReserved;
     314     2622976 :         if (mapping)
     315             :         {
     316         623 :             pDestAny->pReserved = _map( *(void **)pSource, pType, pTypeDescr, mapping );
     317             :         }
     318             :         else
     319             :         {
     320     2622353 :             _acquire( pDestAny->pReserved = *(void **)pSource, acquire );
     321             :         }
     322     2622976 :         break;
     323             :     default:
     324             :         OSL_ASSERT(false);
     325           0 :         break;
     326             :     }
     327     7172170 : }
     328             : //--------------------------------------------------------------------------------------------------
     329     8509097 : inline void _copyConstructAny(
     330             :     uno_Any * pDestAny, void * pSource,
     331             :     typelib_TypeDescriptionReference * pType, typelib_TypeDescription * pTypeDescr,
     332             :     uno_AcquireFunc acquire, uno_Mapping * mapping )
     333             :     SAL_THROW (())
     334             : {
     335     8509097 :     if (typelib_TypeClass_VOID == pType->eTypeClass)
     336             :     {
     337     1302658 :         CONSTRUCT_EMPTY_ANY( pDestAny );
     338             :     }
     339             :     else
     340             :     {
     341     7206439 :         if (typelib_TypeClass_ANY == pType->eTypeClass)
     342             :         {
     343       71288 :             if (pSource)
     344             :             {
     345       71288 :                 pType = ((uno_Any *)pSource)->pType;
     346       71288 :                 if (typelib_TypeClass_VOID == pType->eTypeClass)
     347             :                 {
     348       41257 :                     CONSTRUCT_EMPTY_ANY( pDestAny );
     349       41257 :                     return;
     350             :                 }
     351       30031 :                 pTypeDescr = 0;
     352       30031 :                 pSource = ((uno_Any *)pSource)->pData;
     353             :             }
     354             :             else
     355             :             {
     356           0 :                 CONSTRUCT_EMPTY_ANY( pDestAny );
     357           0 :                 return;
     358             :             }
     359             :         }
     360     7165182 :         if (pSource)
     361             :         {
     362     7165176 :             _copyConstructAnyFromData( pDestAny, pSource, pType, pTypeDescr, acquire, mapping );
     363             :         }
     364             :         else // default construct
     365             :         {
     366           6 :             TYPE_ACQUIRE( pType );
     367           6 :             pDestAny->pType = pType;
     368           6 :             switch (pType->eTypeClass)
     369             :             {
     370             :             case typelib_TypeClass_CHAR:
     371           0 :                 pDestAny->pData = &pDestAny->pReserved;
     372           0 :                 *(sal_Unicode *)pDestAny->pData = '\0';
     373           0 :                 break;
     374             :             case typelib_TypeClass_BOOLEAN:
     375           0 :                 pDestAny->pData = &pDestAny->pReserved;
     376           0 :                 *(sal_Bool *)pDestAny->pData = sal_False;
     377           0 :                 break;
     378             :             case typelib_TypeClass_BYTE:
     379           0 :                 pDestAny->pData = &pDestAny->pReserved;
     380           0 :                 *(sal_Int8 *)pDestAny->pData = 0;
     381           0 :                 break;
     382             :             case typelib_TypeClass_SHORT:
     383             :             case typelib_TypeClass_UNSIGNED_SHORT:
     384           0 :                 pDestAny->pData = &pDestAny->pReserved;
     385           0 :                 *(sal_Int16 *)pDestAny->pData = 0;
     386           0 :                 break;
     387             :             case typelib_TypeClass_LONG:
     388             :             case typelib_TypeClass_UNSIGNED_LONG:
     389           0 :                 pDestAny->pData = &pDestAny->pReserved;
     390           0 :                 *(sal_Int32 *)pDestAny->pData = 0;
     391           0 :                 break;
     392             :             case typelib_TypeClass_HYPER:
     393             :             case typelib_TypeClass_UNSIGNED_HYPER:
     394             :                 if (sizeof(void *) >= sizeof(sal_Int64))
     395             :                     pDestAny->pData = &pDestAny->pReserved;
     396             :                 else
     397           0 :                     pDestAny->pData = ::rtl_allocateMemory( sizeof(sal_Int64) );
     398           0 :                 *(sal_Int64 *)pDestAny->pData = 0;
     399           0 :                 break;
     400             :             case typelib_TypeClass_FLOAT:
     401             :                 if (sizeof(void *) >= sizeof(float))
     402           0 :                     pDestAny->pData = &pDestAny->pReserved;
     403             :                 else
     404             :                     pDestAny->pData = ::rtl_allocateMemory( sizeof(float) );
     405           0 :                 *(float *)pDestAny->pData = 0.0;
     406           0 :                 break;
     407             :             case typelib_TypeClass_DOUBLE:
     408             :                 if (sizeof(void *) >= sizeof(double))
     409             :                     pDestAny->pData = &pDestAny->pReserved;
     410             :                 else
     411           0 :                     pDestAny->pData = ::rtl_allocateMemory( sizeof(double) );
     412           0 :                 *(double *)pDestAny->pData = 0.0;
     413           0 :                 break;
     414             :             case typelib_TypeClass_STRING:
     415           0 :                 pDestAny->pData = &pDestAny->pReserved;
     416           0 :                 *(rtl_uString **)pDestAny->pData = 0;
     417           0 :                 ::rtl_uString_new( (rtl_uString **)pDestAny->pData );
     418           0 :                 break;
     419             :             case typelib_TypeClass_TYPE:
     420           0 :                 pDestAny->pData = &pDestAny->pReserved;
     421           0 :                 *(typelib_TypeDescriptionReference **)pDestAny->pData = _getVoidType();
     422           0 :                 break;
     423             :             case typelib_TypeClass_ENUM:
     424           0 :                 pDestAny->pData = &pDestAny->pReserved;
     425           0 :                 if (pTypeDescr)
     426             :                 {
     427           0 :                     *(sal_Int32 *)pDestAny->pData = ((typelib_EnumTypeDescription *)pTypeDescr)->nDefaultEnumValue;
     428             :                 }
     429             :                 else
     430             :                 {
     431           0 :                     TYPELIB_DANGER_GET( &pTypeDescr, pType );
     432           0 :                     *(sal_Int32 *)pDestAny->pData = ((typelib_EnumTypeDescription *)pTypeDescr)->nDefaultEnumValue;
     433           0 :                     TYPELIB_DANGER_RELEASE( pTypeDescr );
     434             :                 }
     435           0 :                 break;
     436             :             case typelib_TypeClass_STRUCT:
     437             :             case typelib_TypeClass_EXCEPTION:
     438           6 :                 if (pTypeDescr)
     439             :                 {
     440           6 :                     pDestAny->pData = ::rtl_allocateMemory( pTypeDescr->nSize );
     441             :                     _defaultConstructStruct(
     442           6 :                         pDestAny->pData, (typelib_CompoundTypeDescription *)pTypeDescr );
     443             :                 }
     444             :                 else
     445             :                 {
     446           0 :                     TYPELIB_DANGER_GET( &pTypeDescr, pType );
     447           0 :                     pDestAny->pData = ::rtl_allocateMemory( pTypeDescr->nSize );
     448             :                     _defaultConstructStruct(
     449           0 :                         pDestAny->pData, (typelib_CompoundTypeDescription *)pTypeDescr );
     450           0 :                     TYPELIB_DANGER_RELEASE( pTypeDescr );
     451             :                 }
     452           6 :                 break;
     453             :             case typelib_TypeClass_ARRAY:
     454           0 :                 if (pTypeDescr)
     455             :                 {
     456           0 :                     pDestAny->pData = ::rtl_allocateMemory( pTypeDescr->nSize );
     457             :                     _defaultConstructArray(
     458           0 :                         pDestAny->pData, (typelib_ArrayTypeDescription *)pTypeDescr );
     459             :                 }
     460             :                 else
     461             :                 {
     462           0 :                     TYPELIB_DANGER_GET( &pTypeDescr, pType );
     463           0 :                     pDestAny->pData = ::rtl_allocateMemory( pTypeDescr->nSize );
     464             :                     _defaultConstructArray(
     465           0 :                         pDestAny->pData, (typelib_ArrayTypeDescription *)pTypeDescr );
     466           0 :                     TYPELIB_DANGER_RELEASE( pTypeDescr );
     467             :                 }
     468           0 :                 break;
     469             :             case typelib_TypeClass_UNION:
     470           0 :                 if (pTypeDescr)
     471             :                 {
     472           0 :                     pDestAny->pData = ::rtl_allocateMemory( pTypeDescr->nSize );
     473           0 :                     _defaultConstructUnion( pDestAny->pData, pTypeDescr );
     474             :                 }
     475             :                 else
     476             :                 {
     477           0 :                     TYPELIB_DANGER_GET( &pTypeDescr, pType );
     478           0 :                     pDestAny->pData = ::rtl_allocateMemory( pTypeDescr->nSize );
     479           0 :                     _defaultConstructUnion( pDestAny->pData, pTypeDescr );
     480           0 :                     TYPELIB_DANGER_RELEASE( pTypeDescr );
     481             :                 }
     482           0 :                 break;
     483             :             case typelib_TypeClass_SEQUENCE:
     484           0 :                 pDestAny->pData = &pDestAny->pReserved;
     485           0 :                 *(uno_Sequence **)pDestAny->pData = createEmptySequence();
     486           0 :                 break;
     487             :             case typelib_TypeClass_INTERFACE:
     488           0 :                 pDestAny->pData = &pDestAny->pReserved;
     489           0 :                 pDestAny->pReserved = 0; // either cpp or c-uno interface
     490           0 :                 break;
     491             :             default:
     492             :                 OSL_ASSERT(false);
     493           0 :                 break;
     494             :             }
     495             :         }
     496             :     }
     497             : }
     498             : //------------------------------------------------------------------------------
     499      222042 : inline uno_Sequence * icopyConstructSequence(
     500             :     uno_Sequence * pSource,
     501             :     typelib_TypeDescriptionReference * pElementType,
     502             :     uno_AcquireFunc acquire, uno_Mapping * mapping )
     503             : {
     504      222042 :     typelib_TypeClass eTypeClass = pElementType->eTypeClass;
     505      222042 :     if (!mapping ||
     506             :         (eTypeClass <= typelib_TypeClass_ENUM &&
     507             :          eTypeClass != typelib_TypeClass_ANY))
     508             :     {
     509      218524 :         osl_atomic_increment( &pSource->nRefCount );
     510      218524 :         return pSource;
     511             :     }
     512             :     else // create new sequence
     513             :     {
     514             :         uno_Sequence * pDest;
     515        3518 :         sal_Int32 nElements = pSource->nElements;
     516        3518 :         if (nElements)
     517             :         {
     518        3506 :             switch (eTypeClass)
     519             :             {
     520             :             case typelib_TypeClass_ANY:
     521             :             {
     522        3380 :                 pDest = allocSeq( sizeof (uno_Any), nElements );
     523        3380 :                 if (pDest != 0)
     524             :                 {
     525        3380 :                     uno_Any * pDestElements = (uno_Any *)pDest->elements;
     526        3380 :                     uno_Any * pSourceElements = (uno_Any *)pSource->elements;
     527       13754 :                     for ( sal_Int32 nPos = nElements; nPos--; )
     528             :                     {
     529             :                         typelib_TypeDescriptionReference * pType =
     530        6994 :                             pSourceElements[nPos].pType;
     531        6994 :                         if (typelib_TypeClass_VOID == pType->eTypeClass)
     532             :                         {
     533           0 :                             CONSTRUCT_EMPTY_ANY( &pDestElements[nPos] );
     534             :                         }
     535             :                         else
     536             :                         {
     537             :                             _copyConstructAnyFromData(
     538             :                                 &pDestElements[nPos],
     539        6994 :                                 pSourceElements[nPos].pData,
     540             :                                 pType, 0,
     541        6994 :                                 acquire, mapping );
     542             :                         }
     543             :                     }
     544             :                 }
     545        3380 :                 break;
     546             :             }
     547             :             case typelib_TypeClass_STRUCT:
     548             :             case typelib_TypeClass_EXCEPTION:
     549             :             {
     550          78 :                 typelib_TypeDescription * pElementTypeDescr = 0;
     551          78 :                 TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType );
     552          78 :                 sal_Int32 nElementSize = pElementTypeDescr->nSize;
     553          78 :                 char * pSourceElements = pSource->elements;
     554          78 :                 pDest = allocSeq( nElementSize, nElements );
     555          78 :                 if (pDest != 0)
     556             :                 {
     557          78 :                     char * pElements = pDest->elements;
     558         280 :                     for ( sal_Int32 nPos = nElements; nPos--; )
     559             :                     {
     560             :                         _copyConstructStruct(
     561         124 :                             pElements + (nPos * nElementSize),
     562         124 :                             pSourceElements + (nPos * nElementSize),
     563             :                             (typelib_CompoundTypeDescription *)
     564             :                             pElementTypeDescr,
     565         372 :                             acquire, mapping );
     566             :                     }
     567             :                 }
     568          78 :                 TYPELIB_DANGER_RELEASE( pElementTypeDescr );
     569             :                 break;
     570             :             }
     571             :             case typelib_TypeClass_ARRAY:
     572             :             {
     573           0 :                 typelib_TypeDescription * pElementTypeDescr = 0;
     574           0 :                 TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType );
     575           0 :                 sal_Int32 nElementSize = pElementTypeDescr->nSize;
     576           0 :                 char * pSourceElements = pSource->elements;
     577           0 :                 pDest = allocSeq( nElementSize, nElements );
     578           0 :                 if (pDest != 0)
     579             :                 {
     580           0 :                     char * pElements = pDest->elements;
     581           0 :                     for ( sal_Int32 nPos = nElements; nPos--; )
     582             :                     {
     583             :                         _copyConstructArray(
     584           0 :                             pElements + (nPos * nElementSize),
     585           0 :                             pSourceElements + (nPos * nElementSize),
     586             :                             (typelib_ArrayTypeDescription *)pElementTypeDescr,
     587           0 :                             acquire, mapping );
     588             :                     }
     589             :                 }
     590           0 :                 TYPELIB_DANGER_RELEASE( pElementTypeDescr );
     591             :                 break;
     592             :             }
     593             :             case typelib_TypeClass_UNION:
     594             :             {
     595           0 :                 typelib_TypeDescription * pElementTypeDescr = 0;
     596           0 :                 TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType );
     597           0 :                 sal_Int32 nElementSize = pElementTypeDescr->nSize;
     598             :                 sal_Int32 nValueOffset =
     599             :                     ((typelib_UnionTypeDescription *)
     600           0 :                      pElementTypeDescr)->nValueOffset;
     601           0 :                 pDest = allocSeq( nElementSize, nElements );
     602           0 :                 if (pDest != 0)
     603             :                 {
     604           0 :                     char * pElements = pDest->elements;
     605           0 :                     char * pSourceElements = pSource->elements;
     606           0 :                     for ( sal_Int32 nPos = nElements; nPos--; )
     607             :                     {
     608             :                         char * pDest2 =
     609           0 :                             pElements + (nPos * nElementSize);
     610             :                         char * pSource2 =
     611           0 :                             pSourceElements + (nPos * nElementSize);
     612             : 
     613             :                         typelib_TypeDescriptionReference * pSetType =
     614           0 :                             _unionGetSetType( pSource2, pElementTypeDescr );
     615             :                         ::uno_type_copyAndConvertData(
     616           0 :                             pDest2 + nValueOffset, pSource2 + nValueOffset,
     617           0 :                             pSetType, mapping );
     618           0 :                         *(sal_Int64 *)pDest2 = *(sal_Int64 *)pSource2;
     619           0 :                         ::typelib_typedescriptionreference_release( pSetType );
     620             :                     }
     621             :                 }
     622           0 :                 TYPELIB_DANGER_RELEASE( pElementTypeDescr );
     623             :                 break;
     624             :             }
     625             :             case typelib_TypeClass_SEQUENCE: // sequence of sequence
     626             :             {
     627          30 :                 pDest = allocSeq( sizeof (uno_Sequence *), nElements );
     628          30 :                 if (pDest != 0)
     629             :                 {
     630          30 :                     typelib_TypeDescription * pElementTypeDescr = 0;
     631          30 :                     TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType );
     632             :                     typelib_TypeDescriptionReference * pSeqElementType =
     633             :                         ((typelib_IndirectTypeDescription *)
     634          30 :                          pElementTypeDescr)->pType;
     635             : 
     636             :                     uno_Sequence ** pDestElements =
     637          30 :                         (uno_Sequence **) pDest->elements;
     638             :                     uno_Sequence ** pSourceElements =
     639          30 :                         (uno_Sequence **) pSource->elements;
     640         110 :                     for ( sal_Int32 nPos = nElements; nPos--; )
     641             :                     {
     642             :                         uno_Sequence * pNew = copyConstructSequence(
     643          50 :                             pSourceElements[nPos],
     644             :                             pSeqElementType,
     645          50 :                             acquire, mapping );
     646             :                         OSL_ASSERT( pNew != 0 );
     647             :                         // ought never be a memory allocation problem,
     648             :                         // because of reference counted sequence handles
     649          50 :                         pDestElements[ nPos ] = pNew;
     650             :                     }
     651             : 
     652          30 :                     TYPELIB_DANGER_RELEASE( pElementTypeDescr );
     653             :                 }
     654          30 :                 break;
     655             :             }
     656             :             case typelib_TypeClass_INTERFACE:
     657             :             {
     658          18 :                 pDest = allocSeq( sizeof (void *), nElements );
     659          18 :                 if (pDest != 0)
     660             :                 {
     661          18 :                     char * pElements = pDest->elements;
     662          18 :                     void ** pSourceElements = (void **)pSource->elements;
     663          18 :                     if (mapping)
     664             :                     {
     665          18 :                         typelib_TypeDescription * pElementTypeDescr = 0;
     666          18 :                         TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType );
     667          74 :                         for ( sal_Int32 nPos = nElements; nPos--; )
     668             :                         {
     669          38 :                             ((void **)pElements)[nPos] = 0;
     670          38 :                             if (((void **)pSourceElements)[nPos])
     671             :                             {
     672             :                                 (*mapping->mapInterface)(
     673             :                                     mapping, (void **)pElements + nPos,
     674          34 :                                     pSourceElements[nPos],
     675             :                                     (typelib_InterfaceTypeDescription *)
     676          68 :                                     pElementTypeDescr );
     677             :                             }
     678             :                         }
     679          18 :                         TYPELIB_DANGER_RELEASE( pElementTypeDescr );
     680             :                     }
     681             :                     else
     682             :                     {
     683           0 :                         for ( sal_Int32 nPos = nElements; nPos--; )
     684             :                         {
     685           0 :                             ((void **)pElements)[nPos] = pSourceElements[nPos];
     686           0 :                             _acquire( ((void **)pElements)[nPos], acquire );
     687             :                         }
     688             :                     }
     689             :                 }
     690          18 :                 break;
     691             :             }
     692             :             default:
     693             :                 OSL_FAIL( "### unexepcted sequence element type!" );
     694           0 :                 pDest = 0;
     695           0 :                 break;
     696             :             }
     697             :         }
     698             :         else // empty sequence
     699             :         {
     700          12 :             pDest = allocSeq( 0, 0 );
     701             :         }
     702             : 
     703        3518 :         return pDest;
     704             :     }
     705             : }
     706             : 
     707             : //--------------------------------------------------------------------------------------------------
     708     3188822 : inline void _copyConstructData(
     709             :     void * pDest, void * pSource,
     710             :     typelib_TypeDescriptionReference * pType, typelib_TypeDescription * pTypeDescr,
     711             :     uno_AcquireFunc acquire, uno_Mapping * mapping )
     712             :     SAL_THROW (())
     713             : {
     714     3188822 :     switch (pType->eTypeClass)
     715             :     {
     716             :     case typelib_TypeClass_CHAR:
     717         189 :         *(sal_Unicode *)pDest = *(sal_Unicode *)pSource;
     718         189 :         break;
     719             :     case typelib_TypeClass_BOOLEAN:
     720        7561 :         *(sal_Bool *)pDest = (*(sal_Bool *)pSource != sal_False);
     721        7561 :         break;
     722             :     case typelib_TypeClass_BYTE:
     723         128 :         *(sal_Int8 *)pDest = *(sal_Int8 *)pSource;
     724         128 :         break;
     725             :     case typelib_TypeClass_SHORT:
     726             :     case typelib_TypeClass_UNSIGNED_SHORT:
     727      134560 :         *(sal_Int16 *)pDest = *(sal_Int16 *)pSource;
     728      134560 :         break;
     729             :     case typelib_TypeClass_LONG:
     730             :     case typelib_TypeClass_UNSIGNED_LONG:
     731      766075 :         *(sal_Int32 *)pDest = *(sal_Int32 *)pSource;
     732      766075 :         break;
     733             :     case typelib_TypeClass_HYPER:
     734             :     case typelib_TypeClass_UNSIGNED_HYPER:
     735         256 :         *(sal_Int64 *)pDest = *(sal_Int64 *)pSource;
     736         256 :         break;
     737             :     case typelib_TypeClass_FLOAT:
     738         668 :         *(float *)pDest = *(float *)pSource;
     739         668 :         break;
     740             :     case typelib_TypeClass_DOUBLE:
     741       21888 :         *(double *)pDest = *(double *)pSource;
     742       21888 :         break;
     743             :     case typelib_TypeClass_STRING:
     744      842088 :         ::rtl_uString_acquire( *(rtl_uString **)pSource );
     745      842088 :         *(rtl_uString **)pDest = *(rtl_uString **)pSource;
     746      842088 :         break;
     747             :     case typelib_TypeClass_TYPE:
     748       35707 :         TYPE_ACQUIRE( *(typelib_TypeDescriptionReference **)pSource );
     749       35707 :         *(typelib_TypeDescriptionReference **)pDest = *(typelib_TypeDescriptionReference **)pSource;
     750       35707 :         break;
     751             :     case typelib_TypeClass_ANY:
     752             :         _copyConstructAny(
     753             :             (uno_Any *)pDest, ((uno_Any *)pSource)->pData,
     754             :             ((uno_Any *)pSource)->pType, 0,
     755      652659 :             acquire, mapping );
     756      652659 :         break;
     757             :     case typelib_TypeClass_ENUM:
     758      657845 :         *(sal_Int32 *)pDest = *(sal_Int32 *)pSource;
     759      657845 :         break;
     760             :     case typelib_TypeClass_STRUCT:
     761             :     case typelib_TypeClass_EXCEPTION:
     762       19539 :         if (pTypeDescr)
     763             :         {
     764             :             _copyConstructStruct(
     765             :                 pDest, pSource,
     766             :                 (typelib_CompoundTypeDescription *)pTypeDescr,
     767        1697 :                 acquire, mapping );
     768             :         }
     769             :         else
     770             :         {
     771       17842 :             TYPELIB_DANGER_GET( &pTypeDescr, pType );
     772             :             _copyConstructStruct(
     773             :                 pDest, pSource,
     774             :                 (typelib_CompoundTypeDescription *)pTypeDescr,
     775       17842 :                 acquire, mapping );
     776       17842 :             TYPELIB_DANGER_RELEASE( pTypeDescr );
     777             :         }
     778       19539 :         break;
     779             :     case typelib_TypeClass_ARRAY:
     780           0 :         if (pTypeDescr)
     781             :         {
     782             :             _copyConstructArray(
     783             :                 pDest, pSource,
     784             :                 (typelib_ArrayTypeDescription *)pTypeDescr,
     785           0 :                 acquire, mapping );
     786             :         }
     787             :         else
     788             :         {
     789           0 :             TYPELIB_DANGER_GET( &pTypeDescr, pType );
     790             :             _copyConstructArray(
     791             :                 pDest, pSource,
     792             :                 (typelib_ArrayTypeDescription *)pTypeDescr,
     793           0 :                 acquire, mapping );
     794           0 :             TYPELIB_DANGER_RELEASE( pTypeDescr );
     795             :         }
     796           0 :         break;
     797             :     case typelib_TypeClass_UNION:
     798           0 :         if (pTypeDescr)
     799             :         {
     800           0 :             _copyConstructUnion( pDest, pSource, pTypeDescr, acquire, mapping );
     801             :         }
     802             :         else
     803             :         {
     804           0 :             TYPELIB_DANGER_GET( &pTypeDescr, pType );
     805           0 :             _copyConstructUnion( pDest, pSource, pTypeDescr, acquire, mapping );
     806           0 :             TYPELIB_DANGER_RELEASE( pTypeDescr );
     807             :         }
     808           0 :         break;
     809             :     case typelib_TypeClass_SEQUENCE:
     810       25956 :         if (mapping)
     811             :         {
     812        3498 :             if (pTypeDescr)
     813             :             {
     814             :                 *(uno_Sequence **)pDest = icopyConstructSequence(
     815             :                     *(uno_Sequence **)pSource,
     816             :                     ((typelib_IndirectTypeDescription *)pTypeDescr)->pType,
     817          86 :                     acquire, mapping );
     818             :             }
     819             :             else
     820             :             {
     821        3412 :                 TYPELIB_DANGER_GET( &pTypeDescr, pType );
     822             :                 *(uno_Sequence **)pDest = icopyConstructSequence(
     823             :                     *(uno_Sequence **)pSource,
     824             :                     ((typelib_IndirectTypeDescription *)pTypeDescr)->pType,
     825        3412 :                     acquire, mapping );
     826        3412 :                 TYPELIB_DANGER_RELEASE( pTypeDescr );
     827             :             }
     828             :         }
     829             :         else
     830             :         {
     831       22458 :             osl_atomic_increment( &(*(uno_Sequence **)pSource)->nRefCount );
     832       22458 :             *(uno_Sequence **)pDest = *(uno_Sequence **)pSource;
     833             :         }
     834       25956 :         break;
     835             :     case typelib_TypeClass_INTERFACE:
     836       23703 :         if (mapping)
     837        3788 :             *(void **)pDest = _map( *(void **)pSource, pType, pTypeDescr, mapping );
     838             :         else
     839       19915 :             _acquire( *(void **)pDest = *(void **)pSource, acquire );
     840       23703 :         break;
     841             :     default:
     842           0 :         break;
     843             :     }
     844     3188822 : }
     845             : 
     846             : }
     847             : 
     848             : #endif
     849             : 
     850             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10