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 .
26 using namespace css::reflection
;
27 using namespace css::uno
;
32 #ifdef TEST_LIST_CLASSES
33 ClassNameVector g_aClassNames
;
37 ::osl::Mutex
& getMutexAccess()
39 static osl::Mutex s_aMutex
;
45 IdlClassImpl::IdlClassImpl( IdlReflectionServiceImpl
* pReflection
,
46 OUString aName
, typelib_TypeClass eTypeClass
,
47 typelib_TypeDescription
* pTypeDescr
)
48 : m_xReflection( pReflection
)
49 , _aName(std::move( aName
))
50 , _eTypeClass( static_cast<TypeClass
>(eTypeClass
) )
51 , _pTypeDescr( pTypeDescr
)
55 typelib_typedescription_acquire( _pTypeDescr
);
56 if (! _pTypeDescr
->bComplete
)
57 typelib_typedescription_complete( &_pTypeDescr
);
60 #ifdef TEST_LIST_CLASSES
61 ClassNameVector::const_iterator
iFind( std::find( g_aClassNames
.begin(), g_aClassNames
.end(), _aName
) );
62 OSL_ENSURE( iFind
== g_aClassNames
.end(), "### idl class already exists!" );
63 g_aClassNames
.insert(g_aClassNames
.begin(), _aName
);
67 IdlClassImpl::~IdlClassImpl()
70 typelib_typedescription_release( _pTypeDescr
);
71 m_xReflection
.clear();
73 #ifdef TEST_LIST_CLASSES
74 ClassNameVector::iterator
iFind( std::find( g_aClassNames
.begin(), g_aClassNames
.end(), _aName
) );
75 OSL_ENSURE( iFind
!= g_aClassNames
.end(), "### idl class does not exist!" );
76 g_aClassNames
.erase( iFind
);
80 // XIdlClassImpl default implementation
82 TypeClass
IdlClassImpl::getTypeClass()
87 OUString
IdlClassImpl::getName()
92 sal_Bool
IdlClassImpl::equals( const Reference
< XIdlClass
>& xType
)
95 (xType
->getTypeClass() == _eTypeClass
) && (xType
->getName() == _aName
));
98 const bool s_aAssignableFromTab
[11][11] =
100 /* from CH, BO, BY, SH, US, LO, UL, HY, UH, FL, DO */
101 /* TypeClass_CHAR */ { true, false, false, false, false, false, false, false, false, false, false },
102 /* TypeClass_BOOLEAN */ { false, true, false, false, false, false, false, false, false, false, false },
103 /* TypeClass_BYTE */ { false, false, true, false, false, false, false, false, false, false, false },
104 /* TypeClass_SHORT */ { false, false, true, true, true, false, false, false, false, false, false },
105 /* TypeClass_UNSIGNED_SHORT */ { false, false, true, true, true, false, false, false, false, false, false },
106 /* TypeClass_LONG */ { false, false, true, true, true, true, true, false, false, false, false },
107 /* TypeClass_UNSIGNED_LONG */ { false, false, true, true, true, true, true, false, false, false, false },
108 /* TypeClass_HYPER */ { false, false, true, true, true, true, true, true, true, false, false },
109 /* TypeClass_UNSIGNED_HYPER */ { false, false, true, true, true, true, true, true, true, false, false },
110 /* TypeClass_FLOAT */ { false, false, true, true, true, true, true, true, true, true, false },
111 /* TypeClass_DOUBLE */ { false, false, true, true, true, true, true, true, true, true, true }
114 sal_Bool
IdlClassImpl::isAssignableFrom( const Reference
< XIdlClass
> & xType
)
116 TypeClass eAssign
= getTypeClass();
117 if (equals( xType
) || eAssign
== TypeClass_ANY
) // default shot
123 TypeClass eFrom
= xType
->getTypeClass();
124 if (eAssign
> TypeClass_VOID
&& eAssign
< TypeClass_STRING
&&
125 eFrom
> TypeClass_VOID
&& eFrom
< TypeClass_STRING
)
127 return s_aAssignableFromTab
[static_cast<int>(eAssign
)-1][static_cast<int>(eFrom
)-1];
133 void IdlClassImpl::createObject( Any
& rObj
)
136 uno_any_destruct( &rObj
, reinterpret_cast< uno_ReleaseFunc
>(cpp_release
) );
137 uno_any_construct( &rObj
, nullptr, getTypeDescr(), nullptr );
142 Sequence
< Reference
< XIdlClass
> > IdlClassImpl::getClasses()
144 OSL_FAIL( "### unexpected use!" );
145 return Sequence
< Reference
< XIdlClass
> >();
148 Reference
< XIdlClass
> IdlClassImpl::getClass( const OUString
& )
150 OSL_FAIL( "### unexpected use!" );
151 return Reference
< XIdlClass
>();
154 Sequence
< Reference
< XIdlClass
> > IdlClassImpl::getInterfaces()
156 // OSL_FAIL( "### unexpected use!" );
157 return Sequence
< Reference
< XIdlClass
> >();
160 // structs, interfaces
162 Sequence
< Reference
< XIdlClass
> > IdlClassImpl::getSuperclasses()
164 return Sequence
< Reference
< XIdlClass
> >();
168 Reference
< XIdlField
> IdlClassImpl::getField( const OUString
& )
170 return Reference
< XIdlField
>();
173 Sequence
< Reference
< XIdlField
> > IdlClassImpl::getFields()
175 return Sequence
< Reference
< XIdlField
> >();
179 Uik
IdlClassImpl::getUik()
184 Reference
< XIdlMethod
> IdlClassImpl::getMethod( const OUString
& )
186 return Reference
< XIdlMethod
>();
189 Sequence
< Reference
< XIdlMethod
> > IdlClassImpl::getMethods()
191 return Sequence
< Reference
< XIdlMethod
> >();
195 Reference
< XIdlClass
> IdlClassImpl::getComponentType()
197 return Reference
< XIdlClass
>();
200 Reference
< XIdlArray
> IdlClassImpl::getArray()
202 return Reference
< XIdlArray
>();
206 IdlMemberImpl::IdlMemberImpl( IdlReflectionServiceImpl
* pReflection
, OUString aName
,
207 typelib_TypeDescription
* pTypeDescr
,
208 typelib_TypeDescription
* pDeclTypeDescr
)
209 : m_xReflection( pReflection
)
210 , _aName(std::move( aName
))
211 , _pTypeDescr( pTypeDescr
)
212 , _pDeclTypeDescr( pDeclTypeDescr
)
214 typelib_typedescription_acquire( _pTypeDescr
);
215 if (! _pTypeDescr
->bComplete
)
216 typelib_typedescription_complete( &_pTypeDescr
);
217 typelib_typedescription_acquire( _pDeclTypeDescr
);
218 if (! _pDeclTypeDescr
->bComplete
)
219 typelib_typedescription_complete( &_pDeclTypeDescr
);
222 IdlMemberImpl::~IdlMemberImpl()
224 typelib_typedescription_release( _pDeclTypeDescr
);
225 typelib_typedescription_release( _pTypeDescr
);
230 Reference
< XIdlClass
> IdlMemberImpl::getDeclaringClass()
232 if (! _xDeclClass
.is())
234 Reference
< XIdlClass
> xDeclClass( getReflection()->forType( getDeclTypeDescr() ) );
235 ::osl::MutexGuard
aGuard( getMutexAccess() );
236 if (! _xDeclClass
.is())
237 _xDeclClass
= std::move(xDeclClass
);
242 OUString
IdlMemberImpl::getName()
250 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */