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

Generated by: LCOV version 1.10