diff options
author | Juergen Schmidt <jsc@openoffice.org> | 2001-03-30 12:39:19 +0000 |
---|---|---|
committer | Juergen Schmidt <jsc@openoffice.org> | 2001-03-30 12:39:19 +0000 |
commit | 13c013b16a77355a5f8c84b4b80a1d8d2255d5e5 (patch) | |
tree | 341e4495fde0b16b7ed617ffaa51649d52a601cf /cppu | |
parent | 02dbbaca84af3b91d62d74104b2c906ad8e85e72 (diff) |
insert typelib functions for arrays
Diffstat (limited to 'cppu')
-rw-r--r-- | cppu/inc/typelib/typedescription.h | 54 | ||||
-rw-r--r-- | cppu/source/typelib/static_types.cxx | 75 | ||||
-rw-r--r-- | cppu/source/typelib/typelib.cxx | 116 |
3 files changed, 214 insertions, 31 deletions
diff --git a/cppu/inc/typelib/typedescription.h b/cppu/inc/typelib/typedescription.h index 0eb1b88e653e..f7678954e412 100644 --- a/cppu/inc/typelib/typedescription.h +++ b/cppu/inc/typelib/typedescription.h @@ -2,9 +2,9 @@ * * $RCSfile: typedescription.h,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: dbo $ $Date: 2001-03-28 10:46:05 $ + * last change: $Author: jsc $ $Date: 2001-03-30 13:37:44 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -262,6 +262,26 @@ typedef struct _typelib_IndirectTypeDescription typelib_TypeDescriptionReference * pType; } typelib_IndirectTypeDescription; +/** Type description of an array. + <br> +*/ +typedef struct _typelib_ArrayTypeDescription +{ + /** inherits all members of typelib_IndirectTypeDescription<br> + */ + typelib_IndirectTypeDescription aBase; + + /** number of dimensions<br> + */ + sal_Int32 nDimensions; + /** number of total array elements<br> + */ + sal_Int32 nTotalElements; + /** array of dimensions<br> + */ + sal_Int32 * pDimensions; +} typelib_ArrayTypeDescription; + /** Type description of an enum.<br> The type class of this description is typelib_TypeClass_ENUM. <br> @@ -522,6 +542,20 @@ void SAL_CALL typelib_typedescription_newEnum( sal_Int32 * pEnumValues ) SAL_THROW_EXTERN_C(); +/** Creates an array type description. + <br> + @param ppRet inout enum type description + @param pElementTypeRef element type + @param nDimensions number of dimensions + @param pDimensions dimensions +*/ +void SAL_CALL typelib_typedescription_newArray( + typelib_TypeDescription ** ppRet, + typelib_TypeDescriptionReference * pElementTypeRef, + sal_Int32 nDimensions, + sal_Int32 * pDimensions ) + SAL_THROW_EXTERN_C (); + /** Creates a new type description. <br> @param ppRet inout type description @@ -867,7 +901,21 @@ void SAL_CALL typelib_static_type_init( void SAL_CALL typelib_static_sequence_type_init( typelib_TypeDescriptionReference ** ppRef, typelib_TypeDescriptionReference * pElementType ) - SAL_THROW_EXTERN_C(); + SAL_THROW_EXTERN_C (); + +/** Inits static array type reference. + Thread synchronizes on typelib init mutex. + <br> + @param ppRef pointer to type reference pointer + @param pElementType element type of sequence + @param nDimensions number of dimensions + @param ... additional sal_Int32 parameter for each dimension +*/ +void SAL_CALL typelib_static_array_type_init( + typelib_TypeDescriptionReference ** ppRef, + typelib_TypeDescriptionReference * pElementType, + sal_Int32 nDimensions, ... ) + SAL_THROW_EXTERN_C (); /** Inits <b>in</b>complete static compound type reference. Thread synchronizes on typelib init mutex. diff --git a/cppu/source/typelib/static_types.cxx b/cppu/source/typelib/static_types.cxx index dd490835a4bf..8f57f6165ff8 100644 --- a/cppu/source/typelib/static_types.cxx +++ b/cppu/source/typelib/static_types.cxx @@ -2,9 +2,9 @@ * * $RCSfile: static_types.cxx,v $ * - * $Revision: 1.6 $ + * $Revision: 1.7 $ * - * last change: $Author: dbo $ $Date: 2001-03-28 10:46:09 $ + * last change: $Author: jsc $ $Date: 2001-03-30 13:39:19 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -58,6 +58,11 @@ * * ************************************************************************/ +#ifdef SOLARIS +#include <varargs.h> +#else +#include <stdarg.h> +#endif #include <osl/mutex.hxx> #include <osl/interlck.h> @@ -567,6 +572,72 @@ void SAL_CALL typelib_static_enum_type_init( } #ifndef CPPU_LEAK_STATIC_DATA // another static ref + ++(*(sal_Int32 *)&(*ppRef)->pReserved); +#endif + } + } +} + +//################################################################################################## +void SAL_CALL typelib_static_array_type_init( + typelib_TypeDescriptionReference ** ppRef, + typelib_TypeDescriptionReference * pElementTypeRef, + sal_Int32 nDimensions, ... ) + SAL_THROW_EXTERN_C() +{ + if (! *ppRef) + { + MutexGuard aGuard( typelib_getStaticInitMutex() ); + if (! *ppRef) + { + OUStringBuffer aBuf( 32 ); + aBuf.append( pElementTypeRef->pTypeName ); + + va_list dimArgs; + va_start( dimArgs, nDimensions ); + sal_Int32 dim = 0; + sal_Int32 nElements = 1; + sal_Int32* pDimensions = new sal_Int32[nDimensions]; + for (sal_Int32 i=0; i < nDimensions; i++) + { + dim = va_arg( dimArgs, int); + pDimensions[i] = dim; + aBuf.appendAscii("["); + aBuf.append(dim); + aBuf.appendAscii("]"); + nElements *= dim; + } + va_end( dimArgs ); + OUString aTypeName( aBuf.makeStringAndClear() ); + + OSL_ASSERT( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_ARRAY) ); + if (! (*ppRef = __getTypeByName( aTypeName.pData ))) + { + typelib_TypeDescription * pReg = 0; + ::typelib_typedescription_newEmpty( + &pReg, typelib_TypeClass_ARRAY, aTypeName.pData ); + typelib_ArrayTypeDescription * pArray = (typelib_ArrayTypeDescription *)pReg; + + pArray->nDimensions = nDimensions; + pArray->nTotalElements = nElements; + pArray->pDimensions = pDimensions; + + typelib_typedescriptionreference_acquire(pElementTypeRef); + ((typelib_IndirectTypeDescription*)pArray)->pType = pElementTypeRef; + + pReg->pWeakRef = (typelib_TypeDescriptionReference *)pReg; + // sizeof( void ) not allowed + pReg->nSize = ::typelib_typedescription_getAlignedUnoSize( pReg, 0, pReg->nAlignment ); + pReg->nAlignment = ::adjustAlignment( pReg->nAlignment ); + pReg->bComplete = sal_True; + + ::typelib_typedescription_register( &pReg ); + *ppRef = (typelib_TypeDescriptionReference *)pReg; + OSL_ASSERT( *ppRef == pReg->pWeakRef ); + } else + delete [] pDimensions; +#ifndef CPPU_LEAK_STATIC_DATA + // another static ref ++((*ppRef)->nStaticRefCount); #endif } diff --git a/cppu/source/typelib/typelib.cxx b/cppu/source/typelib/typelib.cxx index 457e8b24800a..96e68751330f 100644 --- a/cppu/source/typelib/typelib.cxx +++ b/cppu/source/typelib/typelib.cxx @@ -2,9 +2,9 @@ * * $RCSfile: typelib.cxx,v $ * - * $Revision: 1.10 $ + * $Revision: 1.11 $ * - * last change: $Author: dbo $ $Date: 2001-03-28 10:46:09 $ + * last change: $Author: jsc $ $Date: 2001-03-30 13:39:19 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -92,6 +92,9 @@ #ifndef _RTL_USTRING_HXX_ #include <rtl/ustring.hxx> #endif +#ifndef _RTL_USTRBUF_HXX_ +#include <rtl/ustrbuf.hxx> +#endif #ifndef _RTL_ALLOC_H_ #include <rtl/alloc.h> #endif @@ -178,6 +181,9 @@ static inline sal_Int32 getDescriptionSize( typelib_TypeClass eTypeClass ) switch( eTypeClass ) { case typelib_TypeClass_ARRAY: + nSize = (sal_Int32)sizeof( typelib_ArrayTypeDescription ); + break; + case typelib_TypeClass_SEQUENCE: nSize = (sal_Int32)sizeof( typelib_IndirectTypeDescription ); break; @@ -273,6 +279,7 @@ struct TypeDescriptor_Init_Impl sal_Int32 nCompoundTypeDescriptionCount; sal_Int32 nUnionTypeDescriptionCount; sal_Int32 nIndirectTypeDescriptionCount; + sal_Int32 nArrayTypeDescriptionCount; sal_Int32 nEnumTypeDescriptionCount; sal_Int32 nInterfaceMethodTypeDescriptionCount; sal_Int32 nInterfaceAttributeTypeDescriptionCount; @@ -396,6 +403,7 @@ TypeDescriptor_Init_Impl::~TypeDescriptor_Init_Impl() SAL_THROW( () ) OSL_ASSERT( nCompoundTypeDescriptionCount == 0 ); OSL_ASSERT( nUnionTypeDescriptionCount == 0 ); OSL_ASSERT( nIndirectTypeDescriptionCount == 0 ); + OSL_ASSERT( nArrayTypeDescriptionCount == 0 ); OSL_ASSERT( nEnumTypeDescriptionCount == 0 ); OSL_ASSERT( nInterfaceMethodTypeDescriptionCount == 0 ); OSL_ASSERT( nInterfaceAttributeTypeDescriptionCount == 0 ); @@ -557,6 +565,20 @@ extern "C" void SAL_CALL typelib_typedescription_newEmpty( switch( eTypeClass ) { case typelib_TypeClass_ARRAY: + { + typelib_ArrayTypeDescription * pTmp = new typelib_ArrayTypeDescription(); + typelib_IndirectTypeDescription * pIndirect = (typelib_IndirectTypeDescription *)pTmp; + pRet = (typelib_TypeDescription *)pTmp; +#ifdef CPPU_ASSERTIONS + osl_incrementInterlockedCount( &aInit.nArrayTypeDescriptionCount ); +#endif + pIndirect->pType = 0; + pTmp->nDimensions = 0; + pTmp->nTotalElements = 0; + pTmp->pDimensions = 0; + } + break; + case typelib_TypeClass_SEQUENCE: { typelib_IndirectTypeDescription * pTmp = new typelib_IndirectTypeDescription(); @@ -708,7 +730,6 @@ extern "C" void SAL_CALL typelib_typedescription_new( switch( eTypeClass ) { - case typelib_TypeClass_ARRAY: case typelib_TypeClass_SEQUENCE: { OSL_ASSERT( nMembers == 0 ); @@ -850,6 +871,44 @@ extern "C" void SAL_CALL typelib_typedescription_newEnum( } //------------------------------------------------------------------------ +extern "C" void SAL_CALL typelib_typedescription_newArray( + typelib_TypeDescription ** ppRet, + typelib_TypeDescriptionReference * pElementTypeRef, + sal_Int32 nDimensions, + sal_Int32 * pDimensions ) + SAL_THROW_EXTERN_C () +{ + OUStringBuffer aBuf( 32 ); + aBuf.append( pElementTypeRef->pTypeName ); + sal_Int32 nElements = 1; + for (sal_Int32 i=0; i < nDimensions; i++) + { + aBuf.appendAscii("["); + aBuf.append(pDimensions[i]); + aBuf.appendAscii("]"); + nElements *= pDimensions[i]; + } + OUString aTypeName( aBuf.makeStringAndClear() ); + + + typelib_typedescription_newEmpty( ppRet, typelib_TypeClass_ARRAY, aTypeName.pData ); + typelib_ArrayTypeDescription * pArray = (typelib_ArrayTypeDescription *)*ppRet; + + pArray->nDimensions = nDimensions; + pArray->nTotalElements = nElements; + pArray->pDimensions = new sal_Int32[ nDimensions ]; + ::memcpy( pArray->pDimensions, pDimensions, nDimensions * sizeof(sal_Int32) ); + + typelib_typedescriptionreference_acquire(pElementTypeRef); + ((typelib_IndirectTypeDescription*)pArray)->pType = pElementTypeRef; + + (*ppRet)->pWeakRef = (typelib_TypeDescriptionReference *)*ppRet; + // sizeof( void ) not allowed + (*ppRet)->nSize = typelib_typedescription_getAlignedUnoSize( *ppRet, 0, (*ppRet)->nAlignment ); + (*ppRet)->nAlignment = adjustAlignment( (*ppRet)->nAlignment ); +} + +//------------------------------------------------------------------------ extern "C" void SAL_CALL typelib_typedescription_newInterface( typelib_InterfaceTypeDescription ** ppRet, rtl_uString * pTypeName, @@ -1046,33 +1105,35 @@ static inline void typelib_typedescription_destructExtendedMembers( switch( pTD->eTypeClass ) { case typelib_TypeClass_ARRAY: + if( ((typelib_IndirectTypeDescription*)pTD)->pType ) + typelib_typedescriptionreference_release( ((typelib_IndirectTypeDescription*)pTD)->pType ); + delete [] ((typelib_ArrayTypeDescription *)pTD)->pDimensions; + break; case typelib_TypeClass_SEQUENCE: if( ((typelib_IndirectTypeDescription*)pTD)->pType ) typelib_typedescriptionreference_release( ((typelib_IndirectTypeDescription*)pTD)->pType ); break; case typelib_TypeClass_UNION: { - typelib_UnionTypeDescription * pUTD = (typelib_UnionTypeDescription *)pTD; - typelib_typedescriptionreference_release( pUTD->pDiscriminantTypeRef ); - typelib_typedescriptionreference_release( pUTD->pDefaultTypeRef ); + typelib_UnionTypeDescription * pUnionTD = (typelib_UnionTypeDescription *)pTD; + typelib_typedescriptionreference_release( pUnionTD->pDiscriminantTypeRef ); + typelib_typedescriptionreference_release( pUnionTD->pDefaultTypeRef ); sal_Int32 nPos; - - typelib_TypeDescriptionReference ** ppTypeRefs = pUTD->ppTypeRefs; - for ( nPos = pUTD->nMembers; nPos--; ) + typelib_TypeDescriptionReference ** ppTypeRefs = pUnionTD->ppTypeRefs; + for ( nPos = pUnionTD->nMembers; nPos--; ) { typelib_typedescriptionreference_release( ppTypeRefs[nPos] ); } - rtl_uString ** ppMemberNames = pUTD->ppMemberNames; - for ( nPos = pUTD->nMembers; nPos--; ) + rtl_uString ** ppMemberNames = pUnionTD->ppMemberNames; + for ( nPos = pUnionTD->nMembers; nPos--; ) { rtl_uString_release( ppMemberNames[nPos] ); } - - delete [] ppTypeRefs; - delete [] ppMemberNames; - delete [] pUTD->pDiscriminants; + delete [] pUnionTD->ppMemberNames; + delete [] pUnionTD->pDiscriminants; + delete [] pUnionTD->ppTypeRefs; } break; case typelib_TypeClass_STRUCT: @@ -1201,6 +1262,8 @@ extern "C" void SAL_CALL typelib_typedescription_release( switch( pTD->eTypeClass ) { case typelib_TypeClass_ARRAY: + osl_decrementInterlockedCount( &aInit.nArrayTypeDescriptionCount ); + break; case typelib_TypeClass_SEQUENCE: osl_decrementInterlockedCount( &aInit.nIndirectTypeDescriptionCount ); break; @@ -1408,7 +1471,7 @@ extern "C" sal_Int32 SAL_CALL typelib_typedescription_getAlignedUnoSize( nSize = rMaxIntegralTypeSize = sizeof( void * ); break; case typelib_TypeClass_UNION: - { + { nSize = rMaxIntegralTypeSize = sizeof(sal_Int64); for ( sal_Int32 nPos = ((typelib_UnionTypeDescription *)pTypeDescription)->nMembers; nPos--; ) { @@ -1423,8 +1486,8 @@ extern "C" sal_Int32 SAL_CALL typelib_typedescription_getAlignedUnoSize( rMaxIntegralTypeSize = nMaxIntegralTypeSize; } ((typelib_UnionTypeDescription *)pTypeDescription)->nValueOffset = rMaxIntegralTypeSize; - } - break; + } + break; case typelib_TypeClass_ENUM: nSize = rMaxIntegralTypeSize = sizeof( typelib_TypeClass ); break; @@ -1439,7 +1502,7 @@ extern "C" sal_Int32 SAL_CALL typelib_typedescription_getAlignedUnoSize( // inherit structs extends the base struct. nStructSize = pTmp->pBaseTypeDescription->aBase.nSize; rMaxIntegralTypeSize = pTmp->pBaseTypeDescription->aBase.nAlignment; - } + } for( sal_Int32 i = 0; i < pTmp->nMembers; i++ ) { typelib_TypeDescription * pMemberType = 0; @@ -1463,7 +1526,7 @@ extern "C" sal_Int32 SAL_CALL typelib_typedescription_getAlignedUnoSize( rMaxIntegralTypeSize = nMaxIntegral; } // Example: A { double; int; } structure has a size of 16 instead of 10. The - // compiler must follow this rule if it is possible to access memvers in arrays through: + // compiler must follow this rule if it is possible to access members in arrays through: // (Element *)((char *)pArray + sizeof( Element ) * ElementPos) nStructSize = (nStructSize + rMaxIntegralTypeSize -1) / rMaxIntegralTypeSize * rMaxIntegralTypeSize; @@ -1471,7 +1534,13 @@ extern "C" sal_Int32 SAL_CALL typelib_typedescription_getAlignedUnoSize( } break; case typelib_TypeClass_ARRAY: - OSL_ENSURE( sal_False, "not implemented" ); + { + typelib_TypeDescription * pTD = 0; + TYPELIB_DANGER_GET( &pTD, ((typelib_IndirectTypeDescription *)pTypeDescription)->pType ); + rMaxIntegralTypeSize = pTD->nSize; + TYPELIB_DANGER_RELEASE( pTD ); + nSize = ((typelib_ArrayTypeDescription *)pTypeDescription)->nTotalElements * rMaxIntegralTypeSize; + } break; case typelib_TypeClass_SEQUENCE: nSize = rMaxIntegralTypeSize = sizeof( void * ); @@ -1500,26 +1569,21 @@ extern "C" sal_Int32 SAL_CALL typelib_typedescription_getAlignedUnoSize( case typelib_TypeClass_DOUBLE: nSize = rMaxIntegralTypeSize = sizeof( double ); break; - case typelib_TypeClass_BYTE: nSize = rMaxIntegralTypeSize = sizeof( sal_Int8 ); break; - case typelib_TypeClass_SHORT: case typelib_TypeClass_UNSIGNED_SHORT: nSize = rMaxIntegralTypeSize = sizeof( sal_Int16 ); break; - case typelib_TypeClass_LONG: case typelib_TypeClass_UNSIGNED_LONG: nSize = rMaxIntegralTypeSize = sizeof( sal_Int32 ); break; - case typelib_TypeClass_HYPER: case typelib_TypeClass_UNSIGNED_HYPER: nSize = rMaxIntegralTypeSize = sizeof( sal_Int64 ); break; - case typelib_TypeClass_UNKNOWN: case typelib_TypeClass_SERVICE: case typelib_TypeClass_MODULE: |