LCOV - code coverage report
Current view: top level - libreoffice/stoc/source/corereflection - crbase.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 62 89 69.7 %
Date: 2012-12-17 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      141495 : Mutex & getMutexAccess()
      34             : {
      35             :     static Mutex * s_pMutex = 0;
      36      141495 :     if (! s_pMutex)
      37             :     {
      38          50 :         MutexGuard aGuard( Mutex::getGlobalMutex() );
      39          50 :         if (! s_pMutex)
      40             :         {
      41          50 :             static Mutex s_aMutex;
      42          50 :             s_pMutex = &s_aMutex;
      43          50 :         }
      44             :     }
      45      141495 :     return *s_pMutex;
      46             : }
      47             : 
      48             : //__________________________________________________________________________________________________
      49        8178 : 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        8178 :     , _pTypeDescr( pTypeDescr )
      56             : {
      57        8178 :     if (_pReflection)
      58        8178 :         _pReflection->acquire();
      59        8178 :     if (_pTypeDescr)
      60             :     {
      61        8178 :         typelib_typedescription_acquire( _pTypeDescr );
      62        8178 :         if (! _pTypeDescr->bComplete)
      63        5030 :             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        8178 : }
      72             : //__________________________________________________________________________________________________
      73        4426 : IdlClassImpl::~IdlClassImpl()
      74             : {
      75        2203 :     if (_pTypeDescr)
      76        2203 :         typelib_typedescription_release( _pTypeDescr );
      77        2203 :     if (_pReflection)
      78        2203 :         _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        2223 : }
      86             : 
      87             : // XIdlClassImpl default implementation
      88             : //__________________________________________________________________________________________________
      89      388070 : TypeClass IdlClassImpl::getTypeClass()
      90             :     throw(::com::sun::star::uno::RuntimeException)
      91             : {
      92      388070 :     return _eTypeClass;
      93             : }
      94             : //__________________________________________________________________________________________________
      95      383295 : OUString IdlClassImpl::getName()
      96             :     throw(::com::sun::star::uno::RuntimeException)
      97             : {
      98      383295 :     return _aName;
      99             : }
     100             : //__________________________________________________________________________________________________
     101      367956 : sal_Bool IdlClassImpl::equals( const Reference< XIdlClass >& xType )
     102             :     throw(::com::sun::star::uno::RuntimeException)
     103             : {
     104      367956 :     return (xType.is() &&
     105      735912 :             (xType->getTypeClass() == _eTypeClass) && (xType->getName() == _aName));
     106             : }
     107             : 
     108             : static 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         348 : sal_Bool IdlClassImpl::isAssignableFrom( const Reference< XIdlClass > & xType )
     125             :     throw(::com::sun::star::uno::RuntimeException)
     126             : {
     127         348 :     TypeClass eAssign = getTypeClass();
     128         348 :     if (equals( xType ) || eAssign == TypeClass_ANY) // default shot
     129             :     {
     130         267 :         return sal_True;
     131             :     }
     132             :     else
     133             :     {
     134          81 :         TypeClass eFrom   = xType->getTypeClass();
     135          81 :         if (eAssign > TypeClass_VOID && eAssign < TypeClass_STRING &&
     136             :             eFrom > TypeClass_VOID && eFrom < TypeClass_STRING)
     137             :         {
     138          81 :             return s_aAssignableFromTab[eAssign-1][eFrom-1];
     139             :         }
     140             :     }
     141           0 :     return sal_False;
     142             : }
     143             : //__________________________________________________________________________________________________
     144          90 : void IdlClassImpl::createObject( Any & rObj )
     145             :     throw(::com::sun::star::uno::RuntimeException)
     146             : {
     147          90 :     rObj.clear();
     148          90 :     uno_any_destruct( &rObj, reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
     149          90 :     uno_any_construct( &rObj, 0, getTypeDescr(), 0 );
     150          90 : }
     151             : 
     152             : // what TODO ????
     153             : //__________________________________________________________________________________________________
     154           0 : Sequence< Reference< XIdlClass > > IdlClassImpl::getClasses()
     155             :     throw(::com::sun::star::uno::RuntimeException)
     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)
     163             : {
     164             :     OSL_FAIL( "### unexpected use!" );
     165           0 :     return Reference< XIdlClass >();
     166             : }
     167             : //__________________________________________________________________________________________________
     168       21436 : Sequence< Reference< XIdlClass > > IdlClassImpl::getInterfaces()
     169             :     throw(::com::sun::star::uno::RuntimeException)
     170             : {
     171             : //      OSL_FAIL( "### unexpected use!" );
     172       21436 :     return Sequence< Reference< XIdlClass > >();
     173             : }
     174             : 
     175             : // structs, interfaces
     176             : //__________________________________________________________________________________________________
     177         614 : Sequence< Reference< XIdlClass > > IdlClassImpl::getSuperclasses() throw(::com::sun::star::uno::RuntimeException)
     178             : {
     179         614 :     return Sequence< Reference< XIdlClass > >();
     180             : }
     181             : // structs
     182             : //__________________________________________________________________________________________________
     183           0 : Reference< XIdlField > IdlClassImpl::getField( const OUString & )
     184             :     throw(::com::sun::star::uno::RuntimeException)
     185             : {
     186           0 :     return Reference< XIdlField >();
     187             : }
     188             : //__________________________________________________________________________________________________
     189           0 : Sequence< Reference< XIdlField > > IdlClassImpl::getFields()
     190             :     throw(::com::sun::star::uno::RuntimeException)
     191             : {
     192           0 :     return Sequence< Reference< XIdlField > >();
     193             : }
     194             : // interfaces
     195             : //__________________________________________________________________________________________________
     196           0 : Uik IdlClassImpl::getUik()
     197             :     throw(::com::sun::star::uno::RuntimeException)
     198             : {
     199           0 :     return Uik();
     200             : }
     201             : //__________________________________________________________________________________________________
     202           0 : Reference< XIdlMethod > IdlClassImpl::getMethod( const OUString & )
     203             :     throw(::com::sun::star::uno::RuntimeException)
     204             : {
     205           0 :     return Reference< XIdlMethod >();
     206             : }
     207             : //__________________________________________________________________________________________________
     208           0 : Sequence< Reference< XIdlMethod > > IdlClassImpl::getMethods()
     209             :     throw(::com::sun::star::uno::RuntimeException)
     210             : {
     211           0 :     return Sequence< Reference< XIdlMethod > >();
     212             : }
     213             : // array
     214             : //__________________________________________________________________________________________________
     215           0 : Reference< XIdlClass > IdlClassImpl::getComponentType()
     216             :     throw(::com::sun::star::uno::RuntimeException)
     217             : {
     218           0 :     return Reference< XIdlClass >();
     219             : }
     220             : //__________________________________________________________________________________________________
     221           0 : Reference< XIdlArray > IdlClassImpl::getArray()
     222             :     throw(::com::sun::star::uno::RuntimeException)
     223             : {
     224           0 :     return Reference< XIdlArray >();
     225             : }
     226             : 
     227             : 
     228             : //##################################################################################################
     229             : //##################################################################################################
     230             : //##################################################################################################
     231             : 
     232             : 
     233             : //__________________________________________________________________________________________________
     234       78528 : 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       78528 :     , _pDeclTypeDescr( pDeclTypeDescr )
     241             : {
     242       78528 :     _pReflection->acquire();
     243       78528 :     typelib_typedescription_acquire( _pTypeDescr );
     244       78528 :     if (! _pTypeDescr->bComplete)
     245           1 :         typelib_typedescription_complete( &_pTypeDescr );
     246       78528 :     typelib_typedescription_acquire( _pDeclTypeDescr );
     247       78528 :     if (! _pDeclTypeDescr->bComplete)
     248           0 :         typelib_typedescription_complete( &_pDeclTypeDescr );
     249       78528 : }
     250             : //__________________________________________________________________________________________________
     251      153146 : IdlMemberImpl::~IdlMemberImpl()
     252             : {
     253       76573 :     typelib_typedescription_release( _pDeclTypeDescr );
     254       76573 :     typelib_typedescription_release( _pTypeDescr );
     255       76573 :     _pReflection->release();
     256       76573 : }
     257             : 
     258             : // XIdlMember
     259             : //__________________________________________________________________________________________________
     260           0 : Reference< XIdlClass > IdlMemberImpl::getDeclaringClass()
     261             :     throw(::com::sun::star::uno::RuntimeException)
     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      192312 : OUString IdlMemberImpl::getName()
     274             :     throw(::com::sun::star::uno::RuntimeException)
     275             : {
     276      192312 :     return _aName;
     277             : }
     278             : 
     279             : }
     280             : 
     281             : 
     282             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10