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

Generated by: LCOV version 1.10