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

Generated by: LCOV version 1.10