update dev300-m58
[ooovba.git] / cppu / source / typelib / static_types.cxx
blob7b54ed498c9fbc600b37fdcb9d149b7ac8bde41c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: static_types.cxx,v $
10 * $Revision: 1.18 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_cppu.hxx"
34 #include <stdarg.h>
35 #include <algorithm>
37 #include <osl/mutex.hxx>
38 #include <osl/interlck.h>
39 #include <rtl/ustring.hxx>
40 #include <rtl/ustrbuf.hxx>
41 #include <rtl/memory.h>
42 #include <rtl/instance.hxx>
44 #include <typelib/typedescription.h>
47 using namespace osl;
48 using namespace rtl;
50 extern "C"
53 //------------------------------------------------------------------------
54 sal_Int32 SAL_CALL typelib_typedescription_getAlignedUnoSize(
55 const typelib_TypeDescription * pTypeDescription,
56 sal_Int32 nOffset,
57 sal_Int32 & rMaxIntegralTypeSize )
58 SAL_THROW_EXTERN_C();
59 //------------------------------------------------------------------------
60 void SAL_CALL typelib_typedescription_newEmpty(
61 typelib_TypeDescription ** ppRet,
62 typelib_TypeClass eTypeClass,
63 rtl_uString * pTypeName )
64 SAL_THROW_EXTERN_C();
65 //-----------------------------------------------------------------------------
66 void SAL_CALL typelib_typedescriptionreference_getByName(
67 typelib_TypeDescriptionReference ** ppRet,
68 rtl_uString * pName )
69 SAL_THROW_EXTERN_C();
71 #ifdef SAL_W32
72 #pragma pack(push, 8)
73 #elif defined(SAL_OS2)
74 #pragma pack(8)
75 #endif
77 /**
78 * The double member determin the alignment.
79 * Under Os2 and MS-Windows the Alignment is min( 8, sizeof( type ) ).
80 * The aligment of a strukture is min( 8, sizeof( max basic type ) ), the greatest basic type
81 * determine the aligment.
83 struct AlignSize_Impl
85 sal_Int16 nInt16;
86 double dDouble;
89 #ifdef SAL_W32
90 #pragma pack(pop)
91 #elif defined(SAL_OS2)
92 #pragma pack()
93 #endif
95 // the value of the maximal alignment
96 static sal_Int32 nMaxAlignment = (sal_Int32)( (sal_Size)(&((AlignSize_Impl *) 16)->dDouble) - 16);
98 static inline sal_Int32 adjustAlignment( sal_Int32 nRequestedAlignment )
99 SAL_THROW( () )
101 if( nRequestedAlignment > nMaxAlignment )
102 nRequestedAlignment = nMaxAlignment;
103 return nRequestedAlignment;
107 * Calculate the new size of the struktur.
109 static inline sal_Int32 newAlignedSize(
110 sal_Int32 OldSize, sal_Int32 ElementSize, sal_Int32 NeededAlignment )
111 SAL_THROW( () )
113 NeededAlignment = adjustAlignment( NeededAlignment );
114 return (OldSize + NeededAlignment -1) / NeededAlignment * NeededAlignment + ElementSize;
117 //--------------------------------------------------------------------------------------------------
119 namespace
121 struct typelib_StaticInitMutex : public rtl::Static< Mutex, typelib_StaticInitMutex > {};
124 // !for NOT REALLY WEAK TYPES only!
125 static inline typelib_TypeDescriptionReference * igetTypeByName( rtl_uString * pTypeName )
126 SAL_THROW( () )
128 typelib_TypeDescriptionReference * pRef = 0;
129 ::typelib_typedescriptionreference_getByName( &pRef, pTypeName );
130 if (pRef && pRef->pType && pRef->pType->pWeakRef) // found initialized td
132 return pRef;
134 else
136 return 0;
140 extern "C"
142 //##################################################################################################
143 typelib_TypeDescriptionReference ** SAL_CALL typelib_static_type_getByTypeClass(
144 typelib_TypeClass eTypeClass )
145 SAL_THROW_EXTERN_C()
147 static typelib_TypeDescriptionReference * s_aTypes[] = {
148 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
149 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
150 0, 0, 0 };
152 if (! s_aTypes[eTypeClass])
154 MutexGuard aGuard( typelib_StaticInitMutex::get() );
155 if (! s_aTypes[eTypeClass])
157 static const char * s_aTypeNames[] = {
158 "void", "char", "boolean", "byte",
159 "short", "unsigned short", "long", "unsigned long",
160 "hyper", "unsigned hyper", "float", "double",
161 "string", "type", "any" };
163 switch (eTypeClass)
165 case typelib_TypeClass_EXCEPTION:
166 case typelib_TypeClass_INTERFACE:
168 // type
169 if (! s_aTypes[typelib_TypeClass_TYPE])
171 OUString sTypeName( RTL_CONSTASCII_USTRINGPARAM("type") );
172 ::typelib_typedescriptionreference_new(
173 &s_aTypes[typelib_TypeClass_TYPE], typelib_TypeClass_TYPE, sTypeName.pData );
174 #ifndef CPPU_LEAK_STATIC_DATA
175 // another static ref
176 ++s_aTypes[typelib_TypeClass_TYPE]->nStaticRefCount;
177 #endif
179 // any
180 if (! s_aTypes[typelib_TypeClass_ANY])
182 OUString sTypeName( RTL_CONSTASCII_USTRINGPARAM("any") );
183 ::typelib_typedescriptionreference_new(
184 &s_aTypes[typelib_TypeClass_ANY], typelib_TypeClass_ANY, sTypeName.pData );
185 #ifndef CPPU_LEAK_STATIC_DATA
186 // another static ref
187 ++s_aTypes[typelib_TypeClass_ANY]->nStaticRefCount;
188 #endif
190 // string
191 if (! s_aTypes[typelib_TypeClass_STRING])
193 OUString sTypeName( RTL_CONSTASCII_USTRINGPARAM("string") );
194 ::typelib_typedescriptionreference_new(
195 &s_aTypes[typelib_TypeClass_STRING], typelib_TypeClass_STRING, sTypeName.pData );
196 #ifndef CPPU_LEAK_STATIC_DATA
197 // another static ref
198 ++s_aTypes[typelib_TypeClass_STRING]->nStaticRefCount;
199 #endif
201 // XInterface
202 if (! s_aTypes[typelib_TypeClass_INTERFACE])
204 OUString sTypeName( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.XInterface") );
206 typelib_InterfaceTypeDescription * pTD = 0;
208 typelib_TypeDescriptionReference * pMembers[3] = { 0,0,0 };
209 OUString sMethodName0( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.XInterface::queryInterface") );
210 ::typelib_typedescriptionreference_new(
211 &pMembers[0], typelib_TypeClass_INTERFACE_METHOD, sMethodName0.pData );
212 OUString sMethodName1( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.XInterface::acquire") );
213 ::typelib_typedescriptionreference_new(
214 &pMembers[1], typelib_TypeClass_INTERFACE_METHOD, sMethodName1.pData );
215 OUString sMethodName2( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.XInterface::release") );
216 ::typelib_typedescriptionreference_new(
217 &pMembers[2], typelib_TypeClass_INTERFACE_METHOD, sMethodName2.pData );
219 ::typelib_typedescription_newInterface(
220 &pTD, sTypeName.pData, 0xe227a391, 0x33d6, 0x11d1, 0xaabe00a0, 0x249d5590,
221 0, 3, pMembers );
223 ::typelib_typedescription_register( (typelib_TypeDescription **)&pTD );
224 ::typelib_typedescriptionreference_acquire(
225 s_aTypes[typelib_TypeClass_INTERFACE] = ((typelib_TypeDescription *)pTD)->pWeakRef );
226 #ifndef CPPU_LEAK_STATIC_DATA
227 // another static ref
228 ++s_aTypes[typelib_TypeClass_INTERFACE]->nStaticRefCount;
229 #endif
230 ::typelib_typedescription_release( (typelib_TypeDescription*)pTD );
232 ::typelib_typedescriptionreference_release( pMembers[0] );
233 ::typelib_typedescriptionreference_release( pMembers[1] );
234 ::typelib_typedescriptionreference_release( pMembers[2] );
235 // Exception
236 OSL_ASSERT( ! s_aTypes[typelib_TypeClass_EXCEPTION] );
238 typelib_TypeDescription * pTD1 = 0;
239 OUString sTypeName1( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.Exception") );
241 typelib_CompoundMember_Init aMembers[2];
242 OUString sMemberType0( RTL_CONSTASCII_USTRINGPARAM("string") );
243 OUString sMemberName0( RTL_CONSTASCII_USTRINGPARAM("Message") );
244 aMembers[0].eTypeClass = typelib_TypeClass_STRING;
245 aMembers[0].pTypeName = sMemberType0.pData;
246 aMembers[0].pMemberName = sMemberName0.pData;
247 OUString sMemberType1( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.XInterface") );
248 OUString sMemberName1( RTL_CONSTASCII_USTRINGPARAM("Context") );
249 aMembers[1].eTypeClass = typelib_TypeClass_INTERFACE;
250 aMembers[1].pTypeName = sMemberType1.pData;
251 aMembers[1].pMemberName = sMemberName1.pData;
253 ::typelib_typedescription_new(
254 &pTD1, typelib_TypeClass_EXCEPTION, sTypeName1.pData, 0, 2, aMembers );
255 typelib_typedescription_register( &pTD1 );
256 typelib_typedescriptionreference_acquire(
257 s_aTypes[typelib_TypeClass_EXCEPTION] = pTD1->pWeakRef );
258 #ifndef CPPU_LEAK_STATIC_DATA
259 // another static ref
260 ++s_aTypes[typelib_TypeClass_EXCEPTION]->nStaticRefCount;
261 #endif
262 // RuntimeException
263 OUString sTypeName2( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.RuntimeException") );
264 ::typelib_typedescription_new(
265 &pTD1, typelib_TypeClass_EXCEPTION, sTypeName2.pData, s_aTypes[typelib_TypeClass_EXCEPTION], 0, 0 );
266 ::typelib_typedescription_register( &pTD1 );
267 ::typelib_typedescription_release( pTD1 );
269 // XInterface members
270 typelib_InterfaceMethodTypeDescription * pMethod = 0;
271 typelib_Parameter_Init aParameters[1];
272 OUString sParamName0( RTL_CONSTASCII_USTRINGPARAM("aType") );
273 OUString sParamType0( RTL_CONSTASCII_USTRINGPARAM("type") );
274 aParameters[0].pParamName = sParamName0.pData;
275 aParameters[0].eTypeClass = typelib_TypeClass_TYPE;
276 aParameters[0].pTypeName = sParamType0.pData;
277 aParameters[0].bIn = sal_True;
278 aParameters[0].bOut = sal_False;
279 rtl_uString * pExceptions[1];
280 OUString sExceptionName0( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.RuntimeException") );
281 pExceptions[0] = sExceptionName0.pData;
282 OUString sReturnType0( RTL_CONSTASCII_USTRINGPARAM("any") );
283 typelib_typedescription_newInterfaceMethod(
284 &pMethod, 0, sal_False, sMethodName0.pData,
285 typelib_TypeClass_ANY, sReturnType0.pData,
286 1, aParameters, 1, pExceptions );
287 ::typelib_typedescription_register( (typelib_TypeDescription**)&pMethod );
289 OUString sReturnType1( RTL_CONSTASCII_USTRINGPARAM("void") );
290 ::typelib_typedescription_newInterfaceMethod(
291 &pMethod, 1, sal_True, sMethodName1.pData,
292 typelib_TypeClass_VOID, sReturnType1.pData, 0, 0, 0, 0 );
293 ::typelib_typedescription_register( (typelib_TypeDescription**)&pMethod );
295 ::typelib_typedescription_newInterfaceMethod(
296 &pMethod, 2, sal_True, sMethodName2.pData,
297 typelib_TypeClass_VOID, sReturnType1.pData,
298 0, 0, 0, 0 );
299 ::typelib_typedescription_register( (typelib_TypeDescription**)&pMethod );
300 ::typelib_typedescription_release( (typelib_TypeDescription*)pMethod );
302 break;
304 default:
306 OUString aTypeName( OUString::createFromAscii( s_aTypeNames[eTypeClass] ) );
307 ::typelib_typedescriptionreference_new( &s_aTypes[eTypeClass], eTypeClass, aTypeName.pData );
308 #ifndef CPPU_LEAK_STATIC_DATA
309 // another static ref
310 ++s_aTypes[eTypeClass]->nStaticRefCount;
311 #endif
316 return &s_aTypes[eTypeClass];
319 //##################################################################################################
320 void SAL_CALL typelib_static_type_init(
321 typelib_TypeDescriptionReference ** ppRef,
322 typelib_TypeClass eTypeClass, const sal_Char * pTypeName )
323 SAL_THROW_EXTERN_C()
325 if (! *ppRef)
327 MutexGuard aGuard( typelib_StaticInitMutex::get() );
328 if (! *ppRef)
330 OUString aTypeName( OUString::createFromAscii( pTypeName ) );
331 ::typelib_typedescriptionreference_new( ppRef, eTypeClass, aTypeName.pData );
333 #ifndef CPPU_LEAK_STATIC_DATA
334 // another static ref
335 ++((*ppRef)->nStaticRefCount);
336 #endif
341 //##################################################################################################
342 void SAL_CALL typelib_static_sequence_type_init(
343 typelib_TypeDescriptionReference ** ppRef,
344 typelib_TypeDescriptionReference * pElementType )
345 SAL_THROW_EXTERN_C()
347 if (! *ppRef)
349 MutexGuard aGuard( typelib_StaticInitMutex::get() );
350 if (! *ppRef)
352 OUStringBuffer aBuf( 32 );
353 aBuf.appendAscii( "[]" );
354 aBuf.append( pElementType->pTypeName );
355 OUString aTypeName( aBuf.makeStringAndClear() );
357 OSL_ASSERT( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_SEQUENCE) );
358 *ppRef = igetTypeByName( aTypeName.pData );
359 if (!*ppRef)
361 typelib_TypeDescription * pReg = 0;
362 ::typelib_typedescription_new(
363 &pReg, typelib_TypeClass_SEQUENCE,
364 aTypeName.pData, pElementType, 0, 0 );
366 ::typelib_typedescription_register( &pReg );
367 *ppRef = (typelib_TypeDescriptionReference *)pReg;
368 OSL_ASSERT( *ppRef == pReg->pWeakRef );
370 #ifndef CPPU_LEAK_STATIC_DATA
371 // another static ref
372 ++((*ppRef)->nStaticRefCount);
373 #endif
378 //##################################################################################################
379 namespace {
381 void init(
382 typelib_TypeDescriptionReference ** ppRef,
383 typelib_TypeClass eTypeClass, const sal_Char * pTypeName,
384 typelib_TypeDescriptionReference * pBaseType,
385 sal_Int32 nMembers, typelib_TypeDescriptionReference ** ppMembers,
386 sal_Bool const * pParameterizedTypes)
388 OSL_ENSURE( typelib_TypeClass_STRUCT == eTypeClass ||
389 typelib_TypeClass_EXCEPTION == eTypeClass, "### unexpected type class!" );
391 if (! *ppRef)
393 MutexGuard aGuard( typelib_StaticInitMutex::get() );
394 if (! *ppRef)
396 OSL_ASSERT( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(eTypeClass) );
397 OUString aTypeName( OUString::createFromAscii( pTypeName ) );
398 *ppRef = igetTypeByName( aTypeName.pData );
399 if (!*ppRef)
401 typelib_CompoundTypeDescription * pComp = 0;
402 ::typelib_typedescription_newEmpty(
403 (typelib_TypeDescription **)&pComp, eTypeClass, aTypeName.pData );
405 sal_Int32 nOffset = 0;
406 if (pBaseType)
408 ::typelib_typedescriptionreference_getDescription(
409 (typelib_TypeDescription **)&pComp->pBaseTypeDescription, pBaseType );
410 OSL_ASSERT( pComp->pBaseTypeDescription );
411 nOffset = ((typelib_TypeDescription *)pComp->pBaseTypeDescription)->nSize;
412 OSL_ENSURE( newAlignedSize( 0, ((typelib_TypeDescription *)pComp->pBaseTypeDescription)->nSize, ((typelib_TypeDescription *)pComp->pBaseTypeDescription)->nAlignment ) == ((typelib_TypeDescription *)pComp->pBaseTypeDescription)->nSize, "### unexpected offset!" );
415 if (nMembers)
417 pComp->nMembers = nMembers;
418 pComp->pMemberOffsets = new sal_Int32[ nMembers ];
419 pComp->ppTypeRefs = new typelib_TypeDescriptionReference *[ nMembers ];
420 if (pParameterizedTypes != 0) {
421 reinterpret_cast< typelib_StructTypeDescription * >(
422 pComp)->pParameterizedTypes
423 = new sal_Bool[nMembers];
425 for ( sal_Int32 i = 0 ; i < nMembers; ++i )
427 ::typelib_typedescriptionreference_acquire(
428 pComp->ppTypeRefs[i] = ppMembers[i] );
429 // write offset
430 typelib_TypeDescription * pTD = 0;
431 TYPELIB_DANGER_GET( &pTD, pComp->ppTypeRefs[i] );
432 OSL_ENSURE( pTD->nSize, "### void member?" );
433 nOffset = newAlignedSize( nOffset, pTD->nSize, pTD->nAlignment );
434 pComp->pMemberOffsets[i] = nOffset - pTD->nSize;
435 TYPELIB_DANGER_RELEASE( pTD );
437 if (pParameterizedTypes != 0) {
438 reinterpret_cast< typelib_StructTypeDescription * >(
439 pComp)->pParameterizedTypes[i]
440 = pParameterizedTypes[i];
445 typelib_TypeDescription * pReg = (typelib_TypeDescription *)pComp;
446 pReg->pWeakRef = (typelib_TypeDescriptionReference *)pReg;
447 // sizeof( void ) not allowed
448 pReg->nSize = ::typelib_typedescription_getAlignedUnoSize( pReg, 0, pReg->nAlignment );
449 pReg->nAlignment = adjustAlignment( pReg->nAlignment );
450 pReg->bComplete = sal_False;
452 ::typelib_typedescription_register( &pReg );
453 *ppRef = (typelib_TypeDescriptionReference *)pReg;
454 OSL_ASSERT( *ppRef == pReg->pWeakRef );
456 #ifndef CPPU_LEAK_STATIC_DATA
457 // another static ref
458 ++((*ppRef)->nStaticRefCount);
459 #endif
466 void SAL_CALL typelib_static_compound_type_init(
467 typelib_TypeDescriptionReference ** ppRef,
468 typelib_TypeClass eTypeClass, const sal_Char * pTypeName,
469 typelib_TypeDescriptionReference * pBaseType,
470 sal_Int32 nMembers, typelib_TypeDescriptionReference ** ppMembers )
471 SAL_THROW_EXTERN_C()
473 init(ppRef, eTypeClass, pTypeName, pBaseType, nMembers, ppMembers, 0);
476 void SAL_CALL typelib_static_struct_type_init(
477 typelib_TypeDescriptionReference ** ppRef, const sal_Char * pTypeName,
478 typelib_TypeDescriptionReference * pBaseType,
479 sal_Int32 nMembers, typelib_TypeDescriptionReference ** ppMembers,
480 sal_Bool const * pParameterizedTypes )
481 SAL_THROW_EXTERN_C()
483 init(
484 ppRef, typelib_TypeClass_STRUCT, pTypeName, pBaseType, nMembers,
485 ppMembers, pParameterizedTypes);
488 //##################################################################################################
489 void SAL_CALL typelib_static_interface_type_init(
490 typelib_TypeDescriptionReference ** ppRef,
491 const sal_Char * pTypeName,
492 typelib_TypeDescriptionReference * pBaseType )
493 SAL_THROW_EXTERN_C()
495 typelib_static_mi_interface_type_init(
496 ppRef, pTypeName, pBaseType == 0 ? 0 : 1, &pBaseType);
499 //##################################################################################################
500 void SAL_CALL typelib_static_mi_interface_type_init(
501 typelib_TypeDescriptionReference ** ppRef,
502 const sal_Char * pTypeName,
503 sal_Int32 nBaseTypes,
504 typelib_TypeDescriptionReference ** ppBaseTypes )
505 SAL_THROW_EXTERN_C()
507 if (! *ppRef)
509 MutexGuard aGuard( typelib_StaticInitMutex::get() );
510 if (! *ppRef)
512 OSL_ASSERT( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_INTERFACE) );
513 OUString aTypeName( OUString::createFromAscii( pTypeName ) );
514 *ppRef = igetTypeByName( aTypeName.pData );
515 if (!*ppRef)
517 typelib_InterfaceTypeDescription * pIface = 0;
518 ::typelib_typedescription_newEmpty(
519 (typelib_TypeDescription **)&pIface, typelib_TypeClass_INTERFACE, aTypeName.pData );
521 pIface->nBaseTypes = std::max< sal_Int32 >(nBaseTypes, 1);
522 pIface->ppBaseTypes = new typelib_InterfaceTypeDescription *[
523 pIface->nBaseTypes];
524 if (nBaseTypes > 0)
526 for (sal_Int32 i = 0; i < nBaseTypes; ++i) {
527 pIface->ppBaseTypes[i] = 0;
528 ::typelib_typedescriptionreference_getDescription(
529 (typelib_TypeDescription **)&pIface->ppBaseTypes[i], ppBaseTypes[i] );
530 OSL_ASSERT( pIface->ppBaseTypes[i] );
533 else
535 pIface->ppBaseTypes[0] = 0;
536 ::typelib_typedescriptionreference_getDescription(
537 (typelib_TypeDescription **)&pIface->ppBaseTypes[0],
538 * ::typelib_static_type_getByTypeClass( typelib_TypeClass_INTERFACE ) );
539 OSL_ASSERT( pIface->ppBaseTypes[0] );
541 pIface->pBaseTypeDescription = pIface->ppBaseTypes[0];
542 typelib_typedescription_acquire(
543 &pIface->pBaseTypeDescription->aBase);
545 typelib_TypeDescription * pReg = (typelib_TypeDescription *)pIface;
546 pReg->pWeakRef = (typelib_TypeDescriptionReference *)pReg;
547 // sizeof( void ) not allowed
548 pReg->nSize = ::typelib_typedescription_getAlignedUnoSize( pReg, 0, pReg->nAlignment );
550 pReg->nAlignment = adjustAlignment( pReg->nAlignment );
551 pReg->bComplete = sal_False;
553 ::typelib_typedescription_register( &pReg );
554 *ppRef = (typelib_TypeDescriptionReference *)pReg;
555 OSL_ASSERT( *ppRef == pReg->pWeakRef );
557 #ifndef CPPU_LEAK_STATIC_DATA
558 // another static ref
559 ++((*ppRef)->nStaticRefCount);
560 #endif
565 //##################################################################################################
566 void SAL_CALL typelib_static_enum_type_init(
567 typelib_TypeDescriptionReference ** ppRef,
568 const sal_Char * pTypeName,
569 sal_Int32 nDefaultValue )
570 SAL_THROW_EXTERN_C()
572 if (! *ppRef)
574 MutexGuard aGuard( typelib_StaticInitMutex::get() );
575 if (! *ppRef)
577 OSL_ASSERT( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_ENUM) );
578 OUString aTypeName( OUString::createFromAscii( pTypeName ) );
579 *ppRef = igetTypeByName( aTypeName.pData );
580 if (!*ppRef)
582 typelib_TypeDescription * pReg = 0;
583 ::typelib_typedescription_newEmpty(
584 &pReg, typelib_TypeClass_ENUM, aTypeName.pData );
585 typelib_EnumTypeDescription * pEnum = (typelib_EnumTypeDescription *)pReg;
587 pEnum->nDefaultEnumValue = nDefaultValue;
589 pReg->pWeakRef = (typelib_TypeDescriptionReference *)pReg;
590 // sizeof( void ) not allowed
591 pReg->nSize = ::typelib_typedescription_getAlignedUnoSize( pReg, 0, pReg->nAlignment );
592 pReg->nAlignment = ::adjustAlignment( pReg->nAlignment );
593 pReg->bComplete = sal_False;
595 ::typelib_typedescription_register( &pReg );
596 *ppRef = (typelib_TypeDescriptionReference *)pReg;
597 OSL_ASSERT( *ppRef == pReg->pWeakRef );
599 #ifndef CPPU_LEAK_STATIC_DATA
600 // another static ref
601 ++(*(sal_Int32 *)&(*ppRef)->pReserved);
602 #endif
607 //##################################################################################################
608 void SAL_CALL typelib_static_array_type_init(
609 typelib_TypeDescriptionReference ** ppRef,
610 typelib_TypeDescriptionReference * pElementTypeRef,
611 sal_Int32 nDimensions, ... )
612 SAL_THROW_EXTERN_C()
614 if (! *ppRef)
616 MutexGuard aGuard( typelib_StaticInitMutex::get() );
617 if (! *ppRef)
619 OUStringBuffer aBuf( 32 );
620 aBuf.append( pElementTypeRef->pTypeName );
622 va_list dimArgs;
623 va_start( dimArgs, nDimensions );
624 sal_Int32 dim = 0;
625 sal_Int32 nElements = 1;
626 sal_Int32* pDimensions = new sal_Int32[nDimensions];
627 for (sal_Int32 i=0; i < nDimensions; i++)
629 dim = va_arg( dimArgs, int);
630 pDimensions[i] = dim;
631 aBuf.appendAscii("[");
632 aBuf.append(dim);
633 aBuf.appendAscii("]");
634 nElements *= dim;
636 va_end( dimArgs );
637 OUString aTypeName( aBuf.makeStringAndClear() );
639 OSL_ASSERT( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_ARRAY) );
640 *ppRef = igetTypeByName( aTypeName.pData );
641 if (!*ppRef)
643 typelib_TypeDescription * pReg = 0;
644 ::typelib_typedescription_newEmpty(
645 &pReg, typelib_TypeClass_ARRAY, aTypeName.pData );
646 typelib_ArrayTypeDescription * pArray = (typelib_ArrayTypeDescription *)pReg;
648 pArray->nDimensions = nDimensions;
649 pArray->nTotalElements = nElements;
650 pArray->pDimensions = pDimensions;
652 typelib_typedescriptionreference_acquire(pElementTypeRef);
653 ((typelib_IndirectTypeDescription*)pArray)->pType = pElementTypeRef;
655 pReg->pWeakRef = (typelib_TypeDescriptionReference *)pReg;
656 // sizeof( void ) not allowed
657 pReg->nSize = ::typelib_typedescription_getAlignedUnoSize( pReg, 0, pReg->nAlignment );
658 pReg->nAlignment = ::adjustAlignment( pReg->nAlignment );
659 pReg->bComplete = sal_True;
661 ::typelib_typedescription_register( &pReg );
662 *ppRef = (typelib_TypeDescriptionReference *)pReg;
663 OSL_ASSERT( *ppRef == pReg->pWeakRef );
664 } else
665 delete [] pDimensions;
666 #ifndef CPPU_LEAK_STATIC_DATA
667 // another static ref
668 ++((*ppRef)->nStaticRefCount);
669 #endif
674 } // extern "C"