1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "sal/config.h"
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>
32 #include <typelib/typedescription.h>
37 using ::rtl::OUString
;
38 using ::rtl::OUStringBuffer
;
43 //------------------------------------------------------------------------
44 sal_Int32 SAL_CALL
typelib_typedescription_getAlignedUnoSize(
45 const typelib_TypeDescription
* pTypeDescription
,
47 sal_Int32
& rMaxIntegralTypeSize
)
49 //------------------------------------------------------------------------
50 void SAL_CALL
typelib_typedescription_newEmpty(
51 typelib_TypeDescription
** ppRet
,
52 typelib_TypeClass eTypeClass
,
53 rtl_uString
* pTypeName
)
55 //-----------------------------------------------------------------------------
56 void SAL_CALL
typelib_typedescriptionreference_getByName(
57 typelib_TypeDescriptionReference
** ppRet
,
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.
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.
88 // the value of the maximal alignment
89 static sal_Int32 nMaxAlignment
= (sal_Int32
)( (sal_Size
)(&((AlignSize_Impl
*) 16)->dDouble
) - 16);
91 static inline sal_Int32
adjustAlignment( sal_Int32 nRequestedAlignment
)
94 if( nRequestedAlignment
> nMaxAlignment
)
95 nRequestedAlignment
= nMaxAlignment
;
96 return nRequestedAlignment
;
100 * Calculate the new size of the struktur.
102 static inline sal_Int32
newAlignedSize(
103 sal_Int32 OldSize
, sal_Int32 ElementSize
, sal_Int32 NeededAlignment
)
106 NeededAlignment
= adjustAlignment( NeededAlignment
);
107 return (OldSize
+ NeededAlignment
-1) / NeededAlignment
* NeededAlignment
+ ElementSize
;
110 //--------------------------------------------------------------------------------------------------
114 struct typelib_StaticInitMutex
: public rtl::Static
< Mutex
, typelib_StaticInitMutex
> {};
117 // !for NOT REALLY WEAK TYPES only!
118 static inline typelib_TypeDescriptionReference
* igetTypeByName( rtl_uString
* pTypeName
)
121 typelib_TypeDescriptionReference
* pRef
= 0;
122 ::typelib_typedescriptionreference_getByName( &pRef
, pTypeName
);
123 if (pRef
&& pRef
->pType
&& pRef
->pType
->pWeakRef
) // found initialized td
135 //##################################################################################################
136 CPPU_DLLPUBLIC typelib_TypeDescriptionReference
** SAL_CALL
typelib_static_type_getByTypeClass(
137 typelib_TypeClass eTypeClass
)
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,
145 if (! s_aTypes
[eTypeClass
])
147 MutexGuard
aGuard( typelib_StaticInitMutex::get() );
148 if (! s_aTypes
[eTypeClass
])
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" };
158 case typelib_TypeClass_EXCEPTION
:
159 case typelib_TypeClass_INTERFACE
:
162 if (! s_aTypes
[typelib_TypeClass_TYPE
])
164 OUString
sTypeName( RTL_CONSTASCII_USTRINGPARAM("type") );
165 ::typelib_typedescriptionreference_new(
166 &s_aTypes
[typelib_TypeClass_TYPE
], typelib_TypeClass_TYPE
, sTypeName
.pData
);
167 // another static ref:
168 ++s_aTypes
[typelib_TypeClass_TYPE
]->nStaticRefCount
;
171 if (! s_aTypes
[typelib_TypeClass_ANY
])
173 OUString
sTypeName( RTL_CONSTASCII_USTRINGPARAM("any") );
174 ::typelib_typedescriptionreference_new(
175 &s_aTypes
[typelib_TypeClass_ANY
], typelib_TypeClass_ANY
, sTypeName
.pData
);
176 // another static ref:
177 ++s_aTypes
[typelib_TypeClass_ANY
]->nStaticRefCount
;
180 if (! s_aTypes
[typelib_TypeClass_STRING
])
182 OUString
sTypeName( RTL_CONSTASCII_USTRINGPARAM("string") );
183 ::typelib_typedescriptionreference_new(
184 &s_aTypes
[typelib_TypeClass_STRING
], typelib_TypeClass_STRING
, sTypeName
.pData
);
185 // another static ref:
186 ++s_aTypes
[typelib_TypeClass_STRING
]->nStaticRefCount
;
189 if (! s_aTypes
[typelib_TypeClass_INTERFACE
])
191 OUString
sTypeName( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.XInterface") );
193 typelib_InterfaceTypeDescription
* pTD
= 0;
195 typelib_TypeDescriptionReference
* pMembers
[3] = { 0,0,0 };
196 OUString
sMethodName0( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.XInterface::queryInterface") );
197 ::typelib_typedescriptionreference_new(
198 &pMembers
[0], typelib_TypeClass_INTERFACE_METHOD
, sMethodName0
.pData
);
199 OUString
sMethodName1( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.XInterface::acquire") );
200 ::typelib_typedescriptionreference_new(
201 &pMembers
[1], typelib_TypeClass_INTERFACE_METHOD
, sMethodName1
.pData
);
202 OUString
sMethodName2( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.XInterface::release") );
203 ::typelib_typedescriptionreference_new(
204 &pMembers
[2], typelib_TypeClass_INTERFACE_METHOD
, sMethodName2
.pData
);
206 ::typelib_typedescription_newInterface(
207 &pTD
, sTypeName
.pData
, 0xe227a391, 0x33d6, 0x11d1, 0xaabe00a0, 0x249d5590,
210 ::typelib_typedescription_register( (typelib_TypeDescription
**)&pTD
);
211 ::typelib_typedescriptionreference_acquire(
212 s_aTypes
[typelib_TypeClass_INTERFACE
] = ((typelib_TypeDescription
*)pTD
)->pWeakRef
);
213 // another static ref:
214 ++s_aTypes
[typelib_TypeClass_INTERFACE
]->nStaticRefCount
;
215 ::typelib_typedescription_release( (typelib_TypeDescription
*)pTD
);
217 ::typelib_typedescriptionreference_release( pMembers
[0] );
218 ::typelib_typedescriptionreference_release( pMembers
[1] );
219 ::typelib_typedescriptionreference_release( pMembers
[2] );
221 assert( ! s_aTypes
[typelib_TypeClass_EXCEPTION
] );
223 typelib_TypeDescription
* pTD1
= 0;
224 OUString
sTypeName1( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.Exception") );
226 typelib_CompoundMember_Init aMembers
[2];
227 OUString
sMemberType0( RTL_CONSTASCII_USTRINGPARAM("string") );
228 OUString
sMemberName0( RTL_CONSTASCII_USTRINGPARAM("Message") );
229 aMembers
[0].eTypeClass
= typelib_TypeClass_STRING
;
230 aMembers
[0].pTypeName
= sMemberType0
.pData
;
231 aMembers
[0].pMemberName
= sMemberName0
.pData
;
232 OUString
sMemberType1( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.XInterface") );
233 OUString
sMemberName1( RTL_CONSTASCII_USTRINGPARAM("Context") );
234 aMembers
[1].eTypeClass
= typelib_TypeClass_INTERFACE
;
235 aMembers
[1].pTypeName
= sMemberType1
.pData
;
236 aMembers
[1].pMemberName
= sMemberName1
.pData
;
238 ::typelib_typedescription_new(
239 &pTD1
, typelib_TypeClass_EXCEPTION
, sTypeName1
.pData
, 0, 2, aMembers
);
240 typelib_typedescription_register( &pTD1
);
241 typelib_typedescriptionreference_acquire(
242 s_aTypes
[typelib_TypeClass_EXCEPTION
] = pTD1
->pWeakRef
);
243 // another static ref:
244 ++s_aTypes
[typelib_TypeClass_EXCEPTION
]->nStaticRefCount
;
246 OUString
sTypeName2( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.RuntimeException") );
247 ::typelib_typedescription_new(
248 &pTD1
, typelib_TypeClass_EXCEPTION
, sTypeName2
.pData
, s_aTypes
[typelib_TypeClass_EXCEPTION
], 0, 0 );
249 ::typelib_typedescription_register( &pTD1
);
250 ::typelib_typedescription_release( pTD1
);
252 // XInterface members
253 typelib_InterfaceMethodTypeDescription
* pMethod
= 0;
254 typelib_Parameter_Init aParameters
[1];
255 OUString
sParamName0( RTL_CONSTASCII_USTRINGPARAM("aType") );
256 OUString
sParamType0( RTL_CONSTASCII_USTRINGPARAM("type") );
257 aParameters
[0].pParamName
= sParamName0
.pData
;
258 aParameters
[0].eTypeClass
= typelib_TypeClass_TYPE
;
259 aParameters
[0].pTypeName
= sParamType0
.pData
;
260 aParameters
[0].bIn
= sal_True
;
261 aParameters
[0].bOut
= sal_False
;
262 rtl_uString
* pExceptions
[1];
263 OUString
sExceptionName0( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.RuntimeException") );
264 pExceptions
[0] = sExceptionName0
.pData
;
265 OUString
sReturnType0( RTL_CONSTASCII_USTRINGPARAM("any") );
266 typelib_typedescription_newInterfaceMethod(
267 &pMethod
, 0, sal_False
, sMethodName0
.pData
,
268 typelib_TypeClass_ANY
, sReturnType0
.pData
,
269 1, aParameters
, 1, pExceptions
);
270 ::typelib_typedescription_register( (typelib_TypeDescription
**)&pMethod
);
272 OUString
sReturnType1( RTL_CONSTASCII_USTRINGPARAM("void") );
273 ::typelib_typedescription_newInterfaceMethod(
274 &pMethod
, 1, sal_True
, sMethodName1
.pData
,
275 typelib_TypeClass_VOID
, sReturnType1
.pData
, 0, 0, 0, 0 );
276 ::typelib_typedescription_register( (typelib_TypeDescription
**)&pMethod
);
278 ::typelib_typedescription_newInterfaceMethod(
279 &pMethod
, 2, sal_True
, sMethodName2
.pData
,
280 typelib_TypeClass_VOID
, sReturnType1
.pData
,
282 ::typelib_typedescription_register( (typelib_TypeDescription
**)&pMethod
);
283 ::typelib_typedescription_release( (typelib_TypeDescription
*)pMethod
);
289 OUString
aTypeName( OUString::createFromAscii( s_aTypeNames
[eTypeClass
] ) );
290 ::typelib_typedescriptionreference_new( &s_aTypes
[eTypeClass
], eTypeClass
, aTypeName
.pData
);
291 // another static ref:
292 ++s_aTypes
[eTypeClass
]->nStaticRefCount
;
297 return &s_aTypes
[eTypeClass
];
300 //##################################################################################################
301 CPPU_DLLPUBLIC
void SAL_CALL
typelib_static_type_init(
302 typelib_TypeDescriptionReference
** ppRef
,
303 typelib_TypeClass eTypeClass
, const sal_Char
* pTypeName
)
308 MutexGuard
aGuard( typelib_StaticInitMutex::get() );
311 OUString
aTypeName( OUString::createFromAscii( pTypeName
) );
312 ::typelib_typedescriptionreference_new( ppRef
, eTypeClass
, aTypeName
.pData
);
314 // another static ref:
315 ++((*ppRef
)->nStaticRefCount
);
320 //##################################################################################################
321 CPPU_DLLPUBLIC
void SAL_CALL
typelib_static_sequence_type_init(
322 typelib_TypeDescriptionReference
** ppRef
,
323 typelib_TypeDescriptionReference
* pElementType
)
328 MutexGuard
aGuard( typelib_StaticInitMutex::get() );
331 OUStringBuffer
aBuf( 32 );
332 aBuf
.appendAscii( "[]" );
333 aBuf
.append( pElementType
->pTypeName
);
334 OUString
aTypeName( aBuf
.makeStringAndClear() );
336 assert( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_SEQUENCE
) );
337 *ppRef
= igetTypeByName( aTypeName
.pData
);
340 typelib_TypeDescription
* pReg
= 0;
341 ::typelib_typedescription_new(
342 &pReg
, typelib_TypeClass_SEQUENCE
,
343 aTypeName
.pData
, pElementType
, 0, 0 );
345 ::typelib_typedescription_register( &pReg
);
346 *ppRef
= (typelib_TypeDescriptionReference
*)pReg
;
347 assert( *ppRef
== pReg
->pWeakRef
);
349 // another static ref:
350 ++((*ppRef
)->nStaticRefCount
);
355 //##################################################################################################
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
)
365 assert( eTypeClass
== typelib_TypeClass_STRUCT
|| eTypeClass
== typelib_TypeClass_EXCEPTION
);
369 MutexGuard
aGuard( typelib_StaticInitMutex::get() );
372 assert( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(eTypeClass
) );
373 OUString
aTypeName( OUString::createFromAscii( pTypeName
) );
374 *ppRef
= igetTypeByName( aTypeName
.pData
);
377 typelib_CompoundTypeDescription
* pComp
= 0;
378 ::typelib_typedescription_newEmpty(
379 (typelib_TypeDescription
**)&pComp
, eTypeClass
, aTypeName
.pData
);
381 sal_Int32 nOffset
= 0;
384 ::typelib_typedescriptionreference_getDescription(
385 (typelib_TypeDescription
**)&pComp
->pBaseTypeDescription
, pBaseType
);
386 assert( pComp
->pBaseTypeDescription
);
387 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
393 pComp
->nMembers
= nMembers
;
394 pComp
->pMemberOffsets
= new sal_Int32
[ nMembers
];
395 pComp
->ppTypeRefs
= new typelib_TypeDescriptionReference
*[ nMembers
];
396 if (pParameterizedTypes
!= 0) {
397 reinterpret_cast< typelib_StructTypeDescription
* >(
398 pComp
)->pParameterizedTypes
399 = new sal_Bool
[nMembers
];
401 for ( sal_Int32 i
= 0 ; i
< nMembers
; ++i
)
403 ::typelib_typedescriptionreference_acquire(
404 pComp
->ppTypeRefs
[i
] = ppMembers
[i
] );
406 typelib_TypeDescription
* pTD
= 0;
407 TYPELIB_DANGER_GET( &pTD
, pComp
->ppTypeRefs
[i
] );
408 assert( pTD
->nSize
); // void member?
409 nOffset
= newAlignedSize( nOffset
, pTD
->nSize
, pTD
->nAlignment
);
410 pComp
->pMemberOffsets
[i
] = nOffset
- pTD
->nSize
;
411 TYPELIB_DANGER_RELEASE( pTD
);
413 if (pParameterizedTypes
!= 0) {
414 reinterpret_cast< typelib_StructTypeDescription
* >(
415 pComp
)->pParameterizedTypes
[i
]
416 = pParameterizedTypes
[i
];
421 typelib_TypeDescription
* pReg
= (typelib_TypeDescription
*)pComp
;
422 pReg
->pWeakRef
= (typelib_TypeDescriptionReference
*)pReg
;
423 // sizeof( void ) not allowed
424 pReg
->nSize
= ::typelib_typedescription_getAlignedUnoSize( pReg
, 0, pReg
->nAlignment
);
425 pReg
->nAlignment
= adjustAlignment( pReg
->nAlignment
);
426 pReg
->bComplete
= sal_False
;
428 ::typelib_typedescription_register( &pReg
);
429 *ppRef
= (typelib_TypeDescriptionReference
*)pReg
;
430 assert( *ppRef
== pReg
->pWeakRef
);
432 // another static ref:
433 ++((*ppRef
)->nStaticRefCount
);
440 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
)
447 init(ppRef
, eTypeClass
, pTypeName
, pBaseType
, nMembers
, ppMembers
, 0);
450 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
)
458 ppRef
, typelib_TypeClass_STRUCT
, pTypeName
, pBaseType
, nMembers
,
459 ppMembers
, pParameterizedTypes
);
462 //##################################################################################################
463 CPPU_DLLPUBLIC
void SAL_CALL
typelib_static_interface_type_init(
464 typelib_TypeDescriptionReference
** ppRef
,
465 const sal_Char
* pTypeName
,
466 typelib_TypeDescriptionReference
* pBaseType
)
469 typelib_static_mi_interface_type_init(
470 ppRef
, pTypeName
, pBaseType
== 0 ? 0 : 1, &pBaseType
);
473 //##################################################################################################
474 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
)
483 MutexGuard
aGuard( typelib_StaticInitMutex::get() );
486 assert( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_INTERFACE
) );
487 OUString
aTypeName( OUString::createFromAscii( pTypeName
) );
488 *ppRef
= igetTypeByName( aTypeName
.pData
);
491 typelib_InterfaceTypeDescription
* pIface
= 0;
492 ::typelib_typedescription_newEmpty(
493 (typelib_TypeDescription
**)&pIface
, typelib_TypeClass_INTERFACE
, aTypeName
.pData
);
495 pIface
->nBaseTypes
= std::max
< sal_Int32
>(nBaseTypes
, 1);
496 pIface
->ppBaseTypes
= new typelib_InterfaceTypeDescription
*[
500 for (sal_Int32 i
= 0; i
< nBaseTypes
; ++i
) {
501 pIface
->ppBaseTypes
[i
] = 0;
502 ::typelib_typedescriptionreference_getDescription(
503 (typelib_TypeDescription
**)&pIface
->ppBaseTypes
[i
], ppBaseTypes
[i
] );
504 assert( pIface
->ppBaseTypes
[i
] );
509 pIface
->ppBaseTypes
[0] = 0;
510 ::typelib_typedescriptionreference_getDescription(
511 (typelib_TypeDescription
**)&pIface
->ppBaseTypes
[0],
512 * ::typelib_static_type_getByTypeClass( typelib_TypeClass_INTERFACE
) );
513 assert( pIface
->ppBaseTypes
[0] );
515 pIface
->pBaseTypeDescription
= pIface
->ppBaseTypes
[0];
516 typelib_typedescription_acquire(
517 &pIface
->pBaseTypeDescription
->aBase
);
519 typelib_TypeDescription
* pReg
= (typelib_TypeDescription
*)pIface
;
520 pReg
->pWeakRef
= (typelib_TypeDescriptionReference
*)pReg
;
521 // sizeof( void ) not allowed
522 pReg
->nSize
= ::typelib_typedescription_getAlignedUnoSize( pReg
, 0, pReg
->nAlignment
);
524 pReg
->nAlignment
= adjustAlignment( pReg
->nAlignment
);
525 pReg
->bComplete
= sal_False
;
527 ::typelib_typedescription_register( &pReg
);
528 *ppRef
= (typelib_TypeDescriptionReference
*)pReg
;
529 assert( *ppRef
== pReg
->pWeakRef
);
531 // another static ref:
532 ++((*ppRef
)->nStaticRefCount
);
537 //##################################################################################################
538 CPPU_DLLPUBLIC
void SAL_CALL
typelib_static_enum_type_init(
539 typelib_TypeDescriptionReference
** ppRef
,
540 const sal_Char
* pTypeName
,
541 sal_Int32 nDefaultValue
)
546 MutexGuard
aGuard( typelib_StaticInitMutex::get() );
549 assert( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_ENUM
) );
550 OUString
aTypeName( OUString::createFromAscii( pTypeName
) );
551 *ppRef
= igetTypeByName( aTypeName
.pData
);
554 typelib_TypeDescription
* pReg
= 0;
555 ::typelib_typedescription_newEmpty(
556 &pReg
, typelib_TypeClass_ENUM
, aTypeName
.pData
);
557 typelib_EnumTypeDescription
* pEnum
= (typelib_EnumTypeDescription
*)pReg
;
559 pEnum
->nDefaultEnumValue
= nDefaultValue
;
561 pReg
->pWeakRef
= (typelib_TypeDescriptionReference
*)pReg
;
562 // sizeof( void ) not allowed
563 pReg
->nSize
= ::typelib_typedescription_getAlignedUnoSize( pReg
, 0, pReg
->nAlignment
);
564 pReg
->nAlignment
= ::adjustAlignment( pReg
->nAlignment
);
565 pReg
->bComplete
= sal_False
;
567 ::typelib_typedescription_register( &pReg
);
568 *ppRef
= (typelib_TypeDescriptionReference
*)pReg
;
569 assert( *ppRef
== pReg
->pWeakRef
);
571 // another static ref:
572 ++((*ppRef
)->nStaticRefCount
);
577 //##################################################################################################
578 CPPU_DLLPUBLIC
void SAL_CALL
typelib_static_array_type_init(
579 typelib_TypeDescriptionReference
** ppRef
,
580 typelib_TypeDescriptionReference
* pElementTypeRef
,
581 sal_Int32 nDimensions
, ... )
586 MutexGuard
aGuard( typelib_StaticInitMutex::get() );
589 OUStringBuffer
aBuf( 32 );
590 aBuf
.append( pElementTypeRef
->pTypeName
);
593 va_start( dimArgs
, nDimensions
);
595 sal_Int32 nElements
= 1;
596 sal_Int32
* pDimensions
= new sal_Int32
[nDimensions
];
597 for (sal_Int32 i
=0; i
< nDimensions
; i
++)
599 dim
= va_arg( dimArgs
, int);
600 pDimensions
[i
] = dim
;
601 aBuf
.appendAscii("[");
603 aBuf
.appendAscii("]");
607 OUString
aTypeName( aBuf
.makeStringAndClear() );
609 assert( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_ARRAY
) );
610 *ppRef
= igetTypeByName( aTypeName
.pData
);
613 typelib_TypeDescription
* pReg
= 0;
614 ::typelib_typedescription_newEmpty(
615 &pReg
, typelib_TypeClass_ARRAY
, aTypeName
.pData
);
616 typelib_ArrayTypeDescription
* pArray
= (typelib_ArrayTypeDescription
*)pReg
;
618 pArray
->nDimensions
= nDimensions
;
619 pArray
->nTotalElements
= nElements
;
620 pArray
->pDimensions
= pDimensions
;
622 typelib_typedescriptionreference_acquire(pElementTypeRef
);
623 ((typelib_IndirectTypeDescription
*)pArray
)->pType
= pElementTypeRef
;
625 pReg
->pWeakRef
= (typelib_TypeDescriptionReference
*)pReg
;
626 // sizeof( void ) not allowed
627 pReg
->nSize
= ::typelib_typedescription_getAlignedUnoSize( pReg
, 0, pReg
->nAlignment
);
628 pReg
->nAlignment
= ::adjustAlignment( pReg
->nAlignment
);
629 pReg
->bComplete
= sal_True
;
631 ::typelib_typedescription_register( &pReg
);
632 *ppRef
= (typelib_TypeDescriptionReference
*)pReg
;
633 assert( *ppRef
== pReg
->pWeakRef
);
635 delete [] pDimensions
;
636 // another static ref:
637 ++((*ppRef
)->nStaticRefCount
);
646 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */