LCOV - code coverage report
Current view: top level - stoc/source/corereflection - crenum.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 3 69 4.3 %
Date: 2015-06-13 12:38:46 Functions: 2 20 10.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 "base.hxx"
      21             : 
      22             : #include <cppuhelper/queryinterface.hxx>
      23             : 
      24             : using namespace css::lang;
      25             : using namespace css::reflection;
      26             : using namespace css::uno;
      27             : 
      28             : namespace stoc_corefl
      29             : {
      30             : 
      31             : 
      32             : class IdlEnumFieldImpl
      33             :     : public IdlMemberImpl
      34             :     , public XIdlField
      35             :     , public XIdlField2
      36             : {
      37             :     sal_Int32               _nValue;
      38             : 
      39             : public:
      40           0 :     IdlEnumFieldImpl( IdlReflectionServiceImpl * pReflection, const OUString & rName,
      41             :                       typelib_TypeDescription * pTypeDescr, sal_Int32 nValue )
      42             :         : IdlMemberImpl( pReflection, rName, pTypeDescr, pTypeDescr )
      43           0 :         , _nValue( nValue )
      44           0 :         {}
      45             :     virtual ~IdlEnumFieldImpl();
      46             : 
      47             :     // XInterface
      48             :     virtual Any SAL_CALL queryInterface( const Type & rType ) throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      49             :     virtual void SAL_CALL acquire() throw() SAL_OVERRIDE;
      50             :     virtual void SAL_CALL release() throw() SAL_OVERRIDE;
      51             : 
      52             :     // XTypeProvider
      53             :     virtual Sequence< Type > SAL_CALL getTypes() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      54             :     virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      55             : 
      56             :     // XIdlMember
      57             :     virtual Reference< XIdlClass > SAL_CALL getDeclaringClass() throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      58             :     virtual OUString SAL_CALL getName() throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      59             :     // XIdlField
      60             :     virtual Reference< XIdlClass > SAL_CALL getType() throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      61             :     virtual FieldAccessMode SAL_CALL getAccessMode() throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      62             :     virtual Any SAL_CALL get( const Any & rObj ) throw(css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      63             :     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;
      64             :     // XIdlField2: getType, getAccessMode and get are equal to XIdlField
      65             :     virtual void SAL_CALL set( Any & rObj, const Any & rValue ) throw(css::lang::IllegalArgumentException, css::lang::IllegalAccessException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      66             : };
      67             : 
      68           0 : IdlEnumFieldImpl::~IdlEnumFieldImpl()
      69             : {
      70           0 : }
      71             : 
      72             : // XInterface
      73             : 
      74           0 : Any IdlEnumFieldImpl::queryInterface( const Type & rType )
      75             :     throw(css::uno::RuntimeException, std::exception)
      76             : {
      77             :     Any aRet( ::cppu::queryInterface( rType,
      78             :                                       static_cast< XIdlField * >( this ),
      79           0 :                                       static_cast< XIdlField2 * >( this ) ) );
      80           0 :     return (aRet.hasValue() ? aRet : IdlMemberImpl::queryInterface( rType ));
      81             : }
      82             : 
      83           0 : void IdlEnumFieldImpl::acquire() throw()
      84             : {
      85           0 :     IdlMemberImpl::acquire();
      86           0 : }
      87             : 
      88           0 : void IdlEnumFieldImpl::release() throw()
      89             : {
      90           0 :     IdlMemberImpl::release();
      91           0 : }
      92             : 
      93             : // XTypeProvider
      94             : 
      95           0 : Sequence< Type > IdlEnumFieldImpl::getTypes()
      96             :     throw (css::uno::RuntimeException, std::exception)
      97             : {
      98             :     static ::cppu::OTypeCollection * s_pTypes = 0;
      99           0 :     if (! s_pTypes)
     100             :     {
     101           0 :         ::osl::MutexGuard aGuard( getMutexAccess() );
     102           0 :         if (! s_pTypes)
     103             :         {
     104             :             static ::cppu::OTypeCollection s_aTypes(
     105           0 :                 cppu::UnoType<XIdlField2>::get(),
     106           0 :                 cppu::UnoType<XIdlField>::get(),
     107           0 :                 IdlMemberImpl::getTypes() );
     108           0 :             s_pTypes = &s_aTypes;
     109           0 :         }
     110             :     }
     111           0 :     return s_pTypes->getTypes();
     112             : }
     113             : 
     114           0 : Sequence< sal_Int8 > IdlEnumFieldImpl::getImplementationId()
     115             :     throw (css::uno::RuntimeException, std::exception)
     116             : {
     117           0 :     return css::uno::Sequence<sal_Int8>();
     118             : }
     119             : 
     120             : // XIdlMember
     121             : 
     122           0 : Reference< XIdlClass > IdlEnumFieldImpl::getDeclaringClass()
     123             :     throw(css::uno::RuntimeException, std::exception)
     124             : {
     125           0 :     return IdlMemberImpl::getDeclaringClass();
     126             : }
     127             : 
     128           0 : OUString IdlEnumFieldImpl::getName()
     129             :     throw(css::uno::RuntimeException, std::exception)
     130             : {
     131           0 :     return IdlMemberImpl::getName();
     132             : }
     133             : 
     134             : // XIdlField
     135             : 
     136           0 : Reference< XIdlClass > IdlEnumFieldImpl::getType()
     137             :     throw(css::uno::RuntimeException, std::exception)
     138             : {
     139           0 :     return getDeclaringClass();
     140             : }
     141             : 
     142           0 : FieldAccessMode IdlEnumFieldImpl::getAccessMode()
     143             :     throw(css::uno::RuntimeException, std::exception)
     144             : {
     145           0 :     return FieldAccessMode_READONLY;
     146             : }
     147             : 
     148           0 : Any IdlEnumFieldImpl::get( const Any & )
     149             :     throw(css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception)
     150             : {
     151           0 :     return Any( &_nValue, getTypeDescr() );
     152             : }
     153             : 
     154           0 : void IdlEnumFieldImpl::set( const Any &, const Any & )
     155             :     throw(css::lang::IllegalArgumentException, css::lang::IllegalAccessException, css::uno::RuntimeException, std::exception)
     156             : {
     157             :     throw IllegalAccessException(
     158             :         "enum field is constant!",
     159           0 :         static_cast<XWeak *>(static_cast<OWeakObject *>(this)) );
     160             : }
     161             : 
     162           0 : void IdlEnumFieldImpl::set( Any &, const Any & )
     163             :     throw(css::lang::IllegalArgumentException, css::lang::IllegalAccessException, css::uno::RuntimeException, std::exception)
     164             : {
     165             :     throw IllegalAccessException(
     166             :         "enum field is constant!",
     167           0 :         static_cast<XWeak *>(static_cast<OWeakObject *>(this)) );
     168             : }
     169             : 
     170             : 
     171             : 
     172             : 
     173             : 
     174             : 
     175             : 
     176          21 : EnumIdlClassImpl::~EnumIdlClassImpl()
     177             : {
     178           7 :     delete _pFields;
     179          14 : }
     180             : 
     181             : // IdlClassImpl modifications
     182             : 
     183           0 : Reference< XIdlField > EnumIdlClassImpl::getField( const OUString & rName )
     184             :     throw(css::uno::RuntimeException, std::exception)
     185             : {
     186           0 :     if (! _pFields)
     187           0 :         getFields(); // init members
     188             : 
     189           0 :     const OUString2Field::const_iterator iFind( _aName2Field.find( rName ) );
     190           0 :     if (iFind != _aName2Field.end())
     191           0 :         return (*iFind).second;
     192             :     else
     193           0 :         return Reference< XIdlField >();
     194             : }
     195             : 
     196           0 : Sequence< Reference< XIdlField > > EnumIdlClassImpl::getFields()
     197             :     throw(css::uno::RuntimeException, std::exception)
     198             : {
     199           0 :     if (! _pFields)
     200             :     {
     201           0 :         ::osl::MutexGuard aGuard( getMutexAccess() );
     202           0 :         if (! _pFields)
     203             :         {
     204           0 :             sal_Int32 nFields = getTypeDescr()->nEnumValues;
     205             :             Sequence< Reference< XIdlField > > * pFields =
     206           0 :                 new Sequence< Reference< XIdlField > >( nFields );
     207           0 :             Reference< XIdlField > * pSeq = pFields->getArray();
     208             : 
     209           0 :             while (nFields--)
     210             :             {
     211           0 :                 OUString aName( getTypeDescr()->ppEnumNames[nFields] );
     212           0 :                 _aName2Field[aName] = pSeq[nFields] = new IdlEnumFieldImpl(
     213           0 :                     getReflection(), aName, IdlClassImpl::getTypeDescr(), getTypeDescr()->pEnumValues[nFields] );
     214           0 :             }
     215             : 
     216           0 :             _pFields = pFields;
     217           0 :         }
     218             :     }
     219           0 :     return *_pFields;
     220             : }
     221             : 
     222           0 : void EnumIdlClassImpl::createObject( Any & rObj )
     223             :     throw(css::uno::RuntimeException, std::exception)
     224             : {
     225             :     sal_Int32 eVal =
     226           0 :         reinterpret_cast<typelib_EnumTypeDescription *>(IdlClassImpl::getTypeDescr())->nDefaultEnumValue;
     227           0 :     rObj.setValue( &eVal, IdlClassImpl::getTypeDescr() );
     228           0 : }
     229             : 
     230             : }
     231             : 
     232             : 
     233             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11