LCOV - code coverage report
Current view: top level - stoc/source/corereflection - crbase.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 64 90 71.1 %
Date: 2014-11-03 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      308272 : ::osl::Mutex & getMutexAccess()
      37             : {
      38             :     static ::osl::Mutex * s_pMutex = 0;
      39      308272 :     if (! s_pMutex)
      40             :     {
      41         168 :         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
      42         168 :         if (! s_pMutex)
      43             :         {
      44         168 :             static ::osl::Mutex s_aMutex;
      45         168 :             s_pMutex = &s_aMutex;
      46         168 :         }
      47             :     }
      48      308272 :     return *s_pMutex;
      49             : }
      50             : 
      51             : 
      52       20928 : 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       20928 :     , _pTypeDescr( pTypeDescr )
      59             : {
      60       20928 :     if (_pReflection)
      61       20928 :         _pReflection->acquire();
      62       20928 :     if (_pTypeDescr)
      63             :     {
      64       20928 :         typelib_typedescription_acquire( _pTypeDescr );
      65       20928 :         if (! _pTypeDescr->bComplete)
      66       16806 :             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       20928 : }
      75             : 
      76       38732 : IdlClassImpl::~IdlClassImpl()
      77             : {
      78       18845 :     if (_pTypeDescr)
      79       18845 :         typelib_typedescription_release( _pTypeDescr );
      80       18845 :     if (_pReflection)
      81       18845 :         _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       19887 : }
      89             : 
      90             : // XIdlClassImpl default implementation
      91             : 
      92       93340 : TypeClass IdlClassImpl::getTypeClass()
      93             :     throw(css::uno::RuntimeException, std::exception)
      94             : {
      95       93340 :     return _eTypeClass;
      96             : }
      97             : 
      98      278462 : OUString IdlClassImpl::getName()
      99             :     throw(css::uno::RuntimeException, std::exception)
     100             : {
     101      278462 :     return _aName;
     102             : }
     103             : 
     104       33728 : sal_Bool IdlClassImpl::equals( const Reference< XIdlClass >& xType )
     105             :     throw(css::uno::RuntimeException, std::exception)
     106             : {
     107       67456 :     return (xType.is() &&
     108       99690 :             (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        1006 : sal_Bool IdlClassImpl::isAssignableFrom( const Reference< XIdlClass > & xType )
     128             :     throw(css::uno::RuntimeException, std::exception)
     129             : {
     130        1006 :     TypeClass eAssign = getTypeClass();
     131        1006 :     if (equals( xType ) || eAssign == TypeClass_ANY) // default shot
     132             :     {
     133         798 :         return sal_True;
     134             :     }
     135             :     else
     136             :     {
     137         208 :         TypeClass eFrom   = xType->getTypeClass();
     138         376 :         if (eAssign > TypeClass_VOID && eAssign < TypeClass_STRING &&
     139         336 :             eFrom > TypeClass_VOID && eFrom < TypeClass_STRING)
     140             :         {
     141         168 :             return s_aAssignableFromTab[eAssign-1][eFrom-1];
     142             :         }
     143             :     }
     144          40 :     return sal_False;
     145             : }
     146             : 
     147         258 : void IdlClassImpl::createObject( Any & rObj )
     148             :     throw(css::uno::RuntimeException, std::exception)
     149             : {
     150         258 :     rObj.clear();
     151         258 :     uno_any_destruct( &rObj, reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
     152         258 :     uno_any_construct( &rObj, 0, getTypeDescr(), 0 );
     153         258 : }
     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       50070 : Sequence< Reference< XIdlClass > > IdlClassImpl::getInterfaces()
     172             :     throw(css::uno::RuntimeException, std::exception)
     173             : {
     174             : //      OSL_FAIL( "### unexpected use!" );
     175       50070 :     return Sequence< Reference< XIdlClass > >();
     176             : }
     177             : 
     178             : // structs, interfaces
     179             : 
     180        1176 : Sequence< Reference< XIdlClass > > IdlClassImpl::getSuperclasses() throw(css::uno::RuntimeException, std::exception)
     181             : {
     182        1176 :     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      164860 : 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      164860 :     , _pDeclTypeDescr( pDeclTypeDescr )
     244             : {
     245      164860 :     _pReflection->acquire();
     246      164860 :     typelib_typedescription_acquire( _pTypeDescr );
     247      164860 :     if (! _pTypeDescr->bComplete)
     248           4 :         typelib_typedescription_complete( &_pTypeDescr );
     249      164860 :     typelib_typedescription_acquire( _pDeclTypeDescr );
     250      164860 :     if (! _pDeclTypeDescr->bComplete)
     251           0 :         typelib_typedescription_complete( &_pDeclTypeDescr );
     252      164860 : }
     253             : 
     254      315204 : IdlMemberImpl::~IdlMemberImpl()
     255             : {
     256      157602 :     typelib_typedescription_release( _pDeclTypeDescr );
     257      157602 :     typelib_typedescription_release( _pTypeDescr );
     258      157602 :     _pReflection->release();
     259      157602 : }
     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      418412 : OUString IdlMemberImpl::getName()
     277             :     throw(css::uno::RuntimeException, std::exception)
     278             : {
     279      418412 :     return _aName;
     280             : }
     281             : 
     282             : }
     283             : 
     284             : 
     285             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10