LCOV - code coverage report
Current view: top level - comphelper/source/container - namecontainer.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 32 56 57.1 %
Date: 2014-04-11 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         418 :     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             :         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 ::rtl;
      83             : using namespace ::com::sun::star::uno;
      84             : using namespace ::com::sun::star::container;
      85             : using namespace ::com::sun::star::lang;
      86             : 
      87             : 
      88         209 : NameContainer::NameContainer( ::com::sun::star::uno::Type aType )
      89         209 : : maType( aType )
      90             : {
      91         209 : }
      92             : 
      93         418 : NameContainer::~NameContainer()
      94             : {
      95         418 : }
      96             : 
      97             : // XNameContainer
      98         762 : void SAL_CALL NameContainer::insertByName( const OUString& aName, const Any& aElement )
      99             :     throw(IllegalArgumentException, ElementExistException,
     100             :         WrappedTargetException, RuntimeException, std::exception)
     101             : {
     102         762 :     MutexGuard aGuard( maMutex );
     103             : 
     104         762 :     if( maProperties.find( aName ) != maProperties.end() )
     105           0 :         throw ElementExistException();
     106             : 
     107         762 :     if( aElement.getValueType() != maType )
     108           0 :         throw IllegalArgumentException();
     109             : 
     110         762 :     maProperties.insert( SvGenericNameContainerMapImpl::value_type(aName,aElement));
     111         762 : }
     112             : 
     113           0 : void SAL_CALL NameContainer::removeByName( const OUString& Name )
     114             :     throw(NoSuchElementException, WrappedTargetException,
     115             :         RuntimeException, std::exception)
     116             : {
     117           0 :     MutexGuard aGuard( maMutex );
     118             : 
     119           0 :     SvGenericNameContainerMapImpl::iterator aIter = maProperties.find( Name );
     120           0 :     if( aIter == maProperties.end() )
     121           0 :         throw NoSuchElementException();
     122             : 
     123           0 :     maProperties.erase( aIter );
     124           0 : }
     125             : 
     126             : // XNameReplace
     127             : 
     128           0 : void SAL_CALL NameContainer::replaceByName( const OUString& aName, const Any& aElement )
     129             :     throw(IllegalArgumentException, NoSuchElementException,
     130             :         WrappedTargetException, RuntimeException, std::exception)
     131             : {
     132           0 :     MutexGuard aGuard( maMutex );
     133             : 
     134           0 :     SvGenericNameContainerMapImpl::iterator aIter( maProperties.find( aName ) );
     135           0 :     if( aIter == maProperties.end() )
     136           0 :         throw NoSuchElementException();
     137             : 
     138           0 :     if( aElement.getValueType() != maType )
     139           0 :         throw IllegalArgumentException();
     140             : 
     141           0 :     (*aIter).second = aElement;
     142           0 : }
     143             : 
     144             : // XNameAccess
     145             : 
     146         556 : Any SAL_CALL NameContainer::getByName( const OUString& aName )
     147             :     throw(NoSuchElementException, WrappedTargetException,
     148             :         RuntimeException, std::exception)
     149             : {
     150         556 :     MutexGuard aGuard( maMutex );
     151             : 
     152         556 :     SvGenericNameContainerMapImpl::iterator aIter = maProperties.find( aName );
     153         556 :     if( aIter == maProperties.end() )
     154           0 :         throw NoSuchElementException();
     155             : 
     156         556 :     return (*aIter).second;
     157             : }
     158             : 
     159         107 : Sequence< OUString > SAL_CALL NameContainer::getElementNames(  )
     160             :     throw(RuntimeException, std::exception)
     161             : {
     162         107 :     MutexGuard aGuard( maMutex );
     163             : 
     164         107 :     SvGenericNameContainerMapImpl::iterator aIter = maProperties.begin();
     165         107 :     const SvGenericNameContainerMapImpl::iterator aEnd = maProperties.end();
     166             : 
     167         107 :     Sequence< OUString > aNames( maProperties.size() );
     168         107 :     OUString* pNames = aNames.getArray();
     169             : 
     170         753 :     while( aIter != aEnd )
     171             :     {
     172         539 :         *pNames++ = (*aIter++).first;
     173             :     }
     174             : 
     175         107 :     return aNames;
     176             : }
     177             : 
     178          17 : sal_Bool SAL_CALL NameContainer::hasByName( const OUString& aName )
     179             :     throw(RuntimeException, std::exception)
     180             : {
     181          17 :     MutexGuard aGuard( maMutex );
     182             : 
     183          17 :     SvGenericNameContainerMapImpl::iterator aIter = maProperties.find( aName );
     184          17 :     return aIter != maProperties.end();
     185             : }
     186             : 
     187           0 : sal_Bool SAL_CALL NameContainer::hasElements(  )
     188             :     throw(RuntimeException, std::exception)
     189             : {
     190           0 :     MutexGuard aGuard( maMutex );
     191             : 
     192           0 :     return !maProperties.empty();
     193             : }
     194             : 
     195           0 : Type SAL_CALL NameContainer::getElementType()
     196             :     throw( RuntimeException, std::exception )
     197             : {
     198           0 :     return maType;
     199             : }
     200             : 
     201         209 : Reference< XNameContainer > comphelper::NameContainer_createInstance( Type aType )
     202             : {
     203         209 :     return (XNameContainer*) new NameContainer( aType );
     204             : }
     205             : 
     206             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10