LCOV - code coverage report
Current view: top level - stoc/source/corereflection - crcomp.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 77 150 51.3 %
Date: 2015-06-13 12:38:46 Functions: 15 21 71.4 %
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 <rtl/strbuf.hxx>
      21             : #include <cppuhelper/queryinterface.hxx>
      22             : 
      23             : #include <com/sun/star/reflection/XIdlField.hpp>
      24             : #include <com/sun/star/reflection/XIdlField2.hpp>
      25             : #include <com/sun/star/uno/TypeClass.hpp>
      26             : 
      27             : #include "base.hxx"
      28             : 
      29             : using namespace css::lang;
      30             : using namespace css::reflection;
      31             : using namespace css::uno;
      32             : 
      33             : namespace stoc_corefl
      34             : {
      35             : 
      36             : 
      37         164 : class IdlCompFieldImpl
      38             :     : public IdlMemberImpl
      39             :     , public XIdlField
      40             :     , public XIdlField2
      41             : {
      42             :     sal_Int32                   _nOffset;
      43             : 
      44             : public:
      45         157 :     IdlCompFieldImpl( IdlReflectionServiceImpl * pReflection, const OUString & rName,
      46             :                       typelib_TypeDescription * pTypeDescr, typelib_TypeDescription * pDeclTypeDescr,
      47             :                       sal_Int32 nOffset )
      48             :         : IdlMemberImpl( pReflection, rName, pTypeDescr, pDeclTypeDescr )
      49         157 :         , _nOffset( nOffset )
      50         157 :         {}
      51             : 
      52             :     // XInterface
      53             :     virtual Any SAL_CALL queryInterface( const Type & rType ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      54             :     virtual void SAL_CALL acquire() throw () SAL_OVERRIDE;
      55             :     virtual void SAL_CALL release() throw () SAL_OVERRIDE;
      56             : 
      57             :     // XTypeProvider
      58             :     virtual Sequence< Type > SAL_CALL getTypes() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      59             :     virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      60             : 
      61             :     // XIdlMember
      62             :     virtual Reference< XIdlClass > SAL_CALL getDeclaringClass() throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      63             :     virtual OUString SAL_CALL getName() throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      64             :     // XIdlField
      65             :     virtual Reference< XIdlClass > SAL_CALL getType() throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      66             :     virtual FieldAccessMode SAL_CALL getAccessMode() throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      67             :     virtual Any SAL_CALL get( const Any & rObj ) throw(css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      68             :     virtual void SAL_CALL set( const Any & rObj, const Any & rValue ) throw(css::lang::IllegalArgumentException, css::lang::IllegalAccessException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      69             :     // XIdlField2: getType, getAccessMode and get are equal to XIdlField
      70             :     virtual void SAL_CALL set( Any & rObj, const Any & rValue ) throw(css::lang::IllegalArgumentException, css::lang::IllegalAccessException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      71             : };
      72             : 
      73             : // XInterface
      74             : 
      75         296 : Any IdlCompFieldImpl::queryInterface( const Type & rType )
      76             :     throw(css::uno::RuntimeException, std::exception)
      77             : {
      78             :     Any aRet( ::cppu::queryInterface( rType,
      79             :                                       static_cast< XIdlField * >( this ),
      80         296 :                                       static_cast< XIdlField2 * >( this ) ) );
      81         296 :     return (aRet.hasValue() ? aRet : IdlMemberImpl::queryInterface( rType ));
      82             : }
      83             : 
      84        1483 : void IdlCompFieldImpl::acquire() throw()
      85             : {
      86        1483 :     IdlMemberImpl::acquire();
      87        1483 : }
      88             : 
      89        1333 : void IdlCompFieldImpl::release() throw()
      90             : {
      91        1333 :     IdlMemberImpl::release();
      92        1333 : }
      93             : 
      94             : // XTypeProvider
      95             : 
      96           0 : Sequence< Type > IdlCompFieldImpl::getTypes()
      97             :     throw (css::uno::RuntimeException, std::exception)
      98             : {
      99             :     static ::cppu::OTypeCollection * s_pTypes = 0;
     100           0 :     if (! s_pTypes)
     101             :     {
     102           0 :         ::osl::MutexGuard aGuard( getMutexAccess() );
     103           0 :         if (! s_pTypes)
     104             :         {
     105             :             static ::cppu::OTypeCollection s_aTypes(
     106           0 :                 cppu::UnoType<XIdlField2>::get(),
     107           0 :                 cppu::UnoType<XIdlField>::get(),
     108           0 :                 IdlMemberImpl::getTypes() );
     109           0 :             s_pTypes = &s_aTypes;
     110           0 :         }
     111             :     }
     112           0 :     return s_pTypes->getTypes();
     113             : }
     114             : 
     115           0 : Sequence< sal_Int8 > IdlCompFieldImpl::getImplementationId()
     116             :     throw (css::uno::RuntimeException, std::exception)
     117             : {
     118           0 :     return css::uno::Sequence<sal_Int8>();
     119             : }
     120             : 
     121             : // XIdlMember
     122             : 
     123           0 : Reference< XIdlClass > IdlCompFieldImpl::getDeclaringClass()
     124             :     throw(css::uno::RuntimeException, std::exception)
     125             : {
     126           0 :     if (! _xDeclClass.is())
     127             :     {
     128           0 :         ::osl::MutexGuard aGuard( getMutexAccess() );
     129           0 :         if (! _xDeclClass.is())
     130             :         {
     131             :             typelib_CompoundTypeDescription * pTD =
     132           0 :                 reinterpret_cast<typelib_CompoundTypeDescription *>(getDeclTypeDescr());
     133           0 :             while (pTD)
     134             :             {
     135           0 :                 typelib_TypeDescriptionReference ** ppTypeRefs = pTD->ppTypeRefs;
     136           0 :                 for ( sal_Int32 nPos = pTD->nMembers; nPos--; )
     137             :                 {
     138           0 :                     if (td_equals( getTypeDescr(), ppTypeRefs[nPos] ))
     139             :                     {
     140           0 :                         _xDeclClass = getReflection()->forType( &pTD->aBase );
     141           0 :                         return _xDeclClass;
     142             :                     }
     143             :                 }
     144           0 :                 pTD = pTD->pBaseTypeDescription;
     145             :             }
     146           0 :         }
     147             :     }
     148           0 :     return _xDeclClass;
     149             : }
     150             : 
     151         157 : OUString IdlCompFieldImpl::getName()
     152             :     throw(css::uno::RuntimeException, std::exception)
     153             : {
     154         157 :     return IdlMemberImpl::getName();
     155             : }
     156             : 
     157             : // XIdlField
     158             : 
     159         157 : Reference< XIdlClass > IdlCompFieldImpl::getType()
     160             :     throw(css::uno::RuntimeException, std::exception)
     161             : {
     162         157 :     return getReflection()->forType( getTypeDescr() );
     163             : }
     164             : 
     165         157 : FieldAccessMode IdlCompFieldImpl::getAccessMode()
     166             :     throw(css::uno::RuntimeException, std::exception)
     167             : {
     168         157 :     return FieldAccessMode_READWRITE;
     169             : }
     170             : 
     171         438 : Any IdlCompFieldImpl::get( const Any & rObj )
     172             :     throw(css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception)
     173             : {
     174         438 :     if (rObj.getValueTypeClass() == css::uno::TypeClass_STRUCT ||
     175           0 :         rObj.getValueTypeClass() == css::uno::TypeClass_EXCEPTION)
     176             :     {
     177         438 :         typelib_TypeDescription * pObjTD = 0;
     178         438 :         TYPELIB_DANGER_GET( &pObjTD, rObj.getValueTypeRef() );
     179             : 
     180         438 :         typelib_TypeDescription * pTD = pObjTD;
     181         438 :         typelib_TypeDescription * pDeclTD = getDeclTypeDescr();
     182         876 :         while (pTD && !typelib_typedescription_equals( pTD, pDeclTD ))
     183           0 :             pTD = &reinterpret_cast<typelib_CompoundTypeDescription *>(pTD)->pBaseTypeDescription->aBase;
     184             : 
     185             :         OSL_ENSURE( pTD, "### illegal object type!" );
     186         438 :         if (pTD)
     187             :         {
     188         438 :             TYPELIB_DANGER_RELEASE( pObjTD );
     189         438 :             Any aRet;
     190             :             uno_any_destruct(
     191         438 :                 &aRet, reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
     192             :             uno_any_construct(
     193         876 :                 &aRet, const_cast<char *>(static_cast<char const *>(rObj.getValue()) + _nOffset), getTypeDescr(),
     194        1314 :                 reinterpret_cast< uno_AcquireFunc >(cpp_acquire) );
     195         876 :             return aRet;
     196             :         }
     197           0 :         TYPELIB_DANGER_RELEASE( pObjTD );
     198             :     }
     199             :     throw IllegalArgumentException(
     200             :         "illegal object given!",
     201           0 :         static_cast<XWeak *>(static_cast<OWeakObject *>(this)), 0 );
     202             : }
     203             : 
     204           0 : void IdlCompFieldImpl::set( const Any & rObj, const Any & rValue )
     205             :     throw(css::lang::IllegalArgumentException, css::lang::IllegalAccessException, css::uno::RuntimeException, std::exception)
     206             : {
     207           0 :     if (rObj.getValueTypeClass() == css::uno::TypeClass_STRUCT ||
     208           0 :         rObj.getValueTypeClass() == css::uno::TypeClass_EXCEPTION)
     209             :     {
     210           0 :         typelib_TypeDescription * pObjTD = 0;
     211           0 :         TYPELIB_DANGER_GET( &pObjTD, rObj.getValueTypeRef() );
     212             : 
     213           0 :         typelib_TypeDescription * pTD = pObjTD;
     214           0 :         typelib_TypeDescription * pDeclTD = getDeclTypeDescr();
     215           0 :         while (pTD && !typelib_typedescription_equals( pTD, pDeclTD ))
     216           0 :             pTD = &reinterpret_cast<typelib_CompoundTypeDescription *>(pTD)->pBaseTypeDescription->aBase;
     217             : 
     218             :         OSL_ENSURE( pTD, "### illegal object type!" );
     219           0 :         if (pTD)
     220             :         {
     221           0 :             TYPELIB_DANGER_RELEASE( pObjTD );
     222           0 :             if (coerce_assign( const_cast<char *>(static_cast<char const *>(rObj.getValue()) + _nOffset), getTypeDescr(), rValue, getReflection() ))
     223             :             {
     224           0 :                 return;
     225             :             }
     226             :             else
     227             :             {
     228             :                 throw IllegalArgumentException(
     229             :                     "illegal value given!",
     230           0 :                     static_cast<XWeak *>(static_cast<OWeakObject *>(this)), 1 );
     231             :             }
     232             :         }
     233           0 :         TYPELIB_DANGER_RELEASE( pObjTD );
     234             :     }
     235             :     throw IllegalArgumentException(
     236             :         "illegal object given!",
     237           0 :         static_cast<XWeak *>(static_cast<OWeakObject *>(this)), 0 );
     238             : }
     239             : 
     240             : 
     241         139 : void IdlCompFieldImpl::set( Any & rObj, const Any & rValue )
     242             :     throw(css::lang::IllegalArgumentException, css::lang::IllegalAccessException, css::uno::RuntimeException, std::exception)
     243             : {
     244         139 :     if (rObj.getValueTypeClass() == css::uno::TypeClass_STRUCT ||
     245           0 :         rObj.getValueTypeClass() == css::uno::TypeClass_EXCEPTION)
     246             :     {
     247         139 :         typelib_TypeDescription * pObjTD = 0;
     248         139 :         TYPELIB_DANGER_GET( &pObjTD, rObj.getValueTypeRef() );
     249             : 
     250         139 :         typelib_TypeDescription * pTD = pObjTD;
     251         139 :         typelib_TypeDescription * pDeclTD = getDeclTypeDescr();
     252         278 :         while (pTD && !typelib_typedescription_equals( pTD, pDeclTD ))
     253           0 :             pTD = &reinterpret_cast<typelib_CompoundTypeDescription *>(pTD)->pBaseTypeDescription->aBase;
     254             : 
     255             :         OSL_ENSURE( pTD, "### illegal object type!" );
     256         139 :         if (pTD)
     257             :         {
     258         139 :             TYPELIB_DANGER_RELEASE( pObjTD );
     259         139 :             if (coerce_assign( const_cast<char *>(static_cast<char const *>(rObj.getValue()) + _nOffset), getTypeDescr(), rValue, getReflection() ))
     260             :             {
     261         278 :                 return;
     262             :             }
     263             :             else
     264             :             {
     265             :                 throw IllegalArgumentException(
     266             :                     "illegal value given!",
     267           0 :                     static_cast<XWeak *>(static_cast<OWeakObject *>(this)), 1 );
     268             :             }
     269             :         }
     270           0 :         TYPELIB_DANGER_RELEASE( pObjTD );
     271             :     }
     272             :     throw IllegalArgumentException(
     273             :         "illegal object given!",
     274           0 :         static_cast<XWeak *>(static_cast<OWeakObject *>(this)), 0 );
     275             : }
     276             : 
     277             : 
     278             : 
     279             : 
     280             : 
     281             : 
     282             : 
     283        1059 : CompoundIdlClassImpl::~CompoundIdlClassImpl()
     284             : {
     285         353 :     delete _pFields;
     286         706 : }
     287             : 
     288             : 
     289          19 : sal_Bool CompoundIdlClassImpl::isAssignableFrom( const Reference< XIdlClass > & xType )
     290             :     throw(css::uno::RuntimeException, std::exception)
     291             : {
     292          19 :     if (xType.is())
     293             :     {
     294          19 :         TypeClass eTC = xType->getTypeClass();
     295          19 :         if (eTC == TypeClass_STRUCT || eTC == TypeClass_EXCEPTION)
     296             :         {
     297           7 :             if (equals( xType ))
     298           7 :                 return sal_True;
     299             :             else
     300             :             {
     301           0 :                 const Sequence< Reference< XIdlClass > > & rSeq = xType->getSuperclasses();
     302           0 :                 if (rSeq.getLength())
     303             :                 {
     304             :                     OSL_ENSURE( rSeq.getLength() == 1, "### unexpected len of super classes!" );
     305           0 :                     return isAssignableFrom( rSeq[0] );
     306           0 :                 }
     307             :             }
     308             :         }
     309             :     }
     310          12 :     return sal_False;
     311             : }
     312             : 
     313           0 : Sequence< Reference< XIdlClass > > CompoundIdlClassImpl::getSuperclasses()
     314             :     throw(css::uno::RuntimeException, std::exception)
     315             : {
     316           0 :     if (! _xSuperClass.is())
     317             :     {
     318           0 :         ::osl::MutexGuard aGuard( getMutexAccess() );
     319           0 :         if (! _xSuperClass.is())
     320             :         {
     321           0 :             typelib_CompoundTypeDescription * pCompTypeDescr = getTypeDescr()->pBaseTypeDescription;
     322           0 :             if (pCompTypeDescr)
     323           0 :                 _xSuperClass = getReflection()->forType( &pCompTypeDescr->aBase );
     324           0 :         }
     325             :     }
     326           0 :     if (_xSuperClass.is())
     327           0 :         return Sequence< Reference< XIdlClass > >( &_xSuperClass, 1 );
     328             :     else
     329           0 :         return Sequence< Reference< XIdlClass > >();
     330             : }
     331             : 
     332           0 : Reference< XIdlField > CompoundIdlClassImpl::getField( const OUString & rName )
     333             :     throw(css::uno::RuntimeException, std::exception)
     334             : {
     335           0 :     if (! _pFields)
     336           0 :         getFields(); // init fields
     337             : 
     338           0 :     const OUString2Field::const_iterator iFind( _aName2Field.find( rName ) );
     339           0 :     if (iFind != _aName2Field.end())
     340           0 :         return Reference< XIdlField >( (*iFind).second );
     341             :     else
     342           0 :         return Reference< XIdlField >();
     343             : }
     344             : 
     345          35 : Sequence< Reference< XIdlField > > CompoundIdlClassImpl::getFields()
     346             :     throw(css::uno::RuntimeException, std::exception)
     347             : {
     348          35 :     ::osl::MutexGuard aGuard( getMutexAccess() );
     349          35 :     if (! _pFields)
     350             :     {
     351          35 :         sal_Int32 nAll = 0;
     352          35 :         typelib_CompoundTypeDescription * pCompTypeDescr = getTypeDescr();
     353          83 :         for ( ; pCompTypeDescr; pCompTypeDescr = pCompTypeDescr->pBaseTypeDescription )
     354          48 :             nAll += pCompTypeDescr->nMembers;
     355             : 
     356             :         Sequence< Reference< XIdlField > > * pFields =
     357          35 :             new Sequence< Reference< XIdlField > >( nAll );
     358          35 :         Reference< XIdlField > * pSeq = pFields->getArray();
     359             : 
     360          83 :         for ( pCompTypeDescr = getTypeDescr(); pCompTypeDescr;
     361             :               pCompTypeDescr = pCompTypeDescr->pBaseTypeDescription )
     362             :         {
     363          48 :             typelib_TypeDescriptionReference ** ppTypeRefs = pCompTypeDescr->ppTypeRefs;
     364          48 :             rtl_uString ** ppNames                         = pCompTypeDescr->ppMemberNames;
     365          48 :             sal_Int32 * pMemberOffsets                     = pCompTypeDescr->pMemberOffsets;
     366             : 
     367         253 :             for ( sal_Int32 nPos = pCompTypeDescr->nMembers; nPos--; )
     368             :             {
     369         157 :                 typelib_TypeDescription * pTD = 0;
     370         157 :                 TYPELIB_DANGER_GET( &pTD, ppTypeRefs[nPos] );
     371             :                 OSL_ENSURE( pTD, "### cannot get field in struct!" );
     372         157 :                 if (pTD)
     373             :                 {
     374         157 :                     OUString aName( ppNames[nPos] );
     375         628 :                     _aName2Field[aName] = pSeq[--nAll] = new IdlCompFieldImpl(
     376         785 :                         getReflection(), aName, pTD, IdlClassImpl::getTypeDescr(), pMemberOffsets[nPos] );
     377         157 :                     TYPELIB_DANGER_RELEASE( pTD );
     378             :                 }
     379             :             }
     380             :         }
     381             : 
     382          35 :         _pFields = pFields;
     383             :     }
     384          35 :     return *_pFields;
     385             : }
     386             : 
     387             : }
     388             : 
     389             : 
     390             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11