LCOV - code coverage report
Current view: top level - comphelper/source/container - IndexedPropertyValuesContainer.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 66 85 77.6 %
Date: 2015-06-13 12:38:46 Functions: 16 17 94.1 %
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        4929 : IndexedPropertyValuesContainer::IndexedPropertyValuesContainer() throw()
      83             : {
      84        4929 : }
      85             : 
      86        9832 : IndexedPropertyValuesContainer::~IndexedPropertyValuesContainer() throw()
      87             : {
      88        9832 : }
      89             : 
      90             : // XIndexContainer
      91        3663 : 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        3663 :     sal_Int32 nSize(maProperties.size());
      96        3663 :     if ((nSize >= nIndex) && (nIndex >= 0))
      97             :     {
      98        3662 :         uno::Sequence<beans::PropertyValue> aProps;
      99        3662 :         if (!(aElement >>= aProps))
     100           1 :             throw lang::IllegalArgumentException();
     101        3661 :         if (nSize == nIndex)
     102        3660 :             maProperties.push_back(aProps);
     103             :         else
     104             :         {
     105           1 :             IndexedPropertyValues::iterator aItr;
     106           1 :             if ((nIndex * 2) < nSize)
     107             :             {
     108           1 :                 aItr = maProperties.begin();
     109           1 :                 sal_Int32 i(0);
     110           2 :                 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           1 :             maProperties.insert(aItr, aProps);
     127        3662 :         }
     128             :     }
     129             :     else
     130           1 :         throw lang::IndexOutOfBoundsException();
     131        3661 : }
     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        5759 : sal_Int32 SAL_CALL IndexedPropertyValuesContainer::getCount(  )
     186             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     187             : {
     188        5759 :     return maProperties.size();
     189             : }
     190             : 
     191        8962 : ::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        8962 :     sal_Int32 nSize(maProperties.size());
     196        8962 :     if (!((nIndex < nSize) && (nIndex >= 0)))
     197           0 :         throw lang::IndexOutOfBoundsException();
     198             : 
     199        8962 :     uno::Any aAny;
     200        8962 :     aAny <<= maProperties[nIndex];
     201        8962 :     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 cppu::UnoType<uno::Sequence<beans::PropertyValue>>::get();
     209             : }
     210             : 
     211        1454 : sal_Bool SAL_CALL IndexedPropertyValuesContainer::hasElements(  )
     212             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     213             : {
     214        1454 :     return !maProperties.empty();
     215             : }
     216             : 
     217             : //XServiceInfo
     218           1 : OUString SAL_CALL IndexedPropertyValuesContainer::getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     219             : {
     220           1 :     return getImplementationName_static();
     221             : }
     222             : 
     223         192 : OUString SAL_CALL IndexedPropertyValuesContainer::getImplementationName_static(  )
     224             : {
     225         192 :     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           1 : ::com::sun::star::uno::Sequence< OUString > SAL_CALL IndexedPropertyValuesContainer::getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     234             : {
     235           1 :     return getSupportedServiceNames_static();
     236             : }
     237             : 
     238             : 
     239         192 : ::com::sun::star::uno::Sequence< OUString > SAL_CALL IndexedPropertyValuesContainer::getSupportedServiceNames_static(  )
     240             : {
     241         192 :     const OUString aServiceName( "com.sun.star.document.IndexedPropertyValues" );
     242         192 :     const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
     243         192 :     return aSeq;
     244             : }
     245             : 
     246             : 
     247        4929 : uno::Reference< uno::XInterface > SAL_CALL IndexedPropertyValuesContainer::Create(
     248             :                 SAL_UNUSED_PARAMETER const uno::Reference< uno::XComponentContext >&)
     249             : {
     250        4929 :     return static_cast<cppu::OWeakObject*>(new IndexedPropertyValuesContainer());
     251             : }
     252             : 
     253         191 : void createRegistryInfo_IndexedPropertyValuesContainer()
     254             : {
     255         191 :     static ::comphelper::module::OAutoRegistration< IndexedPropertyValuesContainer > aAutoRegistration;
     256         191 : }
     257             : 
     258             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11