merged tag ooo/DEV300_m102
[LibreOffice.git] / cppu / source / typelib / static_types.cxx
blob605bc5aadbdca083eb7cb30ead3f8e18f4024b36
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cppu.hxx"
31 #include <stdarg.h>
32 #include <algorithm>
34 #include <osl/mutex.hxx>
35 #include <osl/interlck.h>
36 #include <rtl/ustring.hxx>
37 #include <rtl/ustrbuf.hxx>
38 #include <rtl/memory.h>
39 #include <rtl/instance.hxx>
41 #include <typelib/typedescription.h>
44 using namespace osl;
45 using namespace rtl;
47 extern "C"
50 //------------------------------------------------------------------------
51 sal_Int32 SAL_CALL typelib_typedescription_getAlignedUnoSize(
52 const typelib_TypeDescription * pTypeDescription,
53 sal_Int32 nOffset,
54 sal_Int32 & rMaxIntegralTypeSize )
55 SAL_THROW_EXTERN_C();
56 //------------------------------------------------------------------------
57 void SAL_CALL typelib_typedescription_newEmpty(
58 typelib_TypeDescription ** ppRet,
59 typelib_TypeClass eTypeClass,
60 rtl_uString * pTypeName )
61 SAL_THROW_EXTERN_C();
62 //-----------------------------------------------------------------------------
63 void SAL_CALL typelib_typedescriptionreference_getByName(
64 typelib_TypeDescriptionReference ** ppRet,
65 rtl_uString * pName )
66 SAL_THROW_EXTERN_C();
68 #ifdef SAL_W32
69 #pragma pack(push, 8)
70 #elif defined(SAL_OS2)
71 #pragma pack(8)
72 #endif
74 /**
75 * The double member determin the alignment.
76 * Under Os2 and MS-Windows the Alignment is min( 8, sizeof( type ) ).
77 * The aligment of a strukture is min( 8, sizeof( max basic type ) ), the greatest basic type
78 * determine the aligment.
80 struct AlignSize_Impl
82 sal_Int16 nInt16;
83 double dDouble;
86 #ifdef SAL_W32
87 #pragma pack(pop)
88 #elif defined(SAL_OS2)
89 #pragma pack()
90 #endif
92 // the value of the maximal alignment
93 static sal_Int32 nMaxAlignment = (sal_Int32)( (sal_Size)(&((AlignSize_Impl *) 16)->dDouble) - 16);
95 static inline sal_Int32 adjustAlignment( sal_Int32 nRequestedAlignment )
96 SAL_THROW( () )
98 if( nRequestedAlignment > nMaxAlignment )
99 nRequestedAlignment = nMaxAlignment;
100 return nRequestedAlignment;
104 * Calculate the new size of the struktur.
106 static inline sal_Int32 newAlignedSize(
107 sal_Int32 OldSize, sal_Int32 ElementSize, sal_Int32 NeededAlignment )
108 SAL_THROW( () )
110 NeededAlignment = adjustAlignment( NeededAlignment );
111 return (OldSize + NeededAlignment -1) / NeededAlignment * NeededAlignment + ElementSize;
114 //--------------------------------------------------------------------------------------------------
116 namespace
118 struct typelib_StaticInitMutex : public rtl::Static< Mutex, typelib_StaticInitMutex > {};
121 // !for NOT REALLY WEAK TYPES only!
122 static inline typelib_TypeDescriptionReference * igetTypeByName( rtl_uString * pTypeName )
123 SAL_THROW( () )
125 typelib_TypeDescriptionReference * pRef = 0;
126 ::typelib_typedescriptionreference_getByName( &pRef, pTypeName );
127 if (pRef && pRef->pType && pRef->pType->pWeakRef) // found initialized td
129 return pRef;
131 else
133 return 0;
137 extern "C"
139 //##################################################################################################
140 typelib_TypeDescriptionReference ** SAL_CALL typelib_static_type_getByTypeClass(
141 typelib_TypeClass eTypeClass )
142 SAL_THROW_EXTERN_C()
144 static typelib_TypeDescriptionReference * s_aTypes[] = {
145 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
146 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
147 0, 0, 0 };
149 if (! s_aTypes[eTypeClass])
151 MutexGuard aGuard( typelib_StaticInitMutex::get() );
152 if (! s_aTypes[eTypeClass])
154 static const char * s_aTypeNames[] = {
155 "void", "char", "boolean", "byte",
156 "short", "unsigned short", "long", "unsigned long",
157 "hyper", "unsigned hyper", "float", "double",
158 "string", "type", "any" };
160 switch (eTypeClass)
162 case typelib_TypeClass_EXCEPTION:
163 case typelib_TypeClass_INTERFACE:
165 // type
166 if (! s_aTypes[typelib_TypeClass_TYPE])
168 OUString sTypeName( RTL_CONSTASCII_USTRINGPARAM("type") );
169 ::typelib_typedescriptionreference_new(
170 &s_aTypes[typelib_TypeClass_TYPE], typelib_TypeClass_TYPE, sTypeName.pData );
171 // another static ref:
172 ++s_aTypes[typelib_TypeClass_TYPE]->nStaticRefCount;
174 // any
175 if (! s_aTypes[typelib_TypeClass_ANY])
177 OUString sTypeName( RTL_CONSTASCII_USTRINGPARAM("any") );
178 ::typelib_typedescriptionreference_new(
179 &s_aTypes[typelib_TypeClass_ANY], typelib_TypeClass_ANY, sTypeName.pData );
180 // another static ref:
181 ++s_aTypes[typelib_TypeClass_ANY]->nStaticRefCount;
183 // string
184 if (! s_aTypes[typelib_TypeClass_STRING])
186 OUString sTypeName( RTL_CONSTASCII_USTRINGPARAM("string") );
187 ::typelib_typedescriptionreference_new(
188 &s_aTypes[typelib_TypeClass_STRING], typelib_TypeClass_STRING, sTypeName.pData );
189 // another static ref:
190 ++s_aTypes[typelib_TypeClass_STRING]->nStaticRefCount;
192 // XInterface
193 if (! s_aTypes[typelib_TypeClass_INTERFACE])
195 OUString sTypeName( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.XInterface") );
197 typelib_InterfaceTypeDescription * pTD = 0;
199 typelib_TypeDescriptionReference * pMembers[3] = { 0,0,0 };
200 OUString sMethodName0( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.XInterface::queryInterface") );
201 ::typelib_typedescriptionreference_new(
202 &pMembers[0], typelib_TypeClass_INTERFACE_METHOD, sMethodName0.pData );
203 OUString sMethodName1( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.XInterface::acquire") );
204 ::typelib_typedescriptionreference_new(
205 &pMembers[1], typelib_TypeClass_INTERFACE_METHOD, sMethodName1.pData );
206 OUString sMethodName2( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.XInterface::release") );
207 ::typelib_typedescriptionreference_new(
208 &pMembers[2], typelib_TypeClass_INTERFACE_METHOD, sMethodName2.pData );
210 ::typelib_typedescription_newInterface(
211 &pTD, sTypeName.pData, 0xe227a391, 0x33d6, 0x11d1, 0xaabe00a0, 0x249d5590,
212 0, 3, pMembers );
214 ::typelib_typedescription_register( (typelib_TypeDescription **)&pTD );
215 ::typelib_typedescriptionreference_acquire(
216 s_aTypes[typelib_TypeClass_INTERFACE] = ((typelib_TypeDescription *)pTD)->pWeakRef );
217 // another static ref:
218 ++s_aTypes[typelib_TypeClass_INTERFACE]->nStaticRefCount;
219 ::typelib_typedescription_release( (typelib_TypeDescription*)pTD );
221 ::typelib_typedescriptionreference_release( pMembers[0] );
222 ::typelib_typedescriptionreference_release( pMembers[1] );
223 ::typelib_typedescriptionreference_release( pMembers[2] );
224 // Exception
225 OSL_ASSERT( ! s_aTypes[typelib_TypeClass_EXCEPTION] );
227 typelib_TypeDescription * pTD1 = 0;
228 OUString sTypeName1( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.Exception") );
230 typelib_CompoundMember_Init aMembers[2];
231 OUString sMemberType0( RTL_CONSTASCII_USTRINGPARAM("string") );
232 OUString sMemberName0( RTL_CONSTASCII_USTRINGPARAM("Message") );
233 aMembers[0].eTypeClass = typelib_TypeClass_STRING;
234 aMembers[0].pTypeName = sMemberType0.pData;
235 aMembers[0].pMemberName = sMemberName0.pData;
236 OUString sMemberType1( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.XInterface") );
237 OUString sMemberName1( RTL_CONSTASCII_USTRINGPARAM("Context") );
238 aMembers[1].eTypeClass = typelib_TypeClass_INTERFACE;
239 aMembers[1].pTypeName = sMemberType1.pData;
240 aMembers[1].pMemberName = sMemberName1.pData;
242 ::typelib_typedescription_new(
243 &pTD1, typelib_TypeClass_EXCEPTION, sTypeName1.pData, 0, 2, aMembers );
244 typelib_typedescription_register( &pTD1 );
245 typelib_typedescriptionreference_acquire(
246 s_aTypes[typelib_TypeClass_EXCEPTION] = pTD1->pWeakRef );
247 // another static ref:
248 ++s_aTypes[typelib_TypeClass_EXCEPTION]->nStaticRefCount;
249 // RuntimeException
250 OUString sTypeName2( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.RuntimeException") );
251 ::typelib_typedescription_new(
252 &pTD1, typelib_TypeClass_EXCEPTION, sTypeName2.pData, s_aTypes[typelib_TypeClass_EXCEPTION], 0, 0 );
253 ::typelib_typedescription_register( &pTD1 );
254 ::typelib_typedescription_release( pTD1 );
256 // XInterface members
257 typelib_InterfaceMethodTypeDescription * pMethod = 0;
258 typelib_Parameter_Init aParameters[1];
259 OUString sParamName0( RTL_CONSTASCII_USTRINGPARAM("aType") );
260 OUString sParamType0( RTL_CONSTASCII_USTRINGPARAM("type") );
261 aParameters[0].pParamName = sParamName0.pData;
262 aParameters[0].eTypeClass = typelib_TypeClass_TYPE;
263 aParameters[0].pTypeName = sParamType0.pData;
264 aParameters[0].bIn = sal_True;
265 aParameters[0].bOut = sal_False;
266 rtl_uString * pExceptions[1];
267 OUString sExceptionName0( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.RuntimeException") );
268 pExceptions[0] = sExceptionName0.pData;
269 OUString sReturnType0( RTL_CONSTASCII_USTRINGPARAM("any") );
270 typelib_typedescription_newInterfaceMethod(
271 &pMethod, 0, sal_False, sMethodName0.pData,
272 typelib_TypeClass_ANY, sReturnType0.pData,
273 1, aParameters, 1, pExceptions );
274 ::typelib_typedescription_register( (typelib_TypeDescription**)&pMethod );
276 OUString sReturnType1( RTL_CONSTASCII_USTRINGPARAM("void") );
277 ::typelib_typedescription_newInterfaceMethod(
278 &pMethod, 1, sal_True, sMethodName1.pData,
279 typelib_TypeClass_VOID, sReturnType1.pData, 0, 0, 0, 0 );
280 ::typelib_typedescription_register( (typelib_TypeDescription**)&pMethod );
282 ::typelib_typedescription_newInterfaceMethod(
283 &pMethod, 2, sal_True, sMethodName2.pData,
284 typelib_TypeClass_VOID, sReturnType1.pData,
285 0, 0, 0, 0 );
286 ::typelib_typedescription_register( (typelib_TypeDescription**)&pMethod );
287 ::typelib_typedescription_release( (typelib_TypeDescription*)pMethod );
289 break;
291 default:
293 OUString aTypeName( OUString::createFromAscii( s_aTypeNames[eTypeClass] ) );
294 ::typelib_typedescriptionreference_new( &s_aTypes[eTypeClass], eTypeClass, aTypeName.pData );
295 // another static ref:
296 ++s_aTypes[eTypeClass]->nStaticRefCount;
301 return &s_aTypes[eTypeClass];
304 //##################################################################################################
305 void SAL_CALL typelib_static_type_init(
306 typelib_TypeDescriptionReference ** ppRef,
307 typelib_TypeClass eTypeClass, const sal_Char * pTypeName )
308 SAL_THROW_EXTERN_C()
310 if (! *ppRef)
312 MutexGuard aGuard( typelib_StaticInitMutex::get() );
313 if (! *ppRef)
315 OUString aTypeName( OUString::createFromAscii( pTypeName ) );
316 ::typelib_typedescriptionreference_new( ppRef, eTypeClass, aTypeName.pData );
318 // another static ref:
319 ++((*ppRef)->nStaticRefCount);
324 //##################################################################################################
325 void SAL_CALL typelib_static_sequence_type_init(
326 typelib_TypeDescriptionReference ** ppRef,
327 typelib_TypeDescriptionReference * pElementType )
328 SAL_THROW_EXTERN_C()
330 if (! *ppRef)
332 MutexGuard aGuard( typelib_StaticInitMutex::get() );
333 if (! *ppRef)
335 OUStringBuffer aBuf( 32 );
336 aBuf.appendAscii( "[]" );
337 aBuf.append( pElementType->pTypeName );
338 OUString aTypeName( aBuf.makeStringAndClear() );
340 OSL_ASSERT( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_SEQUENCE) );
341 *ppRef = igetTypeByName( aTypeName.pData );
342 if (!*ppRef)
344 typelib_TypeDescription * pReg = 0;
345 ::typelib_typedescription_new(
346 &pReg, typelib_TypeClass_SEQUENCE,
347 aTypeName.pData, pElementType, 0, 0 );
349 ::typelib_typedescription_register( &pReg );
350 *ppRef = (typelib_TypeDescriptionReference *)pReg;
351 OSL_ASSERT( *ppRef == pReg->pWeakRef );
353 // another static ref:
354 ++((*ppRef)->nStaticRefCount);
359 //##################################################################################################
360 namespace {
362 void init(
363 typelib_TypeDescriptionReference ** ppRef,
364 typelib_TypeClass eTypeClass, const sal_Char * pTypeName,
365 typelib_TypeDescriptionReference * pBaseType,
366 sal_Int32 nMembers, typelib_TypeDescriptionReference ** ppMembers,
367 sal_Bool const * pParameterizedTypes)
369 OSL_ENSURE( typelib_TypeClass_STRUCT == eTypeClass ||
370 typelib_TypeClass_EXCEPTION == eTypeClass, "### unexpected type class!" );
372 if (! *ppRef)
374 MutexGuard aGuard( typelib_StaticInitMutex::get() );
375 if (! *ppRef)
377 OSL_ASSERT( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(eTypeClass) );
378 OUString aTypeName( OUString::createFromAscii( pTypeName ) );
379 *ppRef = igetTypeByName( aTypeName.pData );
380 if (!*ppRef)
382 typelib_CompoundTypeDescription * pComp = 0;
383 ::typelib_typedescription_newEmpty(
384 (typelib_TypeDescription **)&pComp, eTypeClass, aTypeName.pData );
386 sal_Int32 nOffset = 0;
387 if (pBaseType)
389 ::typelib_typedescriptionreference_getDescription(
390 (typelib_TypeDescription **)&pComp->pBaseTypeDescription, pBaseType );
391 OSL_ASSERT( pComp->pBaseTypeDescription );
392 nOffset = ((typelib_TypeDescription *)pComp->pBaseTypeDescription)->nSize;
393 OSL_ENSURE( newAlignedSize( 0, ((typelib_TypeDescription *)pComp->pBaseTypeDescription)->nSize, ((typelib_TypeDescription *)pComp->pBaseTypeDescription)->nAlignment ) == ((typelib_TypeDescription *)pComp->pBaseTypeDescription)->nSize, "### unexpected offset!" );
396 if (nMembers)
398 pComp->nMembers = nMembers;
399 pComp->pMemberOffsets = new sal_Int32[ nMembers ];
400 pComp->ppTypeRefs = new typelib_TypeDescriptionReference *[ nMembers ];
401 if (pParameterizedTypes != 0) {
402 reinterpret_cast< typelib_StructTypeDescription * >(
403 pComp)->pParameterizedTypes
404 = new sal_Bool[nMembers];
406 for ( sal_Int32 i = 0 ; i < nMembers; ++i )
408 ::typelib_typedescriptionreference_acquire(
409 pComp->ppTypeRefs[i] = ppMembers[i] );
410 // write offset
411 typelib_TypeDescription * pTD = 0;
412 TYPELIB_DANGER_GET( &pTD, pComp->ppTypeRefs[i] );
413 OSL_ENSURE( pTD->nSize, "### void member?" );
414 nOffset = newAlignedSize( nOffset, pTD->nSize, pTD->nAlignment );
415 pComp->pMemberOffsets[i] = nOffset - pTD->nSize;
416 TYPELIB_DANGER_RELEASE( pTD );
418 if (pParameterizedTypes != 0) {
419 reinterpret_cast< typelib_StructTypeDescription * >(
420 pComp)->pParameterizedTypes[i]
421 = pParameterizedTypes[i];
426 typelib_TypeDescription * pReg = (typelib_TypeDescription *)pComp;
427 pReg->pWeakRef = (typelib_TypeDescriptionReference *)pReg;
428 // sizeof( void ) not allowed
429 pReg->nSize = ::typelib_typedescription_getAlignedUnoSize( pReg, 0, pReg->nAlignment );
430 pReg->nAlignment = adjustAlignment( pReg->nAlignment );
431 pReg->bComplete = sal_False;
433 ::typelib_typedescription_register( &pReg );
434 *ppRef = (typelib_TypeDescriptionReference *)pReg;
435 OSL_ASSERT( *ppRef == pReg->pWeakRef );
437 // another static ref:
438 ++((*ppRef)->nStaticRefCount);
445 void SAL_CALL typelib_static_compound_type_init(
446 typelib_TypeDescriptionReference ** ppRef,
447 typelib_TypeClass eTypeClass, const sal_Char * pTypeName,
448 typelib_TypeDescriptionReference * pBaseType,
449 sal_Int32 nMembers, typelib_TypeDescriptionReference ** ppMembers )
450 SAL_THROW_EXTERN_C()
452 init(ppRef, eTypeClass, pTypeName, pBaseType, nMembers, ppMembers, 0);
455 void SAL_CALL typelib_static_struct_type_init(
456 typelib_TypeDescriptionReference ** ppRef, const sal_Char * pTypeName,
457 typelib_TypeDescriptionReference * pBaseType,
458 sal_Int32 nMembers, typelib_TypeDescriptionReference ** ppMembers,
459 sal_Bool const * pParameterizedTypes )
460 SAL_THROW_EXTERN_C()
462 init(
463 ppRef, typelib_TypeClass_STRUCT, pTypeName, pBaseType, nMembers,
464 ppMembers, pParameterizedTypes);
467 //##################################################################################################
468 void SAL_CALL typelib_static_interface_type_init(
469 typelib_TypeDescriptionReference ** ppRef,
470 const sal_Char * pTypeName,
471 typelib_TypeDescriptionReference * pBaseType )
472 SAL_THROW_EXTERN_C()
474 typelib_static_mi_interface_type_init(
475 ppRef, pTypeName, pBaseType == 0 ? 0 : 1, &pBaseType);
478 //##################################################################################################
479 void SAL_CALL typelib_static_mi_interface_type_init(
480 typelib_TypeDescriptionReference ** ppRef,
481 const sal_Char * pTypeName,
482 sal_Int32 nBaseTypes,
483 typelib_TypeDescriptionReference ** ppBaseTypes )
484 SAL_THROW_EXTERN_C()
486 if (! *ppRef)
488 MutexGuard aGuard( typelib_StaticInitMutex::get() );
489 if (! *ppRef)
491 OSL_ASSERT( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_INTERFACE) );
492 OUString aTypeName( OUString::createFromAscii( pTypeName ) );
493 *ppRef = igetTypeByName( aTypeName.pData );
494 if (!*ppRef)
496 typelib_InterfaceTypeDescription * pIface = 0;
497 ::typelib_typedescription_newEmpty(
498 (typelib_TypeDescription **)&pIface, typelib_TypeClass_INTERFACE, aTypeName.pData );
500 pIface->nBaseTypes = std::max< sal_Int32 >(nBaseTypes, 1);
501 pIface->ppBaseTypes = new typelib_InterfaceTypeDescription *[
502 pIface->nBaseTypes];
503 if (nBaseTypes > 0)
505 for (sal_Int32 i = 0; i < nBaseTypes; ++i) {
506 pIface->ppBaseTypes[i] = 0;
507 ::typelib_typedescriptionreference_getDescription(
508 (typelib_TypeDescription **)&pIface->ppBaseTypes[i], ppBaseTypes[i] );
509 OSL_ASSERT( pIface->ppBaseTypes[i] );
512 else
514 pIface->ppBaseTypes[0] = 0;
515 ::typelib_typedescriptionreference_getDescription(
516 (typelib_TypeDescription **)&pIface->ppBaseTypes[0],
517 * ::typelib_static_type_getByTypeClass( typelib_TypeClass_INTERFACE ) );
518 OSL_ASSERT( pIface->ppBaseTypes[0] );
520 pIface->pBaseTypeDescription = pIface->ppBaseTypes[0];
521 typelib_typedescription_acquire(
522 &pIface->pBaseTypeDescription->aBase);
524 typelib_TypeDescription * pReg = (typelib_TypeDescription *)pIface;
525 pReg->pWeakRef = (typelib_TypeDescriptionReference *)pReg;
526 // sizeof( void ) not allowed
527 pReg->nSize = ::typelib_typedescription_getAlignedUnoSize( pReg, 0, pReg->nAlignment );
529 pReg->nAlignment = adjustAlignment( pReg->nAlignment );
530 pReg->bComplete = sal_False;
532 ::typelib_typedescription_register( &pReg );
533 *ppRef = (typelib_TypeDescriptionReference *)pReg;
534 OSL_ASSERT( *ppRef == pReg->pWeakRef );
536 // another static ref:
537 ++((*ppRef)->nStaticRefCount);
542 //##################################################################################################
543 void SAL_CALL typelib_static_enum_type_init(
544 typelib_TypeDescriptionReference ** ppRef,
545 const sal_Char * pTypeName,
546 sal_Int32 nDefaultValue )
547 SAL_THROW_EXTERN_C()
549 if (! *ppRef)
551 MutexGuard aGuard( typelib_StaticInitMutex::get() );
552 if (! *ppRef)
554 OSL_ASSERT( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_ENUM) );
555 OUString aTypeName( OUString::createFromAscii( pTypeName ) );
556 *ppRef = igetTypeByName( aTypeName.pData );
557 if (!*ppRef)
559 typelib_TypeDescription * pReg = 0;
560 ::typelib_typedescription_newEmpty(
561 &pReg, typelib_TypeClass_ENUM, aTypeName.pData );
562 typelib_EnumTypeDescription * pEnum = (typelib_EnumTypeDescription *)pReg;
564 pEnum->nDefaultEnumValue = nDefaultValue;
566 pReg->pWeakRef = (typelib_TypeDescriptionReference *)pReg;
567 // sizeof( void ) not allowed
568 pReg->nSize = ::typelib_typedescription_getAlignedUnoSize( pReg, 0, pReg->nAlignment );
569 pReg->nAlignment = ::adjustAlignment( pReg->nAlignment );
570 pReg->bComplete = sal_False;
572 ::typelib_typedescription_register( &pReg );
573 *ppRef = (typelib_TypeDescriptionReference *)pReg;
574 OSL_ASSERT( *ppRef == pReg->pWeakRef );
576 // another static ref:
577 ++(*(sal_Int32 *)&(*ppRef)->pReserved);
582 //##################################################################################################
583 void SAL_CALL typelib_static_array_type_init(
584 typelib_TypeDescriptionReference ** ppRef,
585 typelib_TypeDescriptionReference * pElementTypeRef,
586 sal_Int32 nDimensions, ... )
587 SAL_THROW_EXTERN_C()
589 if (! *ppRef)
591 MutexGuard aGuard( typelib_StaticInitMutex::get() );
592 if (! *ppRef)
594 OUStringBuffer aBuf( 32 );
595 aBuf.append( pElementTypeRef->pTypeName );
597 va_list dimArgs;
598 va_start( dimArgs, nDimensions );
599 sal_Int32 dim = 0;
600 sal_Int32 nElements = 1;
601 sal_Int32* pDimensions = new sal_Int32[nDimensions];
602 for (sal_Int32 i=0; i < nDimensions; i++)
604 dim = va_arg( dimArgs, int);
605 pDimensions[i] = dim;
606 aBuf.appendAscii("[");
607 aBuf.append(dim);
608 aBuf.appendAscii("]");
609 nElements *= dim;
611 va_end( dimArgs );
612 OUString aTypeName( aBuf.makeStringAndClear() );
614 OSL_ASSERT( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_ARRAY) );
615 *ppRef = igetTypeByName( aTypeName.pData );
616 if (!*ppRef)
618 typelib_TypeDescription * pReg = 0;
619 ::typelib_typedescription_newEmpty(
620 &pReg, typelib_TypeClass_ARRAY, aTypeName.pData );
621 typelib_ArrayTypeDescription * pArray = (typelib_ArrayTypeDescription *)pReg;
623 pArray->nDimensions = nDimensions;
624 pArray->nTotalElements = nElements;
625 pArray->pDimensions = pDimensions;
627 typelib_typedescriptionreference_acquire(pElementTypeRef);
628 ((typelib_IndirectTypeDescription*)pArray)->pType = pElementTypeRef;
630 pReg->pWeakRef = (typelib_TypeDescriptionReference *)pReg;
631 // sizeof( void ) not allowed
632 pReg->nSize = ::typelib_typedescription_getAlignedUnoSize( pReg, 0, pReg->nAlignment );
633 pReg->nAlignment = ::adjustAlignment( pReg->nAlignment );
634 pReg->bComplete = sal_True;
636 ::typelib_typedescription_register( &pReg );
637 *ppRef = (typelib_TypeDescriptionReference *)pReg;
638 OSL_ASSERT( *ppRef == pReg->pWeakRef );
639 } else
640 delete [] pDimensions;
641 // another static ref:
642 ++((*ppRef)->nStaticRefCount);
647 } // extern "C"