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-27 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      765200 : inline void _defaultConstructStruct(
      50             :     void * pMem,
      51             :     typelib_CompoundTypeDescription * pTypeDescr )
      52             :     SAL_THROW(())
      53             : {
      54      765200 :     if (pTypeDescr->pBaseTypeDescription)
      55             :     {
      56       23496 :         defaultConstructStruct( pMem, pTypeDescr->pBaseTypeDescription );
      57             :     }
      58             : 
      59      765200 :     typelib_TypeDescriptionReference ** ppTypeRefs = (pTypeDescr)->ppTypeRefs;
      60      765200 :     sal_Int32 * pMemberOffsets = pTypeDescr->pMemberOffsets;
      61      765200 :     sal_Int32 nDescr = pTypeDescr->nMembers;
      62             : 
      63     5505530 :     while (nDescr--)
      64             :     {
      65     3975130 :         ::uno_type_constructData( (char *)pMem + pMemberOffsets[nDescr], ppTypeRefs[nDescr] );
      66             :     }
      67      765200 : }
      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     3975182 : inline void _defaultConstructData(
     152             :     void * pMem,
     153             :     typelib_TypeDescriptionReference * pType,
     154             :     typelib_TypeDescription * pTypeDescr )
     155             :     SAL_THROW(())
     156             : {
     157     3975182 :     switch (pType->eTypeClass)
     158             :     {
     159             :     case typelib_TypeClass_CHAR:
     160         505 :         *(sal_Unicode *)pMem = '\0';
     161         505 :         break;
     162             :     case typelib_TypeClass_BOOLEAN:
     163      384861 :         *(sal_Bool *)pMem = sal_False;
     164      384861 :         break;
     165             :     case typelib_TypeClass_BYTE:
     166           8 :         *(sal_Int8 *)pMem = 0;
     167           8 :         break;
     168             :     case typelib_TypeClass_SHORT:
     169             :     case typelib_TypeClass_UNSIGNED_SHORT:
     170      547178 :         *(sal_Int16 *)pMem = 0;
     171      547178 :         break;
     172             :     case typelib_TypeClass_LONG:
     173             :     case typelib_TypeClass_UNSIGNED_LONG:
     174      336159 :         *(sal_Int32 *)pMem = 0;
     175      336159 :         break;
     176             :     case typelib_TypeClass_HYPER:
     177             :     case typelib_TypeClass_UNSIGNED_HYPER:
     178          16 :         *(sal_Int64 *)pMem = 0;
     179          16 :         break;
     180             :     case typelib_TypeClass_FLOAT:
     181           8 :         *(float *)pMem = 0.0;
     182           8 :         break;
     183             :     case typelib_TypeClass_DOUBLE:
     184         242 :         *(double *)pMem = 0.0;
     185         242 :         break;
     186             :     case typelib_TypeClass_STRING:
     187     2077635 :         *(rtl_uString **)pMem = 0;
     188     2077635 :         ::rtl_uString_new( (rtl_uString **)pMem );
     189     2077635 :         break;
     190             :     case typelib_TypeClass_TYPE:
     191       46673 :         *(typelib_TypeDescriptionReference **)pMem = _getVoidType();
     192       46673 :         break;
     193             :     case typelib_TypeClass_ANY:
     194      294784 :         CONSTRUCT_EMPTY_ANY( (uno_Any *)pMem );
     195      294784 :         break;
     196             :     case typelib_TypeClass_ENUM:
     197      260436 :         if (pTypeDescr)
     198             :         {
     199           2 :             *(sal_Int32 *)pMem = ((typelib_EnumTypeDescription *)pTypeDescr)->nDefaultEnumValue;
     200             :         }
     201             :         else
     202             :         {
     203      260434 :             TYPELIB_DANGER_GET( &pTypeDescr, pType );
     204      260434 :             *(sal_Int32 *)pMem = ((typelib_EnumTypeDescription *)pTypeDescr)->nDefaultEnumValue;
     205      260434 :             TYPELIB_DANGER_RELEASE( pTypeDescr );
     206             :         }
     207      260436 :         break;
     208             :     case typelib_TypeClass_STRUCT:
     209             :     case typelib_TypeClass_EXCEPTION:
     210       13106 :         if (pTypeDescr)
     211             :         {
     212           3 :             _defaultConstructStruct( pMem, (typelib_CompoundTypeDescription *)pTypeDescr );
     213             :         }
     214             :         else
     215             :         {
     216       13103 :             TYPELIB_DANGER_GET( &pTypeDescr, pType );
     217       13103 :             _defaultConstructStruct( pMem, (typelib_CompoundTypeDescription *)pTypeDescr );
     218       13103 :             TYPELIB_DANGER_RELEASE( pTypeDescr );
     219             :         }
     220       13106 :         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        5252 :         *(uno_Sequence **)pMem = createEmptySequence();
     247        5252 :         break;
     248             :     case typelib_TypeClass_INTERFACE:
     249        8319 :         *(void **)pMem = 0; // either cpp or c-uno interface
     250        8319 :         break;
     251             :     default:
     252             :         OSL_ASSERT(false);
     253           0 :         break;
     254             :     }
     255     3975182 : }
     256             : 
     257             : }
     258             : 
     259             : #endif
     260             : 
     261             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10