LCOV - code coverage report
Current view: top level - comphelper/source/container - IndexedPropertyValuesContainer.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 62 85 72.9 %
Date: 2014-04-11 Functions: 14 17 82.4 %
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 "comphelper_module.hxx"
      21             : #include "comphelper_services.hxx"
      22             : 
      23             : #include <com/sun/star/container/XIndexContainer.hpp>
      24             : #include <com/sun/star/uno/Sequence.h>
      25             : #include <com/sun/star/beans/PropertyValue.hpp>
      26             : #include <cppuhelper/implbase2.hxx>
      27             : #include <com/sun/star/lang/XServiceInfo.hpp>
      28             : #include <cppuhelper/supportsservice.hxx>
      29             : 
      30             : #include <vector>
      31             : 
      32             : using namespace com::sun::star;
      33             : 
      34             : typedef std::vector < uno::Sequence< beans::PropertyValue > > IndexedPropertyValues;
      35             : 
      36             : class IndexedPropertyValuesContainer : public cppu::WeakImplHelper2< container::XIndexContainer, lang::XServiceInfo >
      37             : {
      38             : public:
      39             :     IndexedPropertyValuesContainer() throw();
      40             :     virtual ~IndexedPropertyValuesContainer() throw();
      41             : 
      42             :     // XIndexContainer
      43             :     virtual void SAL_CALL insertByIndex( sal_Int32 nIndex, const ::com::sun::star::uno::Any& aElement )
      44             :         throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IndexOutOfBoundsException,
      45             :             ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      46             :     virtual void SAL_CALL removeByIndex( sal_Int32 nIndex )
      47             :         throw(::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::WrappedTargetException,
      48             :             ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      49             : 
      50             :     // XIndexReplace
      51             :     virtual void SAL_CALL replaceByIndex( sal_Int32 nIndex, const ::com::sun::star::uno::Any& aElement )
      52             :         throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IndexOutOfBoundsException,
      53             :             ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      54             : 
      55             :     // XIndexAccess
      56             :     virtual sal_Int32 SAL_CALL getCount(  )
      57             :         throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      58             :     virtual ::com::sun::star::uno::Any SAL_CALL getByIndex( sal_Int32 nIndex )
      59             :         throw(::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::WrappedTargetException,
      60             :             ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      61             : 
      62             :     // XElementAccess
      63             :     virtual ::com::sun::star::uno::Type SAL_CALL getElementType(  )
      64             :         throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      65             :     virtual sal_Bool SAL_CALL hasElements(  )
      66             :         throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      67             : 
      68             :     //XServiceInfo
      69             :     virtual OUString SAL_CALL getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      70             :     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      71             :     virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      72             : 
      73             :     // XServiceInfo - static versions (used for component registration)
      74             :     static OUString SAL_CALL getImplementationName_static();
      75             :     static uno::Sequence< OUString > SAL_CALL getSupportedServiceNames_static();
      76             :     static uno::Reference< uno::XInterface > SAL_CALL Create( const uno::Reference< uno::XComponentContext >& );
      77             : 
      78             : private:
      79             :     IndexedPropertyValues maProperties;
      80             : };
      81             : 
      82        3452 : IndexedPropertyValuesContainer::IndexedPropertyValuesContainer() throw()
      83             : {
      84        3452 : }
      85             : 
      86        6846 : IndexedPropertyValuesContainer::~IndexedPropertyValuesContainer() throw()
      87             : {
      88        6846 : }
      89             : 
      90             : // XIndexContainer
      91        2279 : void SAL_CALL IndexedPropertyValuesContainer::insertByIndex( sal_Int32 nIndex, const ::com::sun::star::uno::Any& aElement )
      92             :     throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IndexOutOfBoundsException,
      93             :         ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception)
      94             : {
      95        2279 :     sal_Int32 nSize(maProperties.size());
      96        2279 :     if ((nSize >= nIndex) && (nIndex >= 0))
      97             :     {
      98        2278 :         uno::Sequence<beans::PropertyValue> aProps;
      99        2278 :         if (!(aElement >>= aProps))
     100           1 :             throw lang::IllegalArgumentException();
     101        2277 :         if (nSize == nIndex)
     102        2275 :             maProperties.push_back(aProps);
     103             :         else
     104             :         {
     105           2 :             IndexedPropertyValues::iterator aItr;
     106           2 :             if ((nIndex * 2) < nSize)
     107             :             {
     108           2 :                 aItr = maProperties.begin();
     109           2 :                 sal_Int32 i(0);
     110           4 :                 while(i < nIndex)
     111             :                 {
     112           0 :                     ++i;
     113           0 :                     ++aItr;
     114             :                 }
     115             :             }
     116             :             else
     117             :             {
     118           0 :                 aItr = maProperties.end();
     119           0 :                 sal_Int32 i(nSize - 1);
     120           0 :                 while(i > nIndex)
     121             :                 {
     122           0 :                     --i;
     123           0 :                     --aItr;
     124             :                 }
     125             :             }
     126           2 :             maProperties.insert(aItr, aProps);
     127        2278 :         }
     128             :     }
     129             :     else
     130           1 :         throw lang::IndexOutOfBoundsException();
     131        2277 : }
     132             : 
     133          10 : void SAL_CALL IndexedPropertyValuesContainer::removeByIndex( sal_Int32 nIndex )
     134             :     throw(::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::WrappedTargetException,
     135             :         ::com::sun::star::uno::RuntimeException, std::exception)
     136             : {
     137          10 :     sal_Int32 nSize(maProperties.size());
     138          10 :     if ((nIndex < nSize) && (nIndex >= 0))
     139             :     {
     140           9 :         IndexedPropertyValues::iterator aItr;
     141           9 :         if ((nIndex * 2) < nSize)
     142             :         {
     143           9 :             aItr = maProperties.begin();
     144           9 :             sal_Int32 i(0);
     145          18 :             while(i < nIndex)
     146             :             {
     147           0 :                 ++i;
     148           0 :                 ++aItr;
     149             :             }
     150             :         }
     151             :         else
     152             :         {
     153           0 :             aItr = maProperties.end();
     154           0 :             sal_Int32 i(nSize - 1);
     155           0 :             while(i > nIndex)
     156             :             {
     157           0 :                 --i;
     158           0 :                 --aItr;
     159             :             }
     160             :         }
     161           9 :         maProperties.erase(aItr);
     162             :     }
     163             :     else
     164           1 :         throw lang::IndexOutOfBoundsException();
     165           9 : }
     166             : 
     167             : // XIndexReplace
     168           1 : void SAL_CALL IndexedPropertyValuesContainer::replaceByIndex( sal_Int32 nIndex, const ::com::sun::star::uno::Any& aElement )
     169             :     throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IndexOutOfBoundsException,
     170             :         ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception)
     171             : {
     172           1 :     sal_Int32 nSize(maProperties.size());
     173           1 :     if ((nIndex < nSize) && (nIndex >= 0))
     174             :     {
     175           1 :         uno::Sequence<beans::PropertyValue> aProps;
     176           1 :         if (!(aElement >>= aProps))
     177           0 :             throw lang::IllegalArgumentException();
     178           1 :         maProperties[nIndex] = aProps;
     179             :     }
     180             :     else
     181           0 :         throw lang::IndexOutOfBoundsException();
     182           1 : }
     183             : 
     184             : // XIndexAccess
     185        3414 : sal_Int32 SAL_CALL IndexedPropertyValuesContainer::getCount(  )
     186             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     187             : {
     188        3414 :     return maProperties.size();
     189             : }
     190             : 
     191        5454 : ::com::sun::star::uno::Any SAL_CALL IndexedPropertyValuesContainer::getByIndex( sal_Int32 nIndex )
     192             :     throw(::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::WrappedTargetException,
     193             :         ::com::sun::star::uno::RuntimeException, std::exception)
     194             : {
     195        5454 :     sal_Int32 nSize(maProperties.size());
     196        5454 :     if (!((nIndex < nSize) && (nIndex >= 0)))
     197           0 :         throw lang::IndexOutOfBoundsException();
     198             : 
     199        5454 :     uno::Any aAny;
     200        5454 :     aAny <<= maProperties[nIndex];
     201        5454 :     return aAny;
     202             : }
     203             : 
     204             : // XElementAccess
     205           1 : ::com::sun::star::uno::Type SAL_CALL IndexedPropertyValuesContainer::getElementType(  )
     206             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     207             : {
     208           1 :     return ::getCppuType((uno::Sequence<beans::PropertyValue> *)0);
     209             : }
     210             : 
     211        1268 : sal_Bool SAL_CALL IndexedPropertyValuesContainer::hasElements(  )
     212             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     213             : {
     214        1268 :     return !maProperties.empty();
     215             : }
     216             : 
     217             : //XServiceInfo
     218           0 : OUString SAL_CALL IndexedPropertyValuesContainer::getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     219             : {
     220           0 :     return getImplementationName_static();
     221             : }
     222             : 
     223         128 : OUString SAL_CALL IndexedPropertyValuesContainer::getImplementationName_static(  )
     224             : {
     225         128 :     return OUString( "IndexedPropertyValuesContainer" );
     226             : }
     227             : 
     228           0 : sal_Bool SAL_CALL IndexedPropertyValuesContainer::supportsService( const OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     229             : {
     230           0 :     return cppu::supportsService(this, ServiceName);
     231             : }
     232             : 
     233           0 : ::com::sun::star::uno::Sequence< OUString > SAL_CALL IndexedPropertyValuesContainer::getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     234             : {
     235           0 :     return getSupportedServiceNames_static();
     236             : }
     237             : 
     238             : 
     239         128 : ::com::sun::star::uno::Sequence< OUString > SAL_CALL IndexedPropertyValuesContainer::getSupportedServiceNames_static(  )
     240             : {
     241         128 :     const OUString aServiceName( "com.sun.star.document.IndexedPropertyValues" );
     242         128 :     const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
     243         128 :     return aSeq;
     244             : }
     245             : 
     246             : 
     247        3452 : uno::Reference< uno::XInterface > SAL_CALL IndexedPropertyValuesContainer::Create(
     248             :                 SAL_UNUSED_PARAMETER const uno::Reference< uno::XComponentContext >&)
     249             : {
     250        3452 :     return (cppu::OWeakObject*)new IndexedPropertyValuesContainer();
     251             : }
     252             : 
     253         128 : void createRegistryInfo_IndexedPropertyValuesContainer()
     254             : {
     255         128 :     static ::comphelper::module::OAutoRegistration< IndexedPropertyValuesContainer > aAutoRegistration;
     256         128 : }
     257             : 
     258             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10