LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/comphelper/source/property - ChainablePropertySetInfo.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 45 48 93.8 %
Date: 2013-07-09 Functions: 8 8 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             : #include <comphelper/ChainablePropertySetInfo.hxx>
      21             : #include <comphelper/TypeGeneration.hxx>
      22             : 
      23             : using ::comphelper::PropertyInfo;
      24             : using ::comphelper::GenerateCppuType;
      25             : using ::comphelper::ChainablePropertySetInfo;
      26             : using ::com::sun::star::uno::Any;
      27             : using ::com::sun::star::uno::Type;
      28             : using ::com::sun::star::uno::Sequence;
      29             : using ::com::sun::star::uno::Reference;
      30             : using ::com::sun::star::uno::XInterface;
      31             : using ::com::sun::star::uno::RuntimeException;
      32             : using ::com::sun::star::beans::Property;
      33             : using ::com::sun::star::beans::XPropertySetInfo;
      34             : using ::com::sun::star::beans::UnknownPropertyException;
      35             : 
      36         926 : ChainablePropertySetInfo::ChainablePropertySetInfo( PropertyInfo* pMap )
      37         926 :     throw()
      38             : {
      39         926 :     add ( pMap );
      40         926 : }
      41             : 
      42        1852 : ChainablePropertySetInfo::~ChainablePropertySetInfo()
      43         926 :     throw()
      44             : {
      45        1852 : }
      46             : 
      47         926 : void ChainablePropertySetInfo::add( PropertyInfo* pMap, sal_Int32 nCount )
      48             :     throw()
      49             : {
      50             :     // nCount < 0   => add all
      51             :     // nCount == 0  => add nothing
      52             :     // nCount > 0   => add at most nCount entries
      53         926 :     if( maProperties.getLength() )
      54           0 :         maProperties.realloc( 0 );
      55             : 
      56       18842 :     while( pMap->mpName && ( ( nCount < 0) || ( nCount-- > 0 ) ) )
      57             :     {
      58       16990 :         OUString aName( pMap->mpName, pMap->mnNameLen, RTL_TEXTENCODING_ASCII_US );
      59             : 
      60             : #ifdef DBG_UTIL
      61             :         PropertyInfoHash::iterator aIter = maMap.find( aName );
      62             :         if( aIter != maMap.end() )
      63             :             OSL_FAIL( "Warning: PropertyInfo added twice, possible error!");
      64             : #endif
      65       16990 :         maMap[aName] = pMap++;
      66       16990 :     }
      67         926 : }
      68             : 
      69           1 : void ChainablePropertySetInfo::remove( const OUString& aName )
      70             :     throw()
      71             : {
      72           1 :     maMap.erase ( aName );
      73           1 :     if ( maProperties.getLength() )
      74           0 :          maProperties.realloc( 0 );
      75           1 : }
      76             : 
      77           1 : Sequence< ::Property > SAL_CALL ChainablePropertySetInfo::getProperties()
      78             :     throw(::com::sun::star::uno::RuntimeException)
      79             : {
      80           1 :     sal_Int32 nSize = maMap.size();
      81           1 :     if( maProperties.getLength() != nSize )
      82             :     {
      83           1 :         maProperties.realloc ( nSize );
      84           1 :         Property* pProperties = maProperties.getArray();
      85             : 
      86          42 :         for (PropertyInfoHash::const_iterator aIter(maMap.begin()), aEnd(maMap.end()); aIter != aEnd; ++aIter, ++pProperties)
      87             :         {
      88          41 :             PropertyInfo* pInfo = (*aIter).second;
      89             : 
      90          41 :             pProperties->Name = OUString( pInfo->mpName, pInfo->mnNameLen, RTL_TEXTENCODING_ASCII_US );
      91          41 :             pProperties->Handle = pInfo->mnHandle;
      92             :             const Type* pType;
      93          41 :             GenerateCppuType ( pInfo->meCppuType, pType);
      94          41 :             pProperties->Type = *pType;
      95          41 :             pProperties->Attributes = pInfo->mnAttributes;
      96             :         }
      97             :     }
      98           1 :     return maProperties;
      99             : }
     100             : 
     101          41 : Property SAL_CALL ChainablePropertySetInfo::getPropertyByName( const OUString& rName )
     102             :     throw(::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
     103             : {
     104          41 :     PropertyInfoHash::iterator aIter = maMap.find( rName );
     105             : 
     106          41 :     if ( maMap.end() == aIter )
     107           0 :         throw UnknownPropertyException( rName, *this );
     108             : 
     109          41 :     PropertyInfo *pInfo = (*aIter).second;
     110          41 :     Property aProperty;
     111          41 :     aProperty.Name   = OUString( pInfo->mpName, pInfo->mnNameLen, RTL_TEXTENCODING_ASCII_US );
     112          41 :     aProperty.Handle = pInfo->mnHandle;
     113          41 :     const Type* pType = &aProperty.Type;
     114          41 :     GenerateCppuType ( pInfo->meCppuType, pType );
     115          41 :     aProperty.Type = *pType;
     116          41 :     aProperty.Attributes = pInfo->mnAttributes;
     117          41 :     return aProperty;
     118             : }
     119             : 
     120          42 : sal_Bool SAL_CALL ChainablePropertySetInfo::hasPropertyByName( const OUString& rName )
     121             :     throw(::com::sun::star::uno::RuntimeException)
     122             : {
     123          42 :     return static_cast < sal_Bool > ( maMap.find ( rName ) != maMap.end() );
     124             : }
     125             : 
     126             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10