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 <typelib/typedescription.h>
21 : #include <uno/data.h>
22 :
23 : #include "base.hxx"
24 :
25 :
26 : namespace stoc_corefl
27 : {
28 :
29 : // XInterface
30 : //__________________________________________________________________________________________________
31 0 : Any ArrayIdlClassImpl::queryInterface( const Type & rType )
32 : throw(::com::sun::star::uno::RuntimeException)
33 : {
34 0 : Any aRet( ::cppu::queryInterface( rType, static_cast< XIdlArray * >( this ) ) );
35 0 : return (aRet.hasValue() ? aRet : IdlClassImpl::queryInterface( rType ));
36 : }
37 : //__________________________________________________________________________________________________
38 13551 : void ArrayIdlClassImpl::acquire() throw()
39 : {
40 13551 : IdlClassImpl::acquire();
41 13551 : }
42 : //__________________________________________________________________________________________________
43 12908 : void ArrayIdlClassImpl::release() throw()
44 : {
45 12908 : IdlClassImpl::release();
46 12908 : }
47 :
48 : // XTypeProvider
49 : //__________________________________________________________________________________________________
50 0 : Sequence< Type > ArrayIdlClassImpl::getTypes()
51 : throw (::com::sun::star::uno::RuntimeException)
52 : {
53 : static OTypeCollection * s_pTypes = 0;
54 0 : if (! s_pTypes)
55 : {
56 0 : MutexGuard aGuard( getMutexAccess() );
57 0 : if (! s_pTypes)
58 : {
59 : static OTypeCollection s_aTypes(
60 0 : ::getCppuType( (const Reference< XIdlArray > *)0 ),
61 0 : IdlClassImpl::getTypes() );
62 0 : s_pTypes = &s_aTypes;
63 0 : }
64 : }
65 0 : return s_pTypes->getTypes();
66 : }
67 : //__________________________________________________________________________________________________
68 0 : Sequence< sal_Int8 > ArrayIdlClassImpl::getImplementationId()
69 : throw (::com::sun::star::uno::RuntimeException)
70 : {
71 : static OImplementationId * s_pId = 0;
72 0 : if (! s_pId)
73 : {
74 0 : MutexGuard aGuard( getMutexAccess() );
75 0 : if (! s_pId)
76 : {
77 0 : static OImplementationId s_aId;
78 0 : s_pId = &s_aId;
79 0 : }
80 : }
81 0 : return s_pId->getImplementationId();
82 : }
83 :
84 : // XIdlArray
85 : //__________________________________________________________________________________________________
86 52 : void ArrayIdlClassImpl::realloc( Any & rArray, sal_Int32 nLen )
87 : throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
88 : {
89 52 : TypeClass eTC = rArray.getValueTypeClass();
90 52 : if (eTC != TypeClass_SEQUENCE && eTC != TypeClass_ARRAY)
91 : {
92 : throw IllegalArgumentException(
93 : OUString("no sequence given!"),
94 0 : (XWeak *)(OWeakObject *)this, 0 );
95 : }
96 52 : if (nLen < 0)
97 : {
98 : throw IllegalArgumentException(
99 : OUString("illegal length given!"),
100 0 : (XWeak *)(OWeakObject *)this, 1 );
101 : }
102 :
103 52 : uno_Sequence ** ppSeq = (uno_Sequence **)rArray.getValue();
104 52 : uno_sequence_realloc( ppSeq, (typelib_TypeDescription *)getTypeDescr(),
105 : nLen,
106 : reinterpret_cast< uno_AcquireFunc >(cpp_acquire),
107 52 : reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
108 52 : rArray.pData = ppSeq;
109 52 : }
110 : //__________________________________________________________________________________________________
111 152 : sal_Int32 ArrayIdlClassImpl::getLen( const Any & rArray )
112 : throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
113 : {
114 152 : TypeClass eTC = rArray.getValueTypeClass();
115 152 : if (eTC != TypeClass_SEQUENCE && eTC != TypeClass_ARRAY)
116 : {
117 : throw IllegalArgumentException(
118 : OUString("no sequence given!"),
119 0 : (XWeak *)(OWeakObject *)this, 0 );
120 : }
121 :
122 152 : return (*(uno_Sequence **)rArray.getValue())->nElements;
123 : }
124 : //__________________________________________________________________________________________________
125 3541 : Any ArrayIdlClassImpl::get( const Any & rArray, sal_Int32 nIndex )
126 : throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::ArrayIndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
127 : {
128 3541 : TypeClass eTC = rArray.getValueTypeClass();
129 3541 : if (eTC != TypeClass_SEQUENCE && eTC != TypeClass_ARRAY)
130 : {
131 : throw IllegalArgumentException(
132 : OUString("no sequence given!"),
133 0 : (XWeak *)(OWeakObject *)this, 0 );
134 : }
135 :
136 3541 : uno_Sequence * pSeq = *(uno_Sequence **)rArray.getValue();
137 3541 : if (pSeq->nElements <= nIndex)
138 : {
139 : throw ArrayIndexOutOfBoundsException(
140 : OUString("illegal index given!"),
141 0 : (XWeak *)(OWeakObject *)this );
142 : }
143 :
144 3541 : Any aRet;
145 3541 : typelib_TypeDescription * pElemTypeDescr = 0;
146 3541 : TYPELIB_DANGER_GET( &pElemTypeDescr, getTypeDescr()->pType );
147 3541 : uno_any_destruct( &aRet, reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
148 3541 : uno_any_construct( &aRet, &pSeq->elements[nIndex * pElemTypeDescr->nSize],
149 : pElemTypeDescr,
150 7082 : reinterpret_cast< uno_AcquireFunc >(cpp_acquire) );
151 3541 : TYPELIB_DANGER_RELEASE( pElemTypeDescr );
152 3541 : return aRet;
153 : }
154 :
155 : //__________________________________________________________________________________________________
156 88 : void ArrayIdlClassImpl::set( Any & rArray, sal_Int32 nIndex, const Any & rNewValue )
157 : throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::ArrayIndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
158 : {
159 88 : TypeClass eTC = rArray.getValueTypeClass();
160 88 : if (eTC != TypeClass_SEQUENCE && eTC != TypeClass_ARRAY)
161 : {
162 : throw IllegalArgumentException(
163 : OUString("no sequence given!"),
164 0 : (XWeak *)(OWeakObject *)this, 0 );
165 : }
166 :
167 88 : uno_Sequence * pSeq = *(uno_Sequence **)rArray.getValue();
168 88 : if (pSeq->nElements <= nIndex)
169 : {
170 : throw ArrayIndexOutOfBoundsException(
171 : OUString("illegal index given!"),
172 0 : (XWeak *)(OWeakObject *)this );
173 : }
174 :
175 88 : uno_Sequence ** ppSeq = (uno_Sequence **)rArray.getValue();
176 : uno_sequence_reference2One(
177 88 : ppSeq, (typelib_TypeDescription *)getTypeDescr(),
178 : reinterpret_cast< uno_AcquireFunc >(cpp_acquire),
179 88 : reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
180 88 : rArray.pData = ppSeq;
181 88 : pSeq = *ppSeq;
182 :
183 88 : typelib_TypeDescription * pElemTypeDescr = 0;
184 88 : TYPELIB_DANGER_GET( &pElemTypeDescr, getTypeDescr()->pType );
185 :
186 176 : if (! coerce_assign( &pSeq->elements[nIndex * pElemTypeDescr->nSize],
187 176 : pElemTypeDescr, rNewValue, getReflection() ))
188 : {
189 0 : TYPELIB_DANGER_RELEASE( pElemTypeDescr );
190 : throw IllegalArgumentException(
191 : OUString("sequence element is not assignable by given value!"),
192 0 : (XWeak *)(OWeakObject *)this, 2 );
193 : }
194 88 : TYPELIB_DANGER_RELEASE( pElemTypeDescr );
195 88 : }
196 :
197 : // ArrayIdlClassImpl
198 : //__________________________________________________________________________________________________
199 7 : sal_Bool ArrayIdlClassImpl::isAssignableFrom( const Reference< XIdlClass > & xType )
200 : throw(::com::sun::star::uno::RuntimeException)
201 : {
202 14 : return (xType.is() &&
203 14 : (equals( xType ) ||
204 28 : (xType->getTypeClass() == getTypeClass() && // must be sequence|array
205 28 : getComponentType()->isAssignableFrom( xType->getComponentType() ))));
206 : }
207 : //__________________________________________________________________________________________________
208 14 : Reference< XIdlClass > ArrayIdlClassImpl::getComponentType()
209 : throw(::com::sun::star::uno::RuntimeException)
210 : {
211 14 : return getReflection()->forType( getTypeDescr()->pType );
212 : }
213 : //__________________________________________________________________________________________________
214 204 : Reference< XIdlArray > ArrayIdlClassImpl::getArray()
215 : throw(::com::sun::star::uno::RuntimeException)
216 : {
217 204 : return this;
218 : }
219 :
220 : }
221 :
222 :
223 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|