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

Generated by: LCOV version 1.11