LCOV - code coverage report
Current view: top level - stoc/source/corereflection - crarray.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 57 80 71.2 %
Date: 2014-04-11 Functions: 9 12 75.0 %
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, std::exception)
      33             : {
      34           0 :     Any aRet( ::cppu::queryInterface( rType, static_cast< XIdlArray * >( this ) ) );
      35           0 :     return (aRet.hasValue() ? aRet : IdlClassImpl::queryInterface( rType ));
      36             : }
      37             : 
      38       15153 : void ArrayIdlClassImpl::acquire() throw()
      39             : {
      40       15153 :     IdlClassImpl::acquire();
      41       15153 : }
      42             : 
      43       14835 : void ArrayIdlClassImpl::release() throw()
      44             : {
      45       14835 :     IdlClassImpl::release();
      46       14835 : }
      47             : 
      48             : // XTypeProvider
      49             : 
      50           0 : Sequence< Type > ArrayIdlClassImpl::getTypes()
      51             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
      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, std::exception)
      70             : {
      71           0 :     return css::uno::Sequence<sal_Int8>();
      72             : }
      73             : 
      74             : // XIdlArray
      75             : 
      76          45 : void ArrayIdlClassImpl::realloc( Any & rArray, sal_Int32 nLen )
      77             :     throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception)
      78             : {
      79          45 :     TypeClass eTC = rArray.getValueTypeClass();
      80          45 :     if (eTC != TypeClass_SEQUENCE)
      81             :     {
      82             :         throw IllegalArgumentException(
      83             :             OUString("no sequence given!"),
      84           0 :             (XWeak *)(OWeakObject *)this, 0 );
      85             :     }
      86          45 :     if (nLen < 0)
      87             :     {
      88             :         throw IllegalArgumentException(
      89             :             OUString("illegal length given!"),
      90           0 :             (XWeak *)(OWeakObject *)this, 1 );
      91             :     }
      92             : 
      93          45 :     uno_Sequence ** ppSeq = (uno_Sequence **)rArray.getValue();
      94          45 :     uno_sequence_realloc( ppSeq, (typelib_TypeDescription *)getTypeDescr(),
      95             :                           nLen,
      96             :                           reinterpret_cast< uno_AcquireFunc >(cpp_acquire),
      97          45 :                           reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
      98          45 :     rArray.pData = ppSeq;
      99          45 : }
     100             : 
     101         152 : sal_Int32 ArrayIdlClassImpl::getLen( const Any & rArray )
     102             :     throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception)
     103             : {
     104         152 :     TypeClass eTC = rArray.getValueTypeClass();
     105         152 :     if (eTC != TypeClass_SEQUENCE)
     106             :     {
     107             :         throw IllegalArgumentException(
     108             :             OUString("no sequence given!"),
     109           0 :             (XWeak *)(OWeakObject *)this, 0 );
     110             :     }
     111             : 
     112         152 :     return (*(uno_Sequence **)rArray.getValue())->nElements;
     113             : }
     114             : 
     115        3541 : Any ArrayIdlClassImpl::get( const Any & rArray, sal_Int32 nIndex )
     116             :     throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::ArrayIndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception)
     117             : {
     118        3541 :     TypeClass eTC = rArray.getValueTypeClass();
     119        3541 :     if (eTC != TypeClass_SEQUENCE)
     120             :     {
     121             :         throw IllegalArgumentException(
     122             :             OUString("no sequence given!"),
     123           0 :             (XWeak *)(OWeakObject *)this, 0 );
     124             :     }
     125             : 
     126        3541 :     uno_Sequence * pSeq = *(uno_Sequence **)rArray.getValue();
     127        3541 :     if (pSeq->nElements <= nIndex)
     128             :     {
     129             :         throw ArrayIndexOutOfBoundsException(
     130             :             OUString("illegal index given!"),
     131           0 :             (XWeak *)(OWeakObject *)this );
     132             :     }
     133             : 
     134        3541 :     Any aRet;
     135        3541 :     typelib_TypeDescription * pElemTypeDescr = 0;
     136        3541 :     TYPELIB_DANGER_GET( &pElemTypeDescr, getTypeDescr()->pType );
     137        3541 :     uno_any_destruct( &aRet, reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
     138        3541 :     uno_any_construct( &aRet, &pSeq->elements[nIndex * pElemTypeDescr->nSize],
     139             :                        pElemTypeDescr,
     140        7082 :                        reinterpret_cast< uno_AcquireFunc >(cpp_acquire) );
     141        3541 :     TYPELIB_DANGER_RELEASE( pElemTypeDescr );
     142        3541 :     return aRet;
     143             : }
     144             : 
     145             : 
     146          81 : void ArrayIdlClassImpl::set( Any & rArray, sal_Int32 nIndex, const Any & rNewValue )
     147             :     throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::ArrayIndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception)
     148             : {
     149          81 :     TypeClass eTC = rArray.getValueTypeClass();
     150          81 :     if (eTC != TypeClass_SEQUENCE)
     151             :     {
     152             :         throw IllegalArgumentException(
     153             :             OUString("no sequence given!"),
     154           0 :             (XWeak *)(OWeakObject *)this, 0 );
     155             :     }
     156             : 
     157          81 :     uno_Sequence * pSeq = *(uno_Sequence **)rArray.getValue();
     158          81 :     if (pSeq->nElements <= nIndex)
     159             :     {
     160             :         throw ArrayIndexOutOfBoundsException(
     161             :             OUString("illegal index given!"),
     162           0 :             (XWeak *)(OWeakObject *)this );
     163             :     }
     164             : 
     165          81 :     uno_Sequence ** ppSeq = (uno_Sequence **)rArray.getValue();
     166             :     uno_sequence_reference2One(
     167          81 :         ppSeq, (typelib_TypeDescription *)getTypeDescr(),
     168             :         reinterpret_cast< uno_AcquireFunc >(cpp_acquire),
     169          81 :         reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
     170          81 :     rArray.pData = ppSeq;
     171          81 :     pSeq = *ppSeq;
     172             : 
     173          81 :     typelib_TypeDescription * pElemTypeDescr = 0;
     174          81 :     TYPELIB_DANGER_GET( &pElemTypeDescr, getTypeDescr()->pType );
     175             : 
     176         162 :     if (! coerce_assign( &pSeq->elements[nIndex * pElemTypeDescr->nSize],
     177         162 :                          pElemTypeDescr, rNewValue, getReflection() ))
     178             :     {
     179           0 :         TYPELIB_DANGER_RELEASE( pElemTypeDescr );
     180             :         throw IllegalArgumentException(
     181             :             OUString("sequence element is not assignable by given value!"),
     182           0 :             (XWeak *)(OWeakObject *)this, 2 );
     183             :     }
     184          81 :     TYPELIB_DANGER_RELEASE( pElemTypeDescr );
     185          81 : }
     186             : 
     187             : // ArrayIdlClassImpl
     188             : 
     189           9 : sal_Bool ArrayIdlClassImpl::isAssignableFrom( const Reference< XIdlClass > & xType )
     190             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     191             : {
     192          18 :     return (xType.is() &&
     193          18 :             (equals( xType ) ||
     194          36 :              (xType->getTypeClass() == getTypeClass() && // must be sequence|array
     195          36 :               getComponentType()->isAssignableFrom( xType->getComponentType() ))));
     196             : }
     197             : 
     198          18 : Reference< XIdlClass > ArrayIdlClassImpl::getComponentType()
     199             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     200             : {
     201          18 :     return getReflection()->forType( getTypeDescr()->pType );
     202             : }
     203             : 
     204         197 : Reference< XIdlArray > ArrayIdlClassImpl::getArray()
     205             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     206             : {
     207         197 :     return this;
     208             : }
     209             : 
     210             : }
     211             : 
     212             : 
     213             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10