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

Generated by: LCOV version 1.10