tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / cppu / source / uno / data.cxx
blobe6279c8bfdbb39c5b60169c7318b8327192100a4
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 .
21 #include <sal/log.hxx>
22 #include <uno/data.h>
24 #include "constr.hxx"
25 #include "destr.hxx"
26 #include "copy.hxx"
27 #include "assign.hxx"
28 #include "eq.hxx"
30 using namespace ::cppu;
32 namespace cppu
35 // Sequence<>() (default ctor) relies on this being static:
36 uno_Sequence g_emptySeq = { 1, 0, { 0 } };
37 typelib_TypeDescriptionReference * g_pVoidType = nullptr;
40 void * binuno_queryInterface( void * pUnoI, typelib_TypeDescriptionReference * pDestType )
42 // init queryInterface() td
43 static typelib_TypeDescription* g_pQITD = []() {
44 typelib_TypeDescriptionReference* type_XInterface
45 = *typelib_static_type_getByTypeClass(typelib_TypeClass_INTERFACE);
46 typelib_InterfaceTypeDescription* pTXInterfaceDescr = nullptr;
47 TYPELIB_DANGER_GET(reinterpret_cast<typelib_TypeDescription**>(&pTXInterfaceDescr),
48 type_XInterface);
49 assert(pTXInterfaceDescr->ppAllMembers);
50 typelib_TypeDescription* pQITD = nullptr;
51 typelib_typedescriptionreference_getDescription(&pQITD,
52 pTXInterfaceDescr->ppAllMembers[0]);
53 // coverity[callee_ptr_arith] - not a bug
54 TYPELIB_DANGER_RELEASE(&pTXInterfaceDescr->aBase);
55 return pQITD;
56 }();
58 uno_Any aRet, aExc;
59 uno_Any * pExc = &aExc;
60 void * aArgs[ 1 ];
61 aArgs[ 0 ] = &pDestType;
62 (*static_cast<uno_Interface *>(pUnoI)->pDispatcher)(
63 static_cast<uno_Interface *>(pUnoI), g_pQITD, &aRet, aArgs, &pExc );
65 uno_Interface * ret = nullptr;
66 if (nullptr == pExc)
68 typelib_TypeDescriptionReference * ret_type = aRet.pType;
69 switch (ret_type->eTypeClass)
71 case typelib_TypeClass_VOID: // common case
72 typelib_typedescriptionreference_release( ret_type );
73 break;
74 case typelib_TypeClass_INTERFACE:
75 // tweaky... avoiding acquire/ release pair
76 typelib_typedescriptionreference_release( ret_type );
77 ret = static_cast<uno_Interface *>(aRet.pReserved); // serving acquired interface
78 break;
79 default:
80 _destructAny( &aRet, nullptr );
81 break;
84 else
86 SAL_WARN(
87 "cppu",
88 "exception occurred querying for interface "
89 << OUString(pDestType->pTypeName) << ": ["
90 << OUString(pExc->pType->pTypeName) << "] "
91 << *static_cast<OUString const *>(pExc->pData));
92 // Message is very first member
93 uno_any_destruct( pExc, nullptr );
95 return ret;
99 void defaultConstructStruct(
100 void * pMem,
101 typelib_CompoundTypeDescription * pCompType )
103 _defaultConstructStruct( pMem, pCompType );
106 void copyConstructStruct(
107 void * pDest, void * pSource,
108 typelib_CompoundTypeDescription * pTypeDescr,
109 uno_AcquireFunc acquire, uno_Mapping * mapping )
111 _copyConstructStruct( pDest, pSource, pTypeDescr, acquire, mapping );
114 void destructStruct(
115 void * pValue,
116 typelib_CompoundTypeDescription * pTypeDescr,
117 uno_ReleaseFunc release )
119 _destructStruct( pValue, pTypeDescr, release );
122 bool equalStruct(
123 void * pDest, void *pSource,
124 typelib_CompoundTypeDescription * pTypeDescr,
125 uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release )
127 return _equalStruct( pDest, pSource, pTypeDescr, queryInterface, release );
130 bool assignStruct(
131 void * pDest, void * pSource,
132 typelib_CompoundTypeDescription * pTypeDescr,
133 uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release )
135 return _assignStruct( pDest, pSource, pTypeDescr, queryInterface, acquire, release );
139 uno_Sequence * copyConstructSequence(
140 uno_Sequence * pSource,
141 typelib_TypeDescriptionReference * pElementType,
142 uno_AcquireFunc acquire, uno_Mapping * mapping )
144 return icopyConstructSequence( pSource, pElementType, acquire, mapping );
148 void destructSequence(
149 uno_Sequence * pSequence,
150 typelib_TypeDescriptionReference * pType,
151 typelib_TypeDescription * pTypeDescr,
152 uno_ReleaseFunc release )
154 idestructSequence( pSequence, pType, pTypeDescr, release );
158 bool equalSequence(
159 uno_Sequence * pDest, uno_Sequence * pSource,
160 typelib_TypeDescriptionReference * pElementType,
161 uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release )
163 return _equalSequence( pDest, pSource, pElementType, queryInterface, release );
168 extern "C"
171 void SAL_CALL uno_type_constructData(
172 void * pMem, typelib_TypeDescriptionReference * pType ) noexcept
174 _defaultConstructData( pMem, pType, nullptr );
177 void SAL_CALL uno_constructData(
178 void * pMem, typelib_TypeDescription * pTypeDescr ) noexcept
180 _defaultConstructData( pMem, pTypeDescr->pWeakRef, pTypeDescr );
183 void SAL_CALL uno_type_destructData(
184 void * pValue, typelib_TypeDescriptionReference * pType,
185 uno_ReleaseFunc release ) noexcept
187 _destructData( pValue, pType, nullptr, release );
190 void SAL_CALL uno_destructData(
191 void * pValue,
192 typelib_TypeDescription * pTypeDescr,
193 uno_ReleaseFunc release ) noexcept
195 _destructData( pValue, pTypeDescr->pWeakRef, pTypeDescr, release );
198 void SAL_CALL uno_type_copyData(
199 void * pDest, void * pSource,
200 typelib_TypeDescriptionReference * pType,
201 uno_AcquireFunc acquire ) noexcept
203 _copyConstructData( pDest, pSource, pType, nullptr, acquire, nullptr );
206 void SAL_CALL uno_copyData(
207 void * pDest, void * pSource,
208 typelib_TypeDescription * pTypeDescr,
209 uno_AcquireFunc acquire ) noexcept
211 _copyConstructData( pDest, pSource, pTypeDescr->pWeakRef, pTypeDescr, acquire, nullptr );
214 void SAL_CALL uno_type_copyAndConvertData(
215 void * pDest, void * pSource,
216 typelib_TypeDescriptionReference * pType,
217 uno_Mapping * mapping ) noexcept
219 _copyConstructData( pDest, pSource, pType, nullptr, nullptr, mapping );
222 void SAL_CALL uno_copyAndConvertData(
223 void * pDest, void * pSource,
224 typelib_TypeDescription * pTypeDescr,
225 uno_Mapping * mapping ) noexcept
227 _copyConstructData( pDest, pSource, pTypeDescr->pWeakRef, pTypeDescr, nullptr, mapping );
230 sal_Bool SAL_CALL uno_type_equalData(
231 void * pVal1, typelib_TypeDescriptionReference * pVal1Type,
232 void * pVal2, typelib_TypeDescriptionReference * pVal2Type,
233 uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ) noexcept
235 return _equalData(
236 pVal1, pVal1Type, nullptr,
237 pVal2, pVal2Type,
238 queryInterface, release );
241 sal_Bool SAL_CALL uno_equalData(
242 void * pVal1, typelib_TypeDescription * pVal1TD,
243 void * pVal2, typelib_TypeDescription * pVal2TD,
244 uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ) noexcept
246 return _equalData(
247 pVal1, pVal1TD->pWeakRef, pVal1TD,
248 pVal2, pVal2TD->pWeakRef,
249 queryInterface, release );
252 sal_Bool SAL_CALL uno_type_assignData(
253 void * pDest, typelib_TypeDescriptionReference * pDestType,
254 void * pSource, typelib_TypeDescriptionReference * pSourceType,
255 uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release ) noexcept
257 return _assignData(
258 pDest, pDestType, nullptr,
259 pSource, pSourceType, nullptr,
260 queryInterface, acquire, release );
263 sal_Bool SAL_CALL uno_assignData(
264 void * pDest, typelib_TypeDescription * pDestTD,
265 void * pSource, typelib_TypeDescription * pSourceTD,
266 uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release ) noexcept
268 return _assignData(
269 pDest, pDestTD->pWeakRef, pDestTD,
270 pSource, pSourceTD->pWeakRef, pSourceTD,
271 queryInterface, acquire, release );
274 sal_Bool SAL_CALL uno_type_isAssignableFromData(
275 typelib_TypeDescriptionReference * pAssignable,
276 void * pFrom, typelib_TypeDescriptionReference * pFromType,
277 uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ) noexcept
279 if (::typelib_typedescriptionreference_isAssignableFrom( pAssignable, pFromType ))
280 return true;
281 if (typelib_TypeClass_INTERFACE != pFromType->eTypeClass ||
282 typelib_TypeClass_INTERFACE != pAssignable->eTypeClass)
284 return false;
287 // query
288 if (nullptr == pFrom)
289 return false;
290 void * pInterface = *static_cast<void **>(pFrom);
291 if (nullptr == pInterface)
292 return false;
294 if (nullptr == queryInterface)
295 queryInterface = binuno_queryInterface;
296 void * p = (*queryInterface)( pInterface, pAssignable );
297 _release( p, release );
298 return (nullptr != p);
303 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */