merge the formfield patch from ooo-build
[ooovba.git] / cppu / source / uno / constr.hxx
blob5563dfbfebe68d0e20bf86366f301e689813de40
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: constr.hxx,v $
10 * $Revision: 1.13 $
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 ************************************************************************/
30 #ifndef CONSTR_HXX
31 #define CONSTR_HXX
33 #include "prim.hxx"
36 namespace cppu
39 //##################################################################################################
40 //#### construction ################################################################################
41 //##################################################################################################
43 //--------------------------------------------------------------------------------------------------
44 inline void _defaultConstructUnion(
45 void * pMem,
46 typelib_TypeDescription * pTypeDescr )
47 SAL_THROW( () )
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(
56 void * pMem,
57 typelib_CompoundTypeDescription * pCompType )
58 SAL_THROW( () );
59 //--------------------------------------------------------------------------------------------------
60 inline void _defaultConstructStruct(
61 void * pMem,
62 typelib_CompoundTypeDescription * pTypeDescr )
63 SAL_THROW( () )
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;
74 while (nDescr--)
76 ::uno_type_constructData( (char *)pMem + pMemberOffsets[nDescr], ppTypeRefs[nDescr] );
80 //--------------------------------------------------------------------------------------------------
81 inline void _defaultConstructArray(
82 void * pMem,
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;
89 sal_Int32 i;
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);
105 break;
107 case typelib_TypeClass_STRING:
108 for (i=0; i < nTotalElements; i++)
110 rtl_uString** ppElement = (rtl_uString **)pMem + i;
111 *ppElement = 0;
112 rtl_uString_new( ppElement);
114 break;
115 case typelib_TypeClass_TYPE:
116 for (i=0; i < nTotalElements; i++)
118 typelib_TypeDescriptionReference** ppElement = (typelib_TypeDescriptionReference **)pMem + i;
119 *ppElement = _getVoidType();
121 break;
122 case typelib_TypeClass_ANY:
123 for (i=0; i < nTotalElements; i++)
125 CONSTRUCT_EMPTY_ANY( (uno_Any *)pMem + i );
127 break;
128 case typelib_TypeClass_ENUM:
129 for (i=0; i < nTotalElements; i++)
131 *((sal_Int32 *)pMem + i) = ((typelib_EnumTypeDescription *)pElementType)->nDefaultEnumValue;
133 break;
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 );
140 break;
141 case typelib_TypeClass_UNION:
142 for (i=0; i < nTotalElements; i++)
144 _defaultConstructUnion( (sal_Char*)pMem + i * nElementSize, pElementType );
146 break;
147 case typelib_TypeClass_SEQUENCE:
148 for (i=0; i < nTotalElements; i++)
150 uno_Sequence** ppElement = (uno_Sequence **)pMem + i;
151 *ppElement = createEmptySequence();
153 break;
154 default:
155 OSL_ASSERT(false);
156 break;
158 TYPELIB_DANGER_RELEASE( pElementType );
161 //--------------------------------------------------------------------------------------------------
162 inline void _defaultConstructData(
163 void * pMem,
164 typelib_TypeDescriptionReference * pType,
165 typelib_TypeDescription * pTypeDescr )
166 SAL_THROW( () )
168 switch (pType->eTypeClass)
170 case typelib_TypeClass_CHAR:
171 *(sal_Unicode *)pMem = '\0';
172 break;
173 case typelib_TypeClass_BOOLEAN:
174 *(sal_Bool *)pMem = sal_False;
175 break;
176 case typelib_TypeClass_BYTE:
177 *(sal_Int8 *)pMem = 0;
178 break;
179 case typelib_TypeClass_SHORT:
180 case typelib_TypeClass_UNSIGNED_SHORT:
181 *(sal_Int16 *)pMem = 0;
182 break;
183 case typelib_TypeClass_LONG:
184 case typelib_TypeClass_UNSIGNED_LONG:
185 *(sal_Int32 *)pMem = 0;
186 break;
187 case typelib_TypeClass_HYPER:
188 case typelib_TypeClass_UNSIGNED_HYPER:
189 *(sal_Int64 *)pMem = 0;
190 break;
191 case typelib_TypeClass_FLOAT:
192 *(float *)pMem = 0.0;
193 break;
194 case typelib_TypeClass_DOUBLE:
195 *(double *)pMem = 0.0;
196 break;
197 case typelib_TypeClass_STRING:
198 *(rtl_uString **)pMem = 0;
199 ::rtl_uString_new( (rtl_uString **)pMem );
200 break;
201 case typelib_TypeClass_TYPE:
202 *(typelib_TypeDescriptionReference **)pMem = _getVoidType();
203 break;
204 case typelib_TypeClass_ANY:
205 CONSTRUCT_EMPTY_ANY( (uno_Any *)pMem );
206 break;
207 case typelib_TypeClass_ENUM:
208 if (pTypeDescr)
210 *(sal_Int32 *)pMem = ((typelib_EnumTypeDescription *)pTypeDescr)->nDefaultEnumValue;
212 else
214 TYPELIB_DANGER_GET( &pTypeDescr, pType );
215 *(sal_Int32 *)pMem = ((typelib_EnumTypeDescription *)pTypeDescr)->nDefaultEnumValue;
216 TYPELIB_DANGER_RELEASE( pTypeDescr );
218 break;
219 case typelib_TypeClass_STRUCT:
220 case typelib_TypeClass_EXCEPTION:
221 if (pTypeDescr)
223 _defaultConstructStruct( pMem, (typelib_CompoundTypeDescription *)pTypeDescr );
225 else
227 TYPELIB_DANGER_GET( &pTypeDescr, pType );
228 _defaultConstructStruct( pMem, (typelib_CompoundTypeDescription *)pTypeDescr );
229 TYPELIB_DANGER_RELEASE( pTypeDescr );
231 break;
232 case typelib_TypeClass_ARRAY:
233 if (pTypeDescr)
235 _defaultConstructArray( pMem, (typelib_ArrayTypeDescription *)pTypeDescr );
237 else
239 TYPELIB_DANGER_GET( &pTypeDescr, pType );
240 _defaultConstructArray( pMem, (typelib_ArrayTypeDescription *)pTypeDescr );
241 TYPELIB_DANGER_RELEASE( pTypeDescr );
243 break;
244 case typelib_TypeClass_UNION:
245 if (pTypeDescr)
247 _defaultConstructUnion( pMem, pTypeDescr );
249 else
251 TYPELIB_DANGER_GET( &pTypeDescr, pType );
252 _defaultConstructUnion( pMem, pTypeDescr );
253 TYPELIB_DANGER_RELEASE( pTypeDescr );
255 break;
256 case typelib_TypeClass_SEQUENCE:
257 *(uno_Sequence **)pMem = createEmptySequence();
258 break;
259 case typelib_TypeClass_INTERFACE:
260 *(void **)pMem = 0; // either cpp or c-uno interface
261 break;
262 default:
263 OSL_ASSERT(false);
264 break;
270 #endif