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