Branch data 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 : 81132 : void ArrayIdlClassImpl::acquire() throw()
39 : : {
40 : 81132 : IdlClassImpl::acquire();
41 : 81132 : }
42 : : //__________________________________________________________________________________________________
43 : 79731 : void ArrayIdlClassImpl::release() throw()
44 : : {
45 : 79731 : IdlClassImpl::release();
46 : 79731 : }
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 : 70 : void ArrayIdlClassImpl::realloc( Any & rArray, sal_Int32 nLen )
87 : : throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
88 : : {
89 : 70 : TypeClass eTC = rArray.getValueTypeClass();
90 [ # # ][ - + ]: 70 : if (eTC != TypeClass_SEQUENCE && eTC != TypeClass_ARRAY)
91 : : {
92 : : throw IllegalArgumentException(
93 : : OUString( RTL_CONSTASCII_USTRINGPARAM("no sequence given!") ),
94 [ # # ][ # # ]: 0 : (XWeak *)(OWeakObject *)this, 0 );
[ # # ]
95 : : }
96 [ - + ]: 70 : if (nLen < 0)
97 : : {
98 : : throw IllegalArgumentException(
99 : : OUString( RTL_CONSTASCII_USTRINGPARAM("illegal length given!") ),
100 [ # # ][ # # ]: 0 : (XWeak *)(OWeakObject *)this, 1 );
[ # # ]
101 : : }
102 : :
103 : 70 : uno_Sequence ** ppSeq = (uno_Sequence **)rArray.getValue();
104 : 70 : uno_sequence_realloc( ppSeq, (typelib_TypeDescription *)getTypeDescr(),
105 : : nLen,
106 : : reinterpret_cast< uno_AcquireFunc >(cpp_acquire),
107 : 70 : reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
108 : 70 : rArray.pData = ppSeq;
109 : 70 : }
110 : : //__________________________________________________________________________________________________
111 : 2 : sal_Int32 ArrayIdlClassImpl::getLen( const Any & rArray )
112 : : throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
113 : : {
114 : 2 : TypeClass eTC = rArray.getValueTypeClass();
115 [ # # ][ - + ]: 2 : if (eTC != TypeClass_SEQUENCE && eTC != TypeClass_ARRAY)
116 : : {
117 : : throw IllegalArgumentException(
118 : : OUString( RTL_CONSTASCII_USTRINGPARAM("no sequence given!") ),
119 [ # # ][ # # ]: 0 : (XWeak *)(OWeakObject *)this, 0 );
[ # # ]
120 : : }
121 : :
122 : 2 : return (*(uno_Sequence **)rArray.getValue())->nElements;
123 : : }
124 : : //__________________________________________________________________________________________________
125 : 4 : 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 : 4 : TypeClass eTC = rArray.getValueTypeClass();
129 [ # # ][ - + ]: 4 : if (eTC != TypeClass_SEQUENCE && eTC != TypeClass_ARRAY)
130 : : {
131 : : throw IllegalArgumentException(
132 : : OUString( RTL_CONSTASCII_USTRINGPARAM("no sequence given!") ),
133 [ # # ][ # # ]: 0 : (XWeak *)(OWeakObject *)this, 0 );
[ # # ]
134 : : }
135 : :
136 : 4 : uno_Sequence * pSeq = *(uno_Sequence **)rArray.getValue();
137 [ - + ]: 4 : if (pSeq->nElements <= nIndex)
138 : : {
139 : : throw ArrayIndexOutOfBoundsException(
140 : : OUString( RTL_CONSTASCII_USTRINGPARAM("illegal index given!") ),
141 [ # # ][ # # ]: 0 : (XWeak *)(OWeakObject *)this );
[ # # ]
142 : : }
143 : :
144 : 4 : Any aRet;
145 : 4 : typelib_TypeDescription * pElemTypeDescr = 0;
146 [ - + ][ + - ]: 4 : TYPELIB_DANGER_GET( &pElemTypeDescr, getTypeDescr()->pType );
[ - + ][ # # ]
[ + - ]
147 : 4 : uno_any_destruct( &aRet, reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
148 : 4 : uno_any_construct( &aRet, &pSeq->elements[nIndex * pElemTypeDescr->nSize],
149 : : pElemTypeDescr,
150 : 4 : reinterpret_cast< uno_AcquireFunc >(cpp_acquire) );
151 [ - + ][ + - ]: 4 : TYPELIB_DANGER_RELEASE( pElemTypeDescr );
152 : 4 : return aRet;
153 : : }
154 : :
155 : : //__________________________________________________________________________________________________
156 : 60 : 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 : 60 : TypeClass eTC = rArray.getValueTypeClass();
160 [ # # ][ - + ]: 60 : if (eTC != TypeClass_SEQUENCE && eTC != TypeClass_ARRAY)
161 : : {
162 : : throw IllegalArgumentException(
163 : : OUString( RTL_CONSTASCII_USTRINGPARAM("no sequence given!") ),
164 [ # # ][ # # ]: 0 : (XWeak *)(OWeakObject *)this, 0 );
[ # # ]
165 : : }
166 : :
167 : 60 : uno_Sequence * pSeq = *(uno_Sequence **)rArray.getValue();
168 [ - + ]: 60 : if (pSeq->nElements <= nIndex)
169 : : {
170 : : throw ArrayIndexOutOfBoundsException(
171 : : OUString( RTL_CONSTASCII_USTRINGPARAM("illegal index given!") ),
172 [ # # ][ # # ]: 0 : (XWeak *)(OWeakObject *)this );
[ # # ]
173 : : }
174 : :
175 : 60 : uno_Sequence ** ppSeq = (uno_Sequence **)rArray.getValue();
176 : : uno_sequence_reference2One(
177 : 60 : ppSeq, (typelib_TypeDescription *)getTypeDescr(),
178 : : reinterpret_cast< uno_AcquireFunc >(cpp_acquire),
179 : 60 : reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
180 : 60 : rArray.pData = ppSeq;
181 : 60 : pSeq = *ppSeq;
182 : :
183 : 60 : typelib_TypeDescription * pElemTypeDescr = 0;
184 [ - + ][ + - ]: 60 : TYPELIB_DANGER_GET( &pElemTypeDescr, getTypeDescr()->pType );
[ - + ][ # # ]
[ + - ]
185 : :
186 [ - + ]: 60 : if (! coerce_assign( &pSeq->elements[nIndex * pElemTypeDescr->nSize],
187 [ + - ]: 60 : pElemTypeDescr, rNewValue, getReflection() ))
188 : : {
189 [ # # ][ # # ]: 0 : TYPELIB_DANGER_RELEASE( pElemTypeDescr );
190 : : throw IllegalArgumentException(
191 : : OUString( RTL_CONSTASCII_USTRINGPARAM("sequence element is not assignable by given value!") ),
192 [ # # ][ # # ]: 0 : (XWeak *)(OWeakObject *)this, 2 );
[ # # ]
193 : : }
194 [ + - ][ - + ]: 60 : TYPELIB_DANGER_RELEASE( pElemTypeDescr );
195 : 60 : }
196 : :
197 : : // ArrayIdlClassImpl
198 : : //__________________________________________________________________________________________________
199 : 11140 : sal_Bool ArrayIdlClassImpl::isAssignableFrom( const Reference< XIdlClass > & xType )
200 : : throw(::com::sun::star::uno::RuntimeException)
201 : : {
202 : 11140 : return (xType.is() &&
203 [ + - ]: 11140 : (equals( xType ) ||
204 [ + - ][ + - ]: 11010 : (xType->getTypeClass() == getTypeClass() && // must be sequence|array
[ + - ]
205 [ + + ][ + - ]: 33290 : getComponentType()->isAssignableFrom( xType->getComponentType() ))));
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ - + ]
[ + + ][ + + ]
[ # # # # ]
[ + - ]
206 : : }
207 : : //__________________________________________________________________________________________________
208 : 22020 : Reference< XIdlClass > ArrayIdlClassImpl::getComponentType()
209 : : throw(::com::sun::star::uno::RuntimeException)
210 : : {
211 : 22020 : return getReflection()->forType( getTypeDescr()->pType );
212 : : }
213 : : //__________________________________________________________________________________________________
214 : 72 : Reference< XIdlArray > ArrayIdlClassImpl::getArray()
215 : : throw(::com::sun::star::uno::RuntimeException)
216 : : {
217 : 72 : return this;
218 : : }
219 : :
220 : : }
221 : :
222 : :
223 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|