LCOV - code coverage report
Current view: top level - libreoffice/comphelper/source/container - IndexedPropertyValuesContainer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 56 86 65.1 %
Date: 2012-12-17 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 ::rtl::OUString SAL_CALL getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException);
      69             :     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException);
      70             :     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException);
      71             : 
      72             :     // XServiceInfo - static versions (used for component registration)
      73             :     static ::rtl::OUString SAL_CALL getImplementationName_static();
      74             :     static uno::Sequence< ::rtl::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        1748 : IndexedPropertyValuesContainer::IndexedPropertyValuesContainer() throw()
      82             : {
      83        1748 : }
      84             : 
      85        2664 : IndexedPropertyValuesContainer::~IndexedPropertyValuesContainer() throw()
      86             : {
      87        2664 : }
      88             : 
      89             : // XIndexContainer
      90         612 : 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         612 :     sal_Int32 nSize(maProperties.size());
      95         612 :     if ((nSize >= nIndex) && (nIndex >= 0))
      96             :     {
      97         610 :         uno::Sequence<beans::PropertyValue> aProps;
      98         610 :         if (!(aElement >>= aProps))
      99           2 :             throw lang::IllegalArgumentException();
     100         608 :         if (nSize == nIndex)
     101         608 :             maProperties.push_back(aProps);
     102             :         else
     103             :         {
     104           0 :             IndexedPropertyValues::iterator aItr;
     105           0 :             if ((nIndex * 2) < nSize)
     106             :             {
     107           0 :                 aItr = maProperties.begin();
     108           0 :                 sal_Int32 i(0);
     109           0 :                 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           0 :             maProperties.insert(aItr, aProps);
     126         610 :         }
     127             :     }
     128             :     else
     129           2 :         throw lang::IndexOutOfBoundsException();
     130         608 : }
     131             : 
     132           4 : 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           4 :     sal_Int32 nSize(maProperties.size());
     137           4 :     if ((nIndex < nSize) && (nIndex >= 0))
     138             :     {
     139           2 :         IndexedPropertyValues::iterator aItr;
     140           2 :         if ((nIndex * 2) < nSize)
     141             :         {
     142           2 :             aItr = maProperties.begin();
     143           2 :             sal_Int32 i(0);
     144           4 :             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           2 :         maProperties.erase(aItr);
     161             :     }
     162             :     else
     163           2 :         throw lang::IndexOutOfBoundsException();
     164           2 : }
     165             : 
     166             : // XIndexReplace
     167           2 : 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           2 :     sal_Int32 nSize(maProperties.size());
     172           2 :     if ((nIndex < nSize) && (nIndex >= 0))
     173             :     {
     174           2 :         uno::Sequence<beans::PropertyValue> aProps;
     175           2 :         if (!(aElement >>= aProps))
     176           0 :             throw lang::IllegalArgumentException();
     177           2 :         maProperties[nIndex] = aProps;
     178             :     }
     179             :     else
     180           0 :         throw lang::IndexOutOfBoundsException();
     181           2 : }
     182             : 
     183             : // XIndexAccess
     184         881 : sal_Int32 SAL_CALL IndexedPropertyValuesContainer::getCount(  )
     185             :     throw(::com::sun::star::uno::RuntimeException)
     186             : {
     187         881 :     return maProperties.size();
     188             : }
     189             : 
     190        1391 : ::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        1391 :     sal_Int32 nSize(maProperties.size());
     195        1391 :     if (!((nIndex < nSize) && (nIndex >= 0)))
     196           0 :         throw lang::IndexOutOfBoundsException();
     197             : 
     198        1391 :     uno::Any aAny;
     199        1391 :     aAny <<= maProperties[nIndex];
     200        1391 :     return aAny;
     201             : }
     202             : 
     203             : // XElementAccess
     204           2 : ::com::sun::star::uno::Type SAL_CALL IndexedPropertyValuesContainer::getElementType(  )
     205             :     throw(::com::sun::star::uno::RuntimeException)
     206             : {
     207           2 :     return ::getCppuType((uno::Sequence<beans::PropertyValue> *)0);
     208             : }
     209             : 
     210        1160 : sal_Bool SAL_CALL IndexedPropertyValuesContainer::hasElements(  )
     211             :     throw(::com::sun::star::uno::RuntimeException)
     212             : {
     213        1160 :     return !maProperties.empty();
     214             : }
     215             : 
     216             : //XServiceInfo
     217           0 : ::rtl::OUString SAL_CALL IndexedPropertyValuesContainer::getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException)
     218             : {
     219           0 :     return getImplementationName_static();
     220             : }
     221             : 
     222          64 : ::rtl::OUString SAL_CALL IndexedPropertyValuesContainer::getImplementationName_static(  )
     223             : {
     224          64 :     return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IndexedPropertyValuesContainer" ) );
     225             : }
     226             : 
     227           0 : sal_Bool SAL_CALL IndexedPropertyValuesContainer::supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException)
     228             : {
     229           0 :     rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.IndexedPropertyValues" ) );
     230           0 :     return aServiceName == ServiceName;
     231             : }
     232             : 
     233           0 : ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL IndexedPropertyValuesContainer::getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException)
     234             : {
     235           0 :     return getSupportedServiceNames_static();
     236             : }
     237             : 
     238             : 
     239          64 : ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL IndexedPropertyValuesContainer::getSupportedServiceNames_static(  )
     240             : {
     241          64 :     const rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.IndexedPropertyValues" ) );
     242          64 :     const uno::Sequence< rtl::OUString > aSeq( &aServiceName, 1 );
     243          64 :     return aSeq;
     244             : }
     245             : 
     246             : 
     247        1748 : uno::Reference< uno::XInterface > SAL_CALL IndexedPropertyValuesContainer::Create(
     248             :                 SAL_UNUSED_PARAMETER const uno::Reference< uno::XComponentContext >&)
     249             : {
     250        1748 :     return (cppu::OWeakObject*)new IndexedPropertyValuesContainer();
     251             : }
     252             : 
     253          64 : void createRegistryInfo_IndexedPropertyValuesContainer()
     254             : {
     255          64 :     static ::comphelper::module::OAutoRegistration< IndexedPropertyValuesContainer > aAutoRegistration;
     256          64 : }
     257             : 
     258             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10