LCOV - code coverage report
Current view: top level - framework/source/fwi/uielement - itemcontainer.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 71 99 71.7 %
Date: 2014-11-03 Functions: 11 15 73.3 %
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 <uielement/itemcontainer.hxx>
      21             : #include <uielement/constitemcontainer.hxx>
      22             : #include <comphelper/servicehelper.hxx>
      23             : 
      24             : using namespace cppu;
      25             : using namespace com::sun::star::uno;
      26             : using namespace com::sun::star::lang;
      27             : using namespace com::sun::star::beans;
      28             : using namespace com::sun::star::container;
      29             : 
      30             : const char WRONG_TYPE_EXCEPTION[] = "Type must be com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >";
      31             : 
      32             : namespace framework
      33             : {
      34             : 
      35             : //  XInterface, XTypeProvider
      36             : 
      37        3490 : ItemContainer::ItemContainer( const ShareableMutex& rMutex ) :
      38        3490 :     m_aShareMutex( rMutex )
      39             : {
      40        3490 : }
      41             : 
      42          80 : ItemContainer::ItemContainer( const ConstItemContainer& rConstItemContainer, const ShareableMutex& rMutex ) : m_aShareMutex( rMutex )
      43             : {
      44          80 :     copyItemContainer( rConstItemContainer.m_aItemVector, rMutex );
      45          80 : }
      46             : 
      47         312 : ItemContainer::ItemContainer( const Reference< XIndexAccess >& rSourceContainer, const ShareableMutex& rMutex ) :
      48         312 :     m_aShareMutex( rMutex )
      49             : {
      50         312 :     if ( rSourceContainer.is() )
      51             :     {
      52         312 :         sal_Int32 nCount = rSourceContainer->getCount();
      53             :         try
      54             :         {
      55        3240 :             for ( sal_Int32 i = 0; i < nCount; i++ )
      56             :             {
      57        2928 :                 Sequence< PropertyValue > aPropSeq;
      58        2928 :                 if ( rSourceContainer->getByIndex( i ) >>= aPropSeq )
      59             :                 {
      60        2928 :                     sal_Int32 nContainerIndex = -1;
      61        2928 :                     Reference< XIndexAccess > xIndexAccess;
      62        8336 :                     for ( sal_Int32 j = 0; j < aPropSeq.getLength(); j++ )
      63             :                     {
      64        7888 :                         if ( aPropSeq[j].Name == "ItemDescriptorContainer" )
      65             :                         {
      66        2480 :                             aPropSeq[j].Value >>= xIndexAccess;
      67        2480 :                             nContainerIndex = j;
      68        2480 :                             break;
      69             :                         }
      70             :                     }
      71             : 
      72        2928 :                     if ( xIndexAccess.is() && nContainerIndex >= 0 )
      73         240 :                         aPropSeq[nContainerIndex].Value <<= deepCopyContainer( xIndexAccess, rMutex );
      74             : 
      75        2928 :                     m_aItemVector.push_back( aPropSeq );
      76             :                 }
      77        2928 :             }
      78             :         }
      79           0 :         catch ( const IndexOutOfBoundsException& )
      80             :         {
      81             :         }
      82             :     }
      83         312 : }
      84             : 
      85        7708 : ItemContainer::~ItemContainer()
      86             : {
      87        7708 : }
      88             : 
      89             : // private
      90          80 : void ItemContainer::copyItemContainer( const std::vector< Sequence< PropertyValue > >& rSourceVector, const ShareableMutex& rMutex )
      91             : {
      92          80 :     const sal_uInt32 nCount = rSourceVector.size();
      93         814 :     for ( sal_uInt32 i = 0; i < nCount; ++i )
      94             :     {
      95         734 :         sal_Int32 nContainerIndex = -1;
      96         734 :         Sequence< PropertyValue > aPropSeq( rSourceVector[i] );
      97        1468 :         Reference< XIndexAccess > xIndexAccess;
      98        2092 :         for ( sal_Int32 j = 0; j < aPropSeq.getLength(); j++ )
      99             :         {
     100        1978 :             if ( aPropSeq[j].Name == "ItemDescriptorContainer" )
     101             :             {
     102         620 :                 aPropSeq[j].Value >>= xIndexAccess;
     103         620 :                 nContainerIndex = j;
     104         620 :                 break;
     105             :             }
     106             :         }
     107             : 
     108         734 :         if ( xIndexAccess.is() && nContainerIndex >= 0 )
     109          60 :             aPropSeq[nContainerIndex].Value <<= deepCopyContainer( xIndexAccess, rMutex );
     110             : 
     111         734 :         m_aItemVector.push_back( aPropSeq );
     112         734 :     }
     113          80 : }
     114             : 
     115         300 : Reference< XIndexAccess > ItemContainer::deepCopyContainer( const Reference< XIndexAccess >& rSubContainer, const ShareableMutex& rMutex )
     116             : {
     117         300 :     Reference< XIndexAccess > xReturn;
     118         300 :     if ( rSubContainer.is() )
     119             :     {
     120         300 :         ConstItemContainer* pSource = ConstItemContainer::GetImplementation( rSubContainer );
     121         300 :         ItemContainer* pSubContainer( 0 );
     122         300 :         if ( pSource )
     123          60 :             pSubContainer = new ItemContainer( *pSource, rMutex );
     124             :         else
     125         240 :             pSubContainer = new ItemContainer( rSubContainer, rMutex );
     126         300 :         xReturn = Reference< XIndexAccess >( static_cast< OWeakObject* >( pSubContainer ), UNO_QUERY );
     127             :     }
     128             : 
     129         300 :     return xReturn;
     130             : }
     131             : 
     132             : namespace
     133             : {
     134             :     class theItemContainerUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theItemContainerUnoTunnelId > {};
     135             : }
     136             : 
     137           0 : const Sequence< sal_Int8 >& ItemContainer::GetUnoTunnelId() throw()
     138             : {
     139           0 :     return theItemContainerUnoTunnelId::get().getSeq();
     140             : }
     141             : 
     142         242 : ItemContainer* ItemContainer::GetImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rxIFace ) throw()
     143             : {
     144         242 :     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > xUT( rxIFace, ::com::sun::star::uno::UNO_QUERY );
     145         242 :     return xUT.is() ? reinterpret_cast< ItemContainer* >(sal::static_int_cast< sal_IntPtr >(
     146         242 :                           xUT->getSomething( ItemContainer::GetUnoTunnelId() ))) : NULL;
     147             : }
     148             : 
     149             : // XElementAccess
     150           0 : sal_Bool SAL_CALL ItemContainer::hasElements()
     151             : throw ( RuntimeException, std::exception )
     152             : {
     153           0 :     ShareGuard aLock( m_aShareMutex );
     154           0 :     return ( !m_aItemVector.empty() );
     155             : }
     156             : 
     157             : // XIndexAccess
     158      594804 : sal_Int32 SAL_CALL ItemContainer::getCount()
     159             : throw ( RuntimeException, std::exception )
     160             : {
     161      594804 :     ShareGuard aLock( m_aShareMutex );
     162      594804 :     return m_aItemVector.size();
     163             : }
     164             : 
     165      511912 : Any SAL_CALL ItemContainer::getByIndex( sal_Int32 Index )
     166             : throw ( IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception )
     167             : {
     168      511912 :     ShareGuard aLock( m_aShareMutex );
     169      511912 :     if ( sal_Int32( m_aItemVector.size()) > Index )
     170     1023824 :         return makeAny( m_aItemVector[Index] );
     171             :     else
     172           0 :         throw IndexOutOfBoundsException( OUString(), (OWeakObject *)this );
     173             : }
     174             : 
     175             : // XIndexContainer
     176       31228 : void SAL_CALL ItemContainer::insertByIndex( sal_Int32 Index, const Any& aItem )
     177             : throw ( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception )
     178             : {
     179       31228 :     Sequence< PropertyValue > aSeq;
     180       31228 :     if ( aItem >>= aSeq )
     181             :     {
     182       31228 :         ShareGuard aLock( m_aShareMutex );
     183       31228 :         if ( sal_Int32( m_aItemVector.size()) == Index )
     184       31228 :             m_aItemVector.push_back( aSeq );
     185           0 :         else if ( sal_Int32( m_aItemVector.size()) >Index )
     186             :         {
     187           0 :             std::vector< Sequence< PropertyValue > >::iterator aIter = m_aItemVector.begin();
     188           0 :             aIter += Index;
     189           0 :             m_aItemVector.insert( aIter, aSeq );
     190             :         }
     191             :         else
     192           0 :             throw IndexOutOfBoundsException( OUString(), (OWeakObject *)this );
     193             :     }
     194             :     else
     195             :         throw IllegalArgumentException( OUString( WRONG_TYPE_EXCEPTION ),
     196           0 :                                         (OWeakObject *)this, 2 );
     197       31228 : }
     198             : 
     199           0 : void SAL_CALL ItemContainer::removeByIndex( sal_Int32 nIndex )
     200             : throw ( IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception )
     201             : {
     202           0 :     ShareGuard aLock( m_aShareMutex );
     203           0 :     if ( (sal_Int32)m_aItemVector.size() > nIndex )
     204             :     {
     205           0 :         m_aItemVector.erase(m_aItemVector.begin() + nIndex);
     206             :     }
     207             :     else
     208           0 :         throw IndexOutOfBoundsException( OUString(), (OWeakObject *)this );
     209           0 : }
     210             : 
     211           0 : void SAL_CALL ItemContainer::replaceByIndex( sal_Int32 Index, const Any& aItem )
     212             : throw ( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception )
     213             : {
     214           0 :     Sequence< PropertyValue > aSeq;
     215           0 :     if ( aItem >>= aSeq )
     216             :     {
     217           0 :         ShareGuard aLock( m_aShareMutex );
     218           0 :         if ( sal_Int32( m_aItemVector.size()) > Index )
     219           0 :             m_aItemVector[Index] = aSeq;
     220             :         else
     221           0 :             throw IndexOutOfBoundsException( OUString(), (OWeakObject *)this );
     222             :     }
     223             :     else
     224             :         throw IllegalArgumentException( OUString( WRONG_TYPE_EXCEPTION ),
     225           0 :                                         (OWeakObject *)this, 2 );
     226           0 : }
     227             : 
     228             : } // namespace framework
     229             : 
     230             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10