LCOV - code coverage report
Current view: top level - stoc/source/corereflection - crbase.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 64 90 71.1 %
Date: 2014-04-11 Functions: 14 25 56.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 <cppuhelper/queryinterface.hxx>
      21             : #include <uno/any2.h>
      22             : 
      23             : #include "base.hxx"
      24             : 
      25             : namespace stoc_corefl
      26             : {
      27             : 
      28             : #ifdef TEST_LIST_CLASSES
      29             : ClassNameList g_aClassNames;
      30             : #endif
      31             : 
      32             : 
      33      138625 : Mutex & getMutexAccess()
      34             : {
      35             :     static Mutex * s_pMutex = 0;
      36      138625 :     if (! s_pMutex)
      37             :     {
      38          72 :         MutexGuard aGuard( Mutex::getGlobalMutex() );
      39          72 :         if (! s_pMutex)
      40             :         {
      41          72 :             static Mutex s_aMutex;
      42          72 :             s_pMutex = &s_aMutex;
      43          72 :         }
      44             :     }
      45      138625 :     return *s_pMutex;
      46             : }
      47             : 
      48             : 
      49        8865 : IdlClassImpl::IdlClassImpl( IdlReflectionServiceImpl * pReflection,
      50             :                             const OUString & rName, typelib_TypeClass eTypeClass,
      51             :                             typelib_TypeDescription * pTypeDescr )
      52             :     : _pReflection( pReflection )
      53             :     , _aName( rName )
      54             :     , _eTypeClass( (TypeClass)eTypeClass )
      55        8865 :     , _pTypeDescr( pTypeDescr )
      56             : {
      57        8865 :     if (_pReflection)
      58        8865 :         _pReflection->acquire();
      59        8865 :     if (_pTypeDescr)
      60             :     {
      61        8865 :         typelib_typedescription_acquire( _pTypeDescr );
      62        8865 :         if (! _pTypeDescr->bComplete)
      63        7064 :             typelib_typedescription_complete( &_pTypeDescr );
      64             :     }
      65             : 
      66             : #ifdef TEST_LIST_CLASSES
      67             :     ClassNameList::const_iterator iFind( find( g_aClassNames.begin(), g_aClassNames.end(), _aName ) );
      68             :     OSL_ENSURE( iFind == g_aClassNames.end(), "### idl class already exists!" );
      69             :     g_aClassNames.push_front( _aName );
      70             : #endif
      71        8865 : }
      72             : 
      73       14463 : IdlClassImpl::~IdlClassImpl()
      74             : {
      75        7033 :     if (_pTypeDescr)
      76        7033 :         typelib_typedescription_release( _pTypeDescr );
      77        7033 :     if (_pReflection)
      78        7033 :         _pReflection->release();
      79             : 
      80             : #ifdef TEST_LIST_CLASSES
      81             :     ClassNameList::iterator iFind( find( g_aClassNames.begin(), g_aClassNames.end(), _aName ) );
      82             :     OSL_ENSURE( iFind != g_aClassNames.end(), "### idl class does not exist!" );
      83             :     g_aClassNames.erase( iFind );
      84             : #endif
      85        7430 : }
      86             : 
      87             : // XIdlClassImpl default implementation
      88             : 
      89       42462 : TypeClass IdlClassImpl::getTypeClass()
      90             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
      91             : {
      92       42462 :     return _eTypeClass;
      93             : }
      94             : 
      95      126001 : OUString IdlClassImpl::getName()
      96             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
      97             : {
      98      126001 :     return _aName;
      99             : }
     100             : 
     101       15262 : sal_Bool IdlClassImpl::equals( const Reference< XIdlClass >& xType )
     102             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     103             : {
     104       30524 :     return (xType.is() &&
     105       45099 :             (xType->getTypeClass() == _eTypeClass) && (xType->getName() == _aName));
     106             : }
     107             : 
     108             : static const sal_Bool s_aAssignableFromTab[11][11] =
     109             : {
     110             :                          /* from CH,BO,BY,SH,US,LO,UL,HY,UH,FL,DO */
     111             : /* TypeClass_CHAR */            { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     112             : /* TypeClass_BOOLEAN */         { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     113             : /* TypeClass_BYTE */            { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
     114             : /* TypeClass_SHORT */           { 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0 },
     115             : /* TypeClass_UNSIGNED_SHORT */  { 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0 },
     116             : /* TypeClass_LONG */            { 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0 },
     117             : /* TypeClass_UNSIGNED_LONG */   { 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0 },
     118             : /* TypeClass_HYPER */           { 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
     119             : /* TypeClass_UNSIGNED_HYPER */  { 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
     120             : /* TypeClass_FLOAT */           { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
     121             : /* TypeClass_DOUBLE */          { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
     122             : };
     123             : 
     124         466 : sal_Bool IdlClassImpl::isAssignableFrom( const Reference< XIdlClass > & xType )
     125             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     126             : {
     127         466 :     TypeClass eAssign = getTypeClass();
     128         466 :     if (equals( xType ) || eAssign == TypeClass_ANY) // default shot
     129             :     {
     130         381 :         return sal_True;
     131             :     }
     132             :     else
     133             :     {
     134          85 :         TypeClass eFrom   = xType->getTypeClass();
     135         153 :         if (eAssign > TypeClass_VOID && eAssign < TypeClass_STRING &&
     136         136 :             eFrom > TypeClass_VOID && eFrom < TypeClass_STRING)
     137             :         {
     138          68 :             return s_aAssignableFromTab[eAssign-1][eFrom-1];
     139             :         }
     140             :     }
     141          17 :     return sal_False;
     142             : }
     143             : 
     144         126 : void IdlClassImpl::createObject( Any & rObj )
     145             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     146             : {
     147         126 :     rObj.clear();
     148         126 :     uno_any_destruct( &rObj, reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
     149         126 :     uno_any_construct( &rObj, 0, getTypeDescr(), 0 );
     150         126 : }
     151             : 
     152             : // what TODO ????
     153             : 
     154           0 : Sequence< Reference< XIdlClass > > IdlClassImpl::getClasses()
     155             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     156             : {
     157             :     OSL_FAIL( "### unexpected use!" );
     158           0 :     return Sequence< Reference< XIdlClass > >();
     159             : }
     160             : 
     161           0 : Reference< XIdlClass > IdlClassImpl::getClass( const OUString & )
     162             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     163             : {
     164             :     OSL_FAIL( "### unexpected use!" );
     165           0 :     return Reference< XIdlClass >();
     166             : }
     167             : 
     168       22811 : Sequence< Reference< XIdlClass > > IdlClassImpl::getInterfaces()
     169             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     170             : {
     171             : //      OSL_FAIL( "### unexpected use!" );
     172       22811 :     return Sequence< Reference< XIdlClass > >();
     173             : }
     174             : 
     175             : // structs, interfaces
     176             : 
     177         550 : Sequence< Reference< XIdlClass > > IdlClassImpl::getSuperclasses() throw(::com::sun::star::uno::RuntimeException, std::exception)
     178             : {
     179         550 :     return Sequence< Reference< XIdlClass > >();
     180             : }
     181             : // structs
     182             : 
     183           0 : Reference< XIdlField > IdlClassImpl::getField( const OUString & )
     184             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     185             : {
     186           0 :     return Reference< XIdlField >();
     187             : }
     188             : 
     189           0 : Sequence< Reference< XIdlField > > IdlClassImpl::getFields()
     190             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     191             : {
     192           0 :     return Sequence< Reference< XIdlField > >();
     193             : }
     194             : // interfaces
     195             : 
     196           0 : Uik IdlClassImpl::getUik()
     197             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     198             : {
     199           0 :     return Uik();
     200             : }
     201             : 
     202           0 : Reference< XIdlMethod > IdlClassImpl::getMethod( const OUString & )
     203             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     204             : {
     205           0 :     return Reference< XIdlMethod >();
     206             : }
     207             : 
     208           0 : Sequence< Reference< XIdlMethod > > IdlClassImpl::getMethods()
     209             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     210             : {
     211           0 :     return Sequence< Reference< XIdlMethod > >();
     212             : }
     213             : // array
     214             : 
     215           0 : Reference< XIdlClass > IdlClassImpl::getComponentType()
     216             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     217             : {
     218           0 :     return Reference< XIdlClass >();
     219             : }
     220             : 
     221           0 : Reference< XIdlArray > IdlClassImpl::getArray()
     222             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     223             : {
     224           0 :     return Reference< XIdlArray >();
     225             : }
     226             : 
     227             : 
     228             : 
     229             : 
     230             : 
     231             : 
     232             : 
     233             : 
     234       73940 : IdlMemberImpl::IdlMemberImpl( IdlReflectionServiceImpl * pReflection, const OUString & rName,
     235             :                               typelib_TypeDescription * pTypeDescr,
     236             :                               typelib_TypeDescription * pDeclTypeDescr )
     237             :     : _pReflection( pReflection )
     238             :     , _aName( rName )
     239             :     , _pTypeDescr( pTypeDescr )
     240       73940 :     , _pDeclTypeDescr( pDeclTypeDescr )
     241             : {
     242       73940 :     _pReflection->acquire();
     243       73940 :     typelib_typedescription_acquire( _pTypeDescr );
     244       73940 :     if (! _pTypeDescr->bComplete)
     245           2 :         typelib_typedescription_complete( &_pTypeDescr );
     246       73940 :     typelib_typedescription_acquire( _pDeclTypeDescr );
     247       73940 :     if (! _pDeclTypeDescr->bComplete)
     248           0 :         typelib_typedescription_complete( &_pDeclTypeDescr );
     249       73940 : }
     250             : 
     251      135184 : IdlMemberImpl::~IdlMemberImpl()
     252             : {
     253       67592 :     typelib_typedescription_release( _pDeclTypeDescr );
     254       67592 :     typelib_typedescription_release( _pTypeDescr );
     255       67592 :     _pReflection->release();
     256       67592 : }
     257             : 
     258             : // XIdlMember
     259             : 
     260           0 : Reference< XIdlClass > IdlMemberImpl::getDeclaringClass()
     261             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     262             : {
     263           0 :     if (! _xDeclClass.is())
     264             :     {
     265           0 :         Reference< XIdlClass > xDeclClass( getReflection()->forType( getDeclTypeDescr() ) );
     266           0 :         MutexGuard aGuard( getMutexAccess() );
     267           0 :         if (! _xDeclClass.is())
     268           0 :             _xDeclClass = xDeclClass;
     269             :     }
     270           0 :     return _xDeclClass;
     271             : }
     272             : 
     273      190215 : OUString IdlMemberImpl::getName()
     274             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     275             : {
     276      190215 :     return _aName;
     277             : }
     278             : 
     279             : }
     280             : 
     281             : 
     282             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10