LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/cppu/source/typelib - static_types.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 182 255 71.4 %
Date: 2013-07-09 Functions: 10 13 76.9 %
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             : 
      20             : #include "sal/config.h"
      21             : 
      22             : #include <algorithm>
      23             : #include <cassert>
      24             : #include <stdarg.h>
      25             : 
      26             : #include <osl/mutex.hxx>
      27             : #include <osl/interlck.h>
      28             : #include <rtl/ustring.hxx>
      29             : #include <rtl/ustrbuf.hxx>
      30             : #include <rtl/instance.hxx>
      31             : 
      32             : #include <typelib/typedescription.h>
      33             : 
      34             : 
      35             : using namespace osl;
      36             : 
      37             : using ::rtl::OUString;
      38             : using ::rtl::OUStringBuffer;
      39             : 
      40             : extern "C"
      41             : {
      42             : 
      43             : //------------------------------------------------------------------------
      44             : sal_Int32 SAL_CALL typelib_typedescription_getAlignedUnoSize(
      45             :     const typelib_TypeDescription * pTypeDescription,
      46             :     sal_Int32 nOffset,
      47             :     sal_Int32 & rMaxIntegralTypeSize )
      48             :     SAL_THROW_EXTERN_C();
      49             : //------------------------------------------------------------------------
      50             : void SAL_CALL typelib_typedescription_newEmpty(
      51             :     typelib_TypeDescription ** ppRet,
      52             :     typelib_TypeClass eTypeClass,
      53             :     rtl_uString * pTypeName )
      54             :     SAL_THROW_EXTERN_C();
      55             : //-----------------------------------------------------------------------------
      56             : void SAL_CALL typelib_typedescriptionreference_getByName(
      57             :     typelib_TypeDescriptionReference ** ppRet,
      58             :     rtl_uString * pName )
      59             :     SAL_THROW_EXTERN_C();
      60             : 
      61             : #ifdef SAL_W32
      62             : #pragma pack(push, 8)
      63             : #endif
      64             : 
      65             : /**
      66             :  * The double member determin the alignment.
      67             :  * Under Os2 and MS-Windows the Alignment is min( 8, sizeof( type ) ).
      68             :  * The aligment of a strukture is min( 8, sizeof( max basic type ) ), the greatest basic type
      69             :  * determine the aligment.
      70             :  */
      71             : struct AlignSize_Impl
      72             : {
      73             :     sal_Int16 nInt16;
      74             : #ifdef AIX
      75             :     //double: doubleword aligned if -qalign=natural/-malign=natural
      76             :     //which isn't the default ABI. Otherwise word aligned, While a long long int
      77             :     //is always doubleword aligned, so use that instead.
      78             :     sal_Int64   dDouble;
      79             : #else
      80             :     double dDouble;
      81             : #endif
      82             : };
      83             : 
      84             : #ifdef SAL_W32
      85             : #pragma pack(pop)
      86             : #endif
      87             : 
      88             : // the value of the maximal alignment
      89             : static sal_Int32 nMaxAlignment = (sal_Int32)( (sal_Size)(&((AlignSize_Impl *) 16)->dDouble) - 16);
      90             : 
      91           5 : static inline sal_Int32 adjustAlignment( sal_Int32 nRequestedAlignment )
      92             :     SAL_THROW(())
      93             : {
      94           5 :     if( nRequestedAlignment > nMaxAlignment )
      95           0 :         nRequestedAlignment = nMaxAlignment;
      96           5 :     return nRequestedAlignment;
      97             : }
      98             : 
      99             : /**
     100             :  * Calculate the new size of the struktur.
     101             :  */
     102           0 : static inline sal_Int32 newAlignedSize(
     103             :     sal_Int32 OldSize, sal_Int32 ElementSize, sal_Int32 NeededAlignment )
     104             :     SAL_THROW(())
     105             : {
     106           0 :     NeededAlignment = adjustAlignment( NeededAlignment );
     107           0 :     return (OldSize + NeededAlignment -1) / NeededAlignment * NeededAlignment + ElementSize;
     108             : }
     109             : 
     110             : //--------------------------------------------------------------------------------------------------
     111             : 
     112             : namespace
     113             : {
     114             :     struct typelib_StaticInitMutex : public rtl::Static< Mutex, typelib_StaticInitMutex > {};
     115             : }
     116             : 
     117             : // !for NOT REALLY WEAK TYPES only!
     118       46393 : static inline typelib_TypeDescriptionReference * igetTypeByName( rtl_uString * pTypeName )
     119             :     SAL_THROW(())
     120             : {
     121       46393 :     typelib_TypeDescriptionReference * pRef = 0;
     122       46393 :     ::typelib_typedescriptionreference_getByName( &pRef, pTypeName );
     123       46393 :     if (pRef && pRef->pType && pRef->pType->pWeakRef) // found initialized td
     124             :     {
     125       38402 :         return pRef;
     126             :     }
     127             :     else
     128             :     {
     129        7991 :         return 0;
     130             :     }
     131             : }
     132             : 
     133             : extern "C"
     134             : {
     135             : //##################################################################################################
     136    14331018 : CPPU_DLLPUBLIC typelib_TypeDescriptionReference ** SAL_CALL typelib_static_type_getByTypeClass(
     137             :     typelib_TypeClass eTypeClass )
     138             :     SAL_THROW_EXTERN_C()
     139             : {
     140             :     static typelib_TypeDescriptionReference * s_aTypes[] = {
     141             :         0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     142             :         0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     143             :         0, 0, 0 };
     144             : 
     145    14331018 :     if (! s_aTypes[eTypeClass])
     146             :     {
     147        2402 :         MutexGuard aGuard( typelib_StaticInitMutex::get() );
     148        2402 :         if (! s_aTypes[eTypeClass])
     149             :         {
     150             :             static const char * s_aTypeNames[] = {
     151             :                 "void", "char", "boolean", "byte",
     152             :                 "short", "unsigned short", "long", "unsigned long",
     153             :                 "hyper", "unsigned hyper", "float", "double",
     154             :                 "string", "type", "any" };
     155             : 
     156        2402 :             switch (eTypeClass)
     157             :             {
     158             :             case typelib_TypeClass_EXCEPTION:
     159             :             case typelib_TypeClass_INTERFACE:
     160             :             {
     161             :                 // type
     162         391 :                 if (! s_aTypes[typelib_TypeClass_TYPE])
     163             :                 {
     164         390 :                     OUString sTypeName("type");
     165             :                     ::typelib_typedescriptionreference_new(
     166         390 :                         &s_aTypes[typelib_TypeClass_TYPE], typelib_TypeClass_TYPE, sTypeName.pData );
     167             :                     // another static ref:
     168         390 :                     ++s_aTypes[typelib_TypeClass_TYPE]->nStaticRefCount;
     169             :                 }
     170             :                 // any
     171         391 :                 if (! s_aTypes[typelib_TypeClass_ANY])
     172             :                 {
     173         390 :                     OUString sTypeName("any");
     174             :                     ::typelib_typedescriptionreference_new(
     175         390 :                         &s_aTypes[typelib_TypeClass_ANY], typelib_TypeClass_ANY, sTypeName.pData );
     176             :                     // another static ref:
     177         390 :                     ++s_aTypes[typelib_TypeClass_ANY]->nStaticRefCount;
     178             :                 }
     179             :                 // string
     180         391 :                 if (! s_aTypes[typelib_TypeClass_STRING])
     181             :                 {
     182         387 :                     OUString sTypeName("string");
     183             :                     ::typelib_typedescriptionreference_new(
     184         387 :                         &s_aTypes[typelib_TypeClass_STRING], typelib_TypeClass_STRING, sTypeName.pData );
     185             :                     // another static ref:
     186         387 :                     ++s_aTypes[typelib_TypeClass_STRING]->nStaticRefCount;
     187             :                 }
     188             :                 // XInterface
     189         391 :                 if (! s_aTypes[typelib_TypeClass_INTERFACE])
     190             :                 {
     191         391 :                     OUString sTypeName("com.sun.star.uno.XInterface");
     192             : 
     193         391 :                     typelib_InterfaceTypeDescription * pTD = 0;
     194             : 
     195         391 :                     typelib_TypeDescriptionReference * pMembers[3] = { 0,0,0 };
     196         782 :                     OUString sMethodName0("com.sun.star.uno.XInterface::queryInterface");
     197             :                     ::typelib_typedescriptionreference_new(
     198         391 :                         &pMembers[0], typelib_TypeClass_INTERFACE_METHOD, sMethodName0.pData );
     199         782 :                     OUString sMethodName1("com.sun.star.uno.XInterface::acquire");
     200             :                     ::typelib_typedescriptionreference_new(
     201         391 :                         &pMembers[1], typelib_TypeClass_INTERFACE_METHOD, sMethodName1.pData );
     202         782 :                     OUString sMethodName2("com.sun.star.uno.XInterface::release");
     203             :                     ::typelib_typedescriptionreference_new(
     204         391 :                         &pMembers[2], typelib_TypeClass_INTERFACE_METHOD, sMethodName2.pData );
     205             : 
     206             :                     ::typelib_typedescription_newInterface(
     207             :                         &pTD, sTypeName.pData, 0xe227a391, 0x33d6, 0x11d1, 0xaabe00a0, 0x249d5590,
     208         391 :                         0, 3, pMembers );
     209             : 
     210         391 :                     ::typelib_typedescription_register( (typelib_TypeDescription **)&pTD );
     211             :                     ::typelib_typedescriptionreference_acquire(
     212         391 :                         s_aTypes[typelib_TypeClass_INTERFACE] = ((typelib_TypeDescription *)pTD)->pWeakRef );
     213             :                     // another static ref:
     214         391 :                     ++s_aTypes[typelib_TypeClass_INTERFACE]->nStaticRefCount;
     215         391 :                     ::typelib_typedescription_release( (typelib_TypeDescription*)pTD );
     216             : 
     217         391 :                     ::typelib_typedescriptionreference_release( pMembers[0] );
     218         391 :                     ::typelib_typedescriptionreference_release( pMembers[1] );
     219         391 :                     ::typelib_typedescriptionreference_release( pMembers[2] );
     220             :                     // Exception
     221             :                     assert( ! s_aTypes[typelib_TypeClass_EXCEPTION] );
     222             :                     {
     223         391 :                     typelib_TypeDescription * pTD1 = 0;
     224         391 :                     OUString sTypeName1("com.sun.star.uno.Exception");
     225             : 
     226             :                     typelib_CompoundMember_Init aMembers[2];
     227         782 :                     OUString sMemberType0("string");
     228         782 :                     OUString sMemberName0("Message");
     229         391 :                     aMembers[0].eTypeClass = typelib_TypeClass_STRING;
     230         391 :                     aMembers[0].pTypeName = sMemberType0.pData;
     231         391 :                     aMembers[0].pMemberName = sMemberName0.pData;
     232         782 :                     OUString sMemberType1("com.sun.star.uno.XInterface");
     233         782 :                     OUString sMemberName1("Context");
     234         391 :                     aMembers[1].eTypeClass = typelib_TypeClass_INTERFACE;
     235         391 :                     aMembers[1].pTypeName = sMemberType1.pData;
     236         391 :                     aMembers[1].pMemberName = sMemberName1.pData;
     237             : 
     238             :                     ::typelib_typedescription_new(
     239         391 :                         &pTD1, typelib_TypeClass_EXCEPTION, sTypeName1.pData, 0, 2, aMembers );
     240         391 :                     typelib_typedescription_register( &pTD1 );
     241             :                     typelib_typedescriptionreference_acquire(
     242         391 :                         s_aTypes[typelib_TypeClass_EXCEPTION] = pTD1->pWeakRef );
     243             :                     // another static ref:
     244         391 :                     ++s_aTypes[typelib_TypeClass_EXCEPTION]->nStaticRefCount;
     245             :                     // RuntimeException
     246         782 :                     OUString sTypeName2("com.sun.star.uno.RuntimeException");
     247             :                     ::typelib_typedescription_new(
     248         391 :                         &pTD1, typelib_TypeClass_EXCEPTION, sTypeName2.pData, s_aTypes[typelib_TypeClass_EXCEPTION], 0, 0 );
     249         391 :                     ::typelib_typedescription_register( &pTD1 );
     250         782 :                     ::typelib_typedescription_release( pTD1 );
     251             :                     }
     252             :                     // XInterface members
     253         391 :                     typelib_InterfaceMethodTypeDescription * pMethod = 0;
     254             :                     typelib_Parameter_Init aParameters[1];
     255         782 :                     OUString sParamName0("aType");
     256         782 :                     OUString sParamType0("type");
     257         391 :                     aParameters[0].pParamName = sParamName0.pData;
     258         391 :                     aParameters[0].eTypeClass = typelib_TypeClass_TYPE;
     259         391 :                     aParameters[0].pTypeName = sParamType0.pData;
     260         391 :                     aParameters[0].bIn = sal_True;
     261         391 :                     aParameters[0].bOut = sal_False;
     262             :                     rtl_uString * pExceptions[1];
     263         782 :                     OUString sExceptionName0("com.sun.star.uno.RuntimeException");
     264         391 :                     pExceptions[0] = sExceptionName0.pData;
     265         782 :                     OUString sReturnType0("any");
     266             :                     typelib_typedescription_newInterfaceMethod(
     267             :                         &pMethod, 0, sal_False, sMethodName0.pData,
     268             :                         typelib_TypeClass_ANY, sReturnType0.pData,
     269         391 :                         1, aParameters, 1, pExceptions );
     270         391 :                     ::typelib_typedescription_register( (typelib_TypeDescription**)&pMethod );
     271             : 
     272         782 :                     OUString sReturnType1("void");
     273             :                     ::typelib_typedescription_newInterfaceMethod(
     274             :                         &pMethod, 1, sal_True, sMethodName1.pData,
     275         391 :                         typelib_TypeClass_VOID, sReturnType1.pData, 0, 0, 0, 0 );
     276         391 :                     ::typelib_typedescription_register( (typelib_TypeDescription**)&pMethod );
     277             : 
     278             :                     ::typelib_typedescription_newInterfaceMethod(
     279             :                         &pMethod, 2, sal_True, sMethodName2.pData,
     280             :                         typelib_TypeClass_VOID, sReturnType1.pData,
     281         391 :                         0, 0, 0, 0 );
     282         391 :                     ::typelib_typedescription_register( (typelib_TypeDescription**)&pMethod );
     283         782 :                     ::typelib_typedescription_release( (typelib_TypeDescription*)pMethod );
     284             :                 }
     285         391 :                 break;
     286             :             }
     287             :             default:
     288             :             {
     289        2011 :                 OUString aTypeName( OUString::createFromAscii( s_aTypeNames[eTypeClass] ) );
     290        2011 :                 ::typelib_typedescriptionreference_new( &s_aTypes[eTypeClass], eTypeClass, aTypeName.pData );
     291             :                 // another static ref:
     292        2011 :                 ++s_aTypes[eTypeClass]->nStaticRefCount;
     293             :             }
     294             :             }
     295        2402 :         }
     296             :     }
     297    14331018 :     return &s_aTypes[eTypeClass];
     298             : }
     299             : 
     300             : //##################################################################################################
     301      108033 : CPPU_DLLPUBLIC void SAL_CALL typelib_static_type_init(
     302             :     typelib_TypeDescriptionReference ** ppRef,
     303             :     typelib_TypeClass eTypeClass, const sal_Char * pTypeName )
     304             :     SAL_THROW_EXTERN_C()
     305             : {
     306      108033 :     if (! *ppRef)
     307             :     {
     308      108033 :         MutexGuard aGuard( typelib_StaticInitMutex::get() );
     309      108033 :         if (! *ppRef)
     310             :         {
     311      108033 :             OUString aTypeName( OUString::createFromAscii( pTypeName ) );
     312      108033 :             ::typelib_typedescriptionreference_new( ppRef, eTypeClass, aTypeName.pData );
     313             : 
     314             :             // another static ref:
     315      108033 :             ++((*ppRef)->nStaticRefCount);
     316      108033 :         }
     317             :     }
     318      108033 : }
     319             : 
     320             : //##################################################################################################
     321       46332 : CPPU_DLLPUBLIC void SAL_CALL typelib_static_sequence_type_init(
     322             :     typelib_TypeDescriptionReference ** ppRef,
     323             :     typelib_TypeDescriptionReference * pElementType )
     324             :     SAL_THROW_EXTERN_C()
     325             : {
     326       46332 :     if (! *ppRef)
     327             :     {
     328       46332 :         MutexGuard aGuard( typelib_StaticInitMutex::get() );
     329       46332 :         if (! *ppRef)
     330             :         {
     331       46332 :             OUStringBuffer aBuf( 32 );
     332       46332 :             aBuf.appendAscii( "[]" );
     333       46332 :             aBuf.append( pElementType->pTypeName );
     334       92664 :             OUString aTypeName( aBuf.makeStringAndClear() );
     335             : 
     336             :             assert( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_SEQUENCE) );
     337       46332 :             *ppRef = igetTypeByName( aTypeName.pData );
     338       46332 :             if (!*ppRef)
     339             :             {
     340        7986 :                 typelib_TypeDescription * pReg = 0;
     341             :                 ::typelib_typedescription_new(
     342             :                     &pReg, typelib_TypeClass_SEQUENCE,
     343        7986 :                     aTypeName.pData, pElementType, 0, 0 );
     344             : 
     345        7986 :                 ::typelib_typedescription_register( &pReg );
     346        7986 :                 *ppRef = (typelib_TypeDescriptionReference *)pReg;
     347             :                 assert( *ppRef == pReg->pWeakRef );
     348             :             }
     349             :             // another static ref:
     350       92664 :             ++((*ppRef)->nStaticRefCount);
     351       46332 :         }
     352             :     }
     353       46332 : }
     354             : 
     355             : //##################################################################################################
     356             : namespace {
     357             : 
     358          36 : void init(
     359             :     typelib_TypeDescriptionReference ** ppRef,
     360             :     typelib_TypeClass eTypeClass, const sal_Char * pTypeName,
     361             :     typelib_TypeDescriptionReference * pBaseType,
     362             :     sal_Int32 nMembers, typelib_TypeDescriptionReference ** ppMembers,
     363             :     sal_Bool const * pParameterizedTypes)
     364             : {
     365             :     assert( eTypeClass == typelib_TypeClass_STRUCT || eTypeClass == typelib_TypeClass_EXCEPTION );
     366             : 
     367          36 :     if (! *ppRef)
     368             :     {
     369          36 :         MutexGuard aGuard( typelib_StaticInitMutex::get() );
     370          36 :         if (! *ppRef)
     371             :         {
     372             :             assert( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(eTypeClass) );
     373          36 :             OUString aTypeName( OUString::createFromAscii( pTypeName ) );
     374          36 :             *ppRef = igetTypeByName( aTypeName.pData );
     375          36 :             if (!*ppRef)
     376             :             {
     377           4 :                 typelib_CompoundTypeDescription * pComp = 0;
     378             :                 ::typelib_typedescription_newEmpty(
     379           4 :                     (typelib_TypeDescription **)&pComp, eTypeClass, aTypeName.pData );
     380             : 
     381           4 :                 sal_Int32 nOffset = 0;
     382           4 :                 if (pBaseType)
     383             :                 {
     384             :                     ::typelib_typedescriptionreference_getDescription(
     385           4 :                         (typelib_TypeDescription **)&pComp->pBaseTypeDescription, pBaseType );
     386             :                     assert( pComp->pBaseTypeDescription );
     387           4 :                     nOffset = ((typelib_TypeDescription *)pComp->pBaseTypeDescription)->nSize;
     388             :                     assert( newAlignedSize( 0, ((typelib_TypeDescription *)pComp->pBaseTypeDescription)->nSize, ((typelib_TypeDescription *)pComp->pBaseTypeDescription)->nAlignment ) == ((typelib_TypeDescription *)pComp->pBaseTypeDescription)->nSize ); // unexpected offset
     389             :                 }
     390             : 
     391           4 :                 if (nMembers)
     392             :                 {
     393           0 :                     pComp->nMembers = nMembers;
     394           0 :                     pComp->pMemberOffsets = new sal_Int32[ nMembers ];
     395           0 :                     pComp->ppTypeRefs = new typelib_TypeDescriptionReference *[ nMembers ];
     396           0 :                     if (pParameterizedTypes != 0) {
     397             :                         reinterpret_cast< typelib_StructTypeDescription * >(
     398             :                             pComp)->pParameterizedTypes
     399           0 :                             = new sal_Bool[nMembers];
     400             :                     }
     401           0 :                     for ( sal_Int32 i = 0 ; i < nMembers; ++i )
     402             :                     {
     403             :                         ::typelib_typedescriptionreference_acquire(
     404           0 :                             pComp->ppTypeRefs[i] = ppMembers[i] );
     405             :                         // write offset
     406           0 :                         typelib_TypeDescription * pTD = 0;
     407           0 :                         TYPELIB_DANGER_GET( &pTD, pComp->ppTypeRefs[i] );
     408             :                         assert( pTD->nSize ); // void member?
     409           0 :                         nOffset = newAlignedSize( nOffset, pTD->nSize, pTD->nAlignment );
     410           0 :                         pComp->pMemberOffsets[i] = nOffset - pTD->nSize;
     411           0 :                         TYPELIB_DANGER_RELEASE( pTD );
     412             : 
     413           0 :                         if (pParameterizedTypes != 0) {
     414             :                             reinterpret_cast< typelib_StructTypeDescription * >(
     415           0 :                                 pComp)->pParameterizedTypes[i]
     416           0 :                                 = pParameterizedTypes[i];
     417             :                         }
     418             :                     }
     419             :                 }
     420             : 
     421           4 :                 typelib_TypeDescription * pReg = (typelib_TypeDescription *)pComp;
     422           4 :                 pReg->pWeakRef = (typelib_TypeDescriptionReference *)pReg;
     423             :                 // sizeof( void ) not allowed
     424           4 :                 pReg->nSize = ::typelib_typedescription_getAlignedUnoSize( pReg, 0, pReg->nAlignment );
     425           4 :                 pReg->nAlignment = adjustAlignment( pReg->nAlignment );
     426           4 :                 pReg->bComplete = sal_False;
     427             : 
     428           4 :                 ::typelib_typedescription_register( &pReg );
     429           4 :                 *ppRef = (typelib_TypeDescriptionReference *)pReg;
     430             :                 assert( *ppRef == pReg->pWeakRef );
     431             :             }
     432             :             // another static ref:
     433          36 :             ++((*ppRef)->nStaticRefCount);
     434          36 :         }
     435             :     }
     436          36 : }
     437             : 
     438             : }
     439             : 
     440          32 : CPPU_DLLPUBLIC void SAL_CALL typelib_static_compound_type_init(
     441             :     typelib_TypeDescriptionReference ** ppRef,
     442             :     typelib_TypeClass eTypeClass, const sal_Char * pTypeName,
     443             :     typelib_TypeDescriptionReference * pBaseType,
     444             :     sal_Int32 nMembers, typelib_TypeDescriptionReference ** ppMembers )
     445             :     SAL_THROW_EXTERN_C()
     446             : {
     447          32 :     init(ppRef, eTypeClass, pTypeName, pBaseType, nMembers, ppMembers, 0);
     448          32 : }
     449             : 
     450           4 : CPPU_DLLPUBLIC void SAL_CALL typelib_static_struct_type_init(
     451             :     typelib_TypeDescriptionReference ** ppRef, const sal_Char * pTypeName,
     452             :     typelib_TypeDescriptionReference * pBaseType,
     453             :     sal_Int32 nMembers, typelib_TypeDescriptionReference ** ppMembers,
     454             :     sal_Bool const * pParameterizedTypes )
     455             :     SAL_THROW_EXTERN_C()
     456             : {
     457             :     init(
     458             :         ppRef, typelib_TypeClass_STRUCT, pTypeName, pBaseType, nMembers,
     459           4 :         ppMembers, pParameterizedTypes);
     460           4 : }
     461             : 
     462             : //##################################################################################################
     463           0 : CPPU_DLLPUBLIC void SAL_CALL typelib_static_interface_type_init(
     464             :     typelib_TypeDescriptionReference ** ppRef,
     465             :     const sal_Char * pTypeName,
     466             :     typelib_TypeDescriptionReference * pBaseType )
     467             :     SAL_THROW_EXTERN_C()
     468             : {
     469             :     typelib_static_mi_interface_type_init(
     470           0 :         ppRef, pTypeName, pBaseType == 0 ? 0 : 1, &pBaseType);
     471           0 : }
     472             : 
     473             : //##################################################################################################
     474          21 : CPPU_DLLPUBLIC void SAL_CALL typelib_static_mi_interface_type_init(
     475             :     typelib_TypeDescriptionReference ** ppRef,
     476             :     const sal_Char * pTypeName,
     477             :     sal_Int32 nBaseTypes,
     478             :     typelib_TypeDescriptionReference ** ppBaseTypes )
     479             :     SAL_THROW_EXTERN_C()
     480             : {
     481          21 :     if (! *ppRef)
     482             :     {
     483          21 :         MutexGuard aGuard( typelib_StaticInitMutex::get() );
     484          21 :         if (! *ppRef)
     485             :         {
     486             :             assert( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_INTERFACE) );
     487          21 :             OUString aTypeName( OUString::createFromAscii( pTypeName ) );
     488          21 :             *ppRef = igetTypeByName( aTypeName.pData );
     489          21 :             if (!*ppRef)
     490             :             {
     491           1 :                 typelib_InterfaceTypeDescription * pIface = 0;
     492             :                 ::typelib_typedescription_newEmpty(
     493           1 :                     (typelib_TypeDescription **)&pIface, typelib_TypeClass_INTERFACE, aTypeName.pData );
     494             : 
     495           1 :                 pIface->nBaseTypes = std::max< sal_Int32 >(nBaseTypes, 1);
     496             :                 pIface->ppBaseTypes = new typelib_InterfaceTypeDescription *[
     497           1 :                     pIface->nBaseTypes];
     498           1 :                 if (nBaseTypes > 0)
     499             :                 {
     500           2 :                     for (sal_Int32 i = 0; i < nBaseTypes; ++i) {
     501           1 :                         pIface->ppBaseTypes[i] = 0;
     502             :                         ::typelib_typedescriptionreference_getDescription(
     503           1 :                             (typelib_TypeDescription **)&pIface->ppBaseTypes[i], ppBaseTypes[i] );
     504             :                         assert( pIface->ppBaseTypes[i] );
     505             :                     }
     506             :                 }
     507             :                 else
     508             :                 {
     509           0 :                     pIface->ppBaseTypes[0] = 0;
     510             :                     ::typelib_typedescriptionreference_getDescription(
     511             :                         (typelib_TypeDescription **)&pIface->ppBaseTypes[0],
     512           0 :                         * ::typelib_static_type_getByTypeClass( typelib_TypeClass_INTERFACE ) );
     513             :                     assert( pIface->ppBaseTypes[0] );
     514             :                 }
     515           1 :                 pIface->pBaseTypeDescription = pIface->ppBaseTypes[0];
     516             :                 typelib_typedescription_acquire(
     517           1 :                     &pIface->pBaseTypeDescription->aBase);
     518             : 
     519           1 :                 typelib_TypeDescription * pReg = (typelib_TypeDescription *)pIface;
     520           1 :                 pReg->pWeakRef = (typelib_TypeDescriptionReference *)pReg;
     521             :                 // sizeof( void ) not allowed
     522           1 :                 pReg->nSize = ::typelib_typedescription_getAlignedUnoSize( pReg, 0, pReg->nAlignment );
     523             : 
     524           1 :                 pReg->nAlignment = adjustAlignment( pReg->nAlignment );
     525           1 :                 pReg->bComplete = sal_False;
     526             : 
     527           1 :                 ::typelib_typedescription_register( &pReg );
     528           1 :                 *ppRef = (typelib_TypeDescriptionReference *)pReg;
     529             :                 assert( *ppRef == pReg->pWeakRef );
     530             :             }
     531             :             // another static ref:
     532          21 :             ++((*ppRef)->nStaticRefCount);
     533          21 :         }
     534             :     }
     535          21 : }
     536             : 
     537             : //##################################################################################################
     538           4 : CPPU_DLLPUBLIC void SAL_CALL typelib_static_enum_type_init(
     539             :     typelib_TypeDescriptionReference ** ppRef,
     540             :     const sal_Char * pTypeName,
     541             :     sal_Int32 nDefaultValue )
     542             :     SAL_THROW_EXTERN_C()
     543             : {
     544           4 :     if (! *ppRef)
     545             :     {
     546           4 :         MutexGuard aGuard( typelib_StaticInitMutex::get() );
     547           4 :         if (! *ppRef)
     548             :         {
     549             :             assert( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_ENUM) );
     550           4 :             OUString aTypeName( OUString::createFromAscii( pTypeName ) );
     551           4 :             *ppRef = igetTypeByName( aTypeName.pData );
     552           4 :             if (!*ppRef)
     553             :             {
     554           0 :                 typelib_TypeDescription * pReg = 0;
     555             :                 ::typelib_typedescription_newEmpty(
     556           0 :                     &pReg, typelib_TypeClass_ENUM, aTypeName.pData );
     557           0 :                 typelib_EnumTypeDescription * pEnum = (typelib_EnumTypeDescription *)pReg;
     558             : 
     559           0 :                 pEnum->nDefaultEnumValue = nDefaultValue;
     560             : 
     561           0 :                 pReg->pWeakRef = (typelib_TypeDescriptionReference *)pReg;
     562             :                 // sizeof( void ) not allowed
     563           0 :                 pReg->nSize = ::typelib_typedescription_getAlignedUnoSize( pReg, 0, pReg->nAlignment );
     564           0 :                 pReg->nAlignment = ::adjustAlignment( pReg->nAlignment );
     565           0 :                 pReg->bComplete = sal_False;
     566             : 
     567           0 :                 ::typelib_typedescription_register( &pReg );
     568           0 :                 *ppRef = (typelib_TypeDescriptionReference *)pReg;
     569             :                 assert( *ppRef == pReg->pWeakRef );
     570             :             }
     571             :             // another static ref:
     572           4 :             ++((*ppRef)->nStaticRefCount);
     573           4 :         }
     574             :     }
     575           4 : }
     576             : 
     577             : //##################################################################################################
     578           0 : CPPU_DLLPUBLIC void SAL_CALL typelib_static_array_type_init(
     579             :     typelib_TypeDescriptionReference ** ppRef,
     580             :     typelib_TypeDescriptionReference * pElementTypeRef,
     581             :     sal_Int32 nDimensions, ... )
     582             :     SAL_THROW_EXTERN_C()
     583             : {
     584           0 :     if (! *ppRef)
     585             :     {
     586           0 :         MutexGuard aGuard( typelib_StaticInitMutex::get() );
     587           0 :         if (! *ppRef)
     588             :         {
     589           0 :             OUStringBuffer aBuf( 32 );
     590           0 :             aBuf.append( pElementTypeRef->pTypeName );
     591             : 
     592             :             va_list dimArgs;
     593           0 :             va_start( dimArgs, nDimensions );
     594           0 :             sal_Int32 dim = 0;
     595           0 :             sal_Int32 nElements = 1;
     596           0 :             sal_Int32* pDimensions = new sal_Int32[nDimensions];
     597           0 :             for (sal_Int32 i=0; i < nDimensions; i++)
     598             :             {
     599           0 :                 dim = va_arg( dimArgs, int);
     600           0 :                 pDimensions[i] = dim;
     601           0 :                 aBuf.appendAscii("[");
     602           0 :                 aBuf.append(dim);
     603           0 :                 aBuf.appendAscii("]");
     604           0 :                 nElements *= dim;
     605             :             }
     606           0 :             va_end( dimArgs );
     607           0 :             OUString aTypeName( aBuf.makeStringAndClear() );
     608             : 
     609             :             assert( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_ARRAY) );
     610           0 :             *ppRef = igetTypeByName( aTypeName.pData );
     611           0 :             if (!*ppRef)
     612             :             {
     613           0 :                 typelib_TypeDescription * pReg = 0;
     614             :                 ::typelib_typedescription_newEmpty(
     615           0 :                     &pReg, typelib_TypeClass_ARRAY, aTypeName.pData );
     616           0 :                 typelib_ArrayTypeDescription * pArray = (typelib_ArrayTypeDescription *)pReg;
     617             : 
     618           0 :                 pArray->nDimensions = nDimensions;
     619           0 :                 pArray->nTotalElements = nElements;
     620           0 :                 pArray->pDimensions = pDimensions;
     621             : 
     622           0 :                 typelib_typedescriptionreference_acquire(pElementTypeRef);
     623           0 :                 ((typelib_IndirectTypeDescription*)pArray)->pType = pElementTypeRef;
     624             : 
     625           0 :                 pReg->pWeakRef = (typelib_TypeDescriptionReference *)pReg;
     626             :                 // sizeof( void ) not allowed
     627           0 :                 pReg->nSize = ::typelib_typedescription_getAlignedUnoSize( pReg, 0, pReg->nAlignment );
     628           0 :                 pReg->nAlignment = ::adjustAlignment( pReg->nAlignment );
     629           0 :                 pReg->bComplete = sal_True;
     630             : 
     631           0 :                 ::typelib_typedescription_register( &pReg );
     632           0 :                 *ppRef = (typelib_TypeDescriptionReference *)pReg;
     633             :                 assert( *ppRef == pReg->pWeakRef );
     634             :             } else
     635           0 :                 delete [] pDimensions;
     636             :             // another static ref:
     637           0 :             ++((*ppRef)->nStaticRefCount);
     638           0 :         }
     639             :     }
     640           0 : }
     641             : 
     642             : } // extern "C"
     643             : 
     644             : }
     645             : 
     646             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10