LCOV - code coverage report
Current view: top level - libreoffice/cppu/source/uno - constr.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 51 105 48.6 %
Date: 2012-12-17 Functions: 2 4 50.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 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     2199240 : inline void _defaultConstructStruct(
      50             :     void * pMem,
      51             :     typelib_CompoundTypeDescription * pTypeDescr )
      52             :     SAL_THROW(())
      53             : {
      54     2199240 :     if (pTypeDescr->pBaseTypeDescription)
      55             :     {
      56       66545 :         defaultConstructStruct( pMem, pTypeDescr->pBaseTypeDescription );
      57             :     }
      58             : 
      59     2199240 :     typelib_TypeDescriptionReference ** ppTypeRefs = (pTypeDescr)->ppTypeRefs;
      60     2199240 :     sal_Int32 * pMemberOffsets = pTypeDescr->pMemberOffsets;
      61     2199240 :     sal_Int32 nDescr = pTypeDescr->nMembers;
      62             : 
      63    15909038 :     while (nDescr--)
      64             :     {
      65    11510558 :         ::uno_type_constructData( (char *)pMem + pMemberOffsets[nDescr], ppTypeRefs[nDescr] );
      66             :     }
      67     2199240 : }
      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    11510744 : inline void _defaultConstructData(
     152             :     void * pMem,
     153             :     typelib_TypeDescriptionReference * pType,
     154             :     typelib_TypeDescription * pTypeDescr )
     155             :     SAL_THROW(())
     156             : {
     157    11510744 :     switch (pType->eTypeClass)
     158             :     {
     159             :     case typelib_TypeClass_CHAR:
     160        1026 :         *(sal_Unicode *)pMem = '\0';
     161        1026 :         break;
     162             :     case typelib_TypeClass_BOOLEAN:
     163     1123345 :         *(sal_Bool *)pMem = sal_False;
     164     1123345 :         break;
     165             :     case typelib_TypeClass_BYTE:
     166          16 :         *(sal_Int8 *)pMem = 0;
     167          16 :         break;
     168             :     case typelib_TypeClass_SHORT:
     169             :     case typelib_TypeClass_UNSIGNED_SHORT:
     170     1572890 :         *(sal_Int16 *)pMem = 0;
     171     1572890 :         break;
     172             :     case typelib_TypeClass_LONG:
     173             :     case typelib_TypeClass_UNSIGNED_LONG:
     174      979451 :         *(sal_Int32 *)pMem = 0;
     175      979451 :         break;
     176             :     case typelib_TypeClass_HYPER:
     177             :     case typelib_TypeClass_UNSIGNED_HYPER:
     178          32 :         *(sal_Int64 *)pMem = 0;
     179          32 :         break;
     180             :     case typelib_TypeClass_FLOAT:
     181          16 :         *(float *)pMem = 0.0;
     182          16 :         break;
     183             :     case typelib_TypeClass_DOUBLE:
     184        1494 :         *(double *)pMem = 0.0;
     185        1494 :         break;
     186             :     case typelib_TypeClass_STRING:
     187     6018389 :         *(rtl_uString **)pMem = 0;
     188     6018389 :         ::rtl_uString_new( (rtl_uString **)pMem );
     189     6018389 :         break;
     190             :     case typelib_TypeClass_TYPE:
     191      147412 :         *(typelib_TypeDescriptionReference **)pMem = _getVoidType();
     192      147412 :         break;
     193             :     case typelib_TypeClass_ANY:
     194      842970 :         CONSTRUCT_EMPTY_ANY( (uno_Any *)pMem );
     195      842970 :         break;
     196             :     case typelib_TypeClass_ENUM:
     197      762117 :         if (pTypeDescr)
     198             :         {
     199           4 :             *(sal_Int32 *)pMem = ((typelib_EnumTypeDescription *)pTypeDescr)->nDefaultEnumValue;
     200             :         }
     201             :         else
     202             :         {
     203      762113 :             TYPELIB_DANGER_GET( &pTypeDescr, pType );
     204      762113 :             *(sal_Int32 *)pMem = ((typelib_EnumTypeDescription *)pTypeDescr)->nDefaultEnumValue;
     205      762113 :             TYPELIB_DANGER_RELEASE( pTypeDescr );
     206             :         }
     207      762117 :         break;
     208             :     case typelib_TypeClass_STRUCT:
     209             :     case typelib_TypeClass_EXCEPTION:
     210       26427 :         if (pTypeDescr)
     211             :         {
     212           6 :             _defaultConstructStruct( pMem, (typelib_CompoundTypeDescription *)pTypeDescr );
     213             :         }
     214             :         else
     215             :         {
     216       26421 :             TYPELIB_DANGER_GET( &pTypeDescr, pType );
     217       26421 :             _defaultConstructStruct( pMem, (typelib_CompoundTypeDescription *)pTypeDescr );
     218       26421 :             TYPELIB_DANGER_RELEASE( pTypeDescr );
     219             :         }
     220       26427 :         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       16904 :         *(uno_Sequence **)pMem = createEmptySequence();
     247       16904 :         break;
     248             :     case typelib_TypeClass_INTERFACE:
     249       18255 :         *(void **)pMem = 0; // either cpp or c-uno interface
     250       18255 :         break;
     251             :     default:
     252             :         OSL_ASSERT(false);
     253           0 :         break;
     254             :     }
     255    11510744 : }
     256             : 
     257             : }
     258             : 
     259             : #endif
     260             : 
     261             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10