1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
20 #include <sal/config.h>
27 #include <sal/alloca.h>
29 #include <o3tl/any.hxx>
30 #include <typelib/typedescription.hxx>
35 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
36 #include <com/sun/star/reflection/XIdlField2.hpp>
37 #include <com/sun/star/uno/RuntimeException.hpp>
38 #include <cppuhelper/queryinterface.hxx>
39 #include <cppuhelper/exc_hlp.hxx>
40 #include <cppuhelper/typeprovider.hxx>
42 using namespace css::lang
;
43 using namespace css::reflection
;
44 using namespace css::uno
;
48 std::size_t multipleOf16(std::size_t n
) {
49 assert(n
<= std::numeric_limits
<std::size_t>::max() - 15);
50 return (n
+ 15) & ~std::size_t(15);
60 typedef cppu::ImplInheritanceHelper
<IdlMemberImpl
, XIdlField
, XIdlField2
> IdlAttributeFieldImpl_Base
;
61 class IdlAttributeFieldImpl
: public IdlAttributeFieldImpl_Base
64 typelib_InterfaceAttributeTypeDescription
* getAttributeTypeDescr() const
65 { return reinterpret_cast<typelib_InterfaceAttributeTypeDescription
*>(getTypeDescr()); }
67 IdlAttributeFieldImpl( IdlReflectionServiceImpl
* pReflection
, const OUString
& rName
,
68 typelib_TypeDescription
* pTypeDescr
, typelib_TypeDescription
* pDeclTypeDescr
)
69 : IdlAttributeFieldImpl_Base( pReflection
, rName
, pTypeDescr
, pDeclTypeDescr
)
73 virtual Reference
< XIdlClass
> SAL_CALL
getDeclaringClass() override
;
74 virtual OUString SAL_CALL
getName() override
;
76 virtual Reference
< XIdlClass
> SAL_CALL
getType() override
;
77 virtual FieldAccessMode SAL_CALL
getAccessMode() override
;
78 virtual Any SAL_CALL
get( const Any
& rObj
) override
;
79 virtual void SAL_CALL
set( const Any
& rObj
, const Any
& rValue
) override
;
80 // XIdlField2: getType, getAccessMode and get are equal to XIdlField
81 virtual void SAL_CALL
set( Any
& rObj
, const Any
& rValue
) override
;
85 uno_Any
* exception
, Reference
< XInterface
> const & context
) const;
92 Reference
< XIdlClass
> IdlAttributeFieldImpl::getDeclaringClass()
94 if (! _xDeclClass
.is())
96 ::osl::MutexGuard
aGuard( getMutexAccess() );
97 if (! _xDeclClass
.is())
99 OUString
aName(getAttributeTypeDescr()->aBase
.aBase
.pTypeName
);
100 sal_Int32 i
= aName
.indexOf(':');
102 _xDeclClass
= getReflection()->forName(aName
.copy(0, i
));
108 OUString
IdlAttributeFieldImpl::getName()
110 return IdlMemberImpl::getName();
115 Reference
< XIdlClass
> IdlAttributeFieldImpl::getType()
117 return getReflection()->forType(
118 getAttributeTypeDescr()->pAttributeTypeRef
);
121 FieldAccessMode
IdlAttributeFieldImpl::getAccessMode()
123 return (getAttributeTypeDescr()->bReadOnly
124 ? FieldAccessMode_READONLY
: FieldAccessMode_READWRITE
);
127 Any
IdlAttributeFieldImpl::get( const Any
& rObj
)
129 uno_Interface
* pUnoI
= getReflection()->mapToUno(
130 rObj
, reinterpret_cast<typelib_InterfaceTypeDescription
*>(getDeclTypeDescr()) );
131 OSL_ENSURE( pUnoI
, "### illegal destination object given!" );
134 TypeDescription
aTD( getAttributeTypeDescr()->pAttributeTypeRef
);
135 typelib_TypeDescription
* pTD
= aTD
.get();
138 uno_Any
* pExc
= &aExc
;
139 void * pReturn
= alloca( pTD
->nSize
);
141 (*pUnoI
->pDispatcher
)( pUnoI
, getTypeDescr(), pReturn
, nullptr, &pExc
);
142 (*pUnoI
->release
)( pUnoI
);
144 checkException(pExc
, *o3tl::doAccess
<Reference
<XInterface
>>(rObj
));
147 &aRet
, reinterpret_cast< uno_ReleaseFunc
>(cpp_release
) );
148 uno_any_constructAndConvert( &aRet
, pReturn
, pTD
, getReflection()->getUno2Cpp().get() );
149 uno_destructData( pReturn
, pTD
, nullptr );
152 throw IllegalArgumentException(
153 u
"illegal object given!"_ustr
,
157 void IdlAttributeFieldImpl::set( Any
& rObj
, const Any
& rValue
)
159 if (getAttributeTypeDescr()->bReadOnly
)
161 throw IllegalAccessException(
162 u
"cannot set readonly attribute!"_ustr
,
166 uno_Interface
* pUnoI
= getReflection()->mapToUno(
167 rObj
, reinterpret_cast<typelib_InterfaceTypeDescription
*>(getDeclTypeDescr()) );
168 OSL_ENSURE( pUnoI
, "### illegal destination object given!" );
171 TypeDescription
aTD( getAttributeTypeDescr()->pAttributeTypeRef
);
172 typelib_TypeDescription
* pTD
= aTD
.get();
174 // construct uno value to be set
176 void * pArg
= pArgs
[0] = alloca( pTD
->nSize
);
179 if (pTD
->eTypeClass
== typelib_TypeClass_ANY
)
181 uno_copyAndConvertData( pArg
, const_cast< Any
* >(&rValue
),
182 pTD
, getReflection()->getCpp2Uno().get() );
185 else if (typelib_typedescriptionreference_equals( rValue
.getValueTypeRef(), pTD
->pWeakRef
))
187 uno_copyAndConvertData( pArg
, const_cast< void * >(rValue
.getValue()),
188 pTD
, getReflection()->getCpp2Uno().get() );
191 else if (pTD
->eTypeClass
== typelib_TypeClass_INTERFACE
)
193 Reference
< XInterface
> xObj
;
195 rValue
, reinterpret_cast<typelib_InterfaceTypeDescription
*>(pTD
), xObj
,
199 *static_cast<void **>(pArg
) = getReflection()->getCpp2Uno().mapInterface(
200 xObj
.get(), reinterpret_cast<typelib_InterfaceTypeDescription
*>(pTD
) );
205 typelib_TypeDescription
* pValueTD
= nullptr;
206 TYPELIB_DANGER_GET( &pValueTD
, rValue
.getValueTypeRef() );
207 // construct temp uno val to do proper assignment: todo opt
208 void * pTemp
= alloca( pValueTD
->nSize
);
209 uno_copyAndConvertData(
210 pTemp
, const_cast<void *>(rValue
.getValue()), pValueTD
, getReflection()->getCpp2Uno().get() );
213 // assignment does simple conversion
214 bAssign
= uno_assignData(
215 pArg
, pTD
, pTemp
, pValueTD
, nullptr, nullptr, nullptr );
217 pTemp
, pValueTD
, nullptr );
218 TYPELIB_DANGER_RELEASE( pValueTD
);
224 uno_Any
* pExc
= &aExc
;
225 (*pUnoI
->pDispatcher
)( pUnoI
, getTypeDescr(), nullptr, pArgs
, &pExc
);
226 (*pUnoI
->release
)( pUnoI
);
228 uno_destructData( pArg
, pTD
, nullptr );
229 checkException(pExc
, *o3tl::doAccess
<Reference
<XInterface
>>(rObj
));
232 (*pUnoI
->release
)( pUnoI
);
234 throw IllegalArgumentException(
235 u
"illegal value given!"_ustr
,
236 *o3tl::doAccess
<Reference
<XInterface
>>(rObj
), 1 );
238 throw IllegalArgumentException(
239 u
"illegal destination object given!"_ustr
,
243 void IdlAttributeFieldImpl::set( const Any
& rObj
, const Any
& rValue
)
245 IdlAttributeFieldImpl::set( const_cast< Any
& >( rObj
), rValue
);
248 void IdlAttributeFieldImpl::checkException(
249 uno_Any
* exception
, Reference
< XInterface
> const & context
) const
251 if (exception
== nullptr)
255 uno_any_destruct(&e
, reinterpret_cast< uno_ReleaseFunc
>(cpp_release
));
256 uno_type_any_constructAndConvert(
257 &e
, exception
->pData
, exception
->pType
,
258 getReflection()->getUno2Cpp().get());
259 uno_any_destruct(exception
, nullptr);
260 if (!e
.isExtractableTo(
261 cppu::UnoType
<RuntimeException
>::get()))
263 throw WrappedTargetRuntimeException(
264 u
"non-RuntimeException occurred when accessing an"
265 " interface type attribute"_ustr
,
268 cppu::throwException(e
);
273 typedef cppu::ImplInheritanceHelper
<IdlMemberImpl
, XIdlMethod
> IdlInterfaceMethodImpl_Base
;
274 class IdlInterfaceMethodImpl
: public IdlInterfaceMethodImpl_Base
276 std::optional
<Sequence
< Reference
< XIdlClass
> >> m_xExceptionTypes
;
277 std::optional
<Sequence
< Reference
< XIdlClass
> >> m_xParamTypes
;
278 std::optional
<Sequence
< ParamInfo
>> m_xParamInfos
;
281 typelib_InterfaceMethodTypeDescription
* getMethodTypeDescr() const
282 { return reinterpret_cast<typelib_InterfaceMethodTypeDescription
*>(getTypeDescr()); }
284 IdlInterfaceMethodImpl( IdlReflectionServiceImpl
* pReflection
, const OUString
& rName
,
285 typelib_TypeDescription
* pTypeDescr
, typelib_TypeDescription
* pDeclTypeDescr
)
286 : IdlInterfaceMethodImpl_Base( pReflection
, rName
, pTypeDescr
, pDeclTypeDescr
)
290 virtual Sequence
< sal_Int8
> SAL_CALL
getImplementationId() override
;
293 virtual Reference
< XIdlClass
> SAL_CALL
getDeclaringClass() override
;
294 virtual OUString SAL_CALL
getName() override
;
296 virtual Reference
< XIdlClass
> SAL_CALL
getReturnType() override
;
297 virtual Sequence
< Reference
< XIdlClass
> > SAL_CALL
getParameterTypes() override
;
298 virtual Sequence
< ParamInfo
> SAL_CALL
getParameterInfos() override
;
299 virtual Sequence
< Reference
< XIdlClass
> > SAL_CALL
getExceptionTypes() override
;
300 virtual MethodMode SAL_CALL
getMode() override
;
301 virtual Any SAL_CALL
invoke( const Any
& rObj
, Sequence
< Any
> & rArgs
) override
;
308 Sequence
< sal_Int8
> IdlInterfaceMethodImpl::getImplementationId()
310 return css::uno::Sequence
<sal_Int8
>();
315 Reference
< XIdlClass
> IdlInterfaceMethodImpl::getDeclaringClass()
317 if (! _xDeclClass
.is())
319 ::osl::MutexGuard
aGuard( getMutexAccess() );
320 if (! _xDeclClass
.is())
322 OUString
aName(getMethodTypeDescr()->aBase
.aBase
.pTypeName
);
323 sal_Int32 i
= aName
.indexOf(':');
325 _xDeclClass
= getReflection()->forName(aName
.copy(0, i
));
331 OUString
IdlInterfaceMethodImpl::getName()
333 return IdlMemberImpl::getName();
338 Reference
< XIdlClass
> SAL_CALL
IdlInterfaceMethodImpl::getReturnType()
340 return getReflection()->forType( getMethodTypeDescr()->pReturnTypeRef
);
343 Sequence
< Reference
< XIdlClass
> > IdlInterfaceMethodImpl::getExceptionTypes()
345 if (! m_xExceptionTypes
)
347 ::osl::MutexGuard
aGuard( getMutexAccess() );
348 if (! m_xExceptionTypes
)
350 sal_Int32 nExc
= getMethodTypeDescr()->nExceptions
;
351 Sequence
< Reference
< XIdlClass
> > aTempExceptionTypes( nExc
);
352 Reference
< XIdlClass
> * pExceptionTypes
= aTempExceptionTypes
.getArray();
354 typelib_TypeDescriptionReference
** ppExc
=
355 getMethodTypeDescr()->ppExceptions
;
356 IdlReflectionServiceImpl
* pRefl
= getReflection();
359 pExceptionTypes
[nExc
] = pRefl
->forType( ppExc
[nExc
] );
361 m_xExceptionTypes
= std::move(aTempExceptionTypes
);
364 return *m_xExceptionTypes
;
367 Sequence
< Reference
< XIdlClass
> > IdlInterfaceMethodImpl::getParameterTypes()
371 ::osl::MutexGuard
aGuard( getMutexAccess() );
374 sal_Int32 nParams
= getMethodTypeDescr()->nParams
;
375 Sequence
< Reference
< XIdlClass
> > aTempParamTypes( nParams
);
376 Reference
< XIdlClass
> * pParamTypes
= aTempParamTypes
.getArray();
378 typelib_MethodParameter
* pTypelibParams
=
379 getMethodTypeDescr()->pParams
;
380 IdlReflectionServiceImpl
* pRefl
= getReflection();
383 pParamTypes
[nParams
] = pRefl
->forType( pTypelibParams
[nParams
].pTypeRef
);
385 m_xParamTypes
= std::move(aTempParamTypes
);
388 return *m_xParamTypes
;
391 Sequence
< ParamInfo
> IdlInterfaceMethodImpl::getParameterInfos()
395 ::osl::MutexGuard
aGuard( getMutexAccess() );
398 sal_Int32 nParams
= getMethodTypeDescr()->nParams
;
399 Sequence
< ParamInfo
> aTempParamInfos( nParams
);
400 ParamInfo
* pParamInfos
= aTempParamInfos
.getArray();
402 typelib_MethodParameter
* pTypelibParams
=
403 getMethodTypeDescr()->pParams
;
405 if (m_xParamTypes
) // use param types
407 const Reference
< XIdlClass
> * pParamTypes
= m_xParamTypes
->getConstArray();
411 const typelib_MethodParameter
& rParam
= pTypelibParams
[nParams
];
412 ParamInfo
& rInfo
= pParamInfos
[nParams
];
413 rInfo
.aName
= rParam
.pName
;
415 rInfo
.aMode
= (rParam
.bOut
? ParamMode_INOUT
: ParamMode_IN
);
417 rInfo
.aMode
= ParamMode_OUT
;
418 rInfo
.aType
= pParamTypes
[nParams
];
421 else // make also param types sequence if not already initialized
423 Sequence
< Reference
< XIdlClass
> > aTempParamTypes( nParams
);
424 Reference
< XIdlClass
> * pParamTypes
= aTempParamTypes
.getArray();
426 IdlReflectionServiceImpl
* pRefl
= getReflection();
430 const typelib_MethodParameter
& rParam
= pTypelibParams
[nParams
];
431 ParamInfo
& rInfo
= pParamInfos
[nParams
];
432 rInfo
.aName
= rParam
.pName
;
434 rInfo
.aMode
= (rParam
.bOut
? ParamMode_INOUT
: ParamMode_IN
);
436 rInfo
.aMode
= ParamMode_OUT
;
437 rInfo
.aType
= pParamTypes
[nParams
] = pRefl
->forType( rParam
.pTypeRef
);
440 m_xParamTypes
= std::move(aTempParamTypes
);
443 m_xParamInfos
= std::move(aTempParamInfos
);
446 return *m_xParamInfos
;
449 MethodMode SAL_CALL
IdlInterfaceMethodImpl::getMode()
452 getMethodTypeDescr()->bOneWay
? MethodMode_ONEWAY
: MethodMode_TWOWAY
;
455 Any SAL_CALL
IdlInterfaceMethodImpl::invoke( const Any
& rObj
, Sequence
< Any
> & rArgs
)
457 if (auto ifc
= o3tl::tryAccess
<css::uno::Reference
<css::uno::XInterface
>>(
460 // acquire()/ release()
461 if (rtl_ustr_ascii_compare( getTypeDescr()->pTypeName
->buffer
,
462 "com.sun.star.uno.XInterface::acquire" ) == 0)
467 else if (rtl_ustr_ascii_compare( getTypeDescr()->pTypeName
->buffer
,
468 "com.sun.star.uno.XInterface::release" ) == 0)
475 uno_Interface
* pUnoI
= getReflection()->mapToUno(
476 rObj
, reinterpret_cast<typelib_InterfaceTypeDescription
*>(getDeclTypeDescr()) );
477 OSL_ENSURE( pUnoI
, "### illegal destination object given!" );
480 sal_Int32 nParams
= getMethodTypeDescr()->nParams
;
481 if (rArgs
.getLength() != nParams
)
483 (*pUnoI
->release
)( pUnoI
);
484 throw IllegalArgumentException(
485 "expected " + OUString::number(nParams
) +
486 " arguments, got " + OUString::number(rArgs
.getLength()),
487 *o3tl::doAccess
<Reference
<XInterface
>>(rObj
), 1 );
490 Any
* pCppArgs
= rArgs
.getArray();
491 typelib_MethodParameter
* pParams
= getMethodTypeDescr()->pParams
;
492 typelib_TypeDescription
* pReturnType
= nullptr;
494 &pReturnType
, getMethodTypeDescr()->pReturnTypeRef
);
496 // C/C++ ABIs typically assume that structs are padded at the end, and
497 // that those padding bytes may be written to (e.g., to write into the
498 // end of a "short" struct by writing the full contents of a "long"
499 // register); so create enough space here (assuming that no ABI requires
500 // padding larger than 16 byte boundaries):
501 void * pUnoReturn
= (pReturnType
->nSize
== 0) ? nullptr : alloca( multipleOf16(pReturnType
->nSize
) );
502 void ** ppUnoArgs
= static_cast<void **>(alloca( sizeof(void *) * nParams
*2 ));
503 typelib_TypeDescription
** ppParamTypes
= reinterpret_cast<typelib_TypeDescription
**>(ppUnoArgs
+ nParams
);
506 for ( sal_Int32 nPos
= 0; nPos
< nParams
; ++nPos
)
508 ppParamTypes
[nPos
] = nullptr;
509 TYPELIB_DANGER_GET( ppParamTypes
+ nPos
, pParams
[nPos
].pTypeRef
);
510 typelib_TypeDescription
* pTD
= ppParamTypes
[nPos
];
513 ppUnoArgs
[nPos
] = alloca( pTD
->nSize
);
514 if (pParams
[nPos
].bIn
)
517 if (typelib_typedescriptionreference_equals(
518 pCppArgs
[nPos
].getValueTypeRef(), pTD
->pWeakRef
))
520 uno_type_copyAndConvertData(
521 ppUnoArgs
[nPos
], const_cast<void *>(pCppArgs
[nPos
].getValue()),
522 pCppArgs
[nPos
].getValueTypeRef(), getReflection()->getCpp2Uno().get() );
525 else if (pTD
->eTypeClass
== typelib_TypeClass_ANY
)
527 uno_type_any_constructAndConvert(
528 static_cast<uno_Any
*>(ppUnoArgs
[nPos
]), const_cast<void *>(pCppArgs
[nPos
].getValue()),
529 pCppArgs
[nPos
].getValueTypeRef(), getReflection()->getCpp2Uno().get() );
532 else if (pTD
->eTypeClass
== typelib_TypeClass_INTERFACE
)
534 Reference
< XInterface
> xDest
;
536 pCppArgs
[nPos
], reinterpret_cast<typelib_InterfaceTypeDescription
*>(pTD
),
537 xDest
, getReflection() );
540 *static_cast<void **>(ppUnoArgs
[nPos
]) = getReflection()->getCpp2Uno().mapInterface(
541 xDest
.get(), reinterpret_cast<typelib_InterfaceTypeDescription
*>(pTD
) );
546 typelib_TypeDescription
* pValueTD
= nullptr;
547 TYPELIB_DANGER_GET( &pValueTD
, pCppArgs
[nPos
].getValueTypeRef() );
548 // construct temp uno val to do proper assignment: todo opt
549 void * pTemp
= alloca( pValueTD
->nSize
);
550 uno_copyAndConvertData(
551 pTemp
, const_cast<void *>(pCppArgs
[nPos
].getValue()), pValueTD
,
552 getReflection()->getCpp2Uno().get() );
554 ppUnoArgs
[nPos
], pTD
);
555 // assignment does simple conversion
556 bAssign
= uno_assignData(
557 ppUnoArgs
[nPos
], pTD
, pTemp
, pValueTD
, nullptr, nullptr, nullptr );
559 pTemp
, pValueTD
, nullptr );
560 TYPELIB_DANGER_RELEASE( pValueTD
);
565 IllegalArgumentException
aExc(
566 "cannot coerce argument type during corereflection call:"
567 "\narg no.: " + OUString::number(nPos
)
568 + " expected: \"" + OUString::unacquired(&pTD
->pTypeName
)
569 + "\" actual: \"" + OUString::unacquired(&pCppArgs
[nPos
].getValueTypeRef()->pTypeName
)
571 *o3tl::doAccess
<Reference
<XInterface
>>(rObj
), static_cast<sal_Int16
>(nPos
) );
576 if (pParams
[nPos
].bIn
)
577 uno_destructData( ppUnoArgs
[nPos
], ppParamTypes
[nPos
], nullptr );
578 TYPELIB_DANGER_RELEASE( ppParamTypes
[nPos
] );
580 TYPELIB_DANGER_RELEASE( pReturnType
);
581 (*pUnoI
->release
)( pUnoI
);
589 uno_Any
* pUnoExc
= &aUnoExc
;
591 (*pUnoI
->pDispatcher
)(
592 pUnoI
, getTypeDescr(), pUnoReturn
, ppUnoArgs
, &pUnoExc
);
593 (*pUnoI
->release
)( pUnoI
);
601 if (pParams
[nParams
].bIn
)
602 uno_destructData( ppUnoArgs
[nParams
], ppParamTypes
[nParams
], nullptr );
603 TYPELIB_DANGER_RELEASE( ppParamTypes
[nParams
] );
605 TYPELIB_DANGER_RELEASE( pReturnType
);
607 uno_any_destruct(&aRet
,
608 reinterpret_cast< uno_ReleaseFunc
>(cpp_release
) );
609 uno_type_copyAndConvertData(&aRet
, pUnoExc
, cppu::UnoType
<Any
>::get().getTypeLibType(),
610 getReflection()->getUno2Cpp().get() );
611 uno_any_destruct( pUnoExc
, nullptr );
612 throw InvocationTargetException(u
"exception occurred during invocation!"_ustr
,
613 *o3tl::doAccess
<Reference
<XInterface
>>(rObj
), aRet
);
617 // reconvert arguments and cleanup
620 if (pParams
[nParams
].bOut
) // write back
624 reinterpret_cast< uno_ReleaseFunc
>(cpp_release
) );
625 uno_any_constructAndConvert(
626 &pCppArgs
[nParams
], ppUnoArgs
[nParams
], ppParamTypes
[nParams
],
627 getReflection()->getUno2Cpp().get() );
629 uno_destructData( ppUnoArgs
[nParams
], ppParamTypes
[nParams
], nullptr );
630 TYPELIB_DANGER_RELEASE( ppParamTypes
[nParams
] );
633 &aRet
, reinterpret_cast< uno_ReleaseFunc
>(cpp_release
) );
634 uno_any_constructAndConvert(
635 &aRet
, pUnoReturn
, pReturnType
,
636 getReflection()->getUno2Cpp().get() );
637 uno_destructData( pUnoReturn
, pReturnType
, nullptr );
638 TYPELIB_DANGER_RELEASE( pReturnType
);
642 throw IllegalArgumentException(
643 u
"illegal destination object given!"_ustr
,
648 InterfaceIdlClassImpl::~InterfaceIdlClassImpl()
650 for ( sal_Int32 nPos
= _nMethods
+ _nAttributes
; nPos
--; )
651 typelib_typedescription_release( _pSortedMemberInit
[nPos
].second
);
655 Sequence
< Reference
< XIdlClass
> > InterfaceIdlClassImpl::getSuperclasses()
657 ::osl::MutexGuard
aGuard(getMutexAccess());
658 if (!_xSuperClasses
.hasElements()) {
659 typelib_InterfaceTypeDescription
* pType
= getTypeDescr();
660 _xSuperClasses
.realloc(pType
->nBaseTypes
);
661 auto pSuperClasses
= _xSuperClasses
.getArray();
662 for (sal_Int32 i
= 0; i
< pType
->nBaseTypes
; ++i
) {
663 pSuperClasses
[i
] = getReflection()->forType(
664 &pType
->ppBaseTypes
[i
]->aBase
);
665 OSL_ASSERT(_xSuperClasses
[i
].is());
668 return _xSuperClasses
;
671 void InterfaceIdlClassImpl::initMembers()
673 sal_Int32 nAll
= getTypeDescr()->nAllMembers
;
674 std::unique_ptr
<MemberInit
[]> pSortedMemberInit(new MemberInit
[nAll
]);
675 typelib_TypeDescriptionReference
** ppAllMembers
= getTypeDescr()->ppAllMembers
;
677 for ( sal_Int32 nPos
= 0; nPos
< nAll
; ++nPos
)
680 if (ppAllMembers
[nPos
]->eTypeClass
== typelib_TypeClass_INTERFACE_METHOD
)
689 nIndex
= (nAll
- _nAttributes
);
690 // attributes at the back
693 typelib_TypeDescription
* pTD
= nullptr;
694 typelib_typedescriptionreference_getDescription( &pTD
, ppAllMembers
[nPos
] );
695 assert(pTD
&& "### cannot get type description!");
696 pSortedMemberInit
[nIndex
].first
= reinterpret_cast<typelib_InterfaceMemberTypeDescription
*>(pTD
)->pMemberName
;
697 pSortedMemberInit
[nIndex
].second
= pTD
;
700 _pSortedMemberInit
= std::move(pSortedMemberInit
);
703 sal_Bool
InterfaceIdlClassImpl::isAssignableFrom( const Reference
< XIdlClass
> & xType
)
705 if (xType
.is() && xType
->getTypeClass() == TypeClass_INTERFACE
)
711 const Sequence
< Reference
< XIdlClass
> > aSeq
= xType
->getSuperclasses();
712 if (std::any_of(aSeq
.begin(), aSeq
.end(),
713 [this](const Reference
<XIdlClass
>& rType
){ return isAssignableFrom(rType
); }))
720 Uik
InterfaceIdlClassImpl::getUik()
722 return Uik(0, 0, 0, 0, 0);
723 // Uiks are deprecated and this function must not be called
726 Sequence
< Reference
< XIdlMethod
> > InterfaceIdlClassImpl::getMethods()
728 ::osl::MutexGuard
aGuard( getMutexAccess() );
729 if (! _pSortedMemberInit
)
732 // create methods sequence
733 Sequence
< Reference
< XIdlMethod
> > aRet( _nMethods
);
734 Reference
< XIdlMethod
> * pRet
= aRet
.getArray();
735 for ( sal_Int32 nPos
= _nMethods
; nPos
--; )
738 /*_aName2Method[_pSortedMemberInit[nPos].first] = */pRet
[nPos
] = new IdlInterfaceMethodImpl(
739 getReflection(), _pSortedMemberInit
[nPos
].first
,
740 _pSortedMemberInit
[nPos
].second
, IdlClassImpl::getTypeDescr() );
745 Sequence
< Reference
< XIdlField
> > InterfaceIdlClassImpl::getFields()
747 ::osl::MutexGuard
aGuard( getMutexAccess() );
748 if (! _pSortedMemberInit
)
751 // create fields sequence
752 Sequence
< Reference
< XIdlField
> > aRet( _nAttributes
);
753 Reference
< XIdlField
> * pRet
= aRet
.getArray();
754 for ( sal_Int32 nPos
= _nAttributes
; nPos
--; )
756 /*_aName2Field[_pSortedMemberInit[_nMethods+nPos].first] = */pRet
[_nAttributes
-nPos
-1] =
757 new IdlAttributeFieldImpl(
758 getReflection(), _pSortedMemberInit
[_nMethods
+nPos
].first
,
759 _pSortedMemberInit
[_nMethods
+nPos
].second
, IdlClassImpl::getTypeDescr() );
764 Reference
< XIdlMethod
> InterfaceIdlClassImpl::getMethod( const OUString
& rName
)
766 ::osl::MutexGuard
aGuard( getMutexAccess() );
767 if (! _pSortedMemberInit
)
770 Reference
< XIdlMethod
> xRet
;
773 const OUString2Method::const_iterator
iFind( _aName2Method
.find( rName
) );
774 if (iFind
!= _aName2Method
.end())
775 xRet
= (*iFind
).second
; // harden ref
779 for ( sal_Int32 nPos
= _nMethods
; nPos
--; )
781 if (_pSortedMemberInit
[nPos
].first
== rName
)
783 _aName2Method
[rName
] = xRet
= new IdlInterfaceMethodImpl(
784 getReflection(), rName
,
785 _pSortedMemberInit
[nPos
].second
, IdlClassImpl::getTypeDescr() );
793 Reference
< XIdlField
> InterfaceIdlClassImpl::getField( const OUString
& rName
)
795 ::osl::MutexGuard
aGuard( getMutexAccess() );
796 if (! _pSortedMemberInit
)
799 Reference
< XIdlField
> xRet
;
802 const OUString2Field::const_iterator
iFind( _aName2Field
.find( rName
) );
803 if (iFind
!= _aName2Field
.end())
804 xRet
= (*iFind
).second
; // harden ref
808 for ( sal_Int32 nPos
= _nAttributes
; nPos
--; )
810 if (_pSortedMemberInit
[_nMethods
+nPos
].first
== rName
)
812 _aName2Field
[rName
] = xRet
= new IdlAttributeFieldImpl(
813 getReflection(), rName
,
814 _pSortedMemberInit
[_nMethods
+nPos
].second
, IdlClassImpl::getTypeDescr() );
822 void InterfaceIdlClassImpl::createObject( Any
& rObj
)
824 // interfaces cannot be constructed
831 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */