LCOV - code coverage report
Current view: top level - comphelper/source/container - NamedPropertyValuesContainer.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 57 66 86.4 %
Date: 2014-04-11 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         454 : NamedPropertyValuesContainer::NamedPropertyValuesContainer() throw()
      86             : {
      87         454 : }
      88             : 
      89         898 : NamedPropertyValuesContainer::~NamedPropertyValuesContainer() throw()
      90             : {
      91         898 : }
      92             : 
      93             : // XNameContainer
      94         505 : 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         505 :     if( maProperties.find( aName ) != maProperties.end() )
      99           1 :         throw container::ElementExistException();
     100             : 
     101         504 :     uno::Sequence<beans::PropertyValue> aProps;
     102         504 :     if( !(aElement >>= aProps ) )
     103           1 :         throw lang::IllegalArgumentException();
     104             : 
     105         503 :     maProperties.insert(  NamedPropertyValues::value_type(aName ,aProps) );
     106         503 : }
     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         305 : ::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         305 :     NamedPropertyValues::iterator aIter = maProperties.find( aName );
     141         305 :     if( aIter == maProperties.end() )
     142           0 :         throw container::NoSuchElementException();
     143             : 
     144         305 :     uno::Any aElement;
     145             : 
     146         305 :     aElement <<= (*aIter).second;
     147             : 
     148         305 :     return aElement;
     149             : }
     150             : 
     151         227 : ::com::sun::star::uno::Sequence< OUString > SAL_CALL NamedPropertyValuesContainer::getElementNames(  )
     152             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     153             : {
     154         227 :     NamedPropertyValues::iterator aIter = maProperties.begin();
     155         227 :     const NamedPropertyValues::iterator aEnd = maProperties.end();
     156             : 
     157         227 :     uno::Sequence< OUString > aNames( maProperties.size() );
     158         227 :     OUString* pNames = aNames.getArray();
     159             : 
     160         759 :     while( aIter != aEnd )
     161             :     {
     162         305 :         *pNames++ = (*aIter++).first;
     163             :     }
     164             : 
     165         227 :     return aNames;
     166             : }
     167             : 
     168          85 : sal_Bool SAL_CALL NamedPropertyValuesContainer::hasByName( const OUString& aName )
     169             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     170             : {
     171          85 :     NamedPropertyValues::iterator aIter = maProperties.find( aName );
     172          85 :     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 ::getCppuType((uno::Sequence<beans::PropertyValue> *)0);
     180             : }
     181             : 
     182         229 : sal_Bool SAL_CALL NamedPropertyValuesContainer::hasElements(  )
     183             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     184             : {
     185         229 :     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         128 : OUString SAL_CALL NamedPropertyValuesContainer::getImplementationName_static(  )
     195             : {
     196         128 :     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         128 : ::com::sun::star::uno::Sequence< OUString > SAL_CALL NamedPropertyValuesContainer::getSupportedServiceNames_static(  )
     210             : {
     211         128 :     const OUString aServiceName( "com.sun.star.document.NamedPropertyValues" );
     212         128 :     const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
     213         128 :     return aSeq;
     214             : }
     215             : 
     216         454 : uno::Reference< uno::XInterface > SAL_CALL NamedPropertyValuesContainer::Create(
     217             :                 SAL_UNUSED_PARAMETER const uno::Reference< uno::XComponentContext >&)
     218             : {
     219         454 :     return (cppu::OWeakObject*)new NamedPropertyValuesContainer();
     220             : }
     221             : 
     222         128 : void createRegistryInfo_NamedPropertyValuesContainer()
     223             : {
     224         128 :     static ::comphelper::module::OAutoRegistration< NamedPropertyValuesContainer > aAutoRegistration;
     225         128 : }
     226             : 
     227             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10