LCOV - code coverage report
Current view: top level - libreoffice/comphelper/source/container - IndexedPropertyValuesContainer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 34 86 39.5 %
Date: 2012-12-27 Functions: 11 17 64.7 %
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         567 : IndexedPropertyValuesContainer::IndexedPropertyValuesContainer() throw()
      82             : {
      83         567 : }
      84             : 
      85         838 : IndexedPropertyValuesContainer::~IndexedPropertyValuesContainer() throw()
      86             : {
      87         838 : }
      88             : 
      89             : // XIndexContainer
      90         223 : 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         223 :     sal_Int32 nSize(maProperties.size());
      95         223 :     if ((nSize >= nIndex) && (nIndex >= 0))
      96             :     {
      97         223 :         uno::Sequence<beans::PropertyValue> aProps;
      98         223 :         if (!(aElement >>= aProps))
      99           0 :             throw lang::IllegalArgumentException();
     100         223 :         if (nSize == nIndex)
     101         223 :             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         223 :         }
     127             :     }
     128             :     else
     129           0 :         throw lang::IndexOutOfBoundsException();
     130         223 : }
     131             : 
     132           0 : 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           0 :     sal_Int32 nSize(maProperties.size());
     137           0 :     if ((nIndex < nSize) && (nIndex >= 0))
     138             :     {
     139           0 :         IndexedPropertyValues::iterator aItr;
     140           0 :         if ((nIndex * 2) < nSize)
     141             :         {
     142           0 :             aItr = maProperties.begin();
     143           0 :             sal_Int32 i(0);
     144           0 :             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           0 :         maProperties.erase(aItr);
     161             :     }
     162             :     else
     163           0 :         throw lang::IndexOutOfBoundsException();
     164           0 : }
     165             : 
     166             : // XIndexReplace
     167           0 : 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           0 :     sal_Int32 nSize(maProperties.size());
     172           0 :     if ((nIndex < nSize) && (nIndex >= 0))
     173             :     {
     174           0 :         uno::Sequence<beans::PropertyValue> aProps;
     175           0 :         if (!(aElement >>= aProps))
     176           0 :             throw lang::IllegalArgumentException();
     177           0 :         maProperties[nIndex] = aProps;
     178             :     }
     179             :     else
     180           0 :         throw lang::IndexOutOfBoundsException();
     181           0 : }
     182             : 
     183             : // XIndexAccess
     184         306 : sal_Int32 SAL_CALL IndexedPropertyValuesContainer::getCount(  )
     185             :     throw(::com::sun::star::uno::RuntimeException)
     186             : {
     187         306 :     return maProperties.size();
     188             : }
     189             : 
     190         486 : ::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         486 :     sal_Int32 nSize(maProperties.size());
     195         486 :     if (!((nIndex < nSize) && (nIndex >= 0)))
     196           0 :         throw lang::IndexOutOfBoundsException();
     197             : 
     198         486 :     uno::Any aAny;
     199         486 :     aAny <<= maProperties[nIndex];
     200         486 :     return aAny;
     201             : }
     202             : 
     203             : // XElementAccess
     204           0 : ::com::sun::star::uno::Type SAL_CALL IndexedPropertyValuesContainer::getElementType(  )
     205             :     throw(::com::sun::star::uno::RuntimeException)
     206             : {
     207           0 :     return ::getCppuType((uno::Sequence<beans::PropertyValue> *)0);
     208             : }
     209             : 
     210         350 : sal_Bool SAL_CALL IndexedPropertyValuesContainer::hasElements(  )
     211             :     throw(::com::sun::star::uno::RuntimeException)
     212             : {
     213         350 :     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          14 : ::rtl::OUString SAL_CALL IndexedPropertyValuesContainer::getImplementationName_static(  )
     223             : {
     224          14 :     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          14 : ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL IndexedPropertyValuesContainer::getSupportedServiceNames_static(  )
     240             : {
     241          14 :     const rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.IndexedPropertyValues" ) );
     242          14 :     const uno::Sequence< rtl::OUString > aSeq( &aServiceName, 1 );
     243          14 :     return aSeq;
     244             : }
     245             : 
     246             : 
     247         567 : uno::Reference< uno::XInterface > SAL_CALL IndexedPropertyValuesContainer::Create(
     248             :                 SAL_UNUSED_PARAMETER const uno::Reference< uno::XComponentContext >&)
     249             : {
     250         567 :     return (cppu::OWeakObject*)new IndexedPropertyValuesContainer();
     251             : }
     252             : 
     253          14 : void createRegistryInfo_IndexedPropertyValuesContainer()
     254             : {
     255          14 :     static ::comphelper::module::OAutoRegistration< IndexedPropertyValuesContainer > aAutoRegistration;
     256          14 : }
     257             : 
     258             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10