LCOV - code coverage report
Current view: top level - comphelper/source/container - namecontainer.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 32 56 57.1 %
Date: 2015-06-13 12:38:46 Functions: 10 14 71.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             : #include <sal/config.h>
      21             : 
      22             : #include <map>
      23             : 
      24             : #include <comphelper/namecontainer.hxx>
      25             : #include <cppuhelper/implbase1.hxx>
      26             : #include <osl/diagnose.h>
      27             : #include <osl/mutex.hxx>
      28             : 
      29             : typedef std::map<OUString, ::com::sun::star::uno::Any> SvGenericNameContainerMapImpl;
      30             : 
      31             : namespace comphelper
      32             : {
      33         674 :     class NameContainerImpl
      34             :     {
      35             :     public:
      36             :         osl::Mutex maMutex;
      37             :     };
      38             : 
      39             :     /** this is the base helper class for NameContainer thats also declared in this header. */
      40             :     class NameContainer : public ::cppu::WeakImplHelper1< ::com::sun::star::container::XNameContainer >, private NameContainerImpl
      41             :     {
      42             :     public:
      43             :         explicit NameContainer( ::com::sun::star::uno::Type aType );
      44             :         virtual ~NameContainer();
      45             : 
      46             :         // XNameContainer
      47             :         virtual void SAL_CALL insertByName( const OUString& aName, const ::com::sun::star::uno::Any& aElement )
      48             :             throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException,
      49             :             ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      50             :         virtual void SAL_CALL removeByName( const OUString& Name )
      51             :             throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException,
      52             :                 ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      53             : 
      54             :         // XNameReplace
      55             :         virtual void SAL_CALL replaceByName( const OUString& aName, const ::com::sun::star::uno::Any& aElement )
      56             :             throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException,
      57             :                 ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      58             : 
      59             :         // XNameAccess
      60             :         virtual ::com::sun::star::uno::Any SAL_CALL getByName( const OUString& aName )
      61             :             throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException,
      62             :                 ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      63             :         virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getElementNames(  )
      64             :             throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      65             :         virtual sal_Bool SAL_CALL hasByName( const OUString& aName )
      66             :             throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      67             : 
      68             :         // XElementAccess
      69             :         virtual sal_Bool SAL_CALL hasElements(  )
      70             :             throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      71             :         virtual ::com::sun::star::uno::Type SAL_CALL getElementType(  )
      72             :             throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      73             : 
      74             :     private:
      75             :         SvGenericNameContainerMapImpl maProperties;
      76             :         const ::com::sun::star::uno::Type maType;
      77             :     };
      78             : }
      79             : 
      80             : using namespace ::comphelper;
      81             : using namespace ::osl;
      82             : using namespace ::com::sun::star::uno;
      83             : using namespace ::com::sun::star::container;
      84             : using namespace ::com::sun::star::lang;
      85             : 
      86             : 
      87         337 : NameContainer::NameContainer( ::com::sun::star::uno::Type aType )
      88         337 : : maType( aType )
      89             : {
      90         337 : }
      91             : 
      92         674 : NameContainer::~NameContainer()
      93             : {
      94         674 : }
      95             : 
      96             : // XNameContainer
      97        1400 : void SAL_CALL NameContainer::insertByName( const OUString& aName, const Any& aElement )
      98             :     throw(IllegalArgumentException, ElementExistException,
      99             :         WrappedTargetException, RuntimeException, std::exception)
     100             : {
     101        1400 :     MutexGuard aGuard( maMutex );
     102             : 
     103        1400 :     if( maProperties.find( aName ) != maProperties.end() )
     104           0 :         throw ElementExistException();
     105             : 
     106        1400 :     if( aElement.getValueType() != maType )
     107           0 :         throw IllegalArgumentException();
     108             : 
     109        1400 :     maProperties.insert( SvGenericNameContainerMapImpl::value_type(aName,aElement));
     110        1400 : }
     111             : 
     112           0 : void SAL_CALL NameContainer::removeByName( const OUString& Name )
     113             :     throw(NoSuchElementException, WrappedTargetException,
     114             :         RuntimeException, std::exception)
     115             : {
     116           0 :     MutexGuard aGuard( maMutex );
     117             : 
     118           0 :     SvGenericNameContainerMapImpl::iterator aIter = maProperties.find( Name );
     119           0 :     if( aIter == maProperties.end() )
     120           0 :         throw NoSuchElementException();
     121             : 
     122           0 :     maProperties.erase( aIter );
     123           0 : }
     124             : 
     125             : // XNameReplace
     126             : 
     127           0 : void SAL_CALL NameContainer::replaceByName( const OUString& aName, const Any& aElement )
     128             :     throw(IllegalArgumentException, NoSuchElementException,
     129             :         WrappedTargetException, RuntimeException, std::exception)
     130             : {
     131           0 :     MutexGuard aGuard( maMutex );
     132             : 
     133           0 :     SvGenericNameContainerMapImpl::iterator aIter( maProperties.find( aName ) );
     134           0 :     if( aIter == maProperties.end() )
     135           0 :         throw NoSuchElementException();
     136             : 
     137           0 :     if( aElement.getValueType() != maType )
     138           0 :         throw IllegalArgumentException();
     139             : 
     140           0 :     (*aIter).second = aElement;
     141           0 : }
     142             : 
     143             : // XNameAccess
     144             : 
     145         962 : Any SAL_CALL NameContainer::getByName( const OUString& aName )
     146             :     throw(NoSuchElementException, WrappedTargetException,
     147             :         RuntimeException, std::exception)
     148             : {
     149         962 :     MutexGuard aGuard( maMutex );
     150             : 
     151         962 :     SvGenericNameContainerMapImpl::iterator aIter = maProperties.find( aName );
     152         962 :     if( aIter == maProperties.end() )
     153           0 :         throw NoSuchElementException();
     154             : 
     155         962 :     return (*aIter).second;
     156             : }
     157             : 
     158         168 : Sequence< OUString > SAL_CALL NameContainer::getElementNames(  )
     159             :     throw(RuntimeException, std::exception)
     160             : {
     161         168 :     MutexGuard aGuard( maMutex );
     162             : 
     163         168 :     SvGenericNameContainerMapImpl::iterator aIter = maProperties.begin();
     164         168 :     const SvGenericNameContainerMapImpl::iterator aEnd = maProperties.end();
     165             : 
     166         168 :     Sequence< OUString > aNames( maProperties.size() );
     167         168 :     OUString* pNames = aNames.getArray();
     168             : 
     169        1237 :     while( aIter != aEnd )
     170             :     {
     171         901 :         *pNames++ = (*aIter++).first;
     172             :     }
     173             : 
     174         168 :     return aNames;
     175             : }
     176             : 
     177          62 : sal_Bool SAL_CALL NameContainer::hasByName( const OUString& aName )
     178             :     throw(RuntimeException, std::exception)
     179             : {
     180          62 :     MutexGuard aGuard( maMutex );
     181             : 
     182          62 :     SvGenericNameContainerMapImpl::iterator aIter = maProperties.find( aName );
     183          62 :     return aIter != maProperties.end();
     184             : }
     185             : 
     186           0 : sal_Bool SAL_CALL NameContainer::hasElements(  )
     187             :     throw(RuntimeException, std::exception)
     188             : {
     189           0 :     MutexGuard aGuard( maMutex );
     190             : 
     191           0 :     return !maProperties.empty();
     192             : }
     193             : 
     194           0 : Type SAL_CALL NameContainer::getElementType()
     195             :     throw( RuntimeException, std::exception )
     196             : {
     197           0 :     return maType;
     198             : }
     199             : 
     200         337 : Reference< XNameContainer > comphelper::NameContainer_createInstance( Type aType )
     201             : {
     202         337 :     return static_cast<XNameContainer*>(new NameContainer( aType ));
     203             : }
     204             : 
     205             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11