LCOV - code coverage report
Current view: top level - cppu/source/uno - assign.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 142 213 66.7 %
Date: 2015-06-13 12:38:46 Functions: 4 4 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_ASSIGN_HXX
      20             : #define INCLUDED_CPPU_SOURCE_UNO_ASSIGN_HXX
      21             : 
      22             : #include <string.h>
      23             : 
      24             : #include "prim.hxx"
      25             : #include "destr.hxx"
      26             : #include "constr.hxx"
      27             : #include "copy.hxx"
      28             : 
      29             : 
      30             : namespace cppu
      31             : {
      32             : 
      33             : 
      34             : //#### assignment ##################################################################################
      35             : 
      36             : 
      37             : 
      38             : 
      39     1303366 : inline void _assignInterface(
      40             :     void ** ppDest, void * pSource,
      41             :     uno_AcquireFunc acquire, uno_ReleaseFunc release )
      42             : 
      43             : {
      44     1303366 :     _acquire( pSource, acquire );
      45     1303366 :     void * const pToBeReleased = *ppDest;
      46     1303366 :     *ppDest = pSource;
      47     1303366 :     _release( pToBeReleased, release );
      48     1303366 : }
      49             : 
      50    28224553 : inline void * _queryInterface(
      51             :     void * pSource,
      52             :     typelib_TypeDescriptionReference * pDestType,
      53             :     uno_QueryInterfaceFunc queryInterface )
      54             : {
      55    28224553 :     if (pSource)
      56             :     {
      57    28224553 :         if (0 == queryInterface)
      58           0 :             queryInterface = binuno_queryInterface;
      59    28224553 :         pSource = (*queryInterface)( pSource, pDestType );
      60             :     }
      61    28224553 :     return pSource;
      62             : }
      63             : 
      64             : bool assignStruct(
      65             :     void * pDest, void * pSource,
      66             :     typelib_CompoundTypeDescription * pTypeDescr,
      67             :     uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release );
      68             : 
      69    28675854 : inline bool _assignStruct(
      70             :     void * pDest, void * pSource,
      71             :     typelib_CompoundTypeDescription * pTypeDescr,
      72             :     uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release )
      73             : {
      74    28675854 :     if (pTypeDescr->pBaseTypeDescription)
      75             :     {
      76             :         // copy base value
      77      144759 :         if (! assignStruct( pDest, pSource, pTypeDescr->pBaseTypeDescription,
      78      144759 :                             queryInterface, acquire, release ))
      79             :         {
      80           0 :             return false;
      81             :         }
      82             :     }
      83             :     // then copy members
      84    28675854 :     typelib_TypeDescriptionReference ** ppTypeRefs = pTypeDescr->ppTypeRefs;
      85    28675854 :     sal_Int32 * pMemberOffsets = pTypeDescr->pMemberOffsets;
      86    28675854 :     sal_Int32 nDescr = pTypeDescr->nMembers;
      87   171299053 :     while (nDescr--)
      88             :     {
      89   341842035 :         if (! ::uno_type_assignData( static_cast<char *>(pDest) + pMemberOffsets[nDescr],
      90   113947345 :                                      ppTypeRefs[nDescr],
      91   227894690 :                                      static_cast<char *>(pSource) + pMemberOffsets[nDescr],
      92   113947345 :                                      ppTypeRefs[nDescr],
      93   569736725 :                                      queryInterface, acquire, release ))
      94             :         {
      95           0 :             return false;
      96             :         }
      97             :     }
      98    28675854 :     return true;
      99             : }
     100             : 
     101   202190423 : inline bool _assignData(
     102             :     void * pDest,
     103             :     typelib_TypeDescriptionReference * pDestType, typelib_TypeDescription * pDestTypeDescr,
     104             :     void * pSource,
     105             :     typelib_TypeDescriptionReference * pSourceType, typelib_TypeDescription * pSourceTypeDescr,
     106             :     uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release )
     107             : {
     108   202190423 :     if (pDest == pSource)
     109           0 :         return _type_equals( pDestType, pSourceType );
     110             : 
     111   202190423 :     if (! pSource)
     112             :     {
     113           0 :         _destructData( pDest, pDestType, pDestTypeDescr, release );
     114           0 :         _defaultConstructData( pDest, pDestType, pDestTypeDescr );
     115           0 :         return true;
     116             :     }
     117   432160935 :     while (typelib_TypeClass_ANY == pSourceType->eTypeClass)
     118             :     {
     119    27780089 :         pSourceTypeDescr = 0;
     120    27780089 :         pSourceType = static_cast<uno_Any *>(pSource)->pType;
     121    27780089 :         pSource = static_cast<uno_Any *>(pSource)->pData;
     122    27780089 :         if (pDest == pSource)
     123           0 :             return true;
     124             :     }
     125             : 
     126   202190423 :     switch (pDestType->eTypeClass)
     127             :     {
     128             :     case typelib_TypeClass_VOID:
     129           0 :         return pSourceType->eTypeClass == typelib_TypeClass_VOID;
     130             :     case typelib_TypeClass_CHAR:
     131          12 :         switch (pSourceType->eTypeClass)
     132             :         {
     133             :         case typelib_TypeClass_CHAR:
     134          12 :             *static_cast<sal_Unicode *>(pDest) = *static_cast<sal_Unicode *>(pSource);
     135          12 :             return true;
     136             :         default:
     137           0 :             return false;
     138             :         }
     139             :     case typelib_TypeClass_BOOLEAN:
     140      157394 :         switch (pSourceType->eTypeClass)
     141             :         {
     142             :         case typelib_TypeClass_BOOLEAN:
     143      157376 :             *static_cast<sal_Bool *>(pDest) = (*static_cast<sal_Bool *>(pSource) != sal_False);
     144      157376 :             return true;
     145             :         default:
     146          18 :             return false;
     147             :         }
     148             :     case typelib_TypeClass_BYTE:
     149          15 :         switch (pSourceType->eTypeClass)
     150             :         {
     151             :         case typelib_TypeClass_BYTE:
     152          15 :             *static_cast<sal_Int8 *>(pDest) = *static_cast<sal_Int8 *>(pSource);
     153          15 :             return true;
     154             :         default:
     155           0 :             return false;
     156             :         }
     157             :     case typelib_TypeClass_SHORT:
     158      651355 :         switch (pSourceType->eTypeClass)
     159             :         {
     160             :         case typelib_TypeClass_BYTE:
     161          29 :             *static_cast<sal_Int16 *>(pDest) = *static_cast<sal_Int8 *>(pSource);
     162          29 :             return true;
     163             :         case typelib_TypeClass_SHORT:
     164             :         case typelib_TypeClass_UNSIGNED_SHORT:
     165      651315 :             *static_cast<sal_Int16 *>(pDest) = *static_cast<sal_Int16 *>(pSource);
     166      651315 :             return true;
     167             :         default:
     168          11 :             return false;
     169             :         }
     170             :     case typelib_TypeClass_UNSIGNED_SHORT:
     171       21959 :         switch (pSourceType->eTypeClass)
     172             :         {
     173             :         case typelib_TypeClass_BYTE:
     174           0 :             *static_cast<sal_uInt16 *>(pDest) = *static_cast<sal_Int8 *>(pSource);
     175           0 :             return true;
     176             :         case typelib_TypeClass_SHORT:
     177             :         case typelib_TypeClass_UNSIGNED_SHORT:
     178       21959 :             *static_cast<sal_uInt16 *>(pDest) = *static_cast<sal_uInt16 *>(pSource);
     179       21959 :             return true;
     180             :         default:
     181           0 :             return false;
     182             :         }
     183             :     case typelib_TypeClass_LONG:
     184    28279219 :         switch (pSourceType->eTypeClass)
     185             :         {
     186             :         case typelib_TypeClass_BYTE:
     187         167 :             *static_cast<sal_Int32 *>(pDest) = *static_cast<sal_Int8 *>(pSource);
     188         167 :             return true;
     189             :         case typelib_TypeClass_SHORT:
     190         246 :             *static_cast<sal_Int32 *>(pDest) = *static_cast<sal_Int16 *>(pSource);
     191         246 :             return true;
     192             :         case typelib_TypeClass_UNSIGNED_SHORT:
     193           0 :             *static_cast<sal_Int32 *>(pDest) = *static_cast<sal_uInt16 *>(pSource);
     194           0 :             return true;
     195             :         case typelib_TypeClass_LONG:
     196             :         case typelib_TypeClass_UNSIGNED_LONG:
     197    28275274 :             *static_cast<sal_Int32 *>(pDest) = *static_cast<sal_Int32 *>(pSource);
     198    28275274 :             return true;
     199             :         default:
     200        3532 :             return false;
     201             :         }
     202             :     case typelib_TypeClass_UNSIGNED_LONG:
     203       51985 :         switch (pSourceType->eTypeClass)
     204             :         {
     205             :         case typelib_TypeClass_BYTE:
     206           4 :             *static_cast<sal_uInt32 *>(pDest) = *static_cast<sal_Int8 *>(pSource);
     207           4 :             return true;
     208             :         case typelib_TypeClass_SHORT:
     209           0 :             *static_cast<sal_uInt32 *>(pDest) = *static_cast<sal_Int16 *>(pSource);
     210           0 :             return true;
     211             :         case typelib_TypeClass_UNSIGNED_SHORT:
     212           0 :             *static_cast<sal_uInt32 *>(pDest) = *static_cast<sal_uInt16 *>(pSource);
     213           0 :             return true;
     214             :         case typelib_TypeClass_LONG:
     215             :         case typelib_TypeClass_UNSIGNED_LONG:
     216       51981 :             *static_cast<sal_uInt32 *>(pDest) = *static_cast<sal_uInt32 *>(pSource);
     217       51981 :             return true;
     218             :         default:
     219           0 :             return false;
     220             :         }
     221             :     case typelib_TypeClass_HYPER:
     222           1 :         switch (pSourceType->eTypeClass)
     223             :         {
     224             :         case typelib_TypeClass_BYTE:
     225           0 :             *static_cast<sal_Int64 *>(pDest) = *static_cast<sal_Int8 *>(pSource);
     226           0 :             return true;
     227             :         case typelib_TypeClass_SHORT:
     228           0 :             *static_cast<sal_Int64 *>(pDest) = *static_cast<sal_Int16 *>(pSource);
     229           0 :             return true;
     230             :         case typelib_TypeClass_UNSIGNED_SHORT:
     231           0 :             *static_cast<sal_Int64 *>(pDest) = *static_cast<sal_uInt16 *>(pSource);
     232           0 :             return true;
     233             :         case typelib_TypeClass_LONG:
     234           0 :             *static_cast<sal_Int64 *>(pDest) = *static_cast<sal_Int32 *>(pSource);
     235           0 :             return true;
     236             :         case typelib_TypeClass_UNSIGNED_LONG:
     237           0 :             *static_cast<sal_Int64 *>(pDest) = *static_cast<sal_uInt32 *>(pSource);
     238           0 :             return true;
     239             :         case typelib_TypeClass_HYPER:
     240             :         case typelib_TypeClass_UNSIGNED_HYPER:
     241           1 :             *static_cast<sal_Int64 *>(pDest) = *static_cast<sal_Int64 *>(pSource);
     242           1 :             return true;
     243             :         default:
     244           0 :             return false;
     245             :         }
     246             :     case typelib_TypeClass_UNSIGNED_HYPER:
     247        4368 :         switch (pSourceType->eTypeClass)
     248             :         {
     249             :         case typelib_TypeClass_BYTE:
     250           0 :             *static_cast<sal_uInt64 *>(pDest) = *static_cast<sal_Int8 *>(pSource);
     251           0 :             return true;
     252             :         case typelib_TypeClass_SHORT:
     253           0 :             *static_cast<sal_uInt64 *>(pDest) = *static_cast<sal_Int16 *>(pSource);
     254           0 :             return true;
     255             :         case typelib_TypeClass_UNSIGNED_SHORT:
     256           0 :             *static_cast<sal_uInt64 *>(pDest) = *static_cast<sal_uInt16 *>(pSource);
     257           0 :             return true;
     258             :         case typelib_TypeClass_LONG:
     259           0 :             *static_cast<sal_uInt64 *>(pDest) = *static_cast<sal_Int32 *>(pSource);
     260           0 :             return true;
     261             :         case typelib_TypeClass_UNSIGNED_LONG:
     262           0 :             *static_cast<sal_uInt64 *>(pDest) = *static_cast<sal_uInt32 *>(pSource);
     263           0 :             return true;
     264             :         case typelib_TypeClass_HYPER:
     265             :         case typelib_TypeClass_UNSIGNED_HYPER:
     266        4368 :             *static_cast<sal_uInt64 *>(pDest) = *static_cast<sal_uInt64 *>(pSource);
     267        4368 :             return true;
     268             :         default:
     269           0 :             return false;
     270             :         }
     271             :     case typelib_TypeClass_FLOAT:
     272      118169 :         switch (pSourceType->eTypeClass)
     273             :         {
     274             :         case typelib_TypeClass_BYTE:
     275           0 :             *static_cast<float *>(pDest) = *static_cast<sal_Int8 *>(pSource);
     276           0 :             return true;
     277             :         case typelib_TypeClass_SHORT:
     278           0 :             *static_cast<float *>(pDest) = *static_cast<sal_Int16 *>(pSource);
     279           0 :             return true;
     280             :         case typelib_TypeClass_UNSIGNED_SHORT:
     281           0 :             *static_cast<float *>(pDest) = *static_cast<sal_uInt16 *>(pSource);
     282           0 :             return true;
     283             :         case typelib_TypeClass_FLOAT:
     284      118169 :             *static_cast<float *>(pDest) = *static_cast<float *>(pSource);
     285      118169 :             return true;
     286             :         default:
     287           0 :             return false;
     288             :         }
     289             :     case typelib_TypeClass_DOUBLE:
     290      463887 :         switch (pSourceType->eTypeClass)
     291             :         {
     292             :         case typelib_TypeClass_BYTE:
     293           0 :             *static_cast<double *>(pDest) = *static_cast<sal_Int8 *>(pSource);
     294           0 :             return true;
     295             :         case typelib_TypeClass_SHORT:
     296           0 :             *static_cast<double *>(pDest) = *static_cast<sal_Int16 *>(pSource);
     297           0 :             return true;
     298             :         case typelib_TypeClass_UNSIGNED_SHORT:
     299           0 :             *static_cast<double *>(pDest) = *static_cast<sal_uInt16 *>(pSource);
     300           0 :             return true;
     301             :         case typelib_TypeClass_LONG:
     302           0 :             *static_cast<double *>(pDest) = *static_cast<sal_Int32 *>(pSource);
     303           0 :             return true;
     304             :         case typelib_TypeClass_UNSIGNED_LONG:
     305           0 :             *static_cast<double *>(pDest) = *static_cast<sal_uInt32 *>(pSource);
     306           0 :             return true;
     307             :         case typelib_TypeClass_FLOAT:
     308           0 :             *static_cast<double *>(pDest) = *static_cast<float *>(pSource);
     309           0 :             return true;
     310             :         case typelib_TypeClass_DOUBLE:
     311      463887 :             *static_cast<double *>(pDest) = *static_cast<double *>(pSource);
     312      463887 :             return true;
     313             :         default:
     314           0 :             return false;
     315             :         }
     316             :     case typelib_TypeClass_STRING:
     317    28240291 :         switch (pSourceType->eTypeClass)
     318             :         {
     319             :         case typelib_TypeClass_STRING:
     320    28238148 :             ::rtl_uString_assign( static_cast<rtl_uString **>(pDest), *static_cast<rtl_uString **>(pSource) );
     321    28238148 :             return true;
     322             :         default:
     323        2143 :             return false;
     324             :         }
     325             :     case typelib_TypeClass_TYPE:
     326         365 :         switch (pSourceType->eTypeClass)
     327             :         {
     328             :         case typelib_TypeClass_TYPE:
     329             :         {
     330         364 :             typelib_TypeDescriptionReference ** pp = static_cast<typelib_TypeDescriptionReference **>(pDest);
     331         364 :             ::typelib_typedescriptionreference_release( *pp );
     332         364 :             *pp = *static_cast<typelib_TypeDescriptionReference **>(pSource);
     333         364 :             TYPE_ACQUIRE( *pp );
     334         364 :             return true;
     335             :         }
     336             :         default:
     337           1 :             return false;
     338             :         }
     339             :     case typelib_TypeClass_ANY:
     340    27780111 :         _destructAny( static_cast<uno_Any *>(pDest), release );
     341    27780111 :         _copyConstructAny( static_cast<uno_Any *>(pDest), pSource, pSourceType, pSourceTypeDescr, acquire, 0 );
     342    27780111 :         return true;
     343             :     case typelib_TypeClass_ENUM:
     344    28146245 :         if (_type_equals( pDestType, pSourceType ))
     345             :         {
     346    28139702 :             *static_cast<sal_Int32 *>(pDest) = *static_cast<sal_Int32 *>(pSource);
     347    28139702 :             return true;
     348             :         }
     349        6543 :         return false;
     350             :     case typelib_TypeClass_STRUCT:
     351             :     case typelib_TypeClass_EXCEPTION:
     352    56170750 :         if (typelib_TypeClass_STRUCT == pSourceType->eTypeClass ||
     353      426378 :             typelib_TypeClass_EXCEPTION == pSourceType->eTypeClass)
     354             :         {
     355    55318534 :             bool bRet = false;
     356    55318534 :             if (pSourceTypeDescr)
     357             :             {
     358             :                 typelib_CompoundTypeDescription * pTypeDescr =
     359          24 :                     reinterpret_cast<typelib_CompoundTypeDescription *>(pSourceTypeDescr);
     360          72 :                 while (pTypeDescr &&
     361          24 :                        !_type_equals(pTypeDescr->aBase.pWeakRef, pDestType))
     362             :                 {
     363           0 :                     pTypeDescr = pTypeDescr->pBaseTypeDescription;
     364             :                 }
     365          24 :                 if (pTypeDescr)
     366             :                 {
     367             :                     bRet = _assignStruct(
     368          24 :                         pDest, pSource, pTypeDescr, queryInterface, acquire, release );
     369             :                 }
     370             :             }
     371             :             else
     372             :             {
     373    55318510 :                 TYPELIB_DANGER_GET( &pSourceTypeDescr, pSourceType );
     374             :                 typelib_CompoundTypeDescription * pTypeDescr =
     375    55318510 :                     reinterpret_cast<typelib_CompoundTypeDescription *>(pSourceTypeDescr);
     376   192751611 :                 while (pTypeDescr &&
     377    55322831 :                        !_type_equals(pTypeDescr->aBase.pWeakRef, pDestType))
     378             :                 {
     379    26791760 :                     pTypeDescr = pTypeDescr->pBaseTypeDescription;
     380             :                 }
     381    55318510 :                 if (pTypeDescr)
     382             :                 {
     383             :                     bRet = _assignStruct(
     384    28531071 :                         pDest, pSource, pTypeDescr, queryInterface, acquire, release );
     385             :                 }
     386    55318510 :                 TYPELIB_DANGER_RELEASE( pSourceTypeDescr );
     387             :             }
     388    55318534 :             return bRet;
     389             :         }
     390      425838 :         return false;
     391             :     case typelib_TypeClass_SEQUENCE:
     392     2723669 :         if (typelib_TypeClass_SEQUENCE != pSourceType->eTypeClass)
     393      153449 :             return false;
     394             :         // self assignment:
     395     2570220 :         if (*static_cast<uno_Sequence **>(pSource) == *static_cast<uno_Sequence **>(pDest))
     396      470652 :             return true;
     397     2099568 :         if (_type_equals( pDestType, pSourceType ))
     398             :         {
     399     2060948 :             osl_atomic_increment( &(*static_cast<uno_Sequence **>(pSource))->nRefCount );
     400             :             idestructSequence(
     401     2060948 :                 *static_cast<uno_Sequence **>(pDest), pDestType, pDestTypeDescr, release );
     402     2060948 :             *static_cast<uno_Sequence **>(pDest) = *static_cast<uno_Sequence **>(pSource);
     403     2060948 :             return true;
     404             :         }
     405       38620 :         return false;
     406             :     case typelib_TypeClass_INTERFACE:
     407    29807006 :         if (typelib_TypeClass_INTERFACE != pSourceType->eTypeClass)
     408       72300 :             return false;
     409    29734706 :         if (_type_equals( pDestType, pSourceType ))
     410             :         {
     411     1303366 :             _assignInterface( static_cast<void **>(pDest), *static_cast<void **>(pSource), acquire, release );
     412     1303366 :             return true;
     413             :         }
     414    28431340 :         else if (*static_cast< void ** >(pSource) == 0)
     415             :         {
     416             :             // A null reference of any interface type can be converted to a null
     417             :             // reference of any other interface type:
     418      206787 :             void * const pToBeReleased = *static_cast< void ** >(pDest);
     419      206787 :             *static_cast< void ** >(pDest) = 0;
     420      206787 :             _release( pToBeReleased, release );
     421      206787 :             return true;
     422             :         }
     423             :         else
     424             :         {
     425    28224553 :             if (pSourceTypeDescr)
     426             :             {
     427           0 :                 typelib_TypeDescription * pTD = pSourceTypeDescr;
     428           0 :                 while (pTD && !_type_equals( pTD->pWeakRef, pDestType ))
     429             :                 {
     430           0 :                     pTD = &(reinterpret_cast<typelib_InterfaceTypeDescription *>(pTD))->pBaseTypeDescription->aBase;
     431             :                 }
     432           0 :                 if (pTD) // is base of dest
     433             :                 {
     434           0 :                     _assignInterface( static_cast<void **>(pDest), *static_cast<void **>(pSource), acquire, release );
     435           0 :                     return true;
     436             :                 }
     437             :             }
     438             : 
     439             :             // query for interface:
     440             :             void * pQueried = _queryInterface( *static_cast<void **>(pSource),
     441    28224553 :                                                pDestType, queryInterface );
     442    28224553 :             if (pQueried != 0) {
     443    28141422 :                 void * const pToBeReleased = *static_cast<void **>(pDest);
     444    28141422 :                 *static_cast<void **>(pDest) = pQueried;
     445    28141422 :                 _release( pToBeReleased, release );
     446             :             }
     447    28224553 :             return (pQueried != 0);
     448             :         }
     449             :     default:
     450             :         OSL_ASSERT(false);
     451           0 :         return false;
     452             :     }
     453             : }
     454             : 
     455             : }
     456             : 
     457             : #endif
     458             : 
     459             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11