LCOV - code coverage report
Current view: top level - comphelper/source/container - NamedPropertyValuesContainer.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 57 66 86.4 %
Date: 2014-11-03 Functions: 15 18 83.3 %
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             : #include "comphelper_services.hxx"
      23             : 
      24             : #include <com/sun/star/container/XNameContainer.hpp>
      25             : #include <com/sun/star/uno/Sequence.h>
      26             : #include <com/sun/star/beans/PropertyValue.hpp>
      27             : #include <cppuhelper/implbase2.hxx>
      28             : #include <com/sun/star/lang/XServiceInfo.hpp>
      29             : #include <cppuhelper/supportsservice.hxx>
      30             : #include <map>
      31             : 
      32             : 
      33             : using namespace com::sun::star;
      34             : 
      35             : typedef std::map< OUString, uno::Sequence<beans::PropertyValue> > NamedPropertyValues;
      36             : 
      37             : class NamedPropertyValuesContainer : public cppu::WeakImplHelper2< container::XNameContainer, lang::XServiceInfo >
      38             : {
      39             : public:
      40             :     NamedPropertyValuesContainer() throw();
      41             :     virtual ~NamedPropertyValuesContainer() throw();
      42             : 
      43             :     // XNameContainer
      44             :     virtual void SAL_CALL insertByName( const OUString& aName, const ::com::sun::star::uno::Any& aElement )
      45             :         throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException,
      46             :         ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      47             :     virtual void SAL_CALL removeByName( const OUString& Name )
      48             :         throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException,
      49             :             ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      50             : 
      51             :     // XNameReplace
      52             :     virtual void SAL_CALL replaceByName( const OUString& aName, const ::com::sun::star::uno::Any& aElement )
      53             :         throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException,
      54             :             ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      55             : 
      56             :     // XNameAccess
      57             :     virtual ::com::sun::star::uno::Any SAL_CALL getByName( const OUString& aName )
      58             :         throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException,
      59             :             ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      60             :     virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getElementNames(  )
      61             :         throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      62             :     virtual sal_Bool SAL_CALL hasByName( const OUString& aName )
      63             :         throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      64             : 
      65             :     // XElementAccess
      66             :     virtual ::com::sun::star::uno::Type SAL_CALL getElementType(  )
      67             :         throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      68             :     virtual sal_Bool SAL_CALL hasElements(  )
      69             :         throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      70             : 
      71             :     //XServiceInfo
      72             :     virtual OUString SAL_CALL getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      73             :     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      74             :     virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      75             : 
      76             :     // XServiceInfo - static versions (used for component registration)
      77             :     static OUString SAL_CALL getImplementationName_static();
      78             :     static uno::Sequence< OUString > SAL_CALL getSupportedServiceNames_static();
      79             :     static uno::Reference< uno::XInterface > SAL_CALL Create( const uno::Reference< uno::XComponentContext >& );
      80             : 
      81             : private:
      82             :     NamedPropertyValues maProperties;
      83             : };
      84             : 
      85        1142 : NamedPropertyValuesContainer::NamedPropertyValuesContainer() throw()
      86             : {
      87        1142 : }
      88             : 
      89        2284 : NamedPropertyValuesContainer::~NamedPropertyValuesContainer() throw()
      90             : {
      91        2284 : }
      92             : 
      93             : // XNameContainer
      94        1212 : void SAL_CALL NamedPropertyValuesContainer::insertByName( const OUString& aName, const uno::Any& aElement )
      95             :     throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException,
      96             :         ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception)
      97             : {
      98        1212 :     if( maProperties.find( aName ) != maProperties.end() )
      99           2 :         throw container::ElementExistException();
     100             : 
     101        1210 :     uno::Sequence<beans::PropertyValue> aProps;
     102        1210 :     if( !(aElement >>= aProps ) )
     103           2 :         throw lang::IllegalArgumentException();
     104             : 
     105        1208 :     maProperties.insert(  NamedPropertyValues::value_type(aName ,aProps) );
     106        1208 : }
     107             : 
     108           4 : void SAL_CALL NamedPropertyValuesContainer::removeByName( const OUString& Name )
     109             :     throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException,
     110             :         ::com::sun::star::uno::RuntimeException, std::exception)
     111             : {
     112           4 :     NamedPropertyValues::iterator aIter = maProperties.find( Name );
     113           4 :     if( aIter == maProperties.end() )
     114           2 :         throw container::NoSuchElementException();
     115             : 
     116           2 :     maProperties.erase( aIter );
     117           2 : }
     118             : 
     119             : // XNameReplace
     120           2 : void SAL_CALL NamedPropertyValuesContainer::replaceByName( const OUString& aName, const ::com::sun::star::uno::Any& aElement )
     121             :     throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException,
     122             :         ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception)
     123             : {
     124           2 :     NamedPropertyValues::iterator aIter = maProperties.find( aName );
     125           2 :     if( aIter == maProperties.end() )
     126           0 :         throw container::NoSuchElementException();
     127             : 
     128           2 :     uno::Sequence<beans::PropertyValue> aProps;
     129           2 :     if( !(aElement >>= aProps) )
     130           0 :         throw lang::IllegalArgumentException();
     131             : 
     132           2 :     (*aIter).second = aProps;
     133           2 : }
     134             : 
     135             : // XNameAccess
     136         730 : ::com::sun::star::uno::Any SAL_CALL NamedPropertyValuesContainer::getByName( const OUString& aName )
     137             :     throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException,
     138             :         ::com::sun::star::uno::RuntimeException, std::exception)
     139             : {
     140         730 :     NamedPropertyValues::iterator aIter = maProperties.find( aName );
     141         730 :     if( aIter == maProperties.end() )
     142           0 :         throw container::NoSuchElementException();
     143             : 
     144         730 :     uno::Any aElement;
     145             : 
     146         730 :     aElement <<= (*aIter).second;
     147             : 
     148         730 :     return aElement;
     149             : }
     150             : 
     151         558 : ::com::sun::star::uno::Sequence< OUString > SAL_CALL NamedPropertyValuesContainer::getElementNames(  )
     152             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     153             : {
     154         558 :     NamedPropertyValues::iterator aIter = maProperties.begin();
     155         558 :     const NamedPropertyValues::iterator aEnd = maProperties.end();
     156             : 
     157         558 :     uno::Sequence< OUString > aNames( maProperties.size() );
     158         558 :     OUString* pNames = aNames.getArray();
     159             : 
     160        1846 :     while( aIter != aEnd )
     161             :     {
     162         730 :         *pNames++ = (*aIter++).first;
     163             :     }
     164             : 
     165         558 :     return aNames;
     166             : }
     167             : 
     168         260 : sal_Bool SAL_CALL NamedPropertyValuesContainer::hasByName( const OUString& aName )
     169             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     170             : {
     171         260 :     NamedPropertyValues::iterator aIter = maProperties.find( aName );
     172         260 :     return aIter != maProperties.end();
     173             : }
     174             : 
     175             : // XElementAccess
     176           2 : ::com::sun::star::uno::Type SAL_CALL NamedPropertyValuesContainer::getElementType(  )
     177             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     178             : {
     179           2 :     return ::getCppuType((uno::Sequence<beans::PropertyValue> *)0);
     180             : }
     181             : 
     182         562 : sal_Bool SAL_CALL NamedPropertyValuesContainer::hasElements(  )
     183             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     184             : {
     185         562 :     return !maProperties.empty();
     186             : }
     187             : 
     188             : //XServiceInfo
     189           0 : OUString SAL_CALL NamedPropertyValuesContainer::getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     190             : {
     191           0 :     return getImplementationName_static();
     192             : }
     193             : 
     194         284 : OUString SAL_CALL NamedPropertyValuesContainer::getImplementationName_static(  )
     195             : {
     196         284 :     return OUString( "NamedPropertyValuesContainer" );
     197             : }
     198             : 
     199           0 : sal_Bool SAL_CALL NamedPropertyValuesContainer::supportsService( const OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     200             : {
     201           0 :     return cppu::supportsService(this, ServiceName);
     202             : }
     203             : 
     204           0 : ::com::sun::star::uno::Sequence< OUString > SAL_CALL NamedPropertyValuesContainer::getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     205             : {
     206           0 :     return getSupportedServiceNames_static();
     207             : }
     208             : 
     209         284 : ::com::sun::star::uno::Sequence< OUString > SAL_CALL NamedPropertyValuesContainer::getSupportedServiceNames_static(  )
     210             : {
     211         284 :     const OUString aServiceName( "com.sun.star.document.NamedPropertyValues" );
     212         284 :     const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
     213         284 :     return aSeq;
     214             : }
     215             : 
     216        1142 : uno::Reference< uno::XInterface > SAL_CALL NamedPropertyValuesContainer::Create(
     217             :                 SAL_UNUSED_PARAMETER const uno::Reference< uno::XComponentContext >&)
     218             : {
     219        1142 :     return (cppu::OWeakObject*)new NamedPropertyValuesContainer();
     220             : }
     221             : 
     222         284 : void createRegistryInfo_NamedPropertyValuesContainer()
     223             : {
     224         284 :     static ::comphelper::module::OAutoRegistration< NamedPropertyValuesContainer > aAutoRegistration;
     225         284 : }
     226             : 
     227             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10