LCOV - code coverage report
Current view: top level - comphelper/source/property - propertysetinfo.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 61 64 95.3 %
Date: 2014-11-03 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             : using namespace ::comphelper;
      24             : using namespace ::com::sun::star;
      25             : using namespace ::com::sun::star::uno;
      26             : using namespace ::com::sun::star::beans;
      27             : using namespace ::com::sun::star::lang;
      28             : 
      29             : namespace comphelper
      30             : {
      31             : class PropertyMapImpl
      32             : {
      33             : public:
      34             :     PropertyMapImpl() throw();
      35             :     virtual ~PropertyMapImpl() throw();
      36             : 
      37             :     void add( PropertyMapEntry const * pMap, sal_Int32 nCount = -1 ) throw();
      38             :     void remove( const OUString& aName ) throw();
      39             : 
      40             :     Sequence< Property > getProperties() throw();
      41             : 
      42      394220 :     const PropertyMap& getPropertyMap() const throw() { return maPropertyMap;}
      43             : 
      44             :     Property getPropertyByName( const OUString& aName ) throw( UnknownPropertyException );
      45             :     bool hasPropertyByName( const OUString& aName ) throw();
      46             : 
      47             : private:
      48             :     PropertyMap maPropertyMap;
      49             :     Sequence< Property > maProperties;
      50             : };
      51             : }
      52             : 
      53      141210 : PropertyMapImpl::PropertyMapImpl() throw()
      54             : {
      55      141210 : }
      56             : 
      57      282176 : PropertyMapImpl::~PropertyMapImpl() throw()
      58             : {
      59      282176 : }
      60             : 
      61      141370 : void PropertyMapImpl::add( PropertyMapEntry const * pMap, sal_Int32 nCount ) throw()
      62             : {
      63             :     // nCount < 0   => add all
      64             :     // nCount == 0  => add nothing
      65             :     // nCount > 0   => add at most nCount entries
      66             : 
      67     1466002 :     while( !pMap->maName.isEmpty() && ( ( nCount < 0) || ( nCount-- > 0 ) ) )
      68             :     {
      69             : #ifdef DBG_UTIL
      70             :         PropertyMap::iterator aIter = maPropertyMap.find( pMap->maName );
      71             :         if( aIter != maPropertyMap.end() )
      72             :         {
      73             :             OSL_FAIL( "Warning: PropertyMapEntry added twice, possible error!");
      74             :         }
      75             : #endif
      76             : 
      77     1183262 :         maPropertyMap[pMap->maName] = pMap;
      78             : 
      79     1183262 :         if( maProperties.getLength() )
      80           0 :             maProperties.realloc( 0 );
      81             : 
      82     1183262 :         pMap = &pMap[1];
      83             :     }
      84      141370 : }
      85             : 
      86          54 : void PropertyMapImpl::remove( const OUString& aName ) throw()
      87             : {
      88          54 :     maPropertyMap.erase( aName );
      89             : 
      90          54 :     if( maProperties.getLength() )
      91           0 :         maProperties.realloc( 0 );
      92          54 : }
      93             : 
      94        1174 : Sequence< Property > PropertyMapImpl::getProperties() throw()
      95             : {
      96             :     // maybe we have to generate the properties after
      97             :     // a change in the property map or at first call
      98             :     // to getProperties
      99        1174 :     if( maProperties.getLength() != (sal_Int32)maPropertyMap.size() )
     100             :     {
     101         610 :         maProperties = Sequence< Property >( maPropertyMap.size() );
     102         610 :         Property* pProperties = maProperties.getArray();
     103             : 
     104         610 :         PropertyMap::iterator aIter = maPropertyMap.begin();
     105         610 :         const PropertyMap::iterator aEnd = maPropertyMap.end();
     106       40794 :         while( aIter != aEnd )
     107             :         {
     108       39574 :             PropertyMapEntry const * pEntry = (*aIter).second;
     109             : 
     110       39574 :             pProperties->Name = pEntry->maName;
     111       39574 :             pProperties->Handle = pEntry->mnHandle;
     112       39574 :             pProperties->Type = pEntry->maType;
     113       39574 :             pProperties->Attributes = pEntry->mnAttributes;
     114             : 
     115       39574 :             ++pProperties;
     116       39574 :             ++aIter;
     117             :         }
     118             :     }
     119             : 
     120        1174 :     return maProperties;
     121             : }
     122             : 
     123             : 
     124         110 : Property PropertyMapImpl::getPropertyByName( const OUString& aName ) throw( UnknownPropertyException )
     125             : {
     126         110 :     PropertyMap::iterator aIter = maPropertyMap.find( aName );
     127             : 
     128         110 :     if( maPropertyMap.end() == aIter )
     129           0 :         throw UnknownPropertyException( aName );
     130             : 
     131         110 :     PropertyMapEntry const * pEntry = (*aIter).second;
     132             : 
     133         110 :     return Property( aName, pEntry->mnHandle, pEntry->maType, pEntry->mnAttributes );
     134             : }
     135             : 
     136      149892 : bool PropertyMapImpl::hasPropertyByName( const OUString& aName ) throw()
     137             : {
     138      149892 :     return maPropertyMap.find( aName ) != maPropertyMap.end();
     139             : }
     140             : 
     141             : 
     142             : 
     143      137544 : PropertySetInfo::PropertySetInfo() throw()
     144             : {
     145      137544 :     mpMap = new PropertyMapImpl();
     146      137544 : }
     147             : 
     148        3666 : PropertySetInfo::PropertySetInfo( PropertyMapEntry const * pMap ) throw()
     149             : {
     150        3666 :     mpMap = new PropertyMapImpl();
     151        3666 :     mpMap->add( pMap );
     152        3666 : }
     153             : 
     154      423264 : PropertySetInfo::~PropertySetInfo() throw()
     155             : {
     156      141088 :     delete mpMap;
     157      282176 : }
     158             : 
     159      137704 : void PropertySetInfo::add( PropertyMapEntry const * pMap ) throw()
     160             : {
     161      137704 :     mpMap->add( pMap );
     162      137704 : }
     163             : 
     164          54 : void PropertySetInfo::remove( const OUString& aName ) throw()
     165             : {
     166          54 :     mpMap->remove( aName );
     167          54 : }
     168             : 
     169        1174 : Sequence< ::com::sun::star::beans::Property > SAL_CALL PropertySetInfo::getProperties() throw(::com::sun::star::uno::RuntimeException, std::exception)
     170             : {
     171        1174 :     return mpMap->getProperties();
     172             : }
     173             : 
     174         110 : Property SAL_CALL PropertySetInfo::getPropertyByName( const OUString& aName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException, std::exception)
     175             : {
     176         110 :     return mpMap->getPropertyByName( aName );
     177             : }
     178             : 
     179      149892 : sal_Bool SAL_CALL PropertySetInfo::hasPropertyByName( const OUString& Name ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     180             : {
     181      149892 :     return mpMap->hasPropertyByName( Name );
     182             : }
     183             : 
     184      394220 : const PropertyMap& PropertySetInfo::getPropertyMap() const throw()
     185             : {
     186      394220 :     return mpMap->getPropertyMap();
     187             : }
     188             : 
     189             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10