LCOV - code coverage report
Current view: top level - comphelper/source/property - propertysetinfo.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 65 69 94.2 %
Date: 2012-08-25 Functions: 19 19 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 29 60 48.3 %

           Branch data     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 ::rtl;
      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* pMap, sal_Int32 nCount = -1 ) throw();
      39                 :            :     void remove( const OUString& aName ) throw();
      40                 :            : 
      41                 :            :     Sequence< Property > getProperties() throw();
      42                 :            : 
      43                 :            :     const PropertyMap* getPropertyMap() const throw();
      44                 :            : 
      45                 :            :     Property getPropertyByName( const OUString& aName ) throw( UnknownPropertyException );
      46                 :            :     sal_Bool hasPropertyByName( const OUString& aName ) throw();
      47                 :            : 
      48                 :            : private:
      49                 :            :     PropertyMap maPropertyMap;
      50                 :            :     Sequence< Property > maProperties;
      51                 :            : };
      52                 :            : }
      53                 :            : 
      54         [ +  - ]:      76553 : PropertyMapImpl::PropertyMapImpl() throw()
      55                 :            : {
      56                 :      76553 : }
      57                 :            : 
      58         [ +  - ]:      76083 : PropertyMapImpl::~PropertyMapImpl() throw()
      59                 :            : {
      60         [ -  + ]:     152166 : }
      61                 :            : 
      62                 :      76616 : void PropertyMapImpl::add( PropertyMapEntry* pMap, sal_Int32 nCount ) throw()
      63                 :            : {
      64                 :            :     // nCount < 0   => add all
      65                 :            :     // nCount == 0  => add nothing
      66                 :            :     // nCount > 0   => add at most nCount entries
      67                 :            : 
      68 [ +  + ][ -  + ]:     718837 :     while( pMap->mpName && ( ( nCount < 0) || ( nCount-- > 0 ) ) )
         [ #  # ][ +  + ]
      69                 :            :     {
      70         [ +  - ]:     642221 :         OUString aName( pMap->mpName, pMap->mnNameLen, RTL_TEXTENCODING_ASCII_US );
      71                 :            : 
      72                 :            : #ifdef DBG_UTIL
      73                 :            :         PropertyMap::iterator aIter = maPropertyMap.find( aName );
      74                 :            :         if( aIter != maPropertyMap.end() )
      75                 :            :         {
      76                 :            :             OSL_FAIL( "Warning: PropertyMapEntry added twice, possible error!");
      77                 :            :         }
      78                 :            : #endif
      79         [ -  + ]:     642221 :         if( NULL == pMap->mpType )
      80                 :            :         {
      81                 :            :             OSL_FAIL( "No type in PropertyMapEntry!");
      82         [ #  # ]:          0 :             pMap->mpType = &::getCppuType((const sal_Int32*)0);
      83                 :            :         }
      84                 :            : 
      85         [ +  - ]:     642221 :         maPropertyMap[aName] = pMap;
      86                 :            : 
      87         [ -  + ]:     642221 :         if( maProperties.getLength() )
      88         [ #  # ]:          0 :             maProperties.realloc( 0 );
      89                 :            : 
      90                 :     642221 :         pMap = &pMap[1];
      91                 :     642221 :     }
      92                 :      76616 : }
      93                 :            : 
      94                 :         33 : void PropertyMapImpl::remove( const OUString& aName ) throw()
      95                 :            : {
      96                 :         33 :     maPropertyMap.erase( aName );
      97                 :            : 
      98         [ -  + ]:         33 :     if( maProperties.getLength() )
      99                 :          0 :         maProperties.realloc( 0 );
     100                 :         33 : }
     101                 :            : 
     102                 :        898 : Sequence< Property > PropertyMapImpl::getProperties() throw()
     103                 :            : {
     104                 :            :     // maybe we have to generate the properties after
     105                 :            :     // a change in the property map or at first call
     106                 :            :     // to getProperties
     107         [ +  + ]:        898 :     if( maProperties.getLength() != (sal_Int32)maPropertyMap.size() )
     108                 :            :     {
     109 [ +  - ][ +  - ]:        472 :         maProperties = Sequence< Property >( maPropertyMap.size() );
                 [ +  - ]
     110         [ +  - ]:        472 :         Property* pProperties = maProperties.getArray();
     111                 :            : 
     112                 :        472 :         PropertyMap::iterator aIter = maPropertyMap.begin();
     113                 :        472 :         const PropertyMap::iterator aEnd = maPropertyMap.end();
     114         [ +  + ]:      30768 :         while( aIter != aEnd )
     115                 :            :         {
     116                 :      30296 :             PropertyMapEntry* pEntry = (*aIter).second;
     117                 :            : 
     118         [ +  - ]:      30296 :             pProperties->Name = OUString( pEntry->mpName, pEntry->mnNameLen, RTL_TEXTENCODING_ASCII_US );
     119                 :      30296 :             pProperties->Handle = pEntry->mnHandle;
     120                 :      30296 :             pProperties->Type = *pEntry->mpType;
     121                 :      30296 :             pProperties->Attributes = pEntry->mnAttributes;
     122                 :            : 
     123                 :      30296 :             ++pProperties;
     124                 :      30296 :             ++aIter;
     125                 :            :         }
     126                 :            :     }
     127                 :            : 
     128                 :        898 :     return maProperties;
     129                 :            : }
     130                 :            : 
     131                 :     177846 : const PropertyMap* PropertyMapImpl::getPropertyMap() const throw()
     132                 :            : {
     133                 :     177846 :     return &maPropertyMap;
     134                 :            : }
     135                 :            : 
     136                 :        110 : Property PropertyMapImpl::getPropertyByName( const OUString& aName ) throw( UnknownPropertyException )
     137                 :            : {
     138         [ +  - ]:        110 :     PropertyMap::iterator aIter = maPropertyMap.find( aName );
     139                 :            : 
     140         [ -  + ]:        110 :     if( maPropertyMap.end() == aIter )
     141 [ #  # ][ #  # ]:          0 :         throw UnknownPropertyException( aName, NULL );
     142                 :            : 
     143                 :        110 :     PropertyMapEntry* pEntry = (*aIter).second;
     144                 :            : 
     145                 :        110 :     return Property( aName, pEntry->mnHandle, *pEntry->mpType, pEntry->mnAttributes );
     146                 :            : }
     147                 :            : 
     148                 :      43279 : sal_Bool PropertyMapImpl::hasPropertyByName( const OUString& aName ) throw()
     149                 :            : {
     150         [ +  - ]:      43279 :     return maPropertyMap.find( aName ) != maPropertyMap.end();
     151                 :            : }
     152                 :            : 
     153                 :            : ///////////////////////////////////////////////////////////////////////
     154                 :            : 
     155                 :      74751 : PropertySetInfo::PropertySetInfo() throw()
     156                 :            : {
     157         [ +  - ]:      74751 :     mpMap = new PropertyMapImpl();
     158                 :      74751 : }
     159                 :            : 
     160                 :       1802 : PropertySetInfo::PropertySetInfo( PropertyMapEntry* pMap ) throw()
     161                 :            : {
     162         [ +  - ]:       1802 :     mpMap = new PropertyMapImpl();
     163                 :       1802 :     mpMap->add( pMap );
     164                 :       1802 : }
     165                 :            : 
     166                 :      76083 : PropertySetInfo::~PropertySetInfo() throw()
     167                 :            : {
     168         [ +  - ]:      76083 :     delete mpMap;
     169         [ -  + ]:     152166 : }
     170                 :            : 
     171                 :      74814 : void PropertySetInfo::add( PropertyMapEntry* pMap ) throw()
     172                 :            : {
     173                 :      74814 :     mpMap->add( pMap );
     174                 :      74814 : }
     175                 :            : 
     176                 :         33 : void PropertySetInfo::remove( const rtl::OUString& aName ) throw()
     177                 :            : {
     178                 :         33 :     mpMap->remove( aName );
     179                 :         33 : }
     180                 :            : 
     181                 :        898 : Sequence< ::com::sun::star::beans::Property > SAL_CALL PropertySetInfo::getProperties() throw(::com::sun::star::uno::RuntimeException)
     182                 :            : {
     183                 :        898 :     return mpMap->getProperties();
     184                 :            : }
     185                 :            : 
     186                 :        110 : Property SAL_CALL PropertySetInfo::getPropertyByName( const ::rtl::OUString& aName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
     187                 :            : {
     188                 :        110 :     return mpMap->getPropertyByName( aName );
     189                 :            : }
     190                 :            : 
     191                 :      43279 : sal_Bool SAL_CALL PropertySetInfo::hasPropertyByName( const ::rtl::OUString& Name ) throw(::com::sun::star::uno::RuntimeException)
     192                 :            : {
     193                 :      43279 :     return mpMap->hasPropertyByName( Name );
     194                 :            : }
     195                 :            : 
     196                 :     177846 : const PropertyMap* PropertySetInfo::getPropertyMap() const throw()
     197                 :            : {
     198                 :     177846 :     return mpMap->getPropertyMap();
     199                 :            : }
     200                 :            : 
     201                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10