LibreOffice Module stoc (master) 1
crbase.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <uno/any2.h>
21
22#include <utility>
23
24#include "base.hxx"
25
26using namespace css::reflection;
27using namespace css::uno;
28
29namespace stoc_corefl
30{
31
32#ifdef TEST_LIST_CLASSES
33ClassNameVector g_aClassNames;
34#endif
35
36
37::osl::Mutex & getMutexAccess()
38{
39 static osl::Mutex s_aMutex;
40
41 return s_aMutex;
42}
43
44
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 )
52{
53 if (_pTypeDescr)
54 {
56 if (! _pTypeDescr->bComplete)
58 }
59
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);
64#endif
65}
66
68{
69 if (_pTypeDescr)
71 m_xReflection.clear();
72
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 );
77#endif
78}
79
80// XIdlClassImpl default implementation
81
83{
84 return _eTypeClass;
85}
86
88{
89 return _aName;
90}
91
92sal_Bool IdlClassImpl::equals( const Reference< XIdlClass >& xType )
93{
94 return (xType.is() &&
95 (xType->getTypeClass() == _eTypeClass) && (xType->getName() == _aName));
96}
97
98const bool s_aAssignableFromTab[11][11] =
99{
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 }
112};
113
114sal_Bool IdlClassImpl::isAssignableFrom( const Reference< XIdlClass > & xType )
115{
116 TypeClass eAssign = getTypeClass();
117 if (equals( xType ) || eAssign == TypeClass_ANY) // default shot
118 {
119 return true;
120 }
121 else
122 {
123 TypeClass eFrom = xType->getTypeClass();
124 if (eAssign > TypeClass_VOID && eAssign < TypeClass_STRING &&
125 eFrom > TypeClass_VOID && eFrom < TypeClass_STRING)
126 {
127 return s_aAssignableFromTab[static_cast<int>(eAssign)-1][static_cast<int>(eFrom)-1];
128 }
129 }
130 return false;
131}
132
134{
135 rObj.clear();
136 uno_any_destruct( &rObj, reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
137 uno_any_construct( &rObj, nullptr, getTypeDescr(), nullptr );
138}
139
140// what TODO ????
141
142Sequence< Reference< XIdlClass > > IdlClassImpl::getClasses()
143{
144 OSL_FAIL( "### unexpected use!" );
145 return Sequence< Reference< XIdlClass > >();
146}
147
148Reference< XIdlClass > IdlClassImpl::getClass( const OUString & )
149{
150 OSL_FAIL( "### unexpected use!" );
151 return Reference< XIdlClass >();
152}
153
154Sequence< Reference< XIdlClass > > IdlClassImpl::getInterfaces()
155{
156// OSL_FAIL( "### unexpected use!" );
157 return Sequence< Reference< XIdlClass > >();
158}
159
160// structs, interfaces
161
162Sequence< Reference< XIdlClass > > IdlClassImpl::getSuperclasses()
163{
164 return Sequence< Reference< XIdlClass > >();
165}
166// structs
167
168Reference< XIdlField > IdlClassImpl::getField( const OUString & )
169{
170 return Reference< XIdlField >();
171}
172
173Sequence< Reference< XIdlField > > IdlClassImpl::getFields()
174{
175 return Sequence< Reference< XIdlField > >();
176}
177// interfaces
178
180{
181 return Uik();
182}
183
184Reference< XIdlMethod > IdlClassImpl::getMethod( const OUString & )
185{
186 return Reference< XIdlMethod >();
187}
188
189Sequence< Reference< XIdlMethod > > IdlClassImpl::getMethods()
190{
191 return Sequence< Reference< XIdlMethod > >();
192}
193// array
194
195Reference< XIdlClass > IdlClassImpl::getComponentType()
196{
197 return Reference< XIdlClass >();
198}
199
200Reference< XIdlArray > IdlClassImpl::getArray()
201{
202 return Reference< XIdlArray >();
203}
204
205
207 typelib_TypeDescription * pTypeDescr,
208 typelib_TypeDescription * pDeclTypeDescr )
209 : m_xReflection( pReflection )
210 , _aName(std::move( aName ))
211 , _pTypeDescr( pTypeDescr )
212 , _pDeclTypeDescr( pDeclTypeDescr )
213{
215 if (! _pTypeDescr->bComplete)
218 if (! _pDeclTypeDescr->bComplete)
220}
221
223{
226}
227
228// XIdlMember
229
230Reference< XIdlClass > IdlMemberImpl::getDeclaringClass()
231{
232 if (! _xDeclClass.is())
233 {
234 Reference< XIdlClass > xDeclClass( getReflection()->forType( getDeclTypeDescr() ) );
235 ::osl::MutexGuard aGuard( getMutexAccess() );
236 if (! _xDeclClass.is())
237 _xDeclClass = xDeclClass;
238 }
239 return _xDeclClass;
240}
241
243{
244 return _aName;
245}
246
247}
248
249
250/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SAL_CALL uno_any_construct(uno_Any *pDest, void *pSource, typelib_TypeDescription *pTypeDescr, uno_AcquireFunc acquire) SAL_THROW_EXTERN_C()
void SAL_CALL uno_any_destruct(uno_Any *pValue, uno_ReleaseFunc release) SAL_THROW_EXTERN_C()
virtual sal_Bool SAL_CALL isAssignableFrom(const css::uno::Reference< css::reflection::XIdlClass > &xType) override
Definition: crbase.cxx:114
virtual css::uno::Sequence< css::uno::Reference< css::reflection::XIdlField > > SAL_CALL getFields() override
Definition: crbase.cxx:173
css::uno::TypeClass _eTypeClass
Definition: base.hxx:135
virtual css::uno::Reference< css::reflection::XIdlArray > SAL_CALL getArray() override
Definition: crbase.cxx:200
virtual css::uno::Reference< css::reflection::XIdlMethod > SAL_CALL getMethod(const OUString &rName) override
Definition: crbase.cxx:184
virtual css::uno::Reference< css::reflection::XIdlClass > SAL_CALL getComponentType() override
Definition: crbase.cxx:195
virtual css::uno::Sequence< css::uno::Reference< css::reflection::XIdlClass > > SAL_CALL getInterfaces() override
Definition: crbase.cxx:154
rtl::Reference< IdlReflectionServiceImpl > m_xReflection
Definition: base.hxx:132
virtual void SAL_CALL createObject(css::uno::Any &rObj) override
Definition: crbase.cxx:133
virtual css::uno::Sequence< css::uno::Reference< css::reflection::XIdlMethod > > SAL_CALL getMethods() override
Definition: crbase.cxx:189
virtual css::uno::Sequence< css::uno::Reference< css::reflection::XIdlClass > > SAL_CALL getClasses() override
Definition: crbase.cxx:142
typelib_TypeDescription * getTypeDescr() const
Definition: base.hxx:140
virtual sal_Bool SAL_CALL equals(const css::uno::Reference< css::reflection::XIdlClass > &xType) override
Definition: crbase.cxx:92
virtual OUString SAL_CALL getName() override
Definition: crbase.cxx:87
virtual ~IdlClassImpl() override
Definition: crbase.cxx:67
virtual css::uno::Reference< css::reflection::XIdlField > SAL_CALL getField(const OUString &rName) override
Definition: crbase.cxx:168
virtual css::uno::Sequence< css::uno::Reference< css::reflection::XIdlClass > > SAL_CALL getSuperclasses() override
Definition: crbase.cxx:162
typelib_TypeDescription * _pTypeDescr
Definition: base.hxx:137
virtual css::uno::TypeClass SAL_CALL getTypeClass() override
Definition: crbase.cxx:82
IdlClassImpl(IdlReflectionServiceImpl *pReflection, OUString aName, typelib_TypeClass eTypeClass, typelib_TypeDescription *pTypeDescr)
Definition: crbase.cxx:45
virtual css::uno::Reference< css::reflection::XIdlClass > SAL_CALL getClass(const OUString &rName) override
Definition: crbase.cxx:148
virtual css::uno::Uik SAL_CALL getUik() override
Definition: crbase.cxx:179
virtual css::uno::Reference< css::reflection::XIdlClass > SAL_CALL getDeclaringClass() override
Definition: crbase.cxx:230
virtual ~IdlMemberImpl() override
Definition: crbase.cxx:222
css::uno::Reference< css::reflection::XIdlClass > _xDeclClass
Definition: base.hxx:312
IdlMemberImpl(IdlReflectionServiceImpl *pReflection, OUString aName, typelib_TypeDescription *pTypeDescr, typelib_TypeDescription *pDeclTypeDescr)
Definition: crbase.cxx:206
virtual OUString SAL_CALL getName() override
Definition: crbase.cxx:242
typelib_TypeDescription * _pDeclTypeDescr
Definition: base.hxx:309
typelib_TypeDescription * _pTypeDescr
Definition: base.hxx:308
IdlReflectionServiceImpl * getReflection() const
Definition: base.hxx:315
typelib_TypeDescription * getDeclTypeDescr() const
Definition: base.hxx:319
Reference< XIdlReflection > m_xReflection
OUString aName
Definition: invocation.cxx:689
struct _typelib_TypeDescription typelib_TypeDescription
const bool s_aAssignableFromTab[11][11]
Definition: crbase.cxx:98
::osl::Mutex & getMutexAccess()
Definition: crbase.cxx:37
void SAL_CALL typelib_typedescription_release(typelib_TypeDescription *pTD) SAL_THROW_EXTERN_C()
sal_Bool SAL_CALL typelib_typedescription_complete(typelib_TypeDescription **ppTypeDescr) SAL_THROW_EXTERN_C()
void SAL_CALL typelib_typedescription_acquire(typelib_TypeDescription *pTypeDescription) SAL_THROW_EXTERN_C()
unsigned char sal_Bool