LCOV - code coverage report
Current view: top level - libreoffice/stoc/source/corereflection - crarray.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 6 86 7.0 %
Date: 2012-12-27 Functions: 2 12 16.7 %
Legend: Lines: hit not hit

          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        5850 : void ArrayIdlClassImpl::acquire() throw()
      39             : {
      40        5850 :     IdlClassImpl::acquire();
      41        5850 : }
      42             : //__________________________________________________________________________________________________
      43        5681 : void ArrayIdlClassImpl::release() throw()
      44             : {
      45        5681 :     IdlClassImpl::release();
      46        5681 : }
      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           0 : void ArrayIdlClassImpl::realloc( Any & rArray, sal_Int32 nLen )
      87             :     throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
      88             : {
      89           0 :     TypeClass eTC = rArray.getValueTypeClass();
      90           0 :     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           0 :     if (nLen < 0)
      97             :     {
      98             :         throw IllegalArgumentException(
      99             :             OUString( RTL_CONSTASCII_USTRINGPARAM("illegal length given!") ),
     100           0 :             (XWeak *)(OWeakObject *)this, 1 );
     101             :     }
     102             : 
     103           0 :     uno_Sequence ** ppSeq = (uno_Sequence **)rArray.getValue();
     104           0 :     uno_sequence_realloc( ppSeq, (typelib_TypeDescription *)getTypeDescr(),
     105             :                           nLen,
     106             :                           reinterpret_cast< uno_AcquireFunc >(cpp_acquire),
     107           0 :                           reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
     108           0 :     rArray.pData = ppSeq;
     109           0 : }
     110             : //__________________________________________________________________________________________________
     111           0 : sal_Int32 ArrayIdlClassImpl::getLen( const Any & rArray )
     112             :     throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
     113             : {
     114           0 :     TypeClass eTC = rArray.getValueTypeClass();
     115           0 :     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           0 :     return (*(uno_Sequence **)rArray.getValue())->nElements;
     123             : }
     124             : //__________________________________________________________________________________________________
     125           0 : 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           0 :     TypeClass eTC = rArray.getValueTypeClass();
     129           0 :     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           0 :     uno_Sequence * pSeq = *(uno_Sequence **)rArray.getValue();
     137           0 :     if (pSeq->nElements <= nIndex)
     138             :     {
     139             :         throw ArrayIndexOutOfBoundsException(
     140             :             OUString( RTL_CONSTASCII_USTRINGPARAM("illegal index given!") ),
     141           0 :             (XWeak *)(OWeakObject *)this );
     142             :     }
     143             : 
     144           0 :     Any aRet;
     145           0 :     typelib_TypeDescription * pElemTypeDescr = 0;
     146           0 :     TYPELIB_DANGER_GET( &pElemTypeDescr, getTypeDescr()->pType );
     147           0 :     uno_any_destruct( &aRet, reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
     148           0 :     uno_any_construct( &aRet, &pSeq->elements[nIndex * pElemTypeDescr->nSize],
     149             :                        pElemTypeDescr,
     150           0 :                        reinterpret_cast< uno_AcquireFunc >(cpp_acquire) );
     151           0 :     TYPELIB_DANGER_RELEASE( pElemTypeDescr );
     152           0 :     return aRet;
     153             : }
     154             : 
     155             : //__________________________________________________________________________________________________
     156           0 : 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           0 :     TypeClass eTC = rArray.getValueTypeClass();
     160           0 :     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           0 :     uno_Sequence * pSeq = *(uno_Sequence **)rArray.getValue();
     168           0 :     if (pSeq->nElements <= nIndex)
     169             :     {
     170             :         throw ArrayIndexOutOfBoundsException(
     171             :             OUString( RTL_CONSTASCII_USTRINGPARAM("illegal index given!") ),
     172           0 :             (XWeak *)(OWeakObject *)this );
     173             :     }
     174             : 
     175           0 :     uno_Sequence ** ppSeq = (uno_Sequence **)rArray.getValue();
     176             :     uno_sequence_reference2One(
     177           0 :         ppSeq, (typelib_TypeDescription *)getTypeDescr(),
     178             :         reinterpret_cast< uno_AcquireFunc >(cpp_acquire),
     179           0 :         reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
     180           0 :     rArray.pData = ppSeq;
     181           0 :     pSeq = *ppSeq;
     182             : 
     183           0 :     typelib_TypeDescription * pElemTypeDescr = 0;
     184           0 :     TYPELIB_DANGER_GET( &pElemTypeDescr, getTypeDescr()->pType );
     185             : 
     186           0 :     if (! coerce_assign( &pSeq->elements[nIndex * pElemTypeDescr->nSize],
     187           0 :                          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           0 :     TYPELIB_DANGER_RELEASE( pElemTypeDescr );
     195           0 : }
     196             : 
     197             : // ArrayIdlClassImpl
     198             : //__________________________________________________________________________________________________
     199           0 : sal_Bool ArrayIdlClassImpl::isAssignableFrom( const Reference< XIdlClass > & xType )
     200             :     throw(::com::sun::star::uno::RuntimeException)
     201             : {
     202           0 :     return (xType.is() &&
     203           0 :             (equals( xType ) ||
     204           0 :              (xType->getTypeClass() == getTypeClass() && // must be sequence|array
     205           0 :               getComponentType()->isAssignableFrom( xType->getComponentType() ))));
     206             : }
     207             : //__________________________________________________________________________________________________
     208           0 : Reference< XIdlClass > ArrayIdlClassImpl::getComponentType()
     209             :     throw(::com::sun::star::uno::RuntimeException)
     210             : {
     211           0 :     return getReflection()->forType( getTypeDescr()->pType );
     212             : }
     213             : //__________________________________________________________________________________________________
     214           0 : Reference< XIdlArray > ArrayIdlClassImpl::getArray()
     215             :     throw(::com::sun::star::uno::RuntimeException)
     216             : {
     217           0 :     return this;
     218             : }
     219             : 
     220             : }
     221             : 
     222             : 
     223             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10