Line data Source code
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 <cppuhelper/queryinterface.hxx>
21 : #include <uno/any2.h>
22 :
23 : #include "base.hxx"
24 :
25 : namespace stoc_corefl
26 : {
27 :
28 : #ifdef TEST_LIST_CLASSES
29 : ClassNameList g_aClassNames;
30 : #endif
31 :
32 : //--------------------------------------------------------------------------------------------------
33 53347 : Mutex & getMutexAccess()
34 : {
35 : static Mutex * s_pMutex = 0;
36 53347 : if (! s_pMutex)
37 : {
38 13 : MutexGuard aGuard( Mutex::getGlobalMutex() );
39 13 : if (! s_pMutex)
40 : {
41 13 : static Mutex s_aMutex;
42 13 : s_pMutex = &s_aMutex;
43 13 : }
44 : }
45 53347 : return *s_pMutex;
46 : }
47 :
48 : //__________________________________________________________________________________________________
49 2518 : IdlClassImpl::IdlClassImpl( IdlReflectionServiceImpl * pReflection,
50 : const OUString & rName, typelib_TypeClass eTypeClass,
51 : typelib_TypeDescription * pTypeDescr )
52 : : _pReflection( pReflection )
53 : , _aName( rName )
54 : , _eTypeClass( (TypeClass)eTypeClass )
55 2518 : , _pTypeDescr( pTypeDescr )
56 : {
57 2518 : if (_pReflection)
58 2518 : _pReflection->acquire();
59 2518 : if (_pTypeDescr)
60 : {
61 2518 : typelib_typedescription_acquire( _pTypeDescr );
62 2518 : if (! _pTypeDescr->bComplete)
63 1282 : typelib_typedescription_complete( &_pTypeDescr );
64 : }
65 :
66 : #ifdef TEST_LIST_CLASSES
67 : ClassNameList::const_iterator iFind( find( g_aClassNames.begin(), g_aClassNames.end(), _aName ) );
68 : OSL_ENSURE( iFind == g_aClassNames.end(), "### idl class already exists!" );
69 : g_aClassNames.push_front( _aName );
70 : #endif
71 2518 : }
72 : //__________________________________________________________________________________________________
73 1814 : IdlClassImpl::~IdlClassImpl()
74 : {
75 904 : if (_pTypeDescr)
76 904 : typelib_typedescription_release( _pTypeDescr );
77 904 : if (_pReflection)
78 904 : _pReflection->release();
79 :
80 : #ifdef TEST_LIST_CLASSES
81 : ClassNameList::iterator iFind( 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
85 910 : }
86 :
87 : // XIdlClassImpl default implementation
88 : //__________________________________________________________________________________________________
89 147454 : TypeClass IdlClassImpl::getTypeClass()
90 : throw(::com::sun::star::uno::RuntimeException)
91 : {
92 147454 : return _eTypeClass;
93 : }
94 : //__________________________________________________________________________________________________
95 145891 : OUString IdlClassImpl::getName()
96 : throw(::com::sun::star::uno::RuntimeException)
97 : {
98 145891 : return _aName;
99 : }
100 : //__________________________________________________________________________________________________
101 139884 : sal_Bool IdlClassImpl::equals( const Reference< XIdlClass >& xType )
102 : throw(::com::sun::star::uno::RuntimeException)
103 : {
104 139884 : return (xType.is() &&
105 279768 : (xType->getTypeClass() == _eTypeClass) && (xType->getName() == _aName));
106 : }
107 :
108 : static sal_Bool s_aAssignableFromTab[11][11] =
109 : {
110 : /* from CH,BO,BY,SH,US,LO,UL,HY,UH,FL,DO */
111 : /* TypeClass_CHAR */ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
112 : /* TypeClass_BOOLEAN */ { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
113 : /* TypeClass_BYTE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
114 : /* TypeClass_SHORT */ { 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0 },
115 : /* TypeClass_UNSIGNED_SHORT */ { 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0 },
116 : /* TypeClass_LONG */ { 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0 },
117 : /* TypeClass_UNSIGNED_LONG */ { 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0 },
118 : /* TypeClass_HYPER */ { 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
119 : /* TypeClass_UNSIGNED_HYPER */ { 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
120 : /* TypeClass_FLOAT */ { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
121 : /* TypeClass_DOUBLE */ { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
122 : };
123 : //__________________________________________________________________________________________________
124 0 : sal_Bool IdlClassImpl::isAssignableFrom( const Reference< XIdlClass > & xType )
125 : throw(::com::sun::star::uno::RuntimeException)
126 : {
127 0 : TypeClass eAssign = getTypeClass();
128 0 : if (equals( xType ) || eAssign == TypeClass_ANY) // default shot
129 : {
130 0 : return sal_True;
131 : }
132 : else
133 : {
134 0 : TypeClass eFrom = xType->getTypeClass();
135 0 : if (eAssign > TypeClass_VOID && eAssign < TypeClass_STRING &&
136 : eFrom > TypeClass_VOID && eFrom < TypeClass_STRING)
137 : {
138 0 : return s_aAssignableFromTab[eAssign-1][eFrom-1];
139 : }
140 : }
141 0 : return sal_False;
142 : }
143 : //__________________________________________________________________________________________________
144 6 : void IdlClassImpl::createObject( Any & rObj )
145 : throw(::com::sun::star::uno::RuntimeException)
146 : {
147 6 : rObj.clear();
148 6 : uno_any_destruct( &rObj, reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
149 6 : uno_any_construct( &rObj, 0, getTypeDescr(), 0 );
150 6 : }
151 :
152 : // what TODO ????
153 : //__________________________________________________________________________________________________
154 0 : Sequence< Reference< XIdlClass > > IdlClassImpl::getClasses()
155 : throw(::com::sun::star::uno::RuntimeException)
156 : {
157 : OSL_FAIL( "### unexpected use!" );
158 0 : return Sequence< Reference< XIdlClass > >();
159 : }
160 : //__________________________________________________________________________________________________
161 0 : Reference< XIdlClass > IdlClassImpl::getClass( const OUString & )
162 : throw(::com::sun::star::uno::RuntimeException)
163 : {
164 : OSL_FAIL( "### unexpected use!" );
165 0 : return Reference< XIdlClass >();
166 : }
167 : //__________________________________________________________________________________________________
168 7948 : Sequence< Reference< XIdlClass > > IdlClassImpl::getInterfaces()
169 : throw(::com::sun::star::uno::RuntimeException)
170 : {
171 : // OSL_FAIL( "### unexpected use!" );
172 7948 : return Sequence< Reference< XIdlClass > >();
173 : }
174 :
175 : // structs, interfaces
176 : //__________________________________________________________________________________________________
177 233 : Sequence< Reference< XIdlClass > > IdlClassImpl::getSuperclasses() throw(::com::sun::star::uno::RuntimeException)
178 : {
179 233 : return Sequence< Reference< XIdlClass > >();
180 : }
181 : // structs
182 : //__________________________________________________________________________________________________
183 0 : Reference< XIdlField > IdlClassImpl::getField( const OUString & )
184 : throw(::com::sun::star::uno::RuntimeException)
185 : {
186 0 : return Reference< XIdlField >();
187 : }
188 : //__________________________________________________________________________________________________
189 0 : Sequence< Reference< XIdlField > > IdlClassImpl::getFields()
190 : throw(::com::sun::star::uno::RuntimeException)
191 : {
192 0 : return Sequence< Reference< XIdlField > >();
193 : }
194 : // interfaces
195 : //__________________________________________________________________________________________________
196 0 : Uik IdlClassImpl::getUik()
197 : throw(::com::sun::star::uno::RuntimeException)
198 : {
199 0 : return Uik();
200 : }
201 : //__________________________________________________________________________________________________
202 0 : Reference< XIdlMethod > IdlClassImpl::getMethod( const OUString & )
203 : throw(::com::sun::star::uno::RuntimeException)
204 : {
205 0 : return Reference< XIdlMethod >();
206 : }
207 : //__________________________________________________________________________________________________
208 0 : Sequence< Reference< XIdlMethod > > IdlClassImpl::getMethods()
209 : throw(::com::sun::star::uno::RuntimeException)
210 : {
211 0 : return Sequence< Reference< XIdlMethod > >();
212 : }
213 : // array
214 : //__________________________________________________________________________________________________
215 0 : Reference< XIdlClass > IdlClassImpl::getComponentType()
216 : throw(::com::sun::star::uno::RuntimeException)
217 : {
218 0 : return Reference< XIdlClass >();
219 : }
220 : //__________________________________________________________________________________________________
221 0 : Reference< XIdlArray > IdlClassImpl::getArray()
222 : throw(::com::sun::star::uno::RuntimeException)
223 : {
224 0 : return Reference< XIdlArray >();
225 : }
226 :
227 :
228 : //##################################################################################################
229 : //##################################################################################################
230 : //##################################################################################################
231 :
232 :
233 : //__________________________________________________________________________________________________
234 29671 : IdlMemberImpl::IdlMemberImpl( IdlReflectionServiceImpl * pReflection, const OUString & rName,
235 : typelib_TypeDescription * pTypeDescr,
236 : typelib_TypeDescription * pDeclTypeDescr )
237 : : _pReflection( pReflection )
238 : , _aName( rName )
239 : , _pTypeDescr( pTypeDescr )
240 29671 : , _pDeclTypeDescr( pDeclTypeDescr )
241 : {
242 29671 : _pReflection->acquire();
243 29671 : typelib_typedescription_acquire( _pTypeDescr );
244 29671 : if (! _pTypeDescr->bComplete)
245 0 : typelib_typedescription_complete( &_pTypeDescr );
246 29671 : typelib_typedescription_acquire( _pDeclTypeDescr );
247 29671 : if (! _pDeclTypeDescr->bComplete)
248 0 : typelib_typedescription_complete( &_pDeclTypeDescr );
249 29671 : }
250 : //__________________________________________________________________________________________________
251 57820 : IdlMemberImpl::~IdlMemberImpl()
252 : {
253 28910 : typelib_typedescription_release( _pDeclTypeDescr );
254 28910 : typelib_typedescription_release( _pTypeDescr );
255 28910 : _pReflection->release();
256 28910 : }
257 :
258 : // XIdlMember
259 : //__________________________________________________________________________________________________
260 0 : Reference< XIdlClass > IdlMemberImpl::getDeclaringClass()
261 : throw(::com::sun::star::uno::RuntimeException)
262 : {
263 0 : if (! _xDeclClass.is())
264 : {
265 0 : Reference< XIdlClass > xDeclClass( getReflection()->forType( getDeclTypeDescr() ) );
266 0 : MutexGuard aGuard( getMutexAccess() );
267 0 : if (! _xDeclClass.is())
268 0 : _xDeclClass = xDeclClass;
269 : }
270 0 : return _xDeclClass;
271 : }
272 : //__________________________________________________________________________________________________
273 71729 : OUString IdlMemberImpl::getName()
274 : throw(::com::sun::star::uno::RuntimeException)
275 : {
276 71729 : return _aName;
277 : }
278 :
279 : }
280 :
281 :
282 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|