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

Generated by: LCOV version 1.10