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