LCOV - code coverage report
Current view: top level - cppu/source/uno - constr.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 51 105 48.6 %
Date: 2012-08-25 Functions: 2 4 50.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 35 127 27.6 %

           Branch data     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 CONSTR_HXX
      20                 :            : #define CONSTR_HXX
      21                 :            : 
      22                 :            : #include <string.h>
      23                 :            : #include "prim.hxx"
      24                 :            : 
      25                 :            : namespace cppu
      26                 :            : {
      27                 :            : 
      28                 :            : //##################################################################################################
      29                 :            : //#### construction ################################################################################
      30                 :            : //##################################################################################################
      31                 :            : 
      32                 :            : //--------------------------------------------------------------------------------------------------
      33                 :          0 : inline void _defaultConstructUnion(
      34                 :            :     void * pMem,
      35                 :            :     typelib_TypeDescription * pTypeDescr )
      36                 :            :     SAL_THROW(())
      37                 :            : {
      38                 :            :     ::uno_type_constructData(
      39                 :          0 :         (char *)pMem + ((typelib_UnionTypeDescription *)pTypeDescr)->nValueOffset,
      40                 :          0 :         ((typelib_UnionTypeDescription *)pTypeDescr)->pDefaultTypeRef );
      41                 :          0 :     *(sal_Int64 *)pMem = ((typelib_UnionTypeDescription *)pTypeDescr)->nDefaultDiscriminant;
      42                 :          0 : }
      43                 :            : //==================================================================================================
      44                 :            : void defaultConstructStruct(
      45                 :            :     void * pMem,
      46                 :            :     typelib_CompoundTypeDescription * pCompType )
      47                 :            :     SAL_THROW(());
      48                 :            : //--------------------------------------------------------------------------------------------------
      49                 :    7315783 : inline void _defaultConstructStruct(
      50                 :            :     void * pMem,
      51                 :            :     typelib_CompoundTypeDescription * pTypeDescr )
      52                 :            :     SAL_THROW(())
      53                 :            : {
      54         [ +  + ]:    7315783 :     if (pTypeDescr->pBaseTypeDescription)
      55                 :            :     {
      56                 :     244719 :         defaultConstructStruct( pMem, pTypeDescr->pBaseTypeDescription );
      57                 :            :     }
      58                 :            : 
      59                 :    7315784 :     typelib_TypeDescriptionReference ** ppTypeRefs = (pTypeDescr)->ppTypeRefs;
      60                 :    7315784 :     sal_Int32 * pMemberOffsets = pTypeDescr->pMemberOffsets;
      61                 :    7315784 :     sal_Int32 nDescr = pTypeDescr->nMembers;
      62                 :            : 
      63         [ +  + ]:   40131276 :     while (nDescr--)
      64                 :            :     {
      65                 :   32815492 :         ::uno_type_constructData( (char *)pMem + pMemberOffsets[nDescr], ppTypeRefs[nDescr] );
      66                 :            :     }
      67                 :    7315784 : }
      68                 :            : 
      69                 :            : //--------------------------------------------------------------------------------------------------
      70                 :          0 : inline void _defaultConstructArray(
      71                 :            :     void * pMem,
      72                 :            :     typelib_ArrayTypeDescription * pTypeDescr )
      73                 :            : {
      74                 :          0 :     typelib_TypeDescription * pElementType = NULL;
      75 [ #  # ][ #  # ]:          0 :     TYPELIB_DANGER_GET( &pElementType, ((typelib_IndirectTypeDescription *)pTypeDescr)->pType );
         [ #  # ][ #  # ]
                 [ #  # ]
      76                 :          0 :     sal_Int32 nTotalElements = pTypeDescr->nTotalElements;
      77                 :          0 :     sal_Int32 nElementSize = pElementType->nSize;
      78                 :            :     sal_Int32 i;
      79   [ #  #  #  #  :          0 :     switch ( pElementType->eTypeClass )
             #  #  #  #  
                      # ]
      80                 :            :     {
      81                 :            :     case typelib_TypeClass_CHAR:
      82                 :            :     case typelib_TypeClass_BOOLEAN:
      83                 :            :     case typelib_TypeClass_BYTE:
      84                 :            :     case typelib_TypeClass_SHORT:
      85                 :            :     case typelib_TypeClass_UNSIGNED_SHORT:
      86                 :            :     case typelib_TypeClass_LONG:
      87                 :            :     case typelib_TypeClass_UNSIGNED_LONG:
      88                 :            :     case typelib_TypeClass_HYPER:
      89                 :            :     case typelib_TypeClass_UNSIGNED_HYPER:
      90                 :            :     case typelib_TypeClass_FLOAT:
      91                 :            :     case typelib_TypeClass_DOUBLE:
      92                 :            :     case typelib_TypeClass_INTERFACE:
      93                 :          0 :         memset(pMem, 0, nElementSize * nTotalElements);
      94                 :          0 :         break;
      95                 :            : 
      96                 :            :     case typelib_TypeClass_STRING:
      97         [ #  # ]:          0 :         for (i=0; i < nTotalElements; i++)
      98                 :            :         {
      99                 :          0 :             rtl_uString** ppElement = (rtl_uString **)pMem + i;
     100                 :          0 :             *ppElement = 0;
     101                 :          0 :             rtl_uString_new( ppElement);
     102                 :            :         }
     103                 :          0 :         break;
     104                 :            :     case typelib_TypeClass_TYPE:
     105         [ #  # ]:          0 :         for (i=0; i < nTotalElements; i++)
     106                 :            :         {
     107                 :          0 :             typelib_TypeDescriptionReference** ppElement = (typelib_TypeDescriptionReference **)pMem + i;
     108                 :          0 :             *ppElement = _getVoidType();
     109                 :            :         }
     110                 :          0 :         break;
     111                 :            :     case typelib_TypeClass_ANY:
     112         [ #  # ]:          0 :         for (i=0; i < nTotalElements; i++)
     113                 :            :         {
     114                 :          0 :             CONSTRUCT_EMPTY_ANY( (uno_Any *)pMem + i );
     115                 :            :         }
     116                 :          0 :         break;
     117                 :            :     case typelib_TypeClass_ENUM:
     118         [ #  # ]:          0 :         for (i=0; i < nTotalElements; i++)
     119                 :            :         {
     120                 :          0 :             *((sal_Int32 *)pMem + i) = ((typelib_EnumTypeDescription *)pElementType)->nDefaultEnumValue;
     121                 :            :         }
     122                 :          0 :         break;
     123                 :            :     case typelib_TypeClass_STRUCT:
     124                 :            :     case typelib_TypeClass_EXCEPTION:
     125         [ #  # ]:          0 :         for (i=0; i < nTotalElements; i++)
     126                 :            :         {
     127         [ #  # ]:          0 :             _defaultConstructStruct( (sal_Char*)pMem + i * nElementSize, (typelib_CompoundTypeDescription *)pElementType );
     128                 :            :         }
     129                 :          0 :         break;
     130                 :            :     case typelib_TypeClass_UNION:
     131         [ #  # ]:          0 :         for (i=0; i < nTotalElements; i++)
     132                 :            :         {
     133                 :          0 :             _defaultConstructUnion( (sal_Char*)pMem + i * nElementSize, pElementType );
     134                 :            :         }
     135                 :          0 :         break;
     136                 :            :     case typelib_TypeClass_SEQUENCE:
     137         [ #  # ]:          0 :         for (i=0; i < nTotalElements; i++)
     138                 :            :         {
     139                 :          0 :             uno_Sequence** ppElement = (uno_Sequence **)pMem + i;
     140         [ #  # ]:          0 :             *ppElement = createEmptySequence();
     141                 :            :         }
     142                 :          0 :         break;
     143                 :            :     default:
     144                 :            :         OSL_ASSERT(false);
     145                 :          0 :         break;
     146                 :            :     }
     147 [ #  # ][ #  # ]:          0 :     TYPELIB_DANGER_RELEASE( pElementType );
     148                 :          0 : }
     149                 :            : 
     150                 :            : //--------------------------------------------------------------------------------------------------
     151                 :   32826865 : inline void _defaultConstructData(
     152                 :            :     void * pMem,
     153                 :            :     typelib_TypeDescriptionReference * pType,
     154                 :            :     typelib_TypeDescription * pTypeDescr )
     155                 :            :     SAL_THROW(())
     156                 :            : {
     157   [ +  +  +  +  :   32826865 :     switch (pType->eTypeClass)
          +  +  +  +  +  
          +  +  +  +  -  
             -  +  +  - ]
     158                 :            :     {
     159                 :            :     case typelib_TypeClass_CHAR:
     160                 :       1649 :         *(sal_Unicode *)pMem = '\0';
     161                 :       1649 :         break;
     162                 :            :     case typelib_TypeClass_BOOLEAN:
     163                 :    1849481 :         *(sal_Bool *)pMem = sal_False;
     164                 :    1849481 :         break;
     165                 :            :     case typelib_TypeClass_BYTE:
     166                 :         40 :         *(sal_Int8 *)pMem = 0;
     167                 :         40 :         break;
     168                 :            :     case typelib_TypeClass_SHORT:
     169                 :            :     case typelib_TypeClass_UNSIGNED_SHORT:
     170                 :    3165672 :         *(sal_Int16 *)pMem = 0;
     171                 :    3165672 :         break;
     172                 :            :     case typelib_TypeClass_LONG:
     173                 :            :     case typelib_TypeClass_UNSIGNED_LONG:
     174                 :    5297269 :         *(sal_Int32 *)pMem = 0;
     175                 :    5297269 :         break;
     176                 :            :     case typelib_TypeClass_HYPER:
     177                 :            :     case typelib_TypeClass_UNSIGNED_HYPER:
     178                 :         80 :         *(sal_Int64 *)pMem = 0;
     179                 :         80 :         break;
     180                 :            :     case typelib_TypeClass_FLOAT:
     181                 :         40 :         *(float *)pMem = 0.0;
     182                 :         40 :         break;
     183                 :            :     case typelib_TypeClass_DOUBLE:
     184                 :       6433 :         *(double *)pMem = 0.0;
     185                 :       6433 :         break;
     186                 :            :     case typelib_TypeClass_STRING:
     187                 :   12803614 :         *(rtl_uString **)pMem = 0;
     188                 :   12803614 :         ::rtl_uString_new( (rtl_uString **)pMem );
     189                 :   12803615 :         break;
     190                 :            :     case typelib_TypeClass_TYPE:
     191                 :     632654 :         *(typelib_TypeDescriptionReference **)pMem = _getVoidType();
     192                 :     632654 :         break;
     193                 :            :     case typelib_TypeClass_ANY:
     194                 :    4620285 :         CONSTRUCT_EMPTY_ANY( (uno_Any *)pMem );
     195                 :    4620285 :         break;
     196                 :            :     case typelib_TypeClass_ENUM:
     197         [ +  + ]:    4135809 :         if (pTypeDescr)
     198                 :            :         {
     199                 :         10 :             *(sal_Int32 *)pMem = ((typelib_EnumTypeDescription *)pTypeDescr)->nDefaultEnumValue;
     200                 :            :         }
     201                 :            :         else
     202                 :            :         {
     203 [ +  - ][ -  + ]:    4135799 :             TYPELIB_DANGER_GET( &pTypeDescr, pType );
         [ +  - ][ -  + ]
                 [ #  # ]
     204                 :    4135799 :             *(sal_Int32 *)pMem = ((typelib_EnumTypeDescription *)pTypeDescr)->nDefaultEnumValue;
     205 [ +  - ][ -  + ]:    4135799 :             TYPELIB_DANGER_RELEASE( pTypeDescr );
     206                 :            :         }
     207                 :    4135809 :         break;
     208                 :            :     case typelib_TypeClass_STRUCT:
     209                 :            :     case typelib_TypeClass_EXCEPTION:
     210         [ +  + ]:      31529 :         if (pTypeDescr)
     211                 :            :         {
     212                 :         15 :             _defaultConstructStruct( pMem, (typelib_CompoundTypeDescription *)pTypeDescr );
     213                 :            :         }
     214                 :            :         else
     215                 :            :         {
     216 [ +  - ][ -  + ]:      31514 :             TYPELIB_DANGER_GET( &pTypeDescr, pType );
         [ +  - ][ -  + ]
                 [ #  # ]
     217                 :      31514 :             _defaultConstructStruct( pMem, (typelib_CompoundTypeDescription *)pTypeDescr );
     218 [ -  + ][ +  - ]:      31514 :             TYPELIB_DANGER_RELEASE( pTypeDescr );
     219                 :            :         }
     220                 :      31529 :         break;
     221                 :            :     case typelib_TypeClass_ARRAY:
     222         [ #  # ]:          0 :         if (pTypeDescr)
     223                 :            :         {
     224                 :          0 :             _defaultConstructArray( pMem, (typelib_ArrayTypeDescription *)pTypeDescr );
     225                 :            :         }
     226                 :            :         else
     227                 :            :         {
     228 [ #  # ][ #  # ]:          0 :             TYPELIB_DANGER_GET( &pTypeDescr, pType );
         [ #  # ][ #  # ]
                 [ #  # ]
     229                 :          0 :             _defaultConstructArray( pMem, (typelib_ArrayTypeDescription *)pTypeDescr );
     230 [ #  # ][ #  # ]:          0 :             TYPELIB_DANGER_RELEASE( pTypeDescr );
     231                 :            :         }
     232                 :          0 :         break;
     233                 :            :     case typelib_TypeClass_UNION:
     234         [ #  # ]:          0 :         if (pTypeDescr)
     235                 :            :         {
     236                 :          0 :             _defaultConstructUnion( pMem, pTypeDescr );
     237                 :            :         }
     238                 :            :         else
     239                 :            :         {
     240 [ #  # ][ #  # ]:          0 :             TYPELIB_DANGER_GET( &pTypeDescr, pType );
         [ #  # ][ #  # ]
                 [ #  # ]
     241                 :          0 :             _defaultConstructUnion( pMem, pTypeDescr );
     242 [ #  # ][ #  # ]:          0 :             TYPELIB_DANGER_RELEASE( pTypeDescr );
     243                 :            :         }
     244                 :          0 :         break;
     245                 :            :     case typelib_TypeClass_SEQUENCE:
     246                 :     130386 :         *(uno_Sequence **)pMem = createEmptySequence();
     247                 :     130386 :         break;
     248                 :            :     case typelib_TypeClass_INTERFACE:
     249                 :     151924 :         *(void **)pMem = 0; // either cpp or c-uno interface
     250                 :     151924 :         break;
     251                 :            :     default:
     252                 :            :         OSL_ASSERT(false);
     253                 :          0 :         break;
     254                 :            :     }
     255                 :   32826866 : }
     256                 :            : 
     257                 :            : }
     258                 :            : 
     259                 :            : #endif
     260                 :            : 
     261                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10