LCOV - code coverage report
Current view: top level - cppu/source/uno - copy.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 240 270 88.9 %
Date: 2015-06-13 12:38:46 Functions: 6 6 100.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 INCLUDED_CPPU_SOURCE_UNO_COPY_HXX
      20             : #define INCLUDED_CPPU_SOURCE_UNO_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      745296 : inline uno_Sequence * allocSeq(
      35             :     sal_Int32 nElementSize, sal_Int32 nElements )
      36             : {
      37             :     OSL_ASSERT( nElements >= 0 && nElementSize >= 0 );
      38      745296 :     uno_Sequence * pSeq = 0;
      39      745296 :     sal_uInt32 nSize = calcSeqMemSize( nElementSize, nElements );
      40      745296 :     if (nSize > 0)
      41             :     {
      42      745296 :         pSeq = static_cast<uno_Sequence *>(rtl_allocateMemory( nSize ));
      43      745296 :         if (pSeq != 0)
      44             :         {
      45             :             // header init
      46      745296 :             pSeq->nRefCount = 1;
      47      745296 :             pSeq->nElements = nElements;
      48             :         }
      49             :     }
      50      745296 :     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             : 
      59    34183109 : inline void _copyConstructStruct(
      60             :     void * pDest, void * pSource,
      61             :     typelib_CompoundTypeDescription * pTypeDescr,
      62             :     uno_AcquireFunc acquire, uno_Mapping * mapping )
      63             : {
      64    34183109 :     if (pTypeDescr->pBaseTypeDescription)
      65             :     {
      66             :         // copy base value
      67     1209359 :         copyConstructStruct( pDest, pSource, pTypeDescr->pBaseTypeDescription, acquire, mapping );
      68             :     }
      69             : 
      70             :     // then copy members
      71    34183109 :     typelib_TypeDescriptionReference ** ppTypeRefs = pTypeDescr->ppTypeRefs;
      72    34183109 :     sal_Int32 * pMemberOffsets = pTypeDescr->pMemberOffsets;
      73    34183109 :     sal_Int32 nDescr = pTypeDescr->nMembers;
      74             : 
      75    34183109 :     if (mapping)
      76             :     {
      77     1410232 :         while (nDescr--)
      78             :         {
      79             :             ::uno_type_copyAndConvertData(
      80     1528904 :                 static_cast<char *>(pDest) + pMemberOffsets[nDescr],
      81     1528904 :                 static_cast<char *>(pSource) + pMemberOffsets[nDescr],
      82     3057808 :                 ppTypeRefs[nDescr], mapping );
      83             :         }
      84             :     }
      85             :     else
      86             :     {
      87   197537881 :         while (nDescr--)
      88             :         {
      89             :             ::uno_type_copyData(
      90   259634886 :                 static_cast<char *>(pDest) + pMemberOffsets[nDescr],
      91   259634886 :                 static_cast<char *>(pSource) + pMemberOffsets[nDescr],
      92   519269772 :                 ppTypeRefs[nDescr], acquire );
      93             :         }
      94             :     }
      95    34183109 : }
      96             : 
      97             : 
      98             : uno_Sequence * copyConstructSequence(
      99             :     uno_Sequence * pSource,
     100             :     typelib_TypeDescriptionReference * pElementType,
     101             :     uno_AcquireFunc acquire, uno_Mapping * mapping );
     102             : 
     103             : 
     104  3112970184 : inline void _copyConstructAnyFromData(
     105             :     uno_Any * pDestAny, void * pSource,
     106             :     typelib_TypeDescriptionReference * pType, typelib_TypeDescription * pTypeDescr,
     107             :     uno_AcquireFunc acquire, uno_Mapping * mapping )
     108             : {
     109  3112970184 :     TYPE_ACQUIRE( pType );
     110  3112970184 :     pDestAny->pType = pType;
     111             : 
     112  3112970184 :     switch (pType->eTypeClass)
     113             :     {
     114             :     case typelib_TypeClass_CHAR:
     115         228 :         pDestAny->pData = &pDestAny->pReserved;
     116         228 :         *static_cast<sal_Unicode *>(pDestAny->pData) = *static_cast<sal_Unicode *>(pSource);
     117         228 :         break;
     118             :     case typelib_TypeClass_BOOLEAN:
     119   218929560 :         pDestAny->pData = &pDestAny->pReserved;
     120   218929560 :         *static_cast<sal_Bool *>(pDestAny->pData) = (*static_cast<sal_Bool *>(pSource) != sal_False);
     121   218929560 :         break;
     122             :     case typelib_TypeClass_BYTE:
     123      195119 :         pDestAny->pData = &pDestAny->pReserved;
     124      195119 :         *static_cast<sal_Int8 *>(pDestAny->pData) = *static_cast<sal_Int8 *>(pSource);
     125      195119 :         break;
     126             :     case typelib_TypeClass_SHORT:
     127             :     case typelib_TypeClass_UNSIGNED_SHORT:
     128     8288214 :         pDestAny->pData = &pDestAny->pReserved;
     129     8288214 :         *static_cast<sal_Int16 *>(pDestAny->pData) = *static_cast<sal_Int16 *>(pSource);
     130     8288214 :         break;
     131             :     case typelib_TypeClass_LONG:
     132             :     case typelib_TypeClass_UNSIGNED_LONG:
     133    16260553 :         pDestAny->pData = &pDestAny->pReserved;
     134    16260553 :         *static_cast<sal_Int32 *>(pDestAny->pData) = *static_cast<sal_Int32 *>(pSource);
     135    16260553 :         break;
     136             :     case typelib_TypeClass_HYPER:
     137             :     case typelib_TypeClass_UNSIGNED_HYPER:
     138             :         if (sizeof(void *) >= sizeof(sal_Int64))
     139      452831 :             pDestAny->pData = &pDestAny->pReserved;
     140             :         else
     141             :             pDestAny->pData = ::rtl_allocateMemory( sizeof(sal_Int64) );
     142      452831 :         *static_cast<sal_Int64 *>(pDestAny->pData) = *static_cast<sal_Int64 *>(pSource);
     143      452831 :         break;
     144             :     case typelib_TypeClass_FLOAT:
     145             :         if (sizeof(void *) >= sizeof(float))
     146     1357917 :             pDestAny->pData = &pDestAny->pReserved;
     147             :         else
     148             :             pDestAny->pData = ::rtl_allocateMemory( sizeof(float) );
     149     1357917 :         *static_cast<float *>(pDestAny->pData) = *static_cast<float *>(pSource);
     150     1357917 :         break;
     151             :     case typelib_TypeClass_DOUBLE:
     152             :         if (sizeof(void *) >= sizeof(double))
     153     3917803 :             pDestAny->pData = &pDestAny->pReserved;
     154             :         else
     155             :             pDestAny->pData = ::rtl_allocateMemory( sizeof(double) );
     156     3917803 :         *static_cast<double *>(pDestAny->pData) = *static_cast<double *>(pSource);
     157     3917803 :         break;
     158             :     case typelib_TypeClass_STRING:
     159   182199538 :         ::rtl_uString_acquire( *static_cast<rtl_uString **>(pSource) );
     160   182199537 :         pDestAny->pData = &pDestAny->pReserved;
     161   182199537 :         *static_cast<rtl_uString **>(pDestAny->pData) = *static_cast<rtl_uString **>(pSource);
     162   182199537 :         break;
     163             :     case typelib_TypeClass_TYPE:
     164       69283 :         TYPE_ACQUIRE( *static_cast<typelib_TypeDescriptionReference **>(pSource) );
     165       69283 :         pDestAny->pData = &pDestAny->pReserved;
     166       69283 :         *static_cast<typelib_TypeDescriptionReference **>(pDestAny->pData) = *static_cast<typelib_TypeDescriptionReference **>(pSource);
     167       69283 :         break;
     168             :     case typelib_TypeClass_ANY:
     169             :         OSL_FAIL( "### unexpected nested any!" );
     170           0 :         break;
     171             :     case typelib_TypeClass_ENUM:
     172     2277845 :         pDestAny->pData = &pDestAny->pReserved;
     173             :         // enum is forced to 32bit long
     174     2277845 :         *static_cast<sal_Int32 *>(pDestAny->pData) = *static_cast<sal_Int32 *>(pSource);
     175     2277845 :         break;
     176             :     case typelib_TypeClass_STRUCT:
     177             :     case typelib_TypeClass_EXCEPTION:
     178    31901882 :         if (pTypeDescr)
     179             :         {
     180       11608 :             pDestAny->pData = ::rtl_allocateMemory( pTypeDescr->nSize );
     181             :             _copyConstructStruct(
     182             :                 pDestAny->pData, pSource,
     183             :                 reinterpret_cast<typelib_CompoundTypeDescription *>(pTypeDescr),
     184       11608 :                 acquire, mapping );
     185             :         }
     186             :         else
     187             :         {
     188    31890274 :             TYPELIB_DANGER_GET( &pTypeDescr, pType );
     189    31890274 :             pDestAny->pData = ::rtl_allocateMemory( pTypeDescr->nSize );
     190             :             _copyConstructStruct(
     191             :                 pDestAny->pData, pSource,
     192             :                 reinterpret_cast<typelib_CompoundTypeDescription *>(pTypeDescr),
     193    31890274 :                 acquire, mapping );
     194    31890274 :             TYPELIB_DANGER_RELEASE( pTypeDescr );
     195             :         }
     196    31901882 :         break;
     197             :     case typelib_TypeClass_SEQUENCE:
     198    12268598 :         pDestAny->pData = &pDestAny->pReserved;
     199    12268598 :         if (pTypeDescr)
     200             :         {
     201             :             *static_cast<uno_Sequence **>(pDestAny->pData) = copyConstructSequence(
     202             :                 *static_cast<uno_Sequence **>(pSource),
     203             :                 reinterpret_cast<typelib_IndirectTypeDescription *>(pTypeDescr)->pType,
     204       15231 :                 acquire, mapping );
     205             :         }
     206             :         else
     207             :         {
     208    12253367 :             TYPELIB_DANGER_GET( &pTypeDescr, pType );
     209             :             *static_cast<uno_Sequence **>(pDestAny->pData) = copyConstructSequence(
     210             :                 *static_cast<uno_Sequence **>(pSource),
     211             :                 reinterpret_cast<typelib_IndirectTypeDescription *>(pTypeDescr)->pType,
     212    12253367 :                 acquire, mapping );
     213    12253367 :             TYPELIB_DANGER_RELEASE( pTypeDescr );
     214             :         }
     215    12268598 :         break;
     216             :     case typelib_TypeClass_INTERFACE:
     217  2634850813 :         pDestAny->pData = &pDestAny->pReserved;
     218  2634850813 :         if (mapping)
     219             :         {
     220      291416 :             pDestAny->pReserved = _map( *static_cast<void **>(pSource), pType, pTypeDescr, mapping );
     221             :         }
     222             :         else
     223             :         {
     224  2634559397 :             _acquire( pDestAny->pReserved = *static_cast<void **>(pSource), acquire );
     225             :         }
     226  2634850765 :         break;
     227             :     default:
     228             :         OSL_ASSERT(false);
     229           0 :         break;
     230             :     }
     231  3112970135 : }
     232             : 
     233  3242788543 : inline void _copyConstructAny(
     234             :     uno_Any * pDestAny, void * pSource,
     235             :     typelib_TypeDescriptionReference * pType, typelib_TypeDescription * pTypeDescr,
     236             :     uno_AcquireFunc acquire, uno_Mapping * mapping )
     237             : {
     238  3242788543 :     if (typelib_TypeClass_VOID == pType->eTypeClass)
     239             :     {
     240   125417511 :         CONSTRUCT_EMPTY_ANY( pDestAny );
     241             :     }
     242             :     else
     243             :     {
     244  3117371032 :         if (typelib_TypeClass_ANY == pType->eTypeClass)
     245             :         {
     246     5259518 :             if (pSource)
     247             :             {
     248     5259518 :                 pType = static_cast<uno_Any *>(pSource)->pType;
     249     5259518 :                 if (typelib_TypeClass_VOID == pType->eTypeClass)
     250             :                 {
     251     4550529 :                     CONSTRUCT_EMPTY_ANY( pDestAny );
     252     4550529 :                     return;
     253             :                 }
     254      708989 :                 pTypeDescr = 0;
     255      708989 :                 pSource = static_cast<uno_Any *>(pSource)->pData;
     256             :             }
     257             :             else
     258             :             {
     259           0 :                 CONSTRUCT_EMPTY_ANY( pDestAny );
     260           0 :                 return;
     261             :             }
     262             :         }
     263  3112820503 :         if (pSource)
     264             :         {
     265  3112754367 :             _copyConstructAnyFromData( pDestAny, pSource, pType, pTypeDescr, acquire, mapping );
     266             :         }
     267             :         else // default construct
     268             :         {
     269       66136 :             TYPE_ACQUIRE( pType );
     270       66136 :             pDestAny->pType = pType;
     271       66136 :             switch (pType->eTypeClass)
     272             :             {
     273             :             case typelib_TypeClass_CHAR:
     274           0 :                 pDestAny->pData = &pDestAny->pReserved;
     275           0 :                 *static_cast<sal_Unicode *>(pDestAny->pData) = '\0';
     276           0 :                 break;
     277             :             case typelib_TypeClass_BOOLEAN:
     278          18 :                 pDestAny->pData = &pDestAny->pReserved;
     279          18 :                 *static_cast<sal_Bool *>(pDestAny->pData) = sal_False;
     280          18 :                 break;
     281             :             case typelib_TypeClass_BYTE:
     282           0 :                 pDestAny->pData = &pDestAny->pReserved;
     283           0 :                 *static_cast<sal_Int8 *>(pDestAny->pData) = 0;
     284           0 :                 break;
     285             :             case typelib_TypeClass_SHORT:
     286             :             case typelib_TypeClass_UNSIGNED_SHORT:
     287          11 :                 pDestAny->pData = &pDestAny->pReserved;
     288          11 :                 *static_cast<sal_Int16 *>(pDestAny->pData) = 0;
     289          11 :                 break;
     290             :             case typelib_TypeClass_LONG:
     291             :             case typelib_TypeClass_UNSIGNED_LONG:
     292        3776 :                 pDestAny->pData = &pDestAny->pReserved;
     293        3776 :                 *static_cast<sal_Int32 *>(pDestAny->pData) = 0;
     294        3776 :                 break;
     295             :             case typelib_TypeClass_HYPER:
     296             :             case typelib_TypeClass_UNSIGNED_HYPER:
     297             :                 if (sizeof(void *) >= sizeof(sal_Int64))
     298           0 :                     pDestAny->pData = &pDestAny->pReserved;
     299             :                 else
     300             :                     pDestAny->pData = ::rtl_allocateMemory( sizeof(sal_Int64) );
     301           0 :                 *static_cast<sal_Int64 *>(pDestAny->pData) = 0;
     302           0 :                 break;
     303             :             case typelib_TypeClass_FLOAT:
     304             :                 if (sizeof(void *) >= sizeof(float))
     305           0 :                     pDestAny->pData = &pDestAny->pReserved;
     306             :                 else
     307             :                     pDestAny->pData = ::rtl_allocateMemory( sizeof(float) );
     308           0 :                 *static_cast<float *>(pDestAny->pData) = 0.0;
     309           0 :                 break;
     310             :             case typelib_TypeClass_DOUBLE:
     311             :                 if (sizeof(void *) >= sizeof(double))
     312           0 :                     pDestAny->pData = &pDestAny->pReserved;
     313             :                 else
     314             :                     pDestAny->pData = ::rtl_allocateMemory( sizeof(double) );
     315           0 :                 *static_cast<double *>(pDestAny->pData) = 0.0;
     316           0 :                 break;
     317             :             case typelib_TypeClass_STRING:
     318        2143 :                 pDestAny->pData = &pDestAny->pReserved;
     319        2143 :                 *static_cast<rtl_uString **>(pDestAny->pData) = 0;
     320        2143 :                 ::rtl_uString_new( static_cast<rtl_uString **>(pDestAny->pData) );
     321        2143 :                 break;
     322             :             case typelib_TypeClass_TYPE:
     323           0 :                 pDestAny->pData = &pDestAny->pReserved;
     324           0 :                 *static_cast<typelib_TypeDescriptionReference **>(pDestAny->pData) = _getVoidType();
     325           0 :                 break;
     326             :             case typelib_TypeClass_ENUM:
     327           2 :                 pDestAny->pData = &pDestAny->pReserved;
     328           2 :                 if (pTypeDescr)
     329             :                 {
     330           0 :                     *static_cast<sal_Int32 *>(pDestAny->pData) = reinterpret_cast<typelib_EnumTypeDescription *>(pTypeDescr)->nDefaultEnumValue;
     331             :                 }
     332             :                 else
     333             :                 {
     334           2 :                     TYPELIB_DANGER_GET( &pTypeDescr, pType );
     335           2 :                     *static_cast<sal_Int32 *>(pDestAny->pData) = reinterpret_cast<typelib_EnumTypeDescription *>(pTypeDescr)->nDefaultEnumValue;
     336           2 :                     TYPELIB_DANGER_RELEASE( pTypeDescr );
     337             :                 }
     338           2 :                 break;
     339             :             case typelib_TypeClass_STRUCT:
     340             :             case typelib_TypeClass_EXCEPTION:
     341          88 :                 if (pTypeDescr)
     342             :                 {
     343          88 :                     pDestAny->pData = ::rtl_allocateMemory( pTypeDescr->nSize );
     344             :                     _defaultConstructStruct(
     345          88 :                         pDestAny->pData, reinterpret_cast<typelib_CompoundTypeDescription *>(pTypeDescr) );
     346             :                 }
     347             :                 else
     348             :                 {
     349           0 :                     TYPELIB_DANGER_GET( &pTypeDescr, pType );
     350           0 :                     pDestAny->pData = ::rtl_allocateMemory( pTypeDescr->nSize );
     351             :                     _defaultConstructStruct(
     352           0 :                         pDestAny->pData, reinterpret_cast<typelib_CompoundTypeDescription *>(pTypeDescr) );
     353           0 :                     TYPELIB_DANGER_RELEASE( pTypeDescr );
     354             :                 }
     355          88 :                 break;
     356             :             case typelib_TypeClass_SEQUENCE:
     357       59898 :                 pDestAny->pData = &pDestAny->pReserved;
     358       59898 :                 *static_cast<uno_Sequence **>(pDestAny->pData) = createEmptySequence();
     359       59898 :                 break;
     360             :             case typelib_TypeClass_INTERFACE:
     361         200 :                 pDestAny->pData = &pDestAny->pReserved;
     362         200 :                 pDestAny->pReserved = 0; // either cpp or c-uno interface
     363         200 :                 break;
     364             :             default:
     365             :                 OSL_ASSERT(false);
     366           0 :                 break;
     367             :             }
     368             :         }
     369             :     }
     370             : }
     371             : 
     372    17462139 : inline uno_Sequence * icopyConstructSequence(
     373             :     uno_Sequence * pSource,
     374             :     typelib_TypeDescriptionReference * pElementType,
     375             :     uno_AcquireFunc acquire, uno_Mapping * mapping )
     376             : {
     377    17462139 :     typelib_TypeClass eTypeClass = pElementType->eTypeClass;
     378    17518282 :     if (!mapping ||
     379      106712 :         (eTypeClass <= typelib_TypeClass_ENUM &&
     380             :          eTypeClass != typelib_TypeClass_ANY))
     381             :     {
     382    17407742 :         osl_atomic_increment( &pSource->nRefCount );
     383    17407742 :         return pSource;
     384             :     }
     385             :     else // create new sequence
     386             :     {
     387             :         uno_Sequence * pDest;
     388       54397 :         sal_Int32 nElements = pSource->nElements;
     389       54397 :         if (nElements)
     390             :         {
     391       53249 :             switch (eTypeClass)
     392             :             {
     393             :             case typelib_TypeClass_ANY:
     394             :             {
     395       48603 :                 pDest = allocSeq( sizeof (uno_Any), nElements );
     396       48603 :                 if (pDest != 0)
     397             :                 {
     398       48603 :                     uno_Any * pDestElements = reinterpret_cast<uno_Any *>(pDest->elements);
     399       48603 :                     uno_Any * pSourceElements = reinterpret_cast<uno_Any *>(pSource->elements);
     400      316052 :                     for ( sal_Int32 nPos = nElements; nPos--; )
     401             :                     {
     402             :                         typelib_TypeDescriptionReference * pType =
     403      218846 :                             pSourceElements[nPos].pType;
     404      218846 :                         if (typelib_TypeClass_VOID == pType->eTypeClass)
     405             :                         {
     406        3441 :                             CONSTRUCT_EMPTY_ANY( &pDestElements[nPos] );
     407             :                         }
     408             :                         else
     409             :                         {
     410             :                             _copyConstructAnyFromData(
     411             :                                 &pDestElements[nPos],
     412      215405 :                                 pSourceElements[nPos].pData,
     413             :                                 pType, 0,
     414      215405 :                                 acquire, mapping );
     415             :                         }
     416             :                     }
     417             :                 }
     418       48603 :                 break;
     419             :             }
     420             :             case typelib_TypeClass_STRUCT:
     421             :             case typelib_TypeClass_EXCEPTION:
     422             :             {
     423        4311 :                 typelib_TypeDescription * pElementTypeDescr = 0;
     424        4311 :                 TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType );
     425        4311 :                 sal_Int32 nElementSize = pElementTypeDescr->nSize;
     426        4311 :                 char * pSourceElements = pSource->elements;
     427        4311 :                 pDest = allocSeq( nElementSize, nElements );
     428        4311 :                 if (pDest != 0)
     429             :                 {
     430        4311 :                     char * pElements = pDest->elements;
     431       24025 :                     for ( sal_Int32 nPos = nElements; nPos--; )
     432             :                     {
     433             :                         _copyConstructStruct(
     434       30806 :                             pElements + (nPos * nElementSize),
     435       30806 :                             pSourceElements + (nPos * nElementSize),
     436             :                             reinterpret_cast<typelib_CompoundTypeDescription *>(
     437             :                                 pElementTypeDescr),
     438       61612 :                             acquire, mapping );
     439             :                     }
     440             :                 }
     441        4311 :                 TYPELIB_DANGER_RELEASE( pElementTypeDescr );
     442        4311 :                 break;
     443             :             }
     444             :             case typelib_TypeClass_SEQUENCE: // sequence of sequence
     445             :             {
     446             :                 // coverity[suspicious_sizeof] - sizeof(uno_Sequence*) is correct here
     447         258 :                 pDest = allocSeq( sizeof (uno_Sequence *), nElements );
     448         258 :                 if (pDest != 0)
     449             :                 {
     450         258 :                     typelib_TypeDescription * pElementTypeDescr = 0;
     451         258 :                     TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType );
     452             :                     typelib_TypeDescriptionReference * pSeqElementType =
     453             :                         reinterpret_cast<typelib_IndirectTypeDescription *>(
     454         258 :                             pElementTypeDescr)->pType;
     455             : 
     456             :                     uno_Sequence ** pDestElements =
     457         258 :                         reinterpret_cast<uno_Sequence **>(pDest->elements);
     458             :                     uno_Sequence ** pSourceElements =
     459         258 :                         reinterpret_cast<uno_Sequence **>(pSource->elements);
     460        1651 :                     for ( sal_Int32 nPos = nElements; nPos--; )
     461             :                     {
     462             :                         uno_Sequence * pNew = copyConstructSequence(
     463        1135 :                             pSourceElements[nPos],
     464             :                             pSeqElementType,
     465        1135 :                             acquire, mapping );
     466             :                         OSL_ASSERT( pNew != 0 );
     467             :                         // ought never be a memory allocation problem,
     468             :                         // because of reference counted sequence handles
     469        1135 :                         pDestElements[ nPos ] = pNew;
     470             :                     }
     471             : 
     472         258 :                     TYPELIB_DANGER_RELEASE( pElementTypeDescr );
     473             :                 }
     474         258 :                 break;
     475             :             }
     476             :             case typelib_TypeClass_INTERFACE:
     477             :             {
     478          77 :                 pDest = allocSeq( sizeof (void *), nElements );
     479          77 :                 if (pDest != 0)
     480             :                 {
     481          77 :                     char * pElements = pDest->elements;
     482          77 :                     void ** pSourceElements = reinterpret_cast<void **>(pSource->elements);
     483          77 :                     typelib_TypeDescription * pElementTypeDescr = 0;
     484          77 :                     TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType );
     485         293 :                     for ( sal_Int32 nPos = nElements; nPos--; )
     486             :                     {
     487         139 :                         reinterpret_cast<void **>(pElements)[nPos] = 0;
     488         139 :                         if (pSourceElements[nPos])
     489             :                         {
     490             :                             (*mapping->mapInterface)(
     491             :                                 mapping, reinterpret_cast<void **>(pElements) + nPos,
     492         126 :                                 pSourceElements[nPos],
     493             :                                 reinterpret_cast<typelib_InterfaceTypeDescription *>(
     494         252 :                                     pElementTypeDescr) );
     495             :                         }
     496             :                     }
     497          77 :                     TYPELIB_DANGER_RELEASE( pElementTypeDescr );
     498             :                 }
     499          77 :                 break;
     500             :             }
     501             :             default:
     502             :                 OSL_FAIL( "### unexepcted sequence element type!" );
     503           0 :                 pDest = 0;
     504           0 :                 break;
     505             :             }
     506             :         }
     507             :         else // empty sequence
     508             :         {
     509        1148 :             pDest = allocSeq( 0, 0 );
     510             :         }
     511             : 
     512       54397 :         return pDest;
     513             :     }
     514             : }
     515             : 
     516             : 
     517   210989189 : inline void _copyConstructData(
     518             :     void * pDest, void * pSource,
     519             :     typelib_TypeDescriptionReference * pType, typelib_TypeDescription * pTypeDescr,
     520             :     uno_AcquireFunc acquire, uno_Mapping * mapping )
     521             : {
     522   210989189 :     switch (pType->eTypeClass)
     523             :     {
     524             :     case typelib_TypeClass_CHAR:
     525       15590 :         *static_cast<sal_Unicode *>(pDest) = *static_cast<sal_Unicode *>(pSource);
     526       15590 :         break;
     527             :     case typelib_TypeClass_BOOLEAN:
     528      431821 :         *static_cast<sal_Bool *>(pDest) = (*static_cast<sal_Bool *>(pSource) != sal_False);
     529      431821 :         break;
     530             :     case typelib_TypeClass_BYTE:
     531         528 :         *static_cast<sal_Int8 *>(pDest) = *static_cast<sal_Int8 *>(pSource);
     532         528 :         break;
     533             :     case typelib_TypeClass_SHORT:
     534             :     case typelib_TypeClass_UNSIGNED_SHORT:
     535     6884277 :         *static_cast<sal_Int16 *>(pDest) = *static_cast<sal_Int16 *>(pSource);
     536     6884277 :         break;
     537             :     case typelib_TypeClass_LONG:
     538             :     case typelib_TypeClass_UNSIGNED_LONG:
     539    49735983 :         *static_cast<sal_Int32 *>(pDest) = *static_cast<sal_Int32 *>(pSource);
     540    49735983 :         break;
     541             :     case typelib_TypeClass_HYPER:
     542             :     case typelib_TypeClass_UNSIGNED_HYPER:
     543         272 :         *static_cast<sal_Int64 *>(pDest) = *static_cast<sal_Int64 *>(pSource);
     544         272 :         break;
     545             :     case typelib_TypeClass_FLOAT:
     546      198039 :         *static_cast<float *>(pDest) = *static_cast<float *>(pSource);
     547      198039 :         break;
     548             :     case typelib_TypeClass_DOUBLE:
     549      631284 :         *static_cast<double *>(pDest) = *static_cast<double *>(pSource);
     550      631284 :         break;
     551             :     case typelib_TypeClass_STRING:
     552    58408153 :         ::rtl_uString_acquire( *static_cast<rtl_uString **>(pSource) );
     553    58408153 :         *static_cast<rtl_uString **>(pDest) = *static_cast<rtl_uString **>(pSource);
     554    58408153 :         break;
     555             :     case typelib_TypeClass_TYPE:
     556     2179921 :         TYPE_ACQUIRE( *static_cast<typelib_TypeDescriptionReference **>(pSource) );
     557     2179921 :         *static_cast<typelib_TypeDescriptionReference **>(pDest) = *static_cast<typelib_TypeDescriptionReference **>(pSource);
     558     2179921 :         break;
     559             :     case typelib_TypeClass_ANY:
     560             :         _copyConstructAny(
     561             :             static_cast<uno_Any *>(pDest), static_cast<uno_Any *>(pSource)->pData,
     562             :             static_cast<uno_Any *>(pSource)->pType, 0,
     563    45779320 :             acquire, mapping );
     564    45779320 :         break;
     565             :     case typelib_TypeClass_ENUM:
     566    44719627 :         *static_cast<sal_Int32 *>(pDest) = *static_cast<sal_Int32 *>(pSource);
     567    44719627 :         break;
     568             :     case typelib_TypeClass_STRUCT:
     569             :     case typelib_TypeClass_EXCEPTION:
     570     1012776 :         if (pTypeDescr)
     571             :         {
     572             :             _copyConstructStruct(
     573             :                 pDest, pSource,
     574             :                 reinterpret_cast<typelib_CompoundTypeDescription *>(pTypeDescr),
     575       26351 :                 acquire, mapping );
     576             :         }
     577             :         else
     578             :         {
     579      986425 :             TYPELIB_DANGER_GET( &pTypeDescr, pType );
     580             :             _copyConstructStruct(
     581             :                 pDest, pSource,
     582             :                 reinterpret_cast<typelib_CompoundTypeDescription *>(pTypeDescr),
     583      986425 :                 acquire, mapping );
     584      986425 :             TYPELIB_DANGER_RELEASE( pTypeDescr );
     585             :         }
     586     1012776 :         break;
     587             :     case typelib_TypeClass_SEQUENCE:
     588      479318 :         if (mapping)
     589             :         {
     590       51417 :             if (pTypeDescr)
     591             :             {
     592             :                 *static_cast<uno_Sequence **>(pDest) = icopyConstructSequence(
     593             :                     *static_cast<uno_Sequence **>(pSource),
     594             :                     reinterpret_cast<typelib_IndirectTypeDescription *>(pTypeDescr)->pType,
     595        8766 :                     acquire, mapping );
     596             :             }
     597             :             else
     598             :             {
     599       42651 :                 TYPELIB_DANGER_GET( &pTypeDescr, pType );
     600             :                 *static_cast<uno_Sequence **>(pDest) = icopyConstructSequence(
     601             :                     *static_cast<uno_Sequence **>(pSource),
     602             :                     reinterpret_cast<typelib_IndirectTypeDescription *>(pTypeDescr)->pType,
     603       42651 :                     acquire, mapping );
     604       42651 :                 TYPELIB_DANGER_RELEASE( pTypeDescr );
     605             :             }
     606             :         }
     607             :         else
     608             :         {
     609      427901 :             osl_atomic_increment( &(*static_cast<uno_Sequence **>(pSource))->nRefCount );
     610      427901 :             *static_cast<uno_Sequence **>(pDest) = *static_cast<uno_Sequence **>(pSource);
     611             :         }
     612      479318 :         break;
     613             :     case typelib_TypeClass_INTERFACE:
     614      512183 :         if (mapping)
     615      169627 :             *static_cast<void **>(pDest) = _map( *static_cast<void **>(pSource), pType, pTypeDescr, mapping );
     616             :         else
     617      342556 :             _acquire( *static_cast<void **>(pDest) = *static_cast<void **>(pSource), acquire );
     618      512183 :         break;
     619             :     default:
     620          97 :         break;
     621             :     }
     622   210989189 : }
     623             : 
     624             : }
     625             : 
     626             : #endif
     627             : 
     628             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11