1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: constr.hxx,v $
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 ************************************************************************/
39 //##################################################################################################
40 //#### construction ################################################################################
41 //##################################################################################################
43 //--------------------------------------------------------------------------------------------------
44 inline void _defaultConstructUnion(
46 typelib_TypeDescription
* pTypeDescr
)
49 ::uno_type_constructData(
50 (char *)pMem
+ ((typelib_UnionTypeDescription
*)pTypeDescr
)->nValueOffset
,
51 ((typelib_UnionTypeDescription
*)pTypeDescr
)->pDefaultTypeRef
);
52 *(sal_Int64
*)pMem
= ((typelib_UnionTypeDescription
*)pTypeDescr
)->nDefaultDiscriminant
;
54 //==================================================================================================
55 void defaultConstructStruct(
57 typelib_CompoundTypeDescription
* pCompType
)
59 //--------------------------------------------------------------------------------------------------
60 inline void _defaultConstructStruct(
62 typelib_CompoundTypeDescription
* pTypeDescr
)
65 if (pTypeDescr
->pBaseTypeDescription
)
67 defaultConstructStruct( pMem
, pTypeDescr
->pBaseTypeDescription
);
70 typelib_TypeDescriptionReference
** ppTypeRefs
= (pTypeDescr
)->ppTypeRefs
;
71 sal_Int32
* pMemberOffsets
= pTypeDescr
->pMemberOffsets
;
72 sal_Int32 nDescr
= pTypeDescr
->nMembers
;
76 ::uno_type_constructData( (char *)pMem
+ pMemberOffsets
[nDescr
], ppTypeRefs
[nDescr
] );
80 //--------------------------------------------------------------------------------------------------
81 inline void _defaultConstructArray(
83 typelib_ArrayTypeDescription
* pTypeDescr
)
85 typelib_TypeDescription
* pElementType
= NULL
;
86 TYPELIB_DANGER_GET( &pElementType
, ((typelib_IndirectTypeDescription
*)pTypeDescr
)->pType
);
87 sal_Int32 nTotalElements
= pTypeDescr
->nTotalElements
;
88 sal_Int32 nElementSize
= pElementType
->nSize
;
90 switch ( pElementType
->eTypeClass
)
92 case typelib_TypeClass_CHAR
:
93 case typelib_TypeClass_BOOLEAN
:
94 case typelib_TypeClass_BYTE
:
95 case typelib_TypeClass_SHORT
:
96 case typelib_TypeClass_UNSIGNED_SHORT
:
97 case typelib_TypeClass_LONG
:
98 case typelib_TypeClass_UNSIGNED_LONG
:
99 case typelib_TypeClass_HYPER
:
100 case typelib_TypeClass_UNSIGNED_HYPER
:
101 case typelib_TypeClass_FLOAT
:
102 case typelib_TypeClass_DOUBLE
:
103 case typelib_TypeClass_INTERFACE
:
104 ::rtl_zeroMemory(pMem
, nElementSize
* nTotalElements
);
107 case typelib_TypeClass_STRING
:
108 for (i
=0; i
< nTotalElements
; i
++)
110 rtl_uString
** ppElement
= (rtl_uString
**)pMem
+ i
;
112 rtl_uString_new( ppElement
);
115 case typelib_TypeClass_TYPE
:
116 for (i
=0; i
< nTotalElements
; i
++)
118 typelib_TypeDescriptionReference
** ppElement
= (typelib_TypeDescriptionReference
**)pMem
+ i
;
119 *ppElement
= _getVoidType();
122 case typelib_TypeClass_ANY
:
123 for (i
=0; i
< nTotalElements
; i
++)
125 CONSTRUCT_EMPTY_ANY( (uno_Any
*)pMem
+ i
);
128 case typelib_TypeClass_ENUM
:
129 for (i
=0; i
< nTotalElements
; i
++)
131 *((sal_Int32
*)pMem
+ i
) = ((typelib_EnumTypeDescription
*)pElementType
)->nDefaultEnumValue
;
134 case typelib_TypeClass_STRUCT
:
135 case typelib_TypeClass_EXCEPTION
:
136 for (i
=0; i
< nTotalElements
; i
++)
138 _defaultConstructStruct( (sal_Char
*)pMem
+ i
* nElementSize
, (typelib_CompoundTypeDescription
*)pElementType
);
141 case typelib_TypeClass_UNION
:
142 for (i
=0; i
< nTotalElements
; i
++)
144 _defaultConstructUnion( (sal_Char
*)pMem
+ i
* nElementSize
, pElementType
);
147 case typelib_TypeClass_SEQUENCE
:
148 for (i
=0; i
< nTotalElements
; i
++)
150 uno_Sequence
** ppElement
= (uno_Sequence
**)pMem
+ i
;
151 *ppElement
= createEmptySequence();
158 TYPELIB_DANGER_RELEASE( pElementType
);
161 //--------------------------------------------------------------------------------------------------
162 inline void _defaultConstructData(
164 typelib_TypeDescriptionReference
* pType
,
165 typelib_TypeDescription
* pTypeDescr
)
168 switch (pType
->eTypeClass
)
170 case typelib_TypeClass_CHAR
:
171 *(sal_Unicode
*)pMem
= '\0';
173 case typelib_TypeClass_BOOLEAN
:
174 *(sal_Bool
*)pMem
= sal_False
;
176 case typelib_TypeClass_BYTE
:
177 *(sal_Int8
*)pMem
= 0;
179 case typelib_TypeClass_SHORT
:
180 case typelib_TypeClass_UNSIGNED_SHORT
:
181 *(sal_Int16
*)pMem
= 0;
183 case typelib_TypeClass_LONG
:
184 case typelib_TypeClass_UNSIGNED_LONG
:
185 *(sal_Int32
*)pMem
= 0;
187 case typelib_TypeClass_HYPER
:
188 case typelib_TypeClass_UNSIGNED_HYPER
:
189 *(sal_Int64
*)pMem
= 0;
191 case typelib_TypeClass_FLOAT
:
192 *(float *)pMem
= 0.0;
194 case typelib_TypeClass_DOUBLE
:
195 *(double *)pMem
= 0.0;
197 case typelib_TypeClass_STRING
:
198 *(rtl_uString
**)pMem
= 0;
199 ::rtl_uString_new( (rtl_uString
**)pMem
);
201 case typelib_TypeClass_TYPE
:
202 *(typelib_TypeDescriptionReference
**)pMem
= _getVoidType();
204 case typelib_TypeClass_ANY
:
205 CONSTRUCT_EMPTY_ANY( (uno_Any
*)pMem
);
207 case typelib_TypeClass_ENUM
:
210 *(sal_Int32
*)pMem
= ((typelib_EnumTypeDescription
*)pTypeDescr
)->nDefaultEnumValue
;
214 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
215 *(sal_Int32
*)pMem
= ((typelib_EnumTypeDescription
*)pTypeDescr
)->nDefaultEnumValue
;
216 TYPELIB_DANGER_RELEASE( pTypeDescr
);
219 case typelib_TypeClass_STRUCT
:
220 case typelib_TypeClass_EXCEPTION
:
223 _defaultConstructStruct( pMem
, (typelib_CompoundTypeDescription
*)pTypeDescr
);
227 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
228 _defaultConstructStruct( pMem
, (typelib_CompoundTypeDescription
*)pTypeDescr
);
229 TYPELIB_DANGER_RELEASE( pTypeDescr
);
232 case typelib_TypeClass_ARRAY
:
235 _defaultConstructArray( pMem
, (typelib_ArrayTypeDescription
*)pTypeDescr
);
239 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
240 _defaultConstructArray( pMem
, (typelib_ArrayTypeDescription
*)pTypeDescr
);
241 TYPELIB_DANGER_RELEASE( pTypeDescr
);
244 case typelib_TypeClass_UNION
:
247 _defaultConstructUnion( pMem
, pTypeDescr
);
251 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
252 _defaultConstructUnion( pMem
, pTypeDescr
);
253 TYPELIB_DANGER_RELEASE( pTypeDescr
);
256 case typelib_TypeClass_SEQUENCE
:
257 *(uno_Sequence
**)pMem
= createEmptySequence();
259 case typelib_TypeClass_INTERFACE
:
260 *(void **)pMem
= 0; // either cpp or c-uno interface