Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / stoc / source / corereflection / crbase.cxx
blobc5256cac92f6f31bd8a77d1b58ca406c2b68e619
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 .
20 #include <cppuhelper/queryinterface.hxx>
21 #include <uno/any2.h>
23 #include "base.hxx"
25 using namespace css::reflection;
26 using namespace css::uno;
28 namespace stoc_corefl
31 #ifdef TEST_LIST_CLASSES
32 ClassNameVector g_aClassNames;
33 #endif
36 ::osl::Mutex & getMutexAccess()
38 static ::osl::Mutex * s_pMutex = nullptr;
39 if (! s_pMutex)
41 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
42 if (! s_pMutex)
44 static ::osl::Mutex s_aMutex;
45 s_pMutex = &s_aMutex;
48 return *s_pMutex;
52 IdlClassImpl::IdlClassImpl( IdlReflectionServiceImpl * pReflection,
53 const OUString & rName, typelib_TypeClass eTypeClass,
54 typelib_TypeDescription * pTypeDescr )
55 : m_xReflection( pReflection )
56 , _aName( rName )
57 , _eTypeClass( static_cast<TypeClass>(eTypeClass) )
58 , _pTypeDescr( pTypeDescr )
60 if (_pTypeDescr)
62 typelib_typedescription_acquire( _pTypeDescr );
63 if (! _pTypeDescr->bComplete)
64 typelib_typedescription_complete( &_pTypeDescr );
67 #ifdef TEST_LIST_CLASSES
68 ClassNameVector::const_iterator iFind( std::find( g_aClassNames.begin(), g_aClassNames.end(), _aName ) );
69 OSL_ENSURE( iFind == g_aClassNames.end(), "### idl class already exists!" );
70 g_aClassNames.insert(g_aClassNames.begin(), _aName);
71 #endif
74 IdlClassImpl::~IdlClassImpl()
76 if (_pTypeDescr)
77 typelib_typedescription_release( _pTypeDescr );
78 m_xReflection.clear();
80 #ifdef TEST_LIST_CLASSES
81 ClassNameVector::iterator iFind( std::find( g_aClassNames.begin(), g_aClassNames.end(), _aName ) );
82 OSL_ENSURE( iFind != g_aClassNames.end(), "### idl class does not exist!" );
83 g_aClassNames.erase( iFind );
84 #endif
87 // XIdlClassImpl default implementation
89 TypeClass IdlClassImpl::getTypeClass()
91 return _eTypeClass;
94 OUString IdlClassImpl::getName()
96 return _aName;
99 sal_Bool IdlClassImpl::equals( const Reference< XIdlClass >& xType )
101 return (xType.is() &&
102 (xType->getTypeClass() == _eTypeClass) && (xType->getName() == _aName));
105 static const bool s_aAssignableFromTab[11][11] =
107 /* from CH, BO, BY, SH, US, LO, UL, HY, UH, FL, DO */
108 /* TypeClass_CHAR */ { true, false, false, false, false, false, false, false, false, false, false },
109 /* TypeClass_BOOLEAN */ { false, true, false, false, false, false, false, false, false, false, false },
110 /* TypeClass_BYTE */ { false, false, true, false, false, false, false, false, false, false, false },
111 /* TypeClass_SHORT */ { false, false, true, true, true, false, false, false, false, false, false },
112 /* TypeClass_UNSIGNED_SHORT */ { false, false, true, true, true, false, false, false, false, false, false },
113 /* TypeClass_LONG */ { false, false, true, true, true, true, true, false, false, false, false },
114 /* TypeClass_UNSIGNED_LONG */ { false, false, true, true, true, true, true, false, false, false, false },
115 /* TypeClass_HYPER */ { false, false, true, true, true, true, true, true, true, false, false },
116 /* TypeClass_UNSIGNED_HYPER */ { false, false, true, true, true, true, true, true, true, false, false },
117 /* TypeClass_FLOAT */ { false, false, true, true, true, true, true, true, true, true, false },
118 /* TypeClass_DOUBLE */ { false, false, true, true, true, true, true, true, true, true, true }
121 sal_Bool IdlClassImpl::isAssignableFrom( const Reference< XIdlClass > & xType )
123 TypeClass eAssign = getTypeClass();
124 if (equals( xType ) || eAssign == TypeClass_ANY) // default shot
126 return true;
128 else
130 TypeClass eFrom = xType->getTypeClass();
131 if (eAssign > TypeClass_VOID && eAssign < TypeClass_STRING &&
132 eFrom > TypeClass_VOID && eFrom < TypeClass_STRING)
134 return s_aAssignableFromTab[static_cast<int>(eAssign)-1][static_cast<int>(eFrom)-1];
137 return false;
140 void IdlClassImpl::createObject( Any & rObj )
142 rObj.clear();
143 uno_any_destruct( &rObj, reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
144 uno_any_construct( &rObj, nullptr, getTypeDescr(), nullptr );
147 // what TODO ????
149 Sequence< Reference< XIdlClass > > IdlClassImpl::getClasses()
151 OSL_FAIL( "### unexpected use!" );
152 return Sequence< Reference< XIdlClass > >();
155 Reference< XIdlClass > IdlClassImpl::getClass( const OUString & )
157 OSL_FAIL( "### unexpected use!" );
158 return Reference< XIdlClass >();
161 Sequence< Reference< XIdlClass > > IdlClassImpl::getInterfaces()
163 // OSL_FAIL( "### unexpected use!" );
164 return Sequence< Reference< XIdlClass > >();
167 // structs, interfaces
169 Sequence< Reference< XIdlClass > > IdlClassImpl::getSuperclasses()
171 return Sequence< Reference< XIdlClass > >();
173 // structs
175 Reference< XIdlField > IdlClassImpl::getField( const OUString & )
177 return Reference< XIdlField >();
180 Sequence< Reference< XIdlField > > IdlClassImpl::getFields()
182 return Sequence< Reference< XIdlField > >();
184 // interfaces
186 Uik IdlClassImpl::getUik()
188 return Uik();
191 Reference< XIdlMethod > IdlClassImpl::getMethod( const OUString & )
193 return Reference< XIdlMethod >();
196 Sequence< Reference< XIdlMethod > > IdlClassImpl::getMethods()
198 return Sequence< Reference< XIdlMethod > >();
200 // array
202 Reference< XIdlClass > IdlClassImpl::getComponentType()
204 return Reference< XIdlClass >();
207 Reference< XIdlArray > IdlClassImpl::getArray()
209 return Reference< XIdlArray >();
213 IdlMemberImpl::IdlMemberImpl( IdlReflectionServiceImpl * pReflection, const OUString & rName,
214 typelib_TypeDescription * pTypeDescr,
215 typelib_TypeDescription * pDeclTypeDescr )
216 : m_xReflection( pReflection )
217 , _aName( rName )
218 , _pTypeDescr( pTypeDescr )
219 , _pDeclTypeDescr( pDeclTypeDescr )
221 typelib_typedescription_acquire( _pTypeDescr );
222 if (! _pTypeDescr->bComplete)
223 typelib_typedescription_complete( &_pTypeDescr );
224 typelib_typedescription_acquire( _pDeclTypeDescr );
225 if (! _pDeclTypeDescr->bComplete)
226 typelib_typedescription_complete( &_pDeclTypeDescr );
229 IdlMemberImpl::~IdlMemberImpl()
231 typelib_typedescription_release( _pDeclTypeDescr );
232 typelib_typedescription_release( _pTypeDescr );
235 // XIdlMember
237 Reference< XIdlClass > IdlMemberImpl::getDeclaringClass()
239 if (! _xDeclClass.is())
241 Reference< XIdlClass > xDeclClass( getReflection()->forType( getDeclTypeDescr() ) );
242 ::osl::MutexGuard aGuard( getMutexAccess() );
243 if (! _xDeclClass.is())
244 _xDeclClass = xDeclClass;
246 return _xDeclClass;
249 OUString IdlMemberImpl::getName()
251 return _aName;
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */