xref: /AOO41X/main/cppu/source/uno/assign.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 ASSIGN_HXX
28*cdf0e10cSrcweir #define ASSIGN_HXX
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #include "prim.hxx"
31*cdf0e10cSrcweir #include "destr.hxx"
32*cdf0e10cSrcweir #include "constr.hxx"
33*cdf0e10cSrcweir #include "copy.hxx"
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir namespace cppu
37*cdf0e10cSrcweir {
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir //##################################################################################################
40*cdf0e10cSrcweir //#### assignment ##################################################################################
41*cdf0e10cSrcweir //##################################################################################################
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
45*cdf0e10cSrcweir inline void _assignInterface(
46*cdf0e10cSrcweir 	void ** ppDest, void * pSource,
47*cdf0e10cSrcweir 	uno_AcquireFunc acquire, uno_ReleaseFunc release )
48*cdf0e10cSrcweir 	SAL_THROW( () )
49*cdf0e10cSrcweir {
50*cdf0e10cSrcweir     _acquire( pSource, acquire );
51*cdf0e10cSrcweir     void * const pToBeReleased = *ppDest;
52*cdf0e10cSrcweir 	*ppDest = pSource;
53*cdf0e10cSrcweir     _release( pToBeReleased, release );
54*cdf0e10cSrcweir }
55*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
56*cdf0e10cSrcweir inline void * _queryInterface(
57*cdf0e10cSrcweir 	void * pSource,
58*cdf0e10cSrcweir 	typelib_TypeDescriptionReference * pDestType,
59*cdf0e10cSrcweir 	uno_QueryInterfaceFunc queryInterface )
60*cdf0e10cSrcweir 	SAL_THROW( () )
61*cdf0e10cSrcweir {
62*cdf0e10cSrcweir 	if (pSource)
63*cdf0e10cSrcweir 	{
64*cdf0e10cSrcweir 		if (0 == queryInterface)
65*cdf0e10cSrcweir             queryInterface = binuno_queryInterface;
66*cdf0e10cSrcweir         pSource = (*queryInterface)( pSource, pDestType );
67*cdf0e10cSrcweir 	}
68*cdf0e10cSrcweir     return pSource;
69*cdf0e10cSrcweir }
70*cdf0e10cSrcweir //==================================================================================================
71*cdf0e10cSrcweir sal_Bool assignStruct(
72*cdf0e10cSrcweir 	void * pDest, void * pSource,
73*cdf0e10cSrcweir 	typelib_CompoundTypeDescription * pTypeDescr,
74*cdf0e10cSrcweir 	uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release )
75*cdf0e10cSrcweir 	SAL_THROW( () );
76*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
77*cdf0e10cSrcweir inline sal_Bool _assignStruct(
78*cdf0e10cSrcweir 	void * pDest, void * pSource,
79*cdf0e10cSrcweir 	typelib_CompoundTypeDescription * pTypeDescr,
80*cdf0e10cSrcweir 	uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release )
81*cdf0e10cSrcweir 	SAL_THROW( () )
82*cdf0e10cSrcweir {
83*cdf0e10cSrcweir 	if (pTypeDescr->pBaseTypeDescription)
84*cdf0e10cSrcweir 	{
85*cdf0e10cSrcweir 		// copy base value
86*cdf0e10cSrcweir 		if (! assignStruct( pDest, pSource, pTypeDescr->pBaseTypeDescription,
87*cdf0e10cSrcweir 							queryInterface, acquire, release ))
88*cdf0e10cSrcweir 		{
89*cdf0e10cSrcweir 			return sal_False;
90*cdf0e10cSrcweir 		}
91*cdf0e10cSrcweir 	}
92*cdf0e10cSrcweir 	// then copy members
93*cdf0e10cSrcweir 	typelib_TypeDescriptionReference ** ppTypeRefs = pTypeDescr->ppTypeRefs;
94*cdf0e10cSrcweir 	sal_Int32 * pMemberOffsets = pTypeDescr->pMemberOffsets;
95*cdf0e10cSrcweir 	sal_Int32 nDescr = pTypeDescr->nMembers;
96*cdf0e10cSrcweir 	while (nDescr--)
97*cdf0e10cSrcweir 	{
98*cdf0e10cSrcweir 		if (! ::uno_type_assignData( (char *)pDest + pMemberOffsets[nDescr],
99*cdf0e10cSrcweir 									 ppTypeRefs[nDescr],
100*cdf0e10cSrcweir 									 (char *)pSource + pMemberOffsets[nDescr],
101*cdf0e10cSrcweir 									 ppTypeRefs[nDescr],
102*cdf0e10cSrcweir 									 queryInterface, acquire, release ))
103*cdf0e10cSrcweir 		{
104*cdf0e10cSrcweir 			return sal_False;
105*cdf0e10cSrcweir 		}
106*cdf0e10cSrcweir 	}
107*cdf0e10cSrcweir 	return sal_True;
108*cdf0e10cSrcweir }
109*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
110*cdf0e10cSrcweir inline sal_Bool _assignArray(
111*cdf0e10cSrcweir 	void * pDest, void * pSource,
112*cdf0e10cSrcweir 	typelib_ArrayTypeDescription * pTypeDescr,
113*cdf0e10cSrcweir 	uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release )
114*cdf0e10cSrcweir {
115*cdf0e10cSrcweir 	typelib_TypeDescriptionReference * pElementTypeRef =
116*cdf0e10cSrcweir         ((typelib_IndirectTypeDescription *)pTypeDescr)->pType;
117*cdf0e10cSrcweir 	typelib_TypeDescription * pElementTypeDescr = NULL;
118*cdf0e10cSrcweir 	TYPELIB_DANGER_GET( &pElementTypeDescr, pElementTypeRef );
119*cdf0e10cSrcweir 	sal_Int32 nTotalElements = pTypeDescr->nTotalElements;
120*cdf0e10cSrcweir 	sal_Int32 nElementSize = pElementTypeDescr->nSize;
121*cdf0e10cSrcweir 	sal_Int32 i;
122*cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir 	switch ( pElementTypeRef->eTypeClass )
125*cdf0e10cSrcweir 	{
126*cdf0e10cSrcweir 	case typelib_TypeClass_CHAR:
127*cdf0e10cSrcweir 	case typelib_TypeClass_BOOLEAN:
128*cdf0e10cSrcweir 	case typelib_TypeClass_BYTE:
129*cdf0e10cSrcweir 	case typelib_TypeClass_SHORT:
130*cdf0e10cSrcweir 	case typelib_TypeClass_UNSIGNED_SHORT:
131*cdf0e10cSrcweir 	case typelib_TypeClass_LONG:
132*cdf0e10cSrcweir 	case typelib_TypeClass_UNSIGNED_LONG:
133*cdf0e10cSrcweir 	case typelib_TypeClass_HYPER:
134*cdf0e10cSrcweir 	case typelib_TypeClass_UNSIGNED_HYPER:
135*cdf0e10cSrcweir 	case typelib_TypeClass_FLOAT:
136*cdf0e10cSrcweir 	case typelib_TypeClass_DOUBLE:
137*cdf0e10cSrcweir 		for (i=0; i < nTotalElements; i++)
138*cdf0e10cSrcweir 		{
139*cdf0e10cSrcweir 			::rtl_copyMemory((sal_Char *)pDest + i * nElementSize,
140*cdf0e10cSrcweir 							 (sal_Char *)pSource + i * nElementSize,
141*cdf0e10cSrcweir 							 nElementSize);
142*cdf0e10cSrcweir 		}
143*cdf0e10cSrcweir 		bRet = sal_True;
144*cdf0e10cSrcweir 		break;
145*cdf0e10cSrcweir 	case typelib_TypeClass_STRING:
146*cdf0e10cSrcweir 		for (i=0; i < nTotalElements; i++)
147*cdf0e10cSrcweir 		{
148*cdf0e10cSrcweir 			::rtl_uString_assign( (rtl_uString **)pDest + i,
149*cdf0e10cSrcweir 								  ((rtl_uString **)pSource)[i] );
150*cdf0e10cSrcweir 		}
151*cdf0e10cSrcweir 		bRet = sal_True;
152*cdf0e10cSrcweir 		break;
153*cdf0e10cSrcweir 	case typelib_TypeClass_TYPE:
154*cdf0e10cSrcweir 		for (i=0; i < nTotalElements; i++)
155*cdf0e10cSrcweir 		{
156*cdf0e10cSrcweir             typelib_TypeDescriptionReference ** pp = (typelib_TypeDescriptionReference **)pDest + i;
157*cdf0e10cSrcweir 			::typelib_typedescriptionreference_release( *pp );
158*cdf0e10cSrcweir             *pp = *((typelib_TypeDescriptionReference **)pSource + i);
159*cdf0e10cSrcweir 			TYPE_ACQUIRE( *pp );
160*cdf0e10cSrcweir 		}
161*cdf0e10cSrcweir 		bRet = sal_True;
162*cdf0e10cSrcweir 		break;
163*cdf0e10cSrcweir 	case typelib_TypeClass_ANY:
164*cdf0e10cSrcweir 		for (i=0; i < nTotalElements; i++)
165*cdf0e10cSrcweir 		{
166*cdf0e10cSrcweir 			_destructAny( (uno_Any *)pDest + i, release );
167*cdf0e10cSrcweir 			_copyConstructAny( (uno_Any *)pDest + i, (uno_Any *)pSource + i,
168*cdf0e10cSrcweir                                pElementTypeRef, pElementTypeDescr, acquire, 0 );
169*cdf0e10cSrcweir 		}
170*cdf0e10cSrcweir 		bRet = sal_True;
171*cdf0e10cSrcweir 		break;
172*cdf0e10cSrcweir 	case typelib_TypeClass_ENUM:
173*cdf0e10cSrcweir 		for (i=0; i < nTotalElements; i++)
174*cdf0e10cSrcweir 		{
175*cdf0e10cSrcweir 			*((sal_Int32 *)pDest + i) = *((sal_Int32 *)pSource + i);
176*cdf0e10cSrcweir 		}
177*cdf0e10cSrcweir 		bRet = sal_True;
178*cdf0e10cSrcweir 		break;
179*cdf0e10cSrcweir 	case typelib_TypeClass_STRUCT:
180*cdf0e10cSrcweir 	case typelib_TypeClass_EXCEPTION:
181*cdf0e10cSrcweir 		for (i=0; i < nTotalElements; i++)
182*cdf0e10cSrcweir 		{
183*cdf0e10cSrcweir 			bRet = _assignStruct( (sal_Char *)pDest + i * nElementSize,
184*cdf0e10cSrcweir                                   (sal_Char *)pSource + i * nElementSize,
185*cdf0e10cSrcweir                                   (typelib_CompoundTypeDescription *)pElementTypeDescr,
186*cdf0e10cSrcweir                                   queryInterface, acquire, release );
187*cdf0e10cSrcweir 			if (! bRet)
188*cdf0e10cSrcweir 				break;
189*cdf0e10cSrcweir 		}
190*cdf0e10cSrcweir 		bRet = sal_True;
191*cdf0e10cSrcweir 		break;
192*cdf0e10cSrcweir 	case typelib_TypeClass_UNION:
193*cdf0e10cSrcweir 		for (i=0; i < nTotalElements; i++)
194*cdf0e10cSrcweir 		{
195*cdf0e10cSrcweir 			_destructUnion( (sal_Char*)pDest + i * nElementSize, pElementTypeDescr, release );
196*cdf0e10cSrcweir 			_copyConstructUnion( (sal_Char*)pDest + i * nElementSize,
197*cdf0e10cSrcweir                                  (sal_Char*)pSource + i * nElementSize,
198*cdf0e10cSrcweir                                  pElementTypeDescr, acquire, 0 );
199*cdf0e10cSrcweir 		}
200*cdf0e10cSrcweir 		bRet = sal_True;
201*cdf0e10cSrcweir 		break;
202*cdf0e10cSrcweir 	case typelib_TypeClass_SEQUENCE:
203*cdf0e10cSrcweir 		for (i=0; i < nTotalElements; i++)
204*cdf0e10cSrcweir 		{
205*cdf0e10cSrcweir 			::osl_incrementInterlockedCount(
206*cdf0e10cSrcweir                 &(*((uno_Sequence **)pSource + i))->nRefCount );
207*cdf0e10cSrcweir 			idestructSequence(
208*cdf0e10cSrcweir                 *((uno_Sequence **)pDest + i),
209*cdf0e10cSrcweir                 pElementTypeRef, pElementTypeDescr, release );
210*cdf0e10cSrcweir 			*((uno_Sequence **)pDest + i) = *((uno_Sequence **)pSource + i);
211*cdf0e10cSrcweir 		}
212*cdf0e10cSrcweir 		bRet = sal_True;
213*cdf0e10cSrcweir 		break;
214*cdf0e10cSrcweir 	case typelib_TypeClass_INTERFACE:
215*cdf0e10cSrcweir 		for (i=0; i < nTotalElements; i++)
216*cdf0e10cSrcweir 		{
217*cdf0e10cSrcweir 			_assignInterface(
218*cdf0e10cSrcweir                 (void **)((sal_Char*)pDest + i * nElementSize),
219*cdf0e10cSrcweir                 *(void **)((sal_Char*)pSource + i * nElementSize),
220*cdf0e10cSrcweir                 acquire, release );
221*cdf0e10cSrcweir 		}
222*cdf0e10cSrcweir 		bRet = sal_True;
223*cdf0e10cSrcweir 		break;
224*cdf0e10cSrcweir     default:
225*cdf0e10cSrcweir         OSL_ASSERT(false);
226*cdf0e10cSrcweir         break;
227*cdf0e10cSrcweir 	}
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir 	TYPELIB_DANGER_RELEASE( pElementTypeDescr );
230*cdf0e10cSrcweir 	return bRet;
231*cdf0e10cSrcweir }
232*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
233*cdf0e10cSrcweir inline sal_Bool _assignData(
234*cdf0e10cSrcweir 	void * pDest,
235*cdf0e10cSrcweir 	typelib_TypeDescriptionReference * pDestType, typelib_TypeDescription * pDestTypeDescr,
236*cdf0e10cSrcweir 	void * pSource,
237*cdf0e10cSrcweir 	typelib_TypeDescriptionReference * pSourceType, typelib_TypeDescription * pSourceTypeDescr,
238*cdf0e10cSrcweir 	uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release )
239*cdf0e10cSrcweir 	SAL_THROW( () )
240*cdf0e10cSrcweir {
241*cdf0e10cSrcweir 	if (pDest == pSource)
242*cdf0e10cSrcweir 		return _type_equals( pDestType, pSourceType );
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir 	if (! pSource)
245*cdf0e10cSrcweir 	{
246*cdf0e10cSrcweir 		_destructData( pDest, pDestType, pDestTypeDescr, release );
247*cdf0e10cSrcweir 		_defaultConstructData( pDest, pDestType, pDestTypeDescr );
248*cdf0e10cSrcweir 		return sal_True;
249*cdf0e10cSrcweir 	}
250*cdf0e10cSrcweir 	while (typelib_TypeClass_ANY == pSourceType->eTypeClass)
251*cdf0e10cSrcweir 	{
252*cdf0e10cSrcweir 		pSourceTypeDescr = 0;
253*cdf0e10cSrcweir 		pSourceType = ((uno_Any *)pSource)->pType;
254*cdf0e10cSrcweir 		pSource = ((uno_Any *)pSource)->pData;
255*cdf0e10cSrcweir 		if (pDest == pSource)
256*cdf0e10cSrcweir 			return sal_True;
257*cdf0e10cSrcweir 	}
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir 	switch (pDestType->eTypeClass)
260*cdf0e10cSrcweir 	{
261*cdf0e10cSrcweir 	case typelib_TypeClass_VOID:
262*cdf0e10cSrcweir 		return pSourceType->eTypeClass == typelib_TypeClass_VOID;
263*cdf0e10cSrcweir 	case typelib_TypeClass_CHAR:
264*cdf0e10cSrcweir 		switch (pSourceType->eTypeClass)
265*cdf0e10cSrcweir 		{
266*cdf0e10cSrcweir 		case typelib_TypeClass_CHAR:
267*cdf0e10cSrcweir 			*(sal_Unicode *)pDest = *(sal_Unicode *)pSource;
268*cdf0e10cSrcweir 			return sal_True;
269*cdf0e10cSrcweir         default:
270*cdf0e10cSrcweir             return sal_False;
271*cdf0e10cSrcweir 		}
272*cdf0e10cSrcweir 	case typelib_TypeClass_BOOLEAN:
273*cdf0e10cSrcweir 		switch (pSourceType->eTypeClass)
274*cdf0e10cSrcweir 		{
275*cdf0e10cSrcweir 		case typelib_TypeClass_BOOLEAN:
276*cdf0e10cSrcweir 			*(sal_Bool *)pDest = (*(sal_Bool *)pSource != sal_False);
277*cdf0e10cSrcweir 			return sal_True;
278*cdf0e10cSrcweir         default:
279*cdf0e10cSrcweir             return sal_False;
280*cdf0e10cSrcweir 		}
281*cdf0e10cSrcweir 	case typelib_TypeClass_BYTE:
282*cdf0e10cSrcweir 		switch (pSourceType->eTypeClass)
283*cdf0e10cSrcweir 		{
284*cdf0e10cSrcweir 		case typelib_TypeClass_BYTE:
285*cdf0e10cSrcweir 			*(sal_Int8 *)pDest = *(sal_Int8 *)pSource;
286*cdf0e10cSrcweir 			return sal_True;
287*cdf0e10cSrcweir         default:
288*cdf0e10cSrcweir             return sal_False;
289*cdf0e10cSrcweir 		}
290*cdf0e10cSrcweir 	case typelib_TypeClass_SHORT:
291*cdf0e10cSrcweir 		switch (pSourceType->eTypeClass)
292*cdf0e10cSrcweir 		{
293*cdf0e10cSrcweir 		case typelib_TypeClass_BYTE:
294*cdf0e10cSrcweir 			*(sal_Int16 *)pDest = *(sal_Int8 *)pSource;
295*cdf0e10cSrcweir 			return sal_True;
296*cdf0e10cSrcweir 		case typelib_TypeClass_SHORT:
297*cdf0e10cSrcweir 		case typelib_TypeClass_UNSIGNED_SHORT:
298*cdf0e10cSrcweir 			*(sal_Int16 *)pDest = *(sal_Int16 *)pSource;
299*cdf0e10cSrcweir 			return sal_True;
300*cdf0e10cSrcweir         default:
301*cdf0e10cSrcweir             return sal_False;
302*cdf0e10cSrcweir 		}
303*cdf0e10cSrcweir 	case typelib_TypeClass_UNSIGNED_SHORT:
304*cdf0e10cSrcweir 		switch (pSourceType->eTypeClass)
305*cdf0e10cSrcweir 		{
306*cdf0e10cSrcweir 		case typelib_TypeClass_BYTE:
307*cdf0e10cSrcweir 			*(sal_uInt16 *)pDest = *(sal_Int8 *)pSource;
308*cdf0e10cSrcweir 			return sal_True;
309*cdf0e10cSrcweir 		case typelib_TypeClass_SHORT:
310*cdf0e10cSrcweir 		case typelib_TypeClass_UNSIGNED_SHORT:
311*cdf0e10cSrcweir 			*(sal_uInt16 *)pDest = *(sal_uInt16 *)pSource;
312*cdf0e10cSrcweir 			return sal_True;
313*cdf0e10cSrcweir         default:
314*cdf0e10cSrcweir             return sal_False;
315*cdf0e10cSrcweir 		}
316*cdf0e10cSrcweir 	case typelib_TypeClass_LONG:
317*cdf0e10cSrcweir 		switch (pSourceType->eTypeClass)
318*cdf0e10cSrcweir 		{
319*cdf0e10cSrcweir 		case typelib_TypeClass_BYTE:
320*cdf0e10cSrcweir 			*(sal_Int32 *)pDest = *(sal_Int8 *)pSource;
321*cdf0e10cSrcweir 			return sal_True;
322*cdf0e10cSrcweir 		case typelib_TypeClass_SHORT:
323*cdf0e10cSrcweir 			*(sal_Int32 *)pDest = *(sal_Int16 *)pSource;
324*cdf0e10cSrcweir 			return sal_True;
325*cdf0e10cSrcweir 		case typelib_TypeClass_UNSIGNED_SHORT:
326*cdf0e10cSrcweir 			*(sal_Int32 *)pDest = *(sal_uInt16 *)pSource;
327*cdf0e10cSrcweir 			return sal_True;
328*cdf0e10cSrcweir 		case typelib_TypeClass_LONG:
329*cdf0e10cSrcweir 		case typelib_TypeClass_UNSIGNED_LONG:
330*cdf0e10cSrcweir 			*(sal_Int32 *)pDest = *(sal_Int32 *)pSource;
331*cdf0e10cSrcweir 			return sal_True;
332*cdf0e10cSrcweir         default:
333*cdf0e10cSrcweir             return sal_False;
334*cdf0e10cSrcweir 		}
335*cdf0e10cSrcweir 	case typelib_TypeClass_UNSIGNED_LONG:
336*cdf0e10cSrcweir 		switch (pSourceType->eTypeClass)
337*cdf0e10cSrcweir 		{
338*cdf0e10cSrcweir 		case typelib_TypeClass_BYTE:
339*cdf0e10cSrcweir 			*(sal_uInt32 *)pDest = *(sal_Int8 *)pSource;
340*cdf0e10cSrcweir 			return sal_True;
341*cdf0e10cSrcweir 		case typelib_TypeClass_SHORT:
342*cdf0e10cSrcweir 			*(sal_uInt32 *)pDest = *(sal_Int16 *)pSource;
343*cdf0e10cSrcweir 			return sal_True;
344*cdf0e10cSrcweir 		case typelib_TypeClass_UNSIGNED_SHORT:
345*cdf0e10cSrcweir 			*(sal_uInt32 *)pDest = *(sal_uInt16 *)pSource;
346*cdf0e10cSrcweir 			return sal_True;
347*cdf0e10cSrcweir 		case typelib_TypeClass_LONG:
348*cdf0e10cSrcweir 		case typelib_TypeClass_UNSIGNED_LONG:
349*cdf0e10cSrcweir 			*(sal_uInt32 *)pDest = *(sal_uInt32 *)pSource;
350*cdf0e10cSrcweir 			return sal_True;
351*cdf0e10cSrcweir         default:
352*cdf0e10cSrcweir             return sal_False;
353*cdf0e10cSrcweir 		}
354*cdf0e10cSrcweir 	case typelib_TypeClass_HYPER:
355*cdf0e10cSrcweir 		switch (pSourceType->eTypeClass)
356*cdf0e10cSrcweir 		{
357*cdf0e10cSrcweir 		case typelib_TypeClass_BYTE:
358*cdf0e10cSrcweir 			*(sal_Int64 *)pDest = *(sal_Int8 *)pSource;
359*cdf0e10cSrcweir 			return sal_True;
360*cdf0e10cSrcweir 		case typelib_TypeClass_SHORT:
361*cdf0e10cSrcweir 			*(sal_Int64 *)pDest = *(sal_Int16 *)pSource;
362*cdf0e10cSrcweir 			return sal_True;
363*cdf0e10cSrcweir 		case typelib_TypeClass_UNSIGNED_SHORT:
364*cdf0e10cSrcweir 			*(sal_Int64 *)pDest = *(sal_uInt16 *)pSource;
365*cdf0e10cSrcweir 			return sal_True;
366*cdf0e10cSrcweir 		case typelib_TypeClass_LONG:
367*cdf0e10cSrcweir 			*(sal_Int64 *)pDest = *(sal_Int32 *)pSource;
368*cdf0e10cSrcweir 			return sal_True;
369*cdf0e10cSrcweir 		case typelib_TypeClass_UNSIGNED_LONG:
370*cdf0e10cSrcweir 			*(sal_Int64 *)pDest = *(sal_uInt32 *)pSource;
371*cdf0e10cSrcweir 			return sal_True;
372*cdf0e10cSrcweir 		case typelib_TypeClass_HYPER:
373*cdf0e10cSrcweir 		case typelib_TypeClass_UNSIGNED_HYPER:
374*cdf0e10cSrcweir 			*(sal_Int64 *)pDest = *(sal_Int64 *)pSource;
375*cdf0e10cSrcweir 			return sal_True;
376*cdf0e10cSrcweir         default:
377*cdf0e10cSrcweir             return sal_False;
378*cdf0e10cSrcweir 		}
379*cdf0e10cSrcweir 	case typelib_TypeClass_UNSIGNED_HYPER:
380*cdf0e10cSrcweir 		switch (pSourceType->eTypeClass)
381*cdf0e10cSrcweir 		{
382*cdf0e10cSrcweir 		case typelib_TypeClass_BYTE:
383*cdf0e10cSrcweir 			*(sal_uInt64 *)pDest = *(sal_Int8 *)pSource;
384*cdf0e10cSrcweir 			return sal_True;
385*cdf0e10cSrcweir 		case typelib_TypeClass_SHORT:
386*cdf0e10cSrcweir 			*(sal_uInt64 *)pDest = *(sal_Int16 *)pSource;
387*cdf0e10cSrcweir 			return sal_True;
388*cdf0e10cSrcweir 		case typelib_TypeClass_UNSIGNED_SHORT:
389*cdf0e10cSrcweir 			*(sal_uInt64 *)pDest = *(sal_uInt16 *)pSource;
390*cdf0e10cSrcweir 			return sal_True;
391*cdf0e10cSrcweir 		case typelib_TypeClass_LONG:
392*cdf0e10cSrcweir 			*(sal_uInt64 *)pDest = *(sal_Int32 *)pSource;
393*cdf0e10cSrcweir 			return sal_True;
394*cdf0e10cSrcweir 		case typelib_TypeClass_UNSIGNED_LONG:
395*cdf0e10cSrcweir 			*(sal_uInt64 *)pDest = *(sal_uInt32 *)pSource;
396*cdf0e10cSrcweir 			return sal_True;
397*cdf0e10cSrcweir 		case typelib_TypeClass_HYPER:
398*cdf0e10cSrcweir 		case typelib_TypeClass_UNSIGNED_HYPER:
399*cdf0e10cSrcweir 			*(sal_uInt64 *)pDest = *(sal_uInt64 *)pSource;
400*cdf0e10cSrcweir 			return sal_True;
401*cdf0e10cSrcweir         default:
402*cdf0e10cSrcweir             return sal_False;
403*cdf0e10cSrcweir 		}
404*cdf0e10cSrcweir 	case typelib_TypeClass_FLOAT:
405*cdf0e10cSrcweir 		switch (pSourceType->eTypeClass)
406*cdf0e10cSrcweir 		{
407*cdf0e10cSrcweir 		case typelib_TypeClass_BYTE:
408*cdf0e10cSrcweir 			*(float *)pDest = *(sal_Int8 *)pSource;
409*cdf0e10cSrcweir 			return sal_True;
410*cdf0e10cSrcweir 		case typelib_TypeClass_SHORT:
411*cdf0e10cSrcweir 			*(float *)pDest = *(sal_Int16 *)pSource;
412*cdf0e10cSrcweir 			return sal_True;
413*cdf0e10cSrcweir 		case typelib_TypeClass_UNSIGNED_SHORT:
414*cdf0e10cSrcweir 			*(float *)pDest = *(sal_uInt16 *)pSource;
415*cdf0e10cSrcweir 			return sal_True;
416*cdf0e10cSrcweir 		case typelib_TypeClass_FLOAT:
417*cdf0e10cSrcweir 			*(float *)pDest = *(float *)pSource;
418*cdf0e10cSrcweir 			return sal_True;
419*cdf0e10cSrcweir         default:
420*cdf0e10cSrcweir             return sal_False;
421*cdf0e10cSrcweir 		}
422*cdf0e10cSrcweir 	case typelib_TypeClass_DOUBLE:
423*cdf0e10cSrcweir 		switch (pSourceType->eTypeClass)
424*cdf0e10cSrcweir 		{
425*cdf0e10cSrcweir 		case typelib_TypeClass_BYTE:
426*cdf0e10cSrcweir 			*(double *)pDest = *(sal_Int8 *)pSource;
427*cdf0e10cSrcweir 			return sal_True;
428*cdf0e10cSrcweir 		case typelib_TypeClass_SHORT:
429*cdf0e10cSrcweir 			*(double *)pDest = *(sal_Int16 *)pSource;
430*cdf0e10cSrcweir 			return sal_True;
431*cdf0e10cSrcweir 		case typelib_TypeClass_UNSIGNED_SHORT:
432*cdf0e10cSrcweir 			*(double *)pDest = *(sal_uInt16 *)pSource;
433*cdf0e10cSrcweir 			return sal_True;
434*cdf0e10cSrcweir 		case typelib_TypeClass_LONG:
435*cdf0e10cSrcweir 			*(double *)pDest = *(sal_Int32 *)pSource;
436*cdf0e10cSrcweir 			return sal_True;
437*cdf0e10cSrcweir 		case typelib_TypeClass_UNSIGNED_LONG:
438*cdf0e10cSrcweir 			*(double *)pDest = *(sal_uInt32 *)pSource;
439*cdf0e10cSrcweir 			return sal_True;
440*cdf0e10cSrcweir 		case typelib_TypeClass_FLOAT:
441*cdf0e10cSrcweir 			*(double *)pDest = *(float *)pSource;
442*cdf0e10cSrcweir 			return sal_True;
443*cdf0e10cSrcweir 		case typelib_TypeClass_DOUBLE:
444*cdf0e10cSrcweir 			*(double *)pDest = *(double *)pSource;
445*cdf0e10cSrcweir 			return sal_True;
446*cdf0e10cSrcweir         default:
447*cdf0e10cSrcweir             return sal_False;
448*cdf0e10cSrcweir 		}
449*cdf0e10cSrcweir 	case typelib_TypeClass_STRING:
450*cdf0e10cSrcweir 		switch (pSourceType->eTypeClass)
451*cdf0e10cSrcweir 		{
452*cdf0e10cSrcweir 		case typelib_TypeClass_STRING:
453*cdf0e10cSrcweir 			::rtl_uString_assign( (rtl_uString **)pDest, *(rtl_uString **)pSource );
454*cdf0e10cSrcweir 			return sal_True;
455*cdf0e10cSrcweir         default:
456*cdf0e10cSrcweir             return sal_False;
457*cdf0e10cSrcweir 		}
458*cdf0e10cSrcweir 	case typelib_TypeClass_TYPE:
459*cdf0e10cSrcweir 		switch (pSourceType->eTypeClass)
460*cdf0e10cSrcweir 		{
461*cdf0e10cSrcweir 		case typelib_TypeClass_TYPE:
462*cdf0e10cSrcweir         {
463*cdf0e10cSrcweir             typelib_TypeDescriptionReference ** pp = (typelib_TypeDescriptionReference **)pDest;
464*cdf0e10cSrcweir 			::typelib_typedescriptionreference_release( *pp );
465*cdf0e10cSrcweir             *pp = *(typelib_TypeDescriptionReference **)pSource;
466*cdf0e10cSrcweir             TYPE_ACQUIRE( *pp );
467*cdf0e10cSrcweir 			return sal_True;
468*cdf0e10cSrcweir         }
469*cdf0e10cSrcweir         default:
470*cdf0e10cSrcweir             return sal_False;
471*cdf0e10cSrcweir 		}
472*cdf0e10cSrcweir 	case typelib_TypeClass_ANY:
473*cdf0e10cSrcweir 		_destructAny( (uno_Any *)pDest, release );
474*cdf0e10cSrcweir 		_copyConstructAny( (uno_Any *)pDest, pSource, pSourceType, pSourceTypeDescr, acquire, 0 );
475*cdf0e10cSrcweir 		return sal_True;
476*cdf0e10cSrcweir 	case typelib_TypeClass_ENUM:
477*cdf0e10cSrcweir 		if (_type_equals( pDestType, pSourceType ))
478*cdf0e10cSrcweir 		{
479*cdf0e10cSrcweir 			*(sal_Int32 *)pDest = *(sal_Int32 *)pSource;
480*cdf0e10cSrcweir 			return sal_True;
481*cdf0e10cSrcweir 		}
482*cdf0e10cSrcweir 		return sal_False;
483*cdf0e10cSrcweir 	case typelib_TypeClass_STRUCT:
484*cdf0e10cSrcweir 	case typelib_TypeClass_EXCEPTION:
485*cdf0e10cSrcweir 		if (typelib_TypeClass_STRUCT == pSourceType->eTypeClass ||
486*cdf0e10cSrcweir 			typelib_TypeClass_EXCEPTION == pSourceType->eTypeClass)
487*cdf0e10cSrcweir 		{
488*cdf0e10cSrcweir 			sal_Bool bRet = sal_False;
489*cdf0e10cSrcweir 			if (pSourceTypeDescr)
490*cdf0e10cSrcweir 			{
491*cdf0e10cSrcweir 				typelib_CompoundTypeDescription * pTypeDescr =
492*cdf0e10cSrcweir 					(typelib_CompoundTypeDescription *)pSourceTypeDescr;
493*cdf0e10cSrcweir 				while (pTypeDescr &&
494*cdf0e10cSrcweir                        !_type_equals(
495*cdf0e10cSrcweir                            ((typelib_TypeDescription *)pTypeDescr)->pWeakRef, pDestType ))
496*cdf0e10cSrcweir                 {
497*cdf0e10cSrcweir 					pTypeDescr = pTypeDescr->pBaseTypeDescription;
498*cdf0e10cSrcweir                 }
499*cdf0e10cSrcweir 				if (pTypeDescr)
500*cdf0e10cSrcweir                 {
501*cdf0e10cSrcweir 					bRet = _assignStruct(
502*cdf0e10cSrcweir                         pDest, pSource, pTypeDescr, queryInterface, acquire, release );
503*cdf0e10cSrcweir                 }
504*cdf0e10cSrcweir 			}
505*cdf0e10cSrcweir 			else
506*cdf0e10cSrcweir 			{
507*cdf0e10cSrcweir 				TYPELIB_DANGER_GET( &pSourceTypeDescr, pSourceType );
508*cdf0e10cSrcweir 				typelib_CompoundTypeDescription * pTypeDescr =
509*cdf0e10cSrcweir 					(typelib_CompoundTypeDescription *)pSourceTypeDescr;
510*cdf0e10cSrcweir 				while (pTypeDescr &&
511*cdf0e10cSrcweir                        !_type_equals(
512*cdf0e10cSrcweir                            ((typelib_TypeDescription *)pTypeDescr)->pWeakRef, pDestType ))
513*cdf0e10cSrcweir                 {
514*cdf0e10cSrcweir 					pTypeDescr = pTypeDescr->pBaseTypeDescription;
515*cdf0e10cSrcweir                 }
516*cdf0e10cSrcweir 				if (pTypeDescr)
517*cdf0e10cSrcweir                 {
518*cdf0e10cSrcweir 					bRet = _assignStruct(
519*cdf0e10cSrcweir                         pDest, pSource, pTypeDescr, queryInterface, acquire, release );
520*cdf0e10cSrcweir                 }
521*cdf0e10cSrcweir 				TYPELIB_DANGER_RELEASE( pSourceTypeDescr );
522*cdf0e10cSrcweir 			}
523*cdf0e10cSrcweir 			return bRet;
524*cdf0e10cSrcweir 		}
525*cdf0e10cSrcweir 		return sal_False;
526*cdf0e10cSrcweir 	case typelib_TypeClass_ARRAY:
527*cdf0e10cSrcweir 		{
528*cdf0e10cSrcweir 			sal_Bool bRet = sal_False;
529*cdf0e10cSrcweir 			if (pSourceTypeDescr)
530*cdf0e10cSrcweir 			{
531*cdf0e10cSrcweir 				typelib_ArrayTypeDescription * pTypeDescr =
532*cdf0e10cSrcweir                     (typelib_ArrayTypeDescription *)pSourceTypeDescr;
533*cdf0e10cSrcweir 				bRet = _assignArray( pDest, pSource, pTypeDescr, queryInterface, acquire, release );
534*cdf0e10cSrcweir 			}
535*cdf0e10cSrcweir 			else
536*cdf0e10cSrcweir 			{
537*cdf0e10cSrcweir 				TYPELIB_DANGER_GET( &pSourceTypeDescr, pSourceType );
538*cdf0e10cSrcweir 				typelib_ArrayTypeDescription * pTypeDescr =
539*cdf0e10cSrcweir 					(typelib_ArrayTypeDescription *)pSourceTypeDescr;
540*cdf0e10cSrcweir 				if ( pTypeDescr )
541*cdf0e10cSrcweir                 {
542*cdf0e10cSrcweir 					bRet = _assignArray(
543*cdf0e10cSrcweir                         pDest, pSource, pTypeDescr, queryInterface, acquire, release );
544*cdf0e10cSrcweir                 }
545*cdf0e10cSrcweir 				TYPELIB_DANGER_RELEASE( pSourceTypeDescr );
546*cdf0e10cSrcweir 			}
547*cdf0e10cSrcweir 			return bRet;
548*cdf0e10cSrcweir 		}
549*cdf0e10cSrcweir 	case typelib_TypeClass_UNION:
550*cdf0e10cSrcweir 		if (_type_equals( pDestType, pSourceType ))
551*cdf0e10cSrcweir 		{
552*cdf0e10cSrcweir 			if (pDestTypeDescr)
553*cdf0e10cSrcweir 			{
554*cdf0e10cSrcweir 				_destructUnion( pDest, pDestTypeDescr, release );
555*cdf0e10cSrcweir 				_copyConstructUnion( pDest, pSource, pDestTypeDescr, acquire, 0 );
556*cdf0e10cSrcweir 			}
557*cdf0e10cSrcweir 			else
558*cdf0e10cSrcweir 			{
559*cdf0e10cSrcweir 				TYPELIB_DANGER_GET( &pDestTypeDescr, pDestType );
560*cdf0e10cSrcweir 				_destructUnion( pDest, pDestTypeDescr, release );
561*cdf0e10cSrcweir 				_copyConstructUnion( pDest, pSource, pDestTypeDescr, acquire, 0 );
562*cdf0e10cSrcweir 				TYPELIB_DANGER_RELEASE( pDestTypeDescr );
563*cdf0e10cSrcweir 			}
564*cdf0e10cSrcweir 			return sal_True;
565*cdf0e10cSrcweir 		}
566*cdf0e10cSrcweir 		return sal_False;
567*cdf0e10cSrcweir 	case typelib_TypeClass_SEQUENCE:
568*cdf0e10cSrcweir 		if (typelib_TypeClass_SEQUENCE != pSourceType->eTypeClass)
569*cdf0e10cSrcweir 			return sal_False;
570*cdf0e10cSrcweir         // self assignment:
571*cdf0e10cSrcweir 		if (*(uno_Sequence **)pSource == *(uno_Sequence **)pDest)
572*cdf0e10cSrcweir 			return sal_True;
573*cdf0e10cSrcweir 		if (_type_equals( pDestType, pSourceType ))
574*cdf0e10cSrcweir 		{
575*cdf0e10cSrcweir 			::osl_incrementInterlockedCount(
576*cdf0e10cSrcweir                 &(*(uno_Sequence **)pSource)->nRefCount );
577*cdf0e10cSrcweir 			idestructSequence(
578*cdf0e10cSrcweir                 *(uno_Sequence **)pDest, pDestType, pDestTypeDescr, release );
579*cdf0e10cSrcweir 			*(uno_Sequence **)pDest = *(uno_Sequence **)pSource;
580*cdf0e10cSrcweir 			return sal_True;
581*cdf0e10cSrcweir 		}
582*cdf0e10cSrcweir 		return sal_False;
583*cdf0e10cSrcweir 	case typelib_TypeClass_INTERFACE:
584*cdf0e10cSrcweir 		if (typelib_TypeClass_INTERFACE != pSourceType->eTypeClass)
585*cdf0e10cSrcweir 			return sal_False;
586*cdf0e10cSrcweir 		if (_type_equals( pDestType, pSourceType ))
587*cdf0e10cSrcweir 		{
588*cdf0e10cSrcweir 			_assignInterface( (void **)pDest, *(void **)pSource, acquire, release );
589*cdf0e10cSrcweir 			return sal_True;
590*cdf0e10cSrcweir 		}
591*cdf0e10cSrcweir         else if (*static_cast< void ** >(pSource) == 0)
592*cdf0e10cSrcweir         {
593*cdf0e10cSrcweir             // A null reference of any interface type can be converted to a null
594*cdf0e10cSrcweir             // reference of any other interface type:
595*cdf0e10cSrcweir             void * const pToBeReleased = *static_cast< void ** >(pDest);
596*cdf0e10cSrcweir             *static_cast< void ** >(pDest) = 0;
597*cdf0e10cSrcweir             _release( pToBeReleased, release );
598*cdf0e10cSrcweir             return true;
599*cdf0e10cSrcweir         }
600*cdf0e10cSrcweir 		else
601*cdf0e10cSrcweir 		{
602*cdf0e10cSrcweir 			if (pSourceTypeDescr)
603*cdf0e10cSrcweir 			{
604*cdf0e10cSrcweir 				typelib_TypeDescription * pTD = pSourceTypeDescr;
605*cdf0e10cSrcweir 				while (pTD && !_type_equals( pTD->pWeakRef, pDestType ))
606*cdf0e10cSrcweir                 {
607*cdf0e10cSrcweir 					pTD = (typelib_TypeDescription *)
608*cdf0e10cSrcweir                         ((typelib_InterfaceTypeDescription *)pTD)->pBaseTypeDescription;
609*cdf0e10cSrcweir                 }
610*cdf0e10cSrcweir 				if (pTD) // is base of dest
611*cdf0e10cSrcweir 				{
612*cdf0e10cSrcweir 					_assignInterface( (void **)pDest, *(void **)pSource, acquire, release );
613*cdf0e10cSrcweir                     return true;
614*cdf0e10cSrcweir 				}
615*cdf0e10cSrcweir             }
616*cdf0e10cSrcweir 
617*cdf0e10cSrcweir             // query for interface:
618*cdf0e10cSrcweir             void * pQueried = _queryInterface( *static_cast<void **>(pSource),
619*cdf0e10cSrcweir                                                pDestType, queryInterface );
620*cdf0e10cSrcweir             if (pQueried != 0) {
621*cdf0e10cSrcweir                 void * const pToBeReleased = *static_cast<void **>(pDest);
622*cdf0e10cSrcweir                 *static_cast<void **>(pDest) = pQueried;
623*cdf0e10cSrcweir                 _release( pToBeReleased, release );
624*cdf0e10cSrcweir             }
625*cdf0e10cSrcweir             return (pQueried != 0);
626*cdf0e10cSrcweir 		}
627*cdf0e10cSrcweir     default:
628*cdf0e10cSrcweir         OSL_ASSERT(false);
629*cdf0e10cSrcweir         return sal_False;
630*cdf0e10cSrcweir 	}
631*cdf0e10cSrcweir }
632*cdf0e10cSrcweir 
633*cdf0e10cSrcweir }
634*cdf0e10cSrcweir 
635*cdf0e10cSrcweir #endif
636