LCOV - code coverage report
Current view: top level - comphelper/source/container - IndexedPropertyValuesContainer.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 62 85 72.9 %
Date: 2014-11-03 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        8502 : IndexedPropertyValuesContainer::IndexedPropertyValuesContainer() throw()
      83             : {
      84        8502 : }
      85             : 
      86       17000 : IndexedPropertyValuesContainer::~IndexedPropertyValuesContainer() throw()
      87             : {
      88       17000 : }
      89             : 
      90             : // XIndexContainer
      91        6126 : 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        6126 :     sal_Int32 nSize(maProperties.size());
      96        6126 :     if ((nSize >= nIndex) && (nIndex >= 0))
      97             :     {
      98        6124 :         uno::Sequence<beans::PropertyValue> aProps;
      99        6124 :         if (!(aElement >>= aProps))
     100           2 :             throw lang::IllegalArgumentException();
     101        6122 :         if (nSize == nIndex)
     102        6118 :             maProperties.push_back(aProps);
     103             :         else
     104             :         {
     105           4 :             IndexedPropertyValues::iterator aItr;
     106           4 :             if ((nIndex * 2) < nSize)
     107             :             {
     108           4 :                 aItr = maProperties.begin();
     109           4 :                 sal_Int32 i(0);
     110           8 :                 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           4 :             maProperties.insert(aItr, aProps);
     127        6124 :         }
     128             :     }
     129             :     else
     130           2 :         throw lang::IndexOutOfBoundsException();
     131        6122 : }
     132             : 
     133          20 : 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          20 :     sal_Int32 nSize(maProperties.size());
     138          20 :     if ((nIndex < nSize) && (nIndex >= 0))
     139             :     {
     140          18 :         IndexedPropertyValues::iterator aItr;
     141          18 :         if ((nIndex * 2) < nSize)
     142             :         {
     143          18 :             aItr = maProperties.begin();
     144          18 :             sal_Int32 i(0);
     145          36 :             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          18 :         maProperties.erase(aItr);
     162             :     }
     163             :     else
     164           2 :         throw lang::IndexOutOfBoundsException();
     165          18 : }
     166             : 
     167             : // XIndexReplace
     168           2 : 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           2 :     sal_Int32 nSize(maProperties.size());
     173           2 :     if ((nIndex < nSize) && (nIndex >= 0))
     174             :     {
     175           2 :         uno::Sequence<beans::PropertyValue> aProps;
     176           2 :         if (!(aElement >>= aProps))
     177           0 :             throw lang::IllegalArgumentException();
     178           2 :         maProperties[nIndex] = aProps;
     179             :     }
     180             :     else
     181           0 :         throw lang::IndexOutOfBoundsException();
     182           2 : }
     183             : 
     184             : // XIndexAccess
     185        9532 : sal_Int32 SAL_CALL IndexedPropertyValuesContainer::getCount(  )
     186             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     187             : {
     188        9532 :     return maProperties.size();
     189             : }
     190             : 
     191       15008 : ::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       15008 :     sal_Int32 nSize(maProperties.size());
     196       15008 :     if (!((nIndex < nSize) && (nIndex >= 0)))
     197           0 :         throw lang::IndexOutOfBoundsException();
     198             : 
     199       15008 :     uno::Any aAny;
     200       15008 :     aAny <<= maProperties[nIndex];
     201       15008 :     return aAny;
     202             : }
     203             : 
     204             : // XElementAccess
     205           2 : ::com::sun::star::uno::Type SAL_CALL IndexedPropertyValuesContainer::getElementType(  )
     206             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     207             : {
     208           2 :     return ::getCppuType((uno::Sequence<beans::PropertyValue> *)0);
     209             : }
     210             : 
     211        2610 : sal_Bool SAL_CALL IndexedPropertyValuesContainer::hasElements(  )
     212             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     213             : {
     214        2610 :     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         284 : OUString SAL_CALL IndexedPropertyValuesContainer::getImplementationName_static(  )
     224             : {
     225         284 :     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         284 : ::com::sun::star::uno::Sequence< OUString > SAL_CALL IndexedPropertyValuesContainer::getSupportedServiceNames_static(  )
     240             : {
     241         284 :     const OUString aServiceName( "com.sun.star.document.IndexedPropertyValues" );
     242         284 :     const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
     243         284 :     return aSeq;
     244             : }
     245             : 
     246             : 
     247        8502 : uno::Reference< uno::XInterface > SAL_CALL IndexedPropertyValuesContainer::Create(
     248             :                 SAL_UNUSED_PARAMETER const uno::Reference< uno::XComponentContext >&)
     249             : {
     250        8502 :     return (cppu::OWeakObject*)new IndexedPropertyValuesContainer();
     251             : }
     252             : 
     253         284 : void createRegistryInfo_IndexedPropertyValuesContainer()
     254             : {
     255         284 :     static ::comphelper::module::OAutoRegistration< IndexedPropertyValuesContainer > aAutoRegistration;
     256         284 : }
     257             : 
     258             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10