1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir #ifndef CONSTR_HXX 28*cdf0e10cSrcweir #define CONSTR_HXX 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include "prim.hxx" 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir namespace cppu 34*cdf0e10cSrcweir { 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir //################################################################################################## 37*cdf0e10cSrcweir //#### construction ################################################################################ 38*cdf0e10cSrcweir //################################################################################################## 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir //-------------------------------------------------------------------------------------------------- 41*cdf0e10cSrcweir inline void _defaultConstructUnion( 42*cdf0e10cSrcweir void * pMem, 43*cdf0e10cSrcweir typelib_TypeDescription * pTypeDescr ) 44*cdf0e10cSrcweir SAL_THROW( () ) 45*cdf0e10cSrcweir { 46*cdf0e10cSrcweir ::uno_type_constructData( 47*cdf0e10cSrcweir (char *)pMem + ((typelib_UnionTypeDescription *)pTypeDescr)->nValueOffset, 48*cdf0e10cSrcweir ((typelib_UnionTypeDescription *)pTypeDescr)->pDefaultTypeRef ); 49*cdf0e10cSrcweir *(sal_Int64 *)pMem = ((typelib_UnionTypeDescription *)pTypeDescr)->nDefaultDiscriminant; 50*cdf0e10cSrcweir } 51*cdf0e10cSrcweir //================================================================================================== 52*cdf0e10cSrcweir void defaultConstructStruct( 53*cdf0e10cSrcweir void * pMem, 54*cdf0e10cSrcweir typelib_CompoundTypeDescription * pCompType ) 55*cdf0e10cSrcweir SAL_THROW( () ); 56*cdf0e10cSrcweir //-------------------------------------------------------------------------------------------------- 57*cdf0e10cSrcweir inline void _defaultConstructStruct( 58*cdf0e10cSrcweir void * pMem, 59*cdf0e10cSrcweir typelib_CompoundTypeDescription * pTypeDescr ) 60*cdf0e10cSrcweir SAL_THROW( () ) 61*cdf0e10cSrcweir { 62*cdf0e10cSrcweir if (pTypeDescr->pBaseTypeDescription) 63*cdf0e10cSrcweir { 64*cdf0e10cSrcweir defaultConstructStruct( pMem, pTypeDescr->pBaseTypeDescription ); 65*cdf0e10cSrcweir } 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir typelib_TypeDescriptionReference ** ppTypeRefs = (pTypeDescr)->ppTypeRefs; 68*cdf0e10cSrcweir sal_Int32 * pMemberOffsets = pTypeDescr->pMemberOffsets; 69*cdf0e10cSrcweir sal_Int32 nDescr = pTypeDescr->nMembers; 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir while (nDescr--) 72*cdf0e10cSrcweir { 73*cdf0e10cSrcweir ::uno_type_constructData( (char *)pMem + pMemberOffsets[nDescr], ppTypeRefs[nDescr] ); 74*cdf0e10cSrcweir } 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir //-------------------------------------------------------------------------------------------------- 78*cdf0e10cSrcweir inline void _defaultConstructArray( 79*cdf0e10cSrcweir void * pMem, 80*cdf0e10cSrcweir typelib_ArrayTypeDescription * pTypeDescr ) 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir typelib_TypeDescription * pElementType = NULL; 83*cdf0e10cSrcweir TYPELIB_DANGER_GET( &pElementType, ((typelib_IndirectTypeDescription *)pTypeDescr)->pType ); 84*cdf0e10cSrcweir sal_Int32 nTotalElements = pTypeDescr->nTotalElements; 85*cdf0e10cSrcweir sal_Int32 nElementSize = pElementType->nSize; 86*cdf0e10cSrcweir sal_Int32 i; 87*cdf0e10cSrcweir switch ( pElementType->eTypeClass ) 88*cdf0e10cSrcweir { 89*cdf0e10cSrcweir case typelib_TypeClass_CHAR: 90*cdf0e10cSrcweir case typelib_TypeClass_BOOLEAN: 91*cdf0e10cSrcweir case typelib_TypeClass_BYTE: 92*cdf0e10cSrcweir case typelib_TypeClass_SHORT: 93*cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_SHORT: 94*cdf0e10cSrcweir case typelib_TypeClass_LONG: 95*cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_LONG: 96*cdf0e10cSrcweir case typelib_TypeClass_HYPER: 97*cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_HYPER: 98*cdf0e10cSrcweir case typelib_TypeClass_FLOAT: 99*cdf0e10cSrcweir case typelib_TypeClass_DOUBLE: 100*cdf0e10cSrcweir case typelib_TypeClass_INTERFACE: 101*cdf0e10cSrcweir ::rtl_zeroMemory(pMem, nElementSize * nTotalElements); 102*cdf0e10cSrcweir break; 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir case typelib_TypeClass_STRING: 105*cdf0e10cSrcweir for (i=0; i < nTotalElements; i++) 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir rtl_uString** ppElement = (rtl_uString **)pMem + i; 108*cdf0e10cSrcweir *ppElement = 0; 109*cdf0e10cSrcweir rtl_uString_new( ppElement); 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir break; 112*cdf0e10cSrcweir case typelib_TypeClass_TYPE: 113*cdf0e10cSrcweir for (i=0; i < nTotalElements; i++) 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir typelib_TypeDescriptionReference** ppElement = (typelib_TypeDescriptionReference **)pMem + i; 116*cdf0e10cSrcweir *ppElement = _getVoidType(); 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir break; 119*cdf0e10cSrcweir case typelib_TypeClass_ANY: 120*cdf0e10cSrcweir for (i=0; i < nTotalElements; i++) 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir CONSTRUCT_EMPTY_ANY( (uno_Any *)pMem + i ); 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir break; 125*cdf0e10cSrcweir case typelib_TypeClass_ENUM: 126*cdf0e10cSrcweir for (i=0; i < nTotalElements; i++) 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir *((sal_Int32 *)pMem + i) = ((typelib_EnumTypeDescription *)pElementType)->nDefaultEnumValue; 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir break; 131*cdf0e10cSrcweir case typelib_TypeClass_STRUCT: 132*cdf0e10cSrcweir case typelib_TypeClass_EXCEPTION: 133*cdf0e10cSrcweir for (i=0; i < nTotalElements; i++) 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir _defaultConstructStruct( (sal_Char*)pMem + i * nElementSize, (typelib_CompoundTypeDescription *)pElementType ); 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir break; 138*cdf0e10cSrcweir case typelib_TypeClass_UNION: 139*cdf0e10cSrcweir for (i=0; i < nTotalElements; i++) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir _defaultConstructUnion( (sal_Char*)pMem + i * nElementSize, pElementType ); 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir break; 144*cdf0e10cSrcweir case typelib_TypeClass_SEQUENCE: 145*cdf0e10cSrcweir for (i=0; i < nTotalElements; i++) 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir uno_Sequence** ppElement = (uno_Sequence **)pMem + i; 148*cdf0e10cSrcweir *ppElement = createEmptySequence(); 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir break; 151*cdf0e10cSrcweir default: 152*cdf0e10cSrcweir OSL_ASSERT(false); 153*cdf0e10cSrcweir break; 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pElementType ); 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir //-------------------------------------------------------------------------------------------------- 159*cdf0e10cSrcweir inline void _defaultConstructData( 160*cdf0e10cSrcweir void * pMem, 161*cdf0e10cSrcweir typelib_TypeDescriptionReference * pType, 162*cdf0e10cSrcweir typelib_TypeDescription * pTypeDescr ) 163*cdf0e10cSrcweir SAL_THROW( () ) 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir switch (pType->eTypeClass) 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir case typelib_TypeClass_CHAR: 168*cdf0e10cSrcweir *(sal_Unicode *)pMem = '\0'; 169*cdf0e10cSrcweir break; 170*cdf0e10cSrcweir case typelib_TypeClass_BOOLEAN: 171*cdf0e10cSrcweir *(sal_Bool *)pMem = sal_False; 172*cdf0e10cSrcweir break; 173*cdf0e10cSrcweir case typelib_TypeClass_BYTE: 174*cdf0e10cSrcweir *(sal_Int8 *)pMem = 0; 175*cdf0e10cSrcweir break; 176*cdf0e10cSrcweir case typelib_TypeClass_SHORT: 177*cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_SHORT: 178*cdf0e10cSrcweir *(sal_Int16 *)pMem = 0; 179*cdf0e10cSrcweir break; 180*cdf0e10cSrcweir case typelib_TypeClass_LONG: 181*cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_LONG: 182*cdf0e10cSrcweir *(sal_Int32 *)pMem = 0; 183*cdf0e10cSrcweir break; 184*cdf0e10cSrcweir case typelib_TypeClass_HYPER: 185*cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_HYPER: 186*cdf0e10cSrcweir *(sal_Int64 *)pMem = 0; 187*cdf0e10cSrcweir break; 188*cdf0e10cSrcweir case typelib_TypeClass_FLOAT: 189*cdf0e10cSrcweir *(float *)pMem = 0.0; 190*cdf0e10cSrcweir break; 191*cdf0e10cSrcweir case typelib_TypeClass_DOUBLE: 192*cdf0e10cSrcweir *(double *)pMem = 0.0; 193*cdf0e10cSrcweir break; 194*cdf0e10cSrcweir case typelib_TypeClass_STRING: 195*cdf0e10cSrcweir *(rtl_uString **)pMem = 0; 196*cdf0e10cSrcweir ::rtl_uString_new( (rtl_uString **)pMem ); 197*cdf0e10cSrcweir break; 198*cdf0e10cSrcweir case typelib_TypeClass_TYPE: 199*cdf0e10cSrcweir *(typelib_TypeDescriptionReference **)pMem = _getVoidType(); 200*cdf0e10cSrcweir break; 201*cdf0e10cSrcweir case typelib_TypeClass_ANY: 202*cdf0e10cSrcweir CONSTRUCT_EMPTY_ANY( (uno_Any *)pMem ); 203*cdf0e10cSrcweir break; 204*cdf0e10cSrcweir case typelib_TypeClass_ENUM: 205*cdf0e10cSrcweir if (pTypeDescr) 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir *(sal_Int32 *)pMem = ((typelib_EnumTypeDescription *)pTypeDescr)->nDefaultEnumValue; 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir else 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir TYPELIB_DANGER_GET( &pTypeDescr, pType ); 212*cdf0e10cSrcweir *(sal_Int32 *)pMem = ((typelib_EnumTypeDescription *)pTypeDescr)->nDefaultEnumValue; 213*cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pTypeDescr ); 214*cdf0e10cSrcweir } 215*cdf0e10cSrcweir break; 216*cdf0e10cSrcweir case typelib_TypeClass_STRUCT: 217*cdf0e10cSrcweir case typelib_TypeClass_EXCEPTION: 218*cdf0e10cSrcweir if (pTypeDescr) 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir _defaultConstructStruct( pMem, (typelib_CompoundTypeDescription *)pTypeDescr ); 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir else 223*cdf0e10cSrcweir { 224*cdf0e10cSrcweir TYPELIB_DANGER_GET( &pTypeDescr, pType ); 225*cdf0e10cSrcweir _defaultConstructStruct( pMem, (typelib_CompoundTypeDescription *)pTypeDescr ); 226*cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pTypeDescr ); 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir break; 229*cdf0e10cSrcweir case typelib_TypeClass_ARRAY: 230*cdf0e10cSrcweir if (pTypeDescr) 231*cdf0e10cSrcweir { 232*cdf0e10cSrcweir _defaultConstructArray( pMem, (typelib_ArrayTypeDescription *)pTypeDescr ); 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir else 235*cdf0e10cSrcweir { 236*cdf0e10cSrcweir TYPELIB_DANGER_GET( &pTypeDescr, pType ); 237*cdf0e10cSrcweir _defaultConstructArray( pMem, (typelib_ArrayTypeDescription *)pTypeDescr ); 238*cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pTypeDescr ); 239*cdf0e10cSrcweir } 240*cdf0e10cSrcweir break; 241*cdf0e10cSrcweir case typelib_TypeClass_UNION: 242*cdf0e10cSrcweir if (pTypeDescr) 243*cdf0e10cSrcweir { 244*cdf0e10cSrcweir _defaultConstructUnion( pMem, pTypeDescr ); 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir else 247*cdf0e10cSrcweir { 248*cdf0e10cSrcweir TYPELIB_DANGER_GET( &pTypeDescr, pType ); 249*cdf0e10cSrcweir _defaultConstructUnion( pMem, pTypeDescr ); 250*cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pTypeDescr ); 251*cdf0e10cSrcweir } 252*cdf0e10cSrcweir break; 253*cdf0e10cSrcweir case typelib_TypeClass_SEQUENCE: 254*cdf0e10cSrcweir *(uno_Sequence **)pMem = createEmptySequence(); 255*cdf0e10cSrcweir break; 256*cdf0e10cSrcweir case typelib_TypeClass_INTERFACE: 257*cdf0e10cSrcweir *(void **)pMem = 0; // either cpp or c-uno interface 258*cdf0e10cSrcweir break; 259*cdf0e10cSrcweir default: 260*cdf0e10cSrcweir OSL_ASSERT(false); 261*cdf0e10cSrcweir break; 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir } 266*cdf0e10cSrcweir 267*cdf0e10cSrcweir #endif 268