1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_stoc.hxx" 26 #include <typelib/typedescription.h> 27 #include <uno/data.h> 28 29 #include "base.hxx" 30 31 32 namespace stoc_corefl 33 { 34 35 // XInterface 36 //__________________________________________________________________________________________________ 37 Any ArrayIdlClassImpl::queryInterface( const Type & rType ) 38 { 39 Any aRet( ::cppu::queryInterface( rType, static_cast< XIdlArray * >( this ) ) ); 40 return (aRet.hasValue() ? aRet : IdlClassImpl::queryInterface( rType )); 41 } 42 //__________________________________________________________________________________________________ 43 void ArrayIdlClassImpl::acquire() throw() 44 { 45 IdlClassImpl::acquire(); 46 } 47 //__________________________________________________________________________________________________ 48 void ArrayIdlClassImpl::release() throw() 49 { 50 IdlClassImpl::release(); 51 } 52 53 // XTypeProvider 54 //__________________________________________________________________________________________________ 55 Sequence< Type > ArrayIdlClassImpl::getTypes() 56 { 57 static OTypeCollection * s_pTypes = 0; 58 if (! s_pTypes) 59 { 60 MutexGuard aGuard( getMutexAccess() ); 61 if (! s_pTypes) 62 { 63 static OTypeCollection s_aTypes( 64 ::getCppuType( (const Reference< XIdlArray > *)0 ), 65 IdlClassImpl::getTypes() ); 66 s_pTypes = &s_aTypes; 67 } 68 } 69 return s_pTypes->getTypes(); 70 } 71 //__________________________________________________________________________________________________ 72 Sequence< sal_Int8 > ArrayIdlClassImpl::getImplementationId() 73 { 74 static OImplementationId * s_pId = 0; 75 if (! s_pId) 76 { 77 MutexGuard aGuard( getMutexAccess() ); 78 if (! s_pId) 79 { 80 static OImplementationId s_aId; 81 s_pId = &s_aId; 82 } 83 } 84 return s_pId->getImplementationId(); 85 } 86 87 // XIdlArray 88 //__________________________________________________________________________________________________ 89 void ArrayIdlClassImpl::realloc( Any & rArray, sal_Int32 nLen ) 90 { 91 TypeClass eTC = rArray.getValueTypeClass(); 92 if (eTC != TypeClass_SEQUENCE && eTC != TypeClass_ARRAY) 93 { 94 throw IllegalArgumentException( 95 OUString( RTL_CONSTASCII_USTRINGPARAM("no sequence given!") ), 96 (XWeak *)(OWeakObject *)this, 0 ); 97 } 98 if (nLen < 0) 99 { 100 throw IllegalArgumentException( 101 OUString( RTL_CONSTASCII_USTRINGPARAM("illegal length given!") ), 102 (XWeak *)(OWeakObject *)this, 1 ); 103 } 104 105 uno_Sequence ** ppSeq = (uno_Sequence **)rArray.getValue(); 106 uno_sequence_realloc( ppSeq, (typelib_TypeDescription *)getTypeDescr(), 107 nLen, 108 reinterpret_cast< uno_AcquireFunc >(cpp_acquire), 109 reinterpret_cast< uno_ReleaseFunc >(cpp_release) ); 110 rArray.pData = ppSeq; 111 } 112 //__________________________________________________________________________________________________ 113 sal_Int32 ArrayIdlClassImpl::getLen( const Any & rArray ) 114 { 115 TypeClass eTC = rArray.getValueTypeClass(); 116 if (eTC != TypeClass_SEQUENCE && eTC != TypeClass_ARRAY) 117 { 118 throw IllegalArgumentException( 119 OUString( RTL_CONSTASCII_USTRINGPARAM("no sequence given!") ), 120 (XWeak *)(OWeakObject *)this, 0 ); 121 } 122 123 return (*(uno_Sequence **)rArray.getValue())->nElements; 124 } 125 //__________________________________________________________________________________________________ 126 Any ArrayIdlClassImpl::get( const Any & rArray, sal_Int32 nIndex ) 127 { 128 TypeClass eTC = rArray.getValueTypeClass(); 129 if (eTC != TypeClass_SEQUENCE && eTC != TypeClass_ARRAY) 130 { 131 throw IllegalArgumentException( 132 OUString( RTL_CONSTASCII_USTRINGPARAM("no sequence given!") ), 133 (XWeak *)(OWeakObject *)this, 0 ); 134 } 135 136 uno_Sequence * pSeq = *(uno_Sequence **)rArray.getValue(); 137 if (pSeq->nElements <= nIndex) 138 { 139 throw ArrayIndexOutOfBoundsException( 140 OUString( RTL_CONSTASCII_USTRINGPARAM("illegal index given!") ), 141 (XWeak *)(OWeakObject *)this ); 142 } 143 144 Any aRet; 145 typelib_TypeDescription * pElemTypeDescr = 0; 146 TYPELIB_DANGER_GET( &pElemTypeDescr, getTypeDescr()->pType ); 147 uno_any_destruct( &aRet, reinterpret_cast< uno_ReleaseFunc >(cpp_release) ); 148 uno_any_construct( &aRet, &pSeq->elements[nIndex * pElemTypeDescr->nSize], 149 pElemTypeDescr, 150 reinterpret_cast< uno_AcquireFunc >(cpp_acquire) ); 151 TYPELIB_DANGER_RELEASE( pElemTypeDescr ); 152 return aRet; 153 } 154 155 //__________________________________________________________________________________________________ 156 void ArrayIdlClassImpl::set( Any & rArray, sal_Int32 nIndex, const Any & rNewValue ) 157 { 158 TypeClass eTC = rArray.getValueTypeClass(); 159 if (eTC != TypeClass_SEQUENCE && eTC != TypeClass_ARRAY) 160 { 161 throw IllegalArgumentException( 162 OUString( RTL_CONSTASCII_USTRINGPARAM("no sequence given!") ), 163 (XWeak *)(OWeakObject *)this, 0 ); 164 } 165 166 uno_Sequence * pSeq = *(uno_Sequence **)rArray.getValue(); 167 if (pSeq->nElements <= nIndex) 168 { 169 throw ArrayIndexOutOfBoundsException( 170 OUString( RTL_CONSTASCII_USTRINGPARAM("illegal index given!") ), 171 (XWeak *)(OWeakObject *)this ); 172 } 173 174 uno_Sequence ** ppSeq = (uno_Sequence **)rArray.getValue(); 175 uno_sequence_reference2One( 176 ppSeq, (typelib_TypeDescription *)getTypeDescr(), 177 reinterpret_cast< uno_AcquireFunc >(cpp_acquire), 178 reinterpret_cast< uno_ReleaseFunc >(cpp_release) ); 179 rArray.pData = ppSeq; 180 pSeq = *ppSeq; 181 182 typelib_TypeDescription * pElemTypeDescr = 0; 183 TYPELIB_DANGER_GET( &pElemTypeDescr, getTypeDescr()->pType ); 184 185 if (! coerce_assign( &pSeq->elements[nIndex * pElemTypeDescr->nSize], 186 pElemTypeDescr, rNewValue, getReflection() )) 187 { 188 TYPELIB_DANGER_RELEASE( pElemTypeDescr ); 189 throw IllegalArgumentException( 190 OUString( RTL_CONSTASCII_USTRINGPARAM("sequence element is not assignable by given value!") ), 191 (XWeak *)(OWeakObject *)this, 2 ); 192 } 193 TYPELIB_DANGER_RELEASE( pElemTypeDescr ); 194 } 195 196 // ArrayIdlClassImpl 197 //__________________________________________________________________________________________________ 198 sal_Bool ArrayIdlClassImpl::isAssignableFrom( const Reference< XIdlClass > & xType ) 199 { 200 return (xType.is() && 201 (equals( xType ) || 202 (xType->getTypeClass() == getTypeClass() && // must be sequence|array 203 getComponentType()->isAssignableFrom( xType->getComponentType() )))); 204 } 205 //__________________________________________________________________________________________________ 206 Reference< XIdlClass > ArrayIdlClassImpl::getComponentType() 207 { 208 return getReflection()->forType( getTypeDescr()->pType ); 209 } 210 //__________________________________________________________________________________________________ 211 Reference< XIdlArray > ArrayIdlClassImpl::getArray() 212 { 213 return this; 214 } 215 216 } 217