LCOV - code coverage report
Current view: top level - framework/source/fwi/uielement - itemcontainer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 74 101 73.3 %
Date: 2012-08-25 Functions: 11 15 73.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 79 204 38.7 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <uielement/itemcontainer.hxx>
      30                 :            : #include <uielement/constitemcontainer.hxx>
      31                 :            : #include <threadhelp/resetableguard.hxx>
      32                 :            : #include <comphelper/servicehelper.hxx>
      33                 :            : 
      34                 :            : using namespace cppu;
      35                 :            : using namespace com::sun::star::uno;
      36                 :            : using namespace com::sun::star::lang;
      37                 :            : using namespace com::sun::star::beans;
      38                 :            : using namespace com::sun::star::container;
      39                 :            : 
      40                 :            : const char WRONG_TYPE_EXCEPTION[] = "Type must be com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >";
      41                 :            : 
      42                 :            : namespace framework
      43                 :            : {
      44                 :            : 
      45                 :            : //*****************************************************************************************************************
      46                 :            : //  XInterface, XTypeProvider
      47                 :            : //*****************************************************************************************************************
      48                 :            : 
      49                 :       3284 : ItemContainer::ItemContainer( const ShareableMutex& rMutex ) :
      50 [ +  - ][ +  - ]:       3284 :     m_aShareMutex( rMutex )
      51                 :            : {
      52                 :       3284 : }
      53                 :            : 
      54                 :            : 
      55 [ +  - ][ +  - ]:         78 : ItemContainer::ItemContainer( const ConstItemContainer& rConstItemContainer, const ShareableMutex& rMutex ) : m_aShareMutex( rMutex )
      56                 :            : {
      57         [ +  - ]:         78 :     copyItemContainer( rConstItemContainer.m_aItemVector, rMutex );
      58                 :         78 : }
      59                 :            : 
      60                 :        304 : ItemContainer::ItemContainer( const Reference< XIndexAccess >& rSourceContainer, const ShareableMutex& rMutex ) :
      61 [ +  - ][ +  - ]:        304 :     m_aShareMutex( rMutex )
      62                 :            : {
      63         [ +  - ]:        304 :     if ( rSourceContainer.is() )
      64                 :            :     {
      65 [ +  - ][ +  - ]:        304 :         sal_Int32 nCount = rSourceContainer->getCount();
      66                 :            :         try
      67                 :            :         {
      68         [ +  + ]:       3136 :             for ( sal_Int32 i = 0; i < nCount; i++ )
      69                 :            :             {
      70         [ +  - ]:       2832 :                 Sequence< PropertyValue > aPropSeq;
      71 [ +  - ][ +  - ]:       2832 :                 if ( rSourceContainer->getByIndex( i ) >>= aPropSeq )
         [ +  - ][ +  - ]
      72                 :            :                 {
      73                 :       2832 :                     sal_Int32 nContainerIndex = -1;
      74                 :       2832 :                     Reference< XIndexAccess > xIndexAccess;
      75         [ +  + ]:       8064 :                     for ( sal_Int32 j = 0; j < aPropSeq.getLength(); j++ )
      76                 :            :                     {
      77 [ +  - ][ +  + ]:       7632 :                         if ( aPropSeq[j].Name == "ItemDescriptorContainer" )
      78                 :            :                         {
      79 [ +  - ][ +  - ]:       2400 :                             aPropSeq[j].Value >>= xIndexAccess;
      80                 :       2400 :                             nContainerIndex = j;
      81                 :       2400 :                             break;
      82                 :            :                         }
      83                 :            :                     }
      84                 :            : 
      85 [ +  + ][ +  - ]:       2832 :                     if ( xIndexAccess.is() && nContainerIndex >= 0 )
                 [ +  + ]
      86 [ +  - ][ +  - ]:        232 :                         aPropSeq[nContainerIndex].Value <<= deepCopyContainer( xIndexAccess, rMutex );
                 [ +  - ]
      87                 :            : 
      88         [ +  - ]:       2832 :                     m_aItemVector.push_back( aPropSeq );
      89                 :            :                 }
      90   [ +  -  #  # ]:       2832 :             }
      91                 :            :         }
      92         [ #  # ]:          0 :         catch ( const IndexOutOfBoundsException& )
      93                 :            :         {
      94                 :            :         }
      95                 :            :     }
      96                 :        304 : }
      97                 :            : 
      98         [ +  - ]:       3666 : ItemContainer::~ItemContainer()
      99                 :            : {
     100         [ -  + ]:       7332 : }
     101                 :            : 
     102                 :            : // private
     103                 :         78 : void ItemContainer::copyItemContainer( const std::vector< Sequence< PropertyValue > >& rSourceVector, const ShareableMutex& rMutex )
     104                 :            : {
     105                 :         78 :     const sal_uInt32 nCount = rSourceVector.size();
     106         [ +  + ]:        788 :     for ( sal_uInt32 i = 0; i < nCount; ++i )
     107                 :            :     {
     108                 :        710 :         sal_Int32 nContainerIndex = -1;
     109         [ +  - ]:        710 :         Sequence< PropertyValue > aPropSeq( rSourceVector[i] );
     110                 :        710 :         Reference< XIndexAccess > xIndexAccess;
     111         [ +  + ]:       2024 :         for ( sal_Int32 j = 0; j < aPropSeq.getLength(); j++ )
     112                 :            :         {
     113 [ +  - ][ +  + ]:       1914 :             if ( aPropSeq[j].Name == "ItemDescriptorContainer" )
     114                 :            :             {
     115 [ +  - ][ +  - ]:        600 :                 aPropSeq[j].Value >>= xIndexAccess;
     116                 :        600 :                 nContainerIndex = j;
     117                 :        600 :                 break;
     118                 :            :             }
     119                 :            :         }
     120                 :            : 
     121 [ +  + ][ +  - ]:        710 :         if ( xIndexAccess.is() && nContainerIndex >= 0 )
                 [ +  + ]
     122 [ +  - ][ +  - ]:         58 :             aPropSeq[nContainerIndex].Value <<= deepCopyContainer( xIndexAccess, rMutex );
                 [ +  - ]
     123                 :            : 
     124         [ +  - ]:        710 :         m_aItemVector.push_back( aPropSeq );
     125         [ +  - ]:        710 :     }
     126                 :         78 : }
     127                 :            : 
     128                 :        290 : Reference< XIndexAccess > ItemContainer::deepCopyContainer( const Reference< XIndexAccess >& rSubContainer, const ShareableMutex& rMutex )
     129                 :            : {
     130                 :        290 :     Reference< XIndexAccess > xReturn;
     131         [ +  - ]:        290 :     if ( rSubContainer.is() )
     132                 :            :     {
     133                 :        290 :         ConstItemContainer* pSource = ConstItemContainer::GetImplementation( rSubContainer );
     134                 :        290 :         ItemContainer* pSubContainer( 0 );
     135         [ +  + ]:        290 :         if ( pSource )
     136         [ +  - ]:         58 :             pSubContainer = new ItemContainer( *pSource, rMutex );
     137                 :            :         else
     138         [ +  - ]:        232 :             pSubContainer = new ItemContainer( rSubContainer, rMutex );
     139 [ +  - ][ +  - ]:        290 :         xReturn = Reference< XIndexAccess >( static_cast< OWeakObject* >( pSubContainer ), UNO_QUERY );
     140                 :            :     }
     141                 :            : 
     142                 :        290 :     return xReturn;
     143                 :            : }
     144                 :            : 
     145                 :            : namespace
     146                 :            : {
     147                 :            :     class theItemContainerUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theItemContainerUnoTunnelId > {};
     148                 :            : }
     149                 :            : 
     150                 :          0 : const Sequence< sal_Int8 >& ItemContainer::GetUnoTunnelId() throw()
     151                 :            : {
     152                 :          0 :     return theItemContainerUnoTunnelId::get().getSeq();
     153                 :            : }
     154                 :            : 
     155                 :        236 : ItemContainer* ItemContainer::GetImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rxIFace ) throw()
     156                 :            : {
     157         [ +  - ]:        236 :     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > xUT( rxIFace, ::com::sun::star::uno::UNO_QUERY );
     158                 :        236 :     return xUT.is() ? reinterpret_cast< ItemContainer* >(sal::static_int_cast< sal_IntPtr >(
     159 [ #  # ][ #  # ]:        236 :                           xUT->getSomething( ItemContainer::GetUnoTunnelId() ))) : NULL;
                 [ -  + ]
     160                 :            : }
     161                 :            : 
     162                 :            : // XElementAccess
     163                 :          0 : sal_Bool SAL_CALL ItemContainer::hasElements()
     164                 :            : throw ( RuntimeException )
     165                 :            : {
     166         [ #  # ]:          0 :     ShareGuard aLock( m_aShareMutex );
     167         [ #  # ]:          0 :     return ( !m_aItemVector.empty() );
     168                 :            : }
     169                 :            : 
     170                 :            : // XIndexAccess
     171                 :     452031 : sal_Int32 SAL_CALL ItemContainer::getCount()
     172                 :            : throw ( RuntimeException )
     173                 :            : {
     174         [ +  - ]:     452031 :     ShareGuard aLock( m_aShareMutex );
     175         [ +  - ]:     452031 :     return m_aItemVector.size();
     176                 :            : }
     177                 :            : 
     178                 :     385130 : Any SAL_CALL ItemContainer::getByIndex( sal_Int32 Index )
     179                 :            : throw ( IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
     180                 :            : {
     181         [ +  - ]:     385130 :     ShareGuard aLock( m_aShareMutex );
     182         [ +  - ]:     385130 :     if ( sal_Int32( m_aItemVector.size()) > Index )
     183         [ +  - ]:     770260 :         return makeAny( m_aItemVector[Index] );
     184                 :            :     else
     185 [ #  # ][ #  # ]:     385130 :         throw IndexOutOfBoundsException( ::rtl::OUString(), (OWeakObject *)this );
                 [ +  - ]
     186                 :            : }
     187                 :            : 
     188                 :            : // XIndexContainer
     189                 :      28746 : void SAL_CALL ItemContainer::insertByIndex( sal_Int32 Index, const Any& aItem )
     190                 :            : throw ( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
     191                 :            : {
     192         [ +  - ]:      28746 :     Sequence< PropertyValue > aSeq;
     193 [ +  - ][ +  - ]:      28746 :     if ( aItem >>= aSeq )
     194                 :            :     {
     195         [ +  - ]:      28746 :         ShareGuard aLock( m_aShareMutex );
     196         [ +  - ]:      28746 :         if ( sal_Int32( m_aItemVector.size()) == Index )
     197         [ +  - ]:      28746 :             m_aItemVector.push_back( aSeq );
     198         [ #  # ]:          0 :         else if ( sal_Int32( m_aItemVector.size()) >Index )
     199                 :            :         {
     200                 :          0 :             std::vector< Sequence< PropertyValue > >::iterator aIter = m_aItemVector.begin();
     201                 :          0 :             aIter += Index;
     202         [ #  # ]:          0 :             m_aItemVector.insert( aIter, aSeq );
     203                 :            :         }
     204                 :            :         else
     205 [ #  # ][ #  # ]:      28746 :             throw IndexOutOfBoundsException( ::rtl::OUString(), (OWeakObject *)this );
                 [ +  - ]
     206                 :            :     }
     207                 :            :     else
     208                 :            :         throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( WRONG_TYPE_EXCEPTION )),
     209 [ +  - ][ #  # ]:      28746 :                                         (OWeakObject *)this, 2 );
         [ #  # ][ #  # ]
     210                 :      28746 : }
     211                 :            : 
     212                 :          0 : void SAL_CALL ItemContainer::removeByIndex( sal_Int32 Index )
     213                 :            : throw ( IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
     214                 :            : {
     215         [ #  # ]:          0 :     ShareGuard aLock( m_aShareMutex );
     216         [ #  # ]:          0 :     if ( (sal_Int32)m_aItemVector.size() > Index )
     217                 :            :     {
     218                 :          0 :         std::vector< Sequence< PropertyValue > >::iterator aIter = m_aItemVector.begin();
     219                 :          0 :         aIter += Index;
     220         [ #  # ]:          0 :         m_aItemVector.erase( aIter );
     221                 :            :     }
     222                 :            :     else
     223 [ #  # ][ #  # ]:          0 :         throw IndexOutOfBoundsException( ::rtl::OUString(), (OWeakObject *)this );
                 [ #  # ]
     224                 :          0 : }
     225                 :            : 
     226                 :          0 : void SAL_CALL ItemContainer::replaceByIndex( sal_Int32 Index, const Any& aItem )
     227                 :            : throw ( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
     228                 :            : {
     229         [ #  # ]:          0 :     Sequence< PropertyValue > aSeq;
     230 [ #  # ][ #  # ]:          0 :     if ( aItem >>= aSeq )
     231                 :            :     {
     232         [ #  # ]:          0 :         ShareGuard aLock( m_aShareMutex );
     233         [ #  # ]:          0 :         if ( sal_Int32( m_aItemVector.size()) > Index )
     234         [ #  # ]:          0 :             m_aItemVector[Index] = aSeq;
     235                 :            :         else
     236 [ #  # ][ #  # ]:          0 :             throw IndexOutOfBoundsException( ::rtl::OUString(), (OWeakObject *)this );
                 [ #  # ]
     237                 :            :     }
     238                 :            :     else
     239                 :            :         throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( WRONG_TYPE_EXCEPTION )),
     240 [ #  # ][ #  # ]:          0 :                                         (OWeakObject *)this, 2 );
         [ #  # ][ #  # ]
     241                 :          0 : }
     242                 :            : 
     243                 :            : } // namespace framework
     244                 :            : 
     245                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10