LCOV - code coverage report
Current view: top level - cppu/source/typelib - static_types.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 112 216 51.9 %
Date: 2014-04-14 Functions: 4 12 33.3 %
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 determines the alignment.
      67             :  * Under OS2 and MS-Windows the Alignment is min( 8, sizeof( type ) ).
      68             :  * The alignment of a structure is min( 8, sizeof( max basic type ) ), the greatest basic type
      69             :  * determines the alignment.
      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           0 : static inline sal_Int32 adjustAlignment( sal_Int32 nRequestedAlignment )
      92             :     SAL_THROW(())
      93             : {
      94           0 :     if( nRequestedAlignment > nMaxAlignment )
      95           0 :         nRequestedAlignment = nMaxAlignment;
      96           0 :     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          11 : static inline typelib_TypeDescriptionReference * igetTypeByName( rtl_uString * pTypeName )
     119             :     SAL_THROW(())
     120             : {
     121          11 :     typelib_TypeDescriptionReference * pRef = 0;
     122          11 :     ::typelib_typedescriptionreference_getByName( &pRef, pTypeName );
     123          11 :     if (pRef && pRef->pType && pRef->pType->pWeakRef) // found initialized td
     124             :     {
     125           4 :         return pRef;
     126             :     }
     127             :     else
     128             :     {
     129           7 :         return 0;
     130             :     }
     131             : }
     132             : 
     133             : extern "C"
     134             : {
     135             : 
     136       17840 : 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       17840 :     if (! s_aTypes[eTypeClass])
     146             :     {
     147           8 :         MutexGuard aGuard( typelib_StaticInitMutex::get() );
     148           8 :         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           8 :             switch (eTypeClass)
     157             :             {
     158             :             case typelib_TypeClass_EXCEPTION:
     159             :             case typelib_TypeClass_INTERFACE:
     160             :             {
     161             :                 // type
     162           1 :                 if (! s_aTypes[typelib_TypeClass_TYPE])
     163             :                 {
     164           1 :                     OUString sTypeName("type");
     165             :                     ::typelib_typedescriptionreference_new(
     166           1 :                         &s_aTypes[typelib_TypeClass_TYPE], typelib_TypeClass_TYPE, sTypeName.pData );
     167             :                     // another static ref:
     168           1 :                     ++s_aTypes[typelib_TypeClass_TYPE]->nStaticRefCount;
     169             :                 }
     170             :                 // any
     171           1 :                 if (! s_aTypes[typelib_TypeClass_ANY])
     172             :                 {
     173           1 :                     OUString sTypeName("any");
     174             :                     ::typelib_typedescriptionreference_new(
     175           1 :                         &s_aTypes[typelib_TypeClass_ANY], typelib_TypeClass_ANY, sTypeName.pData );
     176             :                     // another static ref:
     177           1 :                     ++s_aTypes[typelib_TypeClass_ANY]->nStaticRefCount;
     178             :                 }
     179             :                 // string
     180           1 :                 if (! s_aTypes[typelib_TypeClass_STRING])
     181             :                 {
     182           1 :                     OUString sTypeName("string");
     183             :                     ::typelib_typedescriptionreference_new(
     184           1 :                         &s_aTypes[typelib_TypeClass_STRING], typelib_TypeClass_STRING, sTypeName.pData );
     185             :                     // another static ref:
     186           1 :                     ++s_aTypes[typelib_TypeClass_STRING]->nStaticRefCount;
     187             :                 }
     188             :                 // XInterface
     189           1 :                 if (! s_aTypes[typelib_TypeClass_INTERFACE])
     190             :                 {
     191           1 :                     OUString sTypeName("com.sun.star.uno.XInterface");
     192             : 
     193           1 :                     typelib_InterfaceTypeDescription * pTD = 0;
     194             : 
     195           1 :                     typelib_TypeDescriptionReference * pMembers[3] = { 0,0,0 };
     196           2 :                     OUString sMethodName0("com.sun.star.uno.XInterface::queryInterface");
     197             :                     ::typelib_typedescriptionreference_new(
     198           1 :                         &pMembers[0], typelib_TypeClass_INTERFACE_METHOD, sMethodName0.pData );
     199           2 :                     OUString sMethodName1("com.sun.star.uno.XInterface::acquire");
     200             :                     ::typelib_typedescriptionreference_new(
     201           1 :                         &pMembers[1], typelib_TypeClass_INTERFACE_METHOD, sMethodName1.pData );
     202           2 :                     OUString sMethodName2("com.sun.star.uno.XInterface::release");
     203             :                     ::typelib_typedescriptionreference_new(
     204           1 :                         &pMembers[2], typelib_TypeClass_INTERFACE_METHOD, sMethodName2.pData );
     205             : 
     206             :                     ::typelib_typedescription_newInterface(
     207           1 :                         &pTD, sTypeName.pData, 0, 0, 0, 0, 0, 0, 3, pMembers );
     208             : 
     209           1 :                     ::typelib_typedescription_register( (typelib_TypeDescription **)&pTD );
     210             :                     ::typelib_typedescriptionreference_acquire(
     211           1 :                         s_aTypes[typelib_TypeClass_INTERFACE] = ((typelib_TypeDescription *)pTD)->pWeakRef );
     212             :                     // another static ref:
     213           1 :                     ++s_aTypes[typelib_TypeClass_INTERFACE]->nStaticRefCount;
     214           1 :                     ::typelib_typedescription_release( (typelib_TypeDescription*)pTD );
     215             : 
     216           1 :                     ::typelib_typedescriptionreference_release( pMembers[0] );
     217           1 :                     ::typelib_typedescriptionreference_release( pMembers[1] );
     218           1 :                     ::typelib_typedescriptionreference_release( pMembers[2] );
     219             :                     // Exception
     220             :                     assert( ! s_aTypes[typelib_TypeClass_EXCEPTION] );
     221             :                     {
     222           1 :                     typelib_TypeDescription * pTD1 = 0;
     223           1 :                     OUString sTypeName1("com.sun.star.uno.Exception");
     224             : 
     225             :                     typelib_CompoundMember_Init aMembers[2];
     226           2 :                     OUString sMemberType0("string");
     227           2 :                     OUString sMemberName0("Message");
     228           1 :                     aMembers[0].eTypeClass = typelib_TypeClass_STRING;
     229           1 :                     aMembers[0].pTypeName = sMemberType0.pData;
     230           1 :                     aMembers[0].pMemberName = sMemberName0.pData;
     231           2 :                     OUString sMemberType1("com.sun.star.uno.XInterface");
     232           2 :                     OUString sMemberName1("Context");
     233           1 :                     aMembers[1].eTypeClass = typelib_TypeClass_INTERFACE;
     234           1 :                     aMembers[1].pTypeName = sMemberType1.pData;
     235           1 :                     aMembers[1].pMemberName = sMemberName1.pData;
     236             : 
     237             :                     ::typelib_typedescription_new(
     238           1 :                         &pTD1, typelib_TypeClass_EXCEPTION, sTypeName1.pData, 0, 2, aMembers );
     239           1 :                     typelib_typedescription_register( &pTD1 );
     240             :                     typelib_typedescriptionreference_acquire(
     241           1 :                         s_aTypes[typelib_TypeClass_EXCEPTION] = pTD1->pWeakRef );
     242             :                     // another static ref:
     243           1 :                     ++s_aTypes[typelib_TypeClass_EXCEPTION]->nStaticRefCount;
     244             :                     // RuntimeException
     245           2 :                     OUString sTypeName2("com.sun.star.uno.RuntimeException");
     246             :                     ::typelib_typedescription_new(
     247           1 :                         &pTD1, typelib_TypeClass_EXCEPTION, sTypeName2.pData, s_aTypes[typelib_TypeClass_EXCEPTION], 0, 0 );
     248           1 :                     ::typelib_typedescription_register( &pTD1 );
     249           2 :                     ::typelib_typedescription_release( pTD1 );
     250             :                     }
     251             :                     // XInterface members
     252           1 :                     typelib_InterfaceMethodTypeDescription * pMethod = 0;
     253             :                     typelib_Parameter_Init aParameters[1];
     254           2 :                     OUString sParamName0("aType");
     255           2 :                     OUString sParamType0("type");
     256           1 :                     aParameters[0].pParamName = sParamName0.pData;
     257           1 :                     aParameters[0].eTypeClass = typelib_TypeClass_TYPE;
     258           1 :                     aParameters[0].pTypeName = sParamType0.pData;
     259           1 :                     aParameters[0].bIn = sal_True;
     260           1 :                     aParameters[0].bOut = sal_False;
     261             :                     rtl_uString * pExceptions[1];
     262           2 :                     OUString sExceptionName0("com.sun.star.uno.RuntimeException");
     263           1 :                     pExceptions[0] = sExceptionName0.pData;
     264           2 :                     OUString sReturnType0("any");
     265             :                     typelib_typedescription_newInterfaceMethod(
     266             :                         &pMethod, 0, sal_False, sMethodName0.pData,
     267             :                         typelib_TypeClass_ANY, sReturnType0.pData,
     268           1 :                         1, aParameters, 1, pExceptions );
     269           1 :                     ::typelib_typedescription_register( (typelib_TypeDescription**)&pMethod );
     270             : 
     271           2 :                     OUString sReturnType1("void");
     272             :                     ::typelib_typedescription_newInterfaceMethod(
     273             :                         &pMethod, 1, sal_True, sMethodName1.pData,
     274           1 :                         typelib_TypeClass_VOID, sReturnType1.pData, 0, 0, 0, 0 );
     275           1 :                     ::typelib_typedescription_register( (typelib_TypeDescription**)&pMethod );
     276             : 
     277             :                     ::typelib_typedescription_newInterfaceMethod(
     278             :                         &pMethod, 2, sal_True, sMethodName2.pData,
     279             :                         typelib_TypeClass_VOID, sReturnType1.pData,
     280           1 :                         0, 0, 0, 0 );
     281           1 :                     ::typelib_typedescription_register( (typelib_TypeDescription**)&pMethod );
     282           2 :                     ::typelib_typedescription_release( (typelib_TypeDescription*)pMethod );
     283             :                 }
     284           1 :                 break;
     285             :             }
     286             :             default:
     287             :             {
     288           7 :                 OUString aTypeName( OUString::createFromAscii( s_aTypeNames[eTypeClass] ) );
     289           7 :                 ::typelib_typedescriptionreference_new( &s_aTypes[eTypeClass], eTypeClass, aTypeName.pData );
     290             :                 // another static ref:
     291           7 :                 ++s_aTypes[eTypeClass]->nStaticRefCount;
     292             :             }
     293             :             }
     294           8 :         }
     295             :     }
     296       17840 :     return &s_aTypes[eTypeClass];
     297             : }
     298             : 
     299             : 
     300          30 : CPPU_DLLPUBLIC void SAL_CALL typelib_static_type_init(
     301             :     typelib_TypeDescriptionReference ** ppRef,
     302             :     typelib_TypeClass eTypeClass, const sal_Char * pTypeName )
     303             :     SAL_THROW_EXTERN_C()
     304             : {
     305          30 :     if (! *ppRef)
     306             :     {
     307          30 :         MutexGuard aGuard( typelib_StaticInitMutex::get() );
     308          30 :         if (! *ppRef)
     309             :         {
     310          30 :             OUString aTypeName( OUString::createFromAscii( pTypeName ) );
     311          30 :             ::typelib_typedescriptionreference_new( ppRef, eTypeClass, aTypeName.pData );
     312             : 
     313             :             // another static ref:
     314          30 :             ++((*ppRef)->nStaticRefCount);
     315          30 :         }
     316             :     }
     317          30 : }
     318             : 
     319             : 
     320          11 : CPPU_DLLPUBLIC void SAL_CALL typelib_static_sequence_type_init(
     321             :     typelib_TypeDescriptionReference ** ppRef,
     322             :     typelib_TypeDescriptionReference * pElementType )
     323             :     SAL_THROW_EXTERN_C()
     324             : {
     325          11 :     if (! *ppRef)
     326             :     {
     327          11 :         MutexGuard aGuard( typelib_StaticInitMutex::get() );
     328          11 :         if (! *ppRef)
     329             :         {
     330          11 :             OUStringBuffer aBuf( 32 );
     331          11 :             aBuf.appendAscii( "[]" );
     332          11 :             aBuf.append( pElementType->pTypeName );
     333          22 :             OUString aTypeName( aBuf.makeStringAndClear() );
     334             : 
     335             :             assert( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_SEQUENCE) );
     336          11 :             *ppRef = igetTypeByName( aTypeName.pData );
     337          11 :             if (!*ppRef)
     338             :             {
     339           7 :                 typelib_TypeDescription * pReg = 0;
     340             :                 ::typelib_typedescription_new(
     341             :                     &pReg, typelib_TypeClass_SEQUENCE,
     342           7 :                     aTypeName.pData, pElementType, 0, 0 );
     343             : 
     344           7 :                 ::typelib_typedescription_register( &pReg );
     345           7 :                 *ppRef = (typelib_TypeDescriptionReference *)pReg;
     346             :                 assert( *ppRef == pReg->pWeakRef );
     347             :             }
     348             :             // another static ref:
     349          22 :             ++((*ppRef)->nStaticRefCount);
     350          11 :         }
     351             :     }
     352          11 : }
     353             : 
     354             : 
     355             : namespace {
     356             : 
     357           0 : void init(
     358             :     typelib_TypeDescriptionReference ** ppRef,
     359             :     typelib_TypeClass eTypeClass, const sal_Char * pTypeName,
     360             :     typelib_TypeDescriptionReference * pBaseType,
     361             :     sal_Int32 nMembers, typelib_TypeDescriptionReference ** ppMembers,
     362             :     sal_Bool const * pParameterizedTypes)
     363             : {
     364             :     assert( eTypeClass == typelib_TypeClass_STRUCT || eTypeClass == typelib_TypeClass_EXCEPTION );
     365             : 
     366           0 :     if (! *ppRef)
     367             :     {
     368           0 :         MutexGuard aGuard( typelib_StaticInitMutex::get() );
     369           0 :         if (! *ppRef)
     370             :         {
     371             :             assert( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(eTypeClass) );
     372           0 :             OUString aTypeName( OUString::createFromAscii( pTypeName ) );
     373           0 :             *ppRef = igetTypeByName( aTypeName.pData );
     374           0 :             if (!*ppRef)
     375             :             {
     376           0 :                 typelib_CompoundTypeDescription * pComp = 0;
     377             :                 ::typelib_typedescription_newEmpty(
     378           0 :                     (typelib_TypeDescription **)&pComp, eTypeClass, aTypeName.pData );
     379             : 
     380           0 :                 sal_Int32 nOffset = 0;
     381           0 :                 if (pBaseType)
     382             :                 {
     383             :                     ::typelib_typedescriptionreference_getDescription(
     384           0 :                         (typelib_TypeDescription **)&pComp->pBaseTypeDescription, pBaseType );
     385             :                     assert( pComp->pBaseTypeDescription );
     386           0 :                     nOffset = ((typelib_TypeDescription *)pComp->pBaseTypeDescription)->nSize;
     387             :                     assert( newAlignedSize( 0, ((typelib_TypeDescription *)pComp->pBaseTypeDescription)->nSize, ((typelib_TypeDescription *)pComp->pBaseTypeDescription)->nAlignment ) == ((typelib_TypeDescription *)pComp->pBaseTypeDescription)->nSize ); // unexpected offset
     388             :                 }
     389             : 
     390           0 :                 if (nMembers)
     391             :                 {
     392           0 :                     pComp->nMembers = nMembers;
     393           0 :                     pComp->pMemberOffsets = new sal_Int32[ nMembers ];
     394           0 :                     pComp->ppTypeRefs = new typelib_TypeDescriptionReference *[ nMembers ];
     395           0 :                     if (pParameterizedTypes != 0) {
     396             :                         reinterpret_cast< typelib_StructTypeDescription * >(
     397             :                             pComp)->pParameterizedTypes
     398           0 :                             = new sal_Bool[nMembers];
     399             :                     }
     400           0 :                     for ( sal_Int32 i = 0 ; i < nMembers; ++i )
     401             :                     {
     402             :                         ::typelib_typedescriptionreference_acquire(
     403           0 :                             pComp->ppTypeRefs[i] = ppMembers[i] );
     404             :                         // write offset
     405           0 :                         typelib_TypeDescription * pTD = 0;
     406           0 :                         TYPELIB_DANGER_GET( &pTD, pComp->ppTypeRefs[i] );
     407             :                         assert( pTD->nSize ); // void member?
     408           0 :                         nOffset = newAlignedSize( nOffset, pTD->nSize, pTD->nAlignment );
     409           0 :                         pComp->pMemberOffsets[i] = nOffset - pTD->nSize;
     410           0 :                         TYPELIB_DANGER_RELEASE( pTD );
     411             : 
     412           0 :                         if (pParameterizedTypes != 0) {
     413             :                             reinterpret_cast< typelib_StructTypeDescription * >(
     414           0 :                                 pComp)->pParameterizedTypes[i]
     415           0 :                                 = pParameterizedTypes[i];
     416             :                         }
     417             :                     }
     418             :                 }
     419             : 
     420           0 :                 typelib_TypeDescription * pReg = (typelib_TypeDescription *)pComp;
     421           0 :                 pReg->pWeakRef = (typelib_TypeDescriptionReference *)pReg;
     422             :                 // sizeof( void ) not allowed
     423           0 :                 pReg->nSize = ::typelib_typedescription_getAlignedUnoSize( pReg, 0, pReg->nAlignment );
     424           0 :                 pReg->nAlignment = adjustAlignment( pReg->nAlignment );
     425           0 :                 pReg->bComplete = sal_False;
     426             : 
     427           0 :                 ::typelib_typedescription_register( &pReg );
     428           0 :                 *ppRef = (typelib_TypeDescriptionReference *)pReg;
     429             :                 assert( *ppRef == pReg->pWeakRef );
     430             :             }
     431             :             // another static ref:
     432           0 :             ++((*ppRef)->nStaticRefCount);
     433           0 :         }
     434             :     }
     435           0 : }
     436             : 
     437             : }
     438             : 
     439           0 : CPPU_DLLPUBLIC void SAL_CALL typelib_static_compound_type_init(
     440             :     typelib_TypeDescriptionReference ** ppRef,
     441             :     typelib_TypeClass eTypeClass, const sal_Char * pTypeName,
     442             :     typelib_TypeDescriptionReference * pBaseType,
     443             :     sal_Int32 nMembers, typelib_TypeDescriptionReference ** ppMembers )
     444             :     SAL_THROW_EXTERN_C()
     445             : {
     446           0 :     init(ppRef, eTypeClass, pTypeName, pBaseType, nMembers, ppMembers, 0);
     447           0 : }
     448             : 
     449           0 : CPPU_DLLPUBLIC void SAL_CALL typelib_static_struct_type_init(
     450             :     typelib_TypeDescriptionReference ** ppRef, const sal_Char * pTypeName,
     451             :     typelib_TypeDescriptionReference * pBaseType,
     452             :     sal_Int32 nMembers, typelib_TypeDescriptionReference ** ppMembers,
     453             :     sal_Bool const * pParameterizedTypes )
     454             :     SAL_THROW_EXTERN_C()
     455             : {
     456             :     init(
     457             :         ppRef, typelib_TypeClass_STRUCT, pTypeName, pBaseType, nMembers,
     458           0 :         ppMembers, pParameterizedTypes);
     459           0 : }
     460             : 
     461             : 
     462           0 : CPPU_DLLPUBLIC void SAL_CALL typelib_static_interface_type_init(
     463             :     typelib_TypeDescriptionReference ** ppRef,
     464             :     const sal_Char * pTypeName,
     465             :     typelib_TypeDescriptionReference * pBaseType )
     466             :     SAL_THROW_EXTERN_C()
     467             : {
     468             :     typelib_static_mi_interface_type_init(
     469           0 :         ppRef, pTypeName, pBaseType == 0 ? 0 : 1, &pBaseType);
     470           0 : }
     471             : 
     472             : 
     473           0 : CPPU_DLLPUBLIC void SAL_CALL typelib_static_mi_interface_type_init(
     474             :     typelib_TypeDescriptionReference ** ppRef,
     475             :     const sal_Char * pTypeName,
     476             :     sal_Int32 nBaseTypes,
     477             :     typelib_TypeDescriptionReference ** ppBaseTypes )
     478             :     SAL_THROW_EXTERN_C()
     479             : {
     480           0 :     if (! *ppRef)
     481             :     {
     482           0 :         MutexGuard aGuard( typelib_StaticInitMutex::get() );
     483           0 :         if (! *ppRef)
     484             :         {
     485             :             assert( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_INTERFACE) );
     486           0 :             OUString aTypeName( OUString::createFromAscii( pTypeName ) );
     487           0 :             *ppRef = igetTypeByName( aTypeName.pData );
     488           0 :             if (!*ppRef)
     489             :             {
     490           0 :                 typelib_InterfaceTypeDescription * pIface = 0;
     491             :                 ::typelib_typedescription_newEmpty(
     492           0 :                     (typelib_TypeDescription **)&pIface, typelib_TypeClass_INTERFACE, aTypeName.pData );
     493             : 
     494           0 :                 pIface->nBaseTypes = std::max< sal_Int32 >(nBaseTypes, 1);
     495             :                 pIface->ppBaseTypes = new typelib_InterfaceTypeDescription *[
     496           0 :                     pIface->nBaseTypes];
     497           0 :                 if (nBaseTypes > 0)
     498             :                 {
     499           0 :                     for (sal_Int32 i = 0; i < nBaseTypes; ++i) {
     500           0 :                         pIface->ppBaseTypes[i] = 0;
     501             :                         ::typelib_typedescriptionreference_getDescription(
     502           0 :                             (typelib_TypeDescription **)&pIface->ppBaseTypes[i], ppBaseTypes[i] );
     503             :                         assert( pIface->ppBaseTypes[i] );
     504             :                     }
     505             :                 }
     506             :                 else
     507             :                 {
     508           0 :                     pIface->ppBaseTypes[0] = 0;
     509             :                     ::typelib_typedescriptionreference_getDescription(
     510             :                         (typelib_TypeDescription **)&pIface->ppBaseTypes[0],
     511           0 :                         * ::typelib_static_type_getByTypeClass( typelib_TypeClass_INTERFACE ) );
     512             :                     assert( pIface->ppBaseTypes[0] );
     513             :                 }
     514           0 :                 pIface->pBaseTypeDescription = pIface->ppBaseTypes[0];
     515             :                 typelib_typedescription_acquire(
     516           0 :                     &pIface->pBaseTypeDescription->aBase);
     517             : 
     518           0 :                 typelib_TypeDescription * pReg = (typelib_TypeDescription *)pIface;
     519           0 :                 pReg->pWeakRef = (typelib_TypeDescriptionReference *)pReg;
     520             :                 // sizeof( void ) not allowed
     521           0 :                 pReg->nSize = ::typelib_typedescription_getAlignedUnoSize( pReg, 0, pReg->nAlignment );
     522             : 
     523           0 :                 pReg->nAlignment = adjustAlignment( pReg->nAlignment );
     524           0 :                 pReg->bComplete = sal_False;
     525             : 
     526           0 :                 ::typelib_typedescription_register( &pReg );
     527           0 :                 *ppRef = (typelib_TypeDescriptionReference *)pReg;
     528             :                 assert( *ppRef == pReg->pWeakRef );
     529             :             }
     530             :             // another static ref:
     531           0 :             ++((*ppRef)->nStaticRefCount);
     532           0 :         }
     533             :     }
     534           0 : }
     535             : 
     536             : 
     537           0 : CPPU_DLLPUBLIC void SAL_CALL typelib_static_enum_type_init(
     538             :     typelib_TypeDescriptionReference ** ppRef,
     539             :     const sal_Char * pTypeName,
     540             :     sal_Int32 nDefaultValue )
     541             :     SAL_THROW_EXTERN_C()
     542             : {
     543           0 :     if (! *ppRef)
     544             :     {
     545           0 :         MutexGuard aGuard( typelib_StaticInitMutex::get() );
     546           0 :         if (! *ppRef)
     547             :         {
     548             :             assert( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_ENUM) );
     549           0 :             OUString aTypeName( OUString::createFromAscii( pTypeName ) );
     550           0 :             *ppRef = igetTypeByName( aTypeName.pData );
     551           0 :             if (!*ppRef)
     552             :             {
     553           0 :                 typelib_TypeDescription * pReg = 0;
     554             :                 ::typelib_typedescription_newEmpty(
     555           0 :                     &pReg, typelib_TypeClass_ENUM, aTypeName.pData );
     556           0 :                 typelib_EnumTypeDescription * pEnum = (typelib_EnumTypeDescription *)pReg;
     557             : 
     558           0 :                 pEnum->nDefaultEnumValue = nDefaultValue;
     559             : 
     560           0 :                 pReg->pWeakRef = (typelib_TypeDescriptionReference *)pReg;
     561             :                 // sizeof( void ) not allowed
     562           0 :                 pReg->nSize = ::typelib_typedescription_getAlignedUnoSize( pReg, 0, pReg->nAlignment );
     563           0 :                 pReg->nAlignment = ::adjustAlignment( pReg->nAlignment );
     564           0 :                 pReg->bComplete = sal_False;
     565             : 
     566           0 :                 ::typelib_typedescription_register( &pReg );
     567           0 :                 *ppRef = (typelib_TypeDescriptionReference *)pReg;
     568             :                 assert( *ppRef == pReg->pWeakRef );
     569             :             }
     570             :             // another static ref:
     571           0 :             ++((*ppRef)->nStaticRefCount);
     572           0 :         }
     573             :     }
     574           0 : }
     575             : 
     576             : } // extern "C"
     577             : 
     578             : }
     579             : 
     580             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10