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 0 : Mutex & getMutexAccess()
34 : {
35 : static Mutex * s_pMutex = 0;
36 0 : if (! s_pMutex)
37 : {
38 0 : MutexGuard aGuard( Mutex::getGlobalMutex() );
39 0 : if (! s_pMutex)
40 : {
41 0 : static Mutex s_aMutex;
42 0 : s_pMutex = &s_aMutex;
43 0 : }
44 : }
45 0 : return *s_pMutex;
46 : }
47 :
48 :
49 0 : 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 0 : , _pTypeDescr( pTypeDescr )
56 : {
57 0 : if (_pReflection)
58 0 : _pReflection->acquire();
59 0 : if (_pTypeDescr)
60 : {
61 0 : typelib_typedescription_acquire( _pTypeDescr );
62 0 : if (! _pTypeDescr->bComplete)
63 0 : 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 0 : }
72 :
73 0 : IdlClassImpl::~IdlClassImpl()
74 : {
75 0 : if (_pTypeDescr)
76 0 : typelib_typedescription_release( _pTypeDescr );
77 0 : if (_pReflection)
78 0 : _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 0 : }
86 :
87 : // XIdlClassImpl default implementation
88 :
89 0 : TypeClass IdlClassImpl::getTypeClass()
90 : throw(::com::sun::star::uno::RuntimeException, std::exception)
91 : {
92 0 : return _eTypeClass;
93 : }
94 :
95 0 : OUString IdlClassImpl::getName()
96 : throw(::com::sun::star::uno::RuntimeException, std::exception)
97 : {
98 0 : return _aName;
99 : }
100 :
101 0 : sal_Bool IdlClassImpl::equals( const Reference< XIdlClass >& xType )
102 : throw(::com::sun::star::uno::RuntimeException, std::exception)
103 : {
104 0 : return (xType.is() &&
105 0 : (xType->getTypeClass() == _eTypeClass) && (xType->getName() == _aName));
106 : }
107 :
108 : static const 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, std::exception)
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 0 : 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 0 : void IdlClassImpl::createObject( Any & rObj )
145 : throw(::com::sun::star::uno::RuntimeException, std::exception)
146 : {
147 0 : rObj.clear();
148 0 : uno_any_destruct( &rObj, reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
149 0 : uno_any_construct( &rObj, 0, getTypeDescr(), 0 );
150 0 : }
151 :
152 : // what TODO ????
153 :
154 0 : Sequence< Reference< XIdlClass > > IdlClassImpl::getClasses()
155 : throw(::com::sun::star::uno::RuntimeException, std::exception)
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, std::exception)
163 : {
164 : OSL_FAIL( "### unexpected use!" );
165 0 : return Reference< XIdlClass >();
166 : }
167 :
168 0 : Sequence< Reference< XIdlClass > > IdlClassImpl::getInterfaces()
169 : throw(::com::sun::star::uno::RuntimeException, std::exception)
170 : {
171 : // OSL_FAIL( "### unexpected use!" );
172 0 : return Sequence< Reference< XIdlClass > >();
173 : }
174 :
175 : // structs, interfaces
176 :
177 0 : Sequence< Reference< XIdlClass > > IdlClassImpl::getSuperclasses() throw(::com::sun::star::uno::RuntimeException, std::exception)
178 : {
179 0 : return Sequence< Reference< XIdlClass > >();
180 : }
181 : // structs
182 :
183 0 : Reference< XIdlField > IdlClassImpl::getField( const OUString & )
184 : throw(::com::sun::star::uno::RuntimeException, std::exception)
185 : {
186 0 : return Reference< XIdlField >();
187 : }
188 :
189 0 : Sequence< Reference< XIdlField > > IdlClassImpl::getFields()
190 : throw(::com::sun::star::uno::RuntimeException, std::exception)
191 : {
192 0 : return Sequence< Reference< XIdlField > >();
193 : }
194 : // interfaces
195 :
196 0 : Uik IdlClassImpl::getUik()
197 : throw(::com::sun::star::uno::RuntimeException, std::exception)
198 : {
199 0 : return Uik();
200 : }
201 :
202 0 : Reference< XIdlMethod > IdlClassImpl::getMethod( const OUString & )
203 : throw(::com::sun::star::uno::RuntimeException, std::exception)
204 : {
205 0 : return Reference< XIdlMethod >();
206 : }
207 :
208 0 : Sequence< Reference< XIdlMethod > > IdlClassImpl::getMethods()
209 : throw(::com::sun::star::uno::RuntimeException, std::exception)
210 : {
211 0 : return Sequence< Reference< XIdlMethod > >();
212 : }
213 : // array
214 :
215 0 : Reference< XIdlClass > IdlClassImpl::getComponentType()
216 : throw(::com::sun::star::uno::RuntimeException, std::exception)
217 : {
218 0 : return Reference< XIdlClass >();
219 : }
220 :
221 0 : Reference< XIdlArray > IdlClassImpl::getArray()
222 : throw(::com::sun::star::uno::RuntimeException, std::exception)
223 : {
224 0 : return Reference< XIdlArray >();
225 : }
226 :
227 :
228 :
229 :
230 :
231 :
232 :
233 :
234 0 : 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 0 : , _pDeclTypeDescr( pDeclTypeDescr )
241 : {
242 0 : _pReflection->acquire();
243 0 : typelib_typedescription_acquire( _pTypeDescr );
244 0 : if (! _pTypeDescr->bComplete)
245 0 : typelib_typedescription_complete( &_pTypeDescr );
246 0 : typelib_typedescription_acquire( _pDeclTypeDescr );
247 0 : if (! _pDeclTypeDescr->bComplete)
248 0 : typelib_typedescription_complete( &_pDeclTypeDescr );
249 0 : }
250 :
251 0 : IdlMemberImpl::~IdlMemberImpl()
252 : {
253 0 : typelib_typedescription_release( _pDeclTypeDescr );
254 0 : typelib_typedescription_release( _pTypeDescr );
255 0 : _pReflection->release();
256 0 : }
257 :
258 : // XIdlMember
259 :
260 0 : Reference< XIdlClass > IdlMemberImpl::getDeclaringClass()
261 : throw(::com::sun::star::uno::RuntimeException, std::exception)
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 0 : OUString IdlMemberImpl::getName()
274 : throw(::com::sun::star::uno::RuntimeException, std::exception)
275 : {
276 0 : return _aName;
277 : }
278 :
279 : }
280 :
281 :
282 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|