LCOV - code coverage report
Current view: top level - comphelper/source/container - NamedPropertyValuesContainer.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 61 66 92.4 %
Date: 2015-06-13 12:38:46 Functions: 17 18 94.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             : #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         821 : NamedPropertyValuesContainer::NamedPropertyValuesContainer() throw()
      86             : {
      87         821 : }
      88             : 
      89        1626 : NamedPropertyValuesContainer::~NamedPropertyValuesContainer() throw()
      90             : {
      91        1626 : }
      92             : 
      93             : // XNameContainer
      94         791 : 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         791 :     if( maProperties.find( aName ) != maProperties.end() )
      99           1 :         throw container::ElementExistException();
     100             : 
     101         790 :     uno::Sequence<beans::PropertyValue> aProps;
     102         790 :     if( !(aElement >>= aProps ) )
     103           1 :         throw lang::IllegalArgumentException();
     104             : 
     105         789 :     maProperties.insert(  NamedPropertyValues::value_type(aName ,aProps) );
     106         789 : }
     107             : 
     108           2 : 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           2 :     NamedPropertyValues::iterator aIter = maProperties.find( Name );
     113           2 :     if( aIter == maProperties.end() )
     114           1 :         throw container::NoSuchElementException();
     115             : 
     116           1 :     maProperties.erase( aIter );
     117           1 : }
     118             : 
     119             : // XNameReplace
     120           1 : 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           1 :     NamedPropertyValues::iterator aIter = maProperties.find( aName );
     125           1 :     if( aIter == maProperties.end() )
     126           0 :         throw container::NoSuchElementException();
     127             : 
     128           1 :     uno::Sequence<beans::PropertyValue> aProps;
     129           1 :     if( !(aElement >>= aProps) )
     130           0 :         throw lang::IllegalArgumentException();
     131             : 
     132           1 :     (*aIter).second = aProps;
     133           1 : }
     134             : 
     135             : // XNameAccess
     136         478 : ::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         478 :     NamedPropertyValues::iterator aIter = maProperties.find( aName );
     141         478 :     if( aIter == maProperties.end() )
     142           0 :         throw container::NoSuchElementException();
     143             : 
     144         478 :     uno::Any aElement;
     145             : 
     146         478 :     aElement <<= (*aIter).second;
     147             : 
     148         478 :     return aElement;
     149             : }
     150             : 
     151         353 : ::com::sun::star::uno::Sequence< OUString > SAL_CALL NamedPropertyValuesContainer::getElementNames(  )
     152             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     153             : {
     154         353 :     NamedPropertyValues::iterator aIter = maProperties.begin();
     155         353 :     const NamedPropertyValues::iterator aEnd = maProperties.end();
     156             : 
     157         353 :     uno::Sequence< OUString > aNames( maProperties.size() );
     158         353 :     OUString* pNames = aNames.getArray();
     159             : 
     160        1184 :     while( aIter != aEnd )
     161             :     {
     162         478 :         *pNames++ = (*aIter++).first;
     163             :     }
     164             : 
     165         353 :     return aNames;
     166             : }
     167             : 
     168         269 : sal_Bool SAL_CALL NamedPropertyValuesContainer::hasByName( const OUString& aName )
     169             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     170             : {
     171         269 :     NamedPropertyValues::iterator aIter = maProperties.find( aName );
     172         269 :     return aIter != maProperties.end();
     173             : }
     174             : 
     175             : // XElementAccess
     176           1 : ::com::sun::star::uno::Type SAL_CALL NamedPropertyValuesContainer::getElementType(  )
     177             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     178             : {
     179           1 :     return cppu::UnoType<uno::Sequence<beans::PropertyValue>>::get();
     180             : }
     181             : 
     182         355 : sal_Bool SAL_CALL NamedPropertyValuesContainer::hasElements(  )
     183             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     184             : {
     185         355 :     return !maProperties.empty();
     186             : }
     187             : 
     188             : //XServiceInfo
     189           1 : OUString SAL_CALL NamedPropertyValuesContainer::getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     190             : {
     191           1 :     return getImplementationName_static();
     192             : }
     193             : 
     194         192 : OUString SAL_CALL NamedPropertyValuesContainer::getImplementationName_static(  )
     195             : {
     196         192 :     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           1 : ::com::sun::star::uno::Sequence< OUString > SAL_CALL NamedPropertyValuesContainer::getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     205             : {
     206           1 :     return getSupportedServiceNames_static();
     207             : }
     208             : 
     209         192 : ::com::sun::star::uno::Sequence< OUString > SAL_CALL NamedPropertyValuesContainer::getSupportedServiceNames_static(  )
     210             : {
     211         192 :     const OUString aServiceName( "com.sun.star.document.NamedPropertyValues" );
     212         192 :     const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
     213         192 :     return aSeq;
     214             : }
     215             : 
     216         821 : uno::Reference< uno::XInterface > SAL_CALL NamedPropertyValuesContainer::Create(
     217             :                 SAL_UNUSED_PARAMETER const uno::Reference< uno::XComponentContext >&)
     218             : {
     219         821 :     return static_cast<cppu::OWeakObject*>(new NamedPropertyValuesContainer());
     220             : }
     221             : 
     222         191 : void createRegistryInfo_NamedPropertyValuesContainer()
     223             : {
     224         191 :     static ::comphelper::module::OAutoRegistration< NamedPropertyValuesContainer > aAutoRegistration;
     225         191 : }
     226             : 
     227             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11