LCOV - code coverage report
Current view: top level - comphelper/source/property - propertysetinfo.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 61 64 95.3 %
Date: 2015-06-13 12:38:46 Functions: 19 19 100.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/propertysetinfo.hxx>
      22             : 
      23             : 
      24             : using namespace ::comphelper;
      25             : using namespace ::com::sun::star;
      26             : using namespace ::com::sun::star::uno;
      27             : using namespace ::com::sun::star::beans;
      28             : using namespace ::com::sun::star::lang;
      29             : 
      30             : namespace comphelper
      31             : {
      32             : class PropertyMapImpl
      33             : {
      34             : public:
      35             :     PropertyMapImpl() throw();
      36             :     virtual ~PropertyMapImpl() throw();
      37             : 
      38             :     void add(PropertyMapEntry const * pMap) throw();
      39             :     void remove( const OUString& aName ) throw();
      40             : 
      41             :     Sequence< Property > getProperties() throw();
      42             : 
      43      278334 :     const PropertyMap& getPropertyMap() const throw() { return maPropertyMap;}
      44             : 
      45             :     Property getPropertyByName( const OUString& aName ) throw( UnknownPropertyException );
      46             :     bool hasPropertyByName( const OUString& aName ) throw();
      47             : 
      48             : private:
      49             :     PropertyMap maPropertyMap;
      50             :     Sequence< Property > maProperties;
      51             : };
      52             : }
      53             : 
      54       82951 : PropertyMapImpl::PropertyMapImpl() throw()
      55             : {
      56       82951 : }
      57             : 
      58      165746 : PropertyMapImpl::~PropertyMapImpl() throw()
      59             : {
      60      165746 : }
      61             : 
      62       83112 : void PropertyMapImpl::add(PropertyMapEntry const * pMap) throw()
      63             : {
      64      863806 :     while (!pMap->maName.isEmpty())
      65             :     {
      66             :         // check for duplicates
      67             :         assert(maPropertyMap.find(pMap->maName) == maPropertyMap.end());
      68             : 
      69      697582 :         maPropertyMap[pMap->maName] = pMap;
      70             : 
      71      697582 :         if( maProperties.getLength() )
      72           0 :             maProperties.realloc( 0 );
      73             : 
      74      697582 :         pMap = &pMap[1];
      75             :     }
      76       83112 : }
      77             : 
      78          36 : void PropertyMapImpl::remove( const OUString& aName ) throw()
      79             : {
      80          36 :     maPropertyMap.erase( aName );
      81             : 
      82          36 :     if( maProperties.getLength() )
      83           0 :         maProperties.realloc( 0 );
      84          36 : }
      85             : 
      86         593 : Sequence< Property > PropertyMapImpl::getProperties() throw()
      87             : {
      88             :     // maybe we have to generate the properties after
      89             :     // a change in the property map or at first call
      90             :     // to getProperties
      91         593 :     if( maProperties.getLength() != (sal_Int32)maPropertyMap.size() )
      92             :     {
      93         311 :         maProperties = Sequence< Property >( maPropertyMap.size() );
      94         311 :         Property* pProperties = maProperties.getArray();
      95             : 
      96         311 :         PropertyMap::iterator aIter = maPropertyMap.begin();
      97         311 :         const PropertyMap::iterator aEnd = maPropertyMap.end();
      98       20689 :         while( aIter != aEnd )
      99             :         {
     100       20067 :             PropertyMapEntry const * pEntry = (*aIter).second;
     101             : 
     102       20067 :             pProperties->Name = pEntry->maName;
     103       20067 :             pProperties->Handle = pEntry->mnHandle;
     104       20067 :             pProperties->Type = pEntry->maType;
     105       20067 :             pProperties->Attributes = pEntry->mnAttributes;
     106             : 
     107       20067 :             ++pProperties;
     108       20067 :             ++aIter;
     109             :         }
     110             :     }
     111             : 
     112         593 :     return maProperties;
     113             : }
     114             : 
     115             : 
     116          55 : Property PropertyMapImpl::getPropertyByName( const OUString& aName ) throw( UnknownPropertyException )
     117             : {
     118          55 :     PropertyMap::iterator aIter = maPropertyMap.find( aName );
     119             : 
     120          55 :     if( maPropertyMap.end() == aIter )
     121           0 :         throw UnknownPropertyException( aName );
     122             : 
     123          55 :     PropertyMapEntry const * pEntry = (*aIter).second;
     124             : 
     125          55 :     return Property( aName, pEntry->mnHandle, pEntry->maType, pEntry->mnAttributes );
     126             : }
     127             : 
     128      120796 : bool PropertyMapImpl::hasPropertyByName( const OUString& aName ) throw()
     129             : {
     130      120796 :     return maPropertyMap.find( aName ) != maPropertyMap.end();
     131             : }
     132             : 
     133             : 
     134             : 
     135       80813 : PropertySetInfo::PropertySetInfo() throw()
     136             : {
     137       80813 :     mpMap = new PropertyMapImpl();
     138       80813 : }
     139             : 
     140        2138 : PropertySetInfo::PropertySetInfo( PropertyMapEntry const * pMap ) throw()
     141             : {
     142        2138 :     mpMap = new PropertyMapImpl();
     143        2138 :     mpMap->add( pMap );
     144        2138 : }
     145             : 
     146      248619 : PropertySetInfo::~PropertySetInfo() throw()
     147             : {
     148       82873 :     delete mpMap;
     149      165746 : }
     150             : 
     151       80974 : void PropertySetInfo::add( PropertyMapEntry const * pMap ) throw()
     152             : {
     153       80974 :     mpMap->add( pMap );
     154       80974 : }
     155             : 
     156          36 : void PropertySetInfo::remove( const OUString& aName ) throw()
     157             : {
     158          36 :     mpMap->remove( aName );
     159          36 : }
     160             : 
     161         593 : Sequence< ::com::sun::star::beans::Property > SAL_CALL PropertySetInfo::getProperties() throw(::com::sun::star::uno::RuntimeException, std::exception)
     162             : {
     163         593 :     return mpMap->getProperties();
     164             : }
     165             : 
     166          55 : Property SAL_CALL PropertySetInfo::getPropertyByName( const OUString& aName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException, std::exception)
     167             : {
     168          55 :     return mpMap->getPropertyByName( aName );
     169             : }
     170             : 
     171      120796 : sal_Bool SAL_CALL PropertySetInfo::hasPropertyByName( const OUString& Name ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     172             : {
     173      120796 :     return mpMap->hasPropertyByName( Name );
     174             : }
     175             : 
     176      278334 : const PropertyMap& PropertySetInfo::getPropertyMap() const throw()
     177             : {
     178      278334 :     return mpMap->getPropertyMap();
     179             : }
     180             : 
     181             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11