LCOV - code coverage report
Current view: top level - framework/source/fwi/uielement - itemcontainer.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 71 99 71.7 %
Date: 2015-06-13 12:38:46 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        2724 : ItemContainer::ItemContainer( const ShareableMutex& rMutex ) :
      38        2724 :     m_aShareMutex( rMutex )
      39             : {
      40        2724 : }
      41             : 
      42          54 : ItemContainer::ItemContainer( const ConstItemContainer& rConstItemContainer, const ShareableMutex& rMutex ) : m_aShareMutex( rMutex )
      43             : {
      44          54 :     copyItemContainer( rConstItemContainer.m_aItemVector, rMutex );
      45          54 : }
      46             : 
      47         212 : ItemContainer::ItemContainer( const Reference< XIndexAccess >& rSourceContainer, const ShareableMutex& rMutex ) :
      48         212 :     m_aShareMutex( rMutex )
      49             : {
      50         212 :     if ( rSourceContainer.is() )
      51             :     {
      52         212 :         sal_Int32 nCount = rSourceContainer->getCount();
      53             :         try
      54             :         {
      55        2196 :             for ( sal_Int32 i = 0; i < nCount; i++ )
      56             :             {
      57        1984 :                 Sequence< PropertyValue > aPropSeq;
      58        1984 :                 if ( rSourceContainer->getByIndex( i ) >>= aPropSeq )
      59             :                 {
      60        1984 :                     sal_Int32 nContainerIndex = -1;
      61        1984 :                     Reference< XIndexAccess > xIndexAccess;
      62        5632 :                     for ( sal_Int32 j = 0; j < aPropSeq.getLength(); j++ )
      63             :                     {
      64        5312 :                         if ( aPropSeq[j].Name == "ItemDescriptorContainer" )
      65             :                         {
      66        1664 :                             aPropSeq[j].Value >>= xIndexAccess;
      67        1664 :                             nContainerIndex = j;
      68        1664 :                             break;
      69             :                         }
      70             :                     }
      71             : 
      72        1984 :                     if ( xIndexAccess.is() && nContainerIndex >= 0 )
      73         176 :                         aPropSeq[nContainerIndex].Value <<= deepCopyContainer( xIndexAccess, rMutex );
      74             : 
      75        1984 :                     m_aItemVector.push_back( aPropSeq );
      76             :                 }
      77        1984 :             }
      78             :         }
      79           0 :         catch ( const IndexOutOfBoundsException& )
      80             :         {
      81             :         }
      82             :     }
      83         212 : }
      84             : 
      85        5952 : ItemContainer::~ItemContainer()
      86             : {
      87        5952 : }
      88             : 
      89             : // private
      90          54 : void ItemContainer::copyItemContainer( const std::vector< Sequence< PropertyValue > >& rSourceVector, const ShareableMutex& rMutex )
      91             : {
      92          54 :     const sal_uInt32 nCount = rSourceVector.size();
      93         551 :     for ( sal_uInt32 i = 0; i < nCount; ++i )
      94             :     {
      95         497 :         sal_Int32 nContainerIndex = -1;
      96         497 :         Sequence< PropertyValue > aPropSeq( rSourceVector[i] );
      97         994 :         Reference< XIndexAccess > xIndexAccess;
      98        1412 :         for ( sal_Int32 j = 0; j < aPropSeq.getLength(); j++ )
      99             :         {
     100        1331 :             if ( aPropSeq[j].Name == "ItemDescriptorContainer" )
     101             :             {
     102         416 :                 aPropSeq[j].Value >>= xIndexAccess;
     103         416 :                 nContainerIndex = j;
     104         416 :                 break;
     105             :             }
     106             :         }
     107             : 
     108         497 :         if ( xIndexAccess.is() && nContainerIndex >= 0 )
     109          44 :             aPropSeq[nContainerIndex].Value <<= deepCopyContainer( xIndexAccess, rMutex );
     110             : 
     111         497 :         m_aItemVector.push_back( aPropSeq );
     112         497 :     }
     113          54 : }
     114             : 
     115         220 : Reference< XIndexAccess > ItemContainer::deepCopyContainer( const Reference< XIndexAccess >& rSubContainer, const ShareableMutex& rMutex )
     116             : {
     117         220 :     Reference< XIndexAccess > xReturn;
     118         220 :     if ( rSubContainer.is() )
     119             :     {
     120         220 :         ConstItemContainer* pSource = ConstItemContainer::GetImplementation( rSubContainer );
     121         220 :         ItemContainer* pSubContainer( 0 );
     122         220 :         if ( pSource )
     123          44 :             pSubContainer = new ItemContainer( *pSource, rMutex );
     124             :         else
     125         176 :             pSubContainer = new ItemContainer( rSubContainer, rMutex );
     126         220 :         xReturn = Reference< XIndexAccess >( static_cast< OWeakObject* >( pSubContainer ), UNO_QUERY );
     127             :     }
     128             : 
     129         220 :     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         163 : ItemContainer* ItemContainer::GetImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rxIFace ) throw()
     143             : {
     144         163 :     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > xUT( rxIFace, ::com::sun::star::uno::UNO_QUERY );
     145         163 :     return xUT.is() ? reinterpret_cast< ItemContainer* >(sal::static_int_cast< sal_IntPtr >(
     146         163 :                           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      317114 : sal_Int32 SAL_CALL ItemContainer::getCount()
     159             : throw ( RuntimeException, std::exception )
     160             : {
     161      317114 :     ShareGuard aLock( m_aShareMutex );
     162      317114 :     return m_aItemVector.size();
     163             : }
     164             : 
     165      266637 : Any SAL_CALL ItemContainer::getByIndex( sal_Int32 Index )
     166             : throw ( IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception )
     167             : {
     168      266637 :     ShareGuard aLock( m_aShareMutex );
     169      266637 :     if ( sal_Int32( m_aItemVector.size()) > Index )
     170      533274 :         return makeAny( m_aItemVector[Index] );
     171             :     else
     172           0 :         throw IndexOutOfBoundsException( OUString(), static_cast<OWeakObject *>(this) );
     173             : }
     174             : 
     175             : // XIndexContainer
     176       24605 : void SAL_CALL ItemContainer::insertByIndex( sal_Int32 Index, const Any& aItem )
     177             : throw ( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception )
     178             : {
     179       24605 :     Sequence< PropertyValue > aSeq;
     180       24605 :     if ( aItem >>= aSeq )
     181             :     {
     182       24605 :         ShareGuard aLock( m_aShareMutex );
     183       24605 :         if ( sal_Int32( m_aItemVector.size()) == Index )
     184       24605 :             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(), static_cast<OWeakObject *>(this) );
     193             :     }
     194             :     else
     195             :         throw IllegalArgumentException( OUString( WRONG_TYPE_EXCEPTION ),
     196           0 :                                         static_cast<OWeakObject *>(this), 2 );
     197       24605 : }
     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(), static_cast<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(), static_cast<OWeakObject *>(this) );
     222             :     }
     223             :     else
     224             :         throw IllegalArgumentException( OUString( WRONG_TYPE_EXCEPTION ),
     225           0 :                                         static_cast<OWeakObject *>(this), 2 );
     226           0 : }
     227             : 
     228             : } // namespace framework
     229             : 
     230             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11