Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / cppu / source / uno / constr.hxx
blobdd0343a5247f81ea446737f2771871d1533dc2b2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
19 #ifndef CONSTR_HXX
20 #define CONSTR_HXX
22 #include <string.h>
23 #include "prim.hxx"
25 namespace cppu
28 //##################################################################################################
29 //#### construction ################################################################################
30 //##################################################################################################
32 //--------------------------------------------------------------------------------------------------
33 inline void _defaultConstructUnion(
34 void * pMem,
35 typelib_TypeDescription * pTypeDescr )
36 SAL_THROW(())
38 ::uno_type_constructData(
39 (char *)pMem + ((typelib_UnionTypeDescription *)pTypeDescr)->nValueOffset,
40 ((typelib_UnionTypeDescription *)pTypeDescr)->pDefaultTypeRef );
41 *(sal_Int64 *)pMem = ((typelib_UnionTypeDescription *)pTypeDescr)->nDefaultDiscriminant;
43 //==================================================================================================
44 void defaultConstructStruct(
45 void * pMem,
46 typelib_CompoundTypeDescription * pCompType )
47 SAL_THROW(());
48 //--------------------------------------------------------------------------------------------------
49 inline void _defaultConstructStruct(
50 void * pMem,
51 typelib_CompoundTypeDescription * pTypeDescr )
52 SAL_THROW(())
54 if (pTypeDescr->pBaseTypeDescription)
56 defaultConstructStruct( pMem, pTypeDescr->pBaseTypeDescription );
59 typelib_TypeDescriptionReference ** ppTypeRefs = (pTypeDescr)->ppTypeRefs;
60 sal_Int32 * pMemberOffsets = pTypeDescr->pMemberOffsets;
61 sal_Int32 nDescr = pTypeDescr->nMembers;
63 while (nDescr--)
65 ::uno_type_constructData( (char *)pMem + pMemberOffsets[nDescr], ppTypeRefs[nDescr] );
69 //--------------------------------------------------------------------------------------------------
70 inline void _defaultConstructArray(
71 void * pMem,
72 typelib_ArrayTypeDescription * pTypeDescr )
74 typelib_TypeDescription * pElementType = NULL;
75 TYPELIB_DANGER_GET( &pElementType, ((typelib_IndirectTypeDescription *)pTypeDescr)->pType );
76 sal_Int32 nTotalElements = pTypeDescr->nTotalElements;
77 sal_Int32 nElementSize = pElementType->nSize;
78 sal_Int32 i;
79 switch ( pElementType->eTypeClass )
81 case typelib_TypeClass_CHAR:
82 case typelib_TypeClass_BOOLEAN:
83 case typelib_TypeClass_BYTE:
84 case typelib_TypeClass_SHORT:
85 case typelib_TypeClass_UNSIGNED_SHORT:
86 case typelib_TypeClass_LONG:
87 case typelib_TypeClass_UNSIGNED_LONG:
88 case typelib_TypeClass_HYPER:
89 case typelib_TypeClass_UNSIGNED_HYPER:
90 case typelib_TypeClass_FLOAT:
91 case typelib_TypeClass_DOUBLE:
92 case typelib_TypeClass_INTERFACE:
93 memset(pMem, 0, nElementSize * nTotalElements);
94 break;
96 case typelib_TypeClass_STRING:
97 for (i=0; i < nTotalElements; i++)
99 rtl_uString** ppElement = (rtl_uString **)pMem + i;
100 *ppElement = 0;
101 rtl_uString_new( ppElement);
103 break;
104 case typelib_TypeClass_TYPE:
105 for (i=0; i < nTotalElements; i++)
107 typelib_TypeDescriptionReference** ppElement = (typelib_TypeDescriptionReference **)pMem + i;
108 *ppElement = _getVoidType();
110 break;
111 case typelib_TypeClass_ANY:
112 for (i=0; i < nTotalElements; i++)
114 CONSTRUCT_EMPTY_ANY( (uno_Any *)pMem + i );
116 break;
117 case typelib_TypeClass_ENUM:
118 for (i=0; i < nTotalElements; i++)
120 *((sal_Int32 *)pMem + i) = ((typelib_EnumTypeDescription *)pElementType)->nDefaultEnumValue;
122 break;
123 case typelib_TypeClass_STRUCT:
124 case typelib_TypeClass_EXCEPTION:
125 for (i=0; i < nTotalElements; i++)
127 _defaultConstructStruct( (sal_Char*)pMem + i * nElementSize, (typelib_CompoundTypeDescription *)pElementType );
129 break;
130 case typelib_TypeClass_UNION:
131 for (i=0; i < nTotalElements; i++)
133 _defaultConstructUnion( (sal_Char*)pMem + i * nElementSize, pElementType );
135 break;
136 case typelib_TypeClass_SEQUENCE:
137 for (i=0; i < nTotalElements; i++)
139 uno_Sequence** ppElement = (uno_Sequence **)pMem + i;
140 *ppElement = createEmptySequence();
142 break;
143 default:
144 OSL_ASSERT(false);
145 break;
147 TYPELIB_DANGER_RELEASE( pElementType );
150 //--------------------------------------------------------------------------------------------------
151 inline void _defaultConstructData(
152 void * pMem,
153 typelib_TypeDescriptionReference * pType,
154 typelib_TypeDescription * pTypeDescr )
155 SAL_THROW(())
157 switch (pType->eTypeClass)
159 case typelib_TypeClass_CHAR:
160 *(sal_Unicode *)pMem = '\0';
161 break;
162 case typelib_TypeClass_BOOLEAN:
163 *(sal_Bool *)pMem = sal_False;
164 break;
165 case typelib_TypeClass_BYTE:
166 *(sal_Int8 *)pMem = 0;
167 break;
168 case typelib_TypeClass_SHORT:
169 case typelib_TypeClass_UNSIGNED_SHORT:
170 *(sal_Int16 *)pMem = 0;
171 break;
172 case typelib_TypeClass_LONG:
173 case typelib_TypeClass_UNSIGNED_LONG:
174 *(sal_Int32 *)pMem = 0;
175 break;
176 case typelib_TypeClass_HYPER:
177 case typelib_TypeClass_UNSIGNED_HYPER:
178 *(sal_Int64 *)pMem = 0;
179 break;
180 case typelib_TypeClass_FLOAT:
181 *(float *)pMem = 0.0;
182 break;
183 case typelib_TypeClass_DOUBLE:
184 *(double *)pMem = 0.0;
185 break;
186 case typelib_TypeClass_STRING:
187 *(rtl_uString **)pMem = 0;
188 ::rtl_uString_new( (rtl_uString **)pMem );
189 break;
190 case typelib_TypeClass_TYPE:
191 *(typelib_TypeDescriptionReference **)pMem = _getVoidType();
192 break;
193 case typelib_TypeClass_ANY:
194 CONSTRUCT_EMPTY_ANY( (uno_Any *)pMem );
195 break;
196 case typelib_TypeClass_ENUM:
197 if (pTypeDescr)
199 *(sal_Int32 *)pMem = ((typelib_EnumTypeDescription *)pTypeDescr)->nDefaultEnumValue;
201 else
203 TYPELIB_DANGER_GET( &pTypeDescr, pType );
204 *(sal_Int32 *)pMem = ((typelib_EnumTypeDescription *)pTypeDescr)->nDefaultEnumValue;
205 TYPELIB_DANGER_RELEASE( pTypeDescr );
207 break;
208 case typelib_TypeClass_STRUCT:
209 case typelib_TypeClass_EXCEPTION:
210 if (pTypeDescr)
212 _defaultConstructStruct( pMem, (typelib_CompoundTypeDescription *)pTypeDescr );
214 else
216 TYPELIB_DANGER_GET( &pTypeDescr, pType );
217 _defaultConstructStruct( pMem, (typelib_CompoundTypeDescription *)pTypeDescr );
218 TYPELIB_DANGER_RELEASE( pTypeDescr );
220 break;
221 case typelib_TypeClass_ARRAY:
222 if (pTypeDescr)
224 _defaultConstructArray( pMem, (typelib_ArrayTypeDescription *)pTypeDescr );
226 else
228 TYPELIB_DANGER_GET( &pTypeDescr, pType );
229 _defaultConstructArray( pMem, (typelib_ArrayTypeDescription *)pTypeDescr );
230 TYPELIB_DANGER_RELEASE( pTypeDescr );
232 break;
233 case typelib_TypeClass_UNION:
234 if (pTypeDescr)
236 _defaultConstructUnion( pMem, pTypeDescr );
238 else
240 TYPELIB_DANGER_GET( &pTypeDescr, pType );
241 _defaultConstructUnion( pMem, pTypeDescr );
242 TYPELIB_DANGER_RELEASE( pTypeDescr );
244 break;
245 case typelib_TypeClass_SEQUENCE:
246 *(uno_Sequence **)pMem = createEmptySequence();
247 break;
248 case typelib_TypeClass_INTERFACE:
249 *(void **)pMem = 0; // either cpp or c-uno interface
250 break;
251 default:
252 OSL_ASSERT(false);
253 break;
259 #endif
261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */