LCOV - code coverage report
Current view: top level - comphelper/source/property - propertysethelper.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 64 125 51.2 %
Date: 2015-06-13 12:38:46 Functions: 9 24 37.5 %
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/propertysetinfo.hxx>
      21             : #include <comphelper/propertysethelper.hxx>
      22             : #include <osl/diagnose.h>
      23             : 
      24             : #include <boost/scoped_array.hpp>
      25             : 
      26             : using namespace ::comphelper;
      27             : using namespace ::com::sun::star;
      28             : using namespace ::com::sun::star::uno;
      29             : using namespace ::com::sun::star::beans;
      30             : using namespace ::com::sun::star::lang;
      31             : 
      32             : namespace comphelper
      33             : {
      34             : class PropertySetHelperImpl
      35             : {
      36             : public:
      37             :     PropertyMapEntry const * find( const OUString& aName ) const throw();
      38             : 
      39             :     PropertySetInfo* mpInfo;
      40             : };
      41             : }
      42             : 
      43      139167 : PropertyMapEntry const * PropertySetHelperImpl::find( const OUString& aName ) const throw()
      44             : {
      45      139167 :     PropertyMap::const_iterator aIter = mpInfo->getPropertyMap().find( aName );
      46             : 
      47      139167 :     if( mpInfo->getPropertyMap().end() != aIter )
      48             :     {
      49      139133 :         return (*aIter).second;
      50             :     }
      51             :     else
      52             :     {
      53          34 :         return NULL;
      54             :     }
      55             : }
      56             : 
      57             : 
      58             : 
      59        2657 : PropertySetHelper::PropertySetHelper( comphelper::PropertySetInfo* pInfo ) throw()
      60             : {
      61        2657 :     mp = new PropertySetHelperImpl;
      62        2657 :     mp->mpInfo = pInfo;
      63        2657 :     pInfo->acquire();
      64        2657 : }
      65             : 
      66       80753 : PropertySetHelper::PropertySetHelper( comphelper::PropertySetInfo* pInfo, __sal_NoAcquire ) throw()
      67             : {
      68       80753 :     mp = new PropertySetHelperImpl;
      69       80753 :     mp->mpInfo = pInfo;
      70       80753 : }
      71             : 
      72      166778 : PropertySetHelper::~PropertySetHelper() throw()
      73             : {
      74       83389 :     mp->mpInfo->release();
      75       83389 :     delete mp;
      76       83389 : }
      77             : 
      78             : // XPropertySet
      79       26798 : Reference< XPropertySetInfo > SAL_CALL PropertySetHelper::getPropertySetInfo(  ) throw(RuntimeException, std::exception)
      80             : {
      81       26798 :     return mp->mpInfo;
      82             : }
      83             : 
      84       21475 : void SAL_CALL PropertySetHelper::setPropertyValue( const OUString& aPropertyName, const Any& aValue ) throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException, std::exception)
      85             : {
      86             :     PropertyMapEntry const * aEntries[2];
      87       21475 :     aEntries[0] = mp->find( aPropertyName );
      88             : 
      89       21475 :     if( NULL == aEntries[0] )
      90           0 :         throw UnknownPropertyException( aPropertyName, static_cast< XPropertySet* >( this ) );
      91             : 
      92       21475 :     aEntries[1] = NULL;
      93             : 
      94       21475 :     _setPropertyValues( aEntries, &aValue );
      95       21475 : }
      96             : 
      97       89254 : Any SAL_CALL PropertySetHelper::getPropertyValue( const OUString& PropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
      98             : {
      99             :     PropertyMapEntry const * aEntries[2];
     100       89254 :     aEntries[0] = mp->find( PropertyName );
     101             : 
     102       89254 :     if( NULL == aEntries[0] )
     103          34 :         throw UnknownPropertyException( PropertyName, static_cast< XPropertySet* >( this ) );
     104             : 
     105       89220 :     aEntries[1] = NULL;
     106             : 
     107       89220 :     Any aAny;
     108       89220 :     _getPropertyValues( aEntries, &aAny );
     109             : 
     110       89220 :     return aAny;
     111             : }
     112             : 
     113           0 : void SAL_CALL PropertySetHelper::addPropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
     114             : {
     115             :     // todo
     116           0 : }
     117             : 
     118           0 : void SAL_CALL PropertySetHelper::removePropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
     119             : {
     120             :     // todo
     121           0 : }
     122             : 
     123           0 : void SAL_CALL PropertySetHelper::addVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
     124             : {
     125             :     // todo
     126           0 : }
     127             : 
     128           0 : void SAL_CALL PropertySetHelper::removeVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
     129             : {
     130             :     // todo
     131           0 : }
     132             : 
     133             : // XMultiPropertySet
     134         472 : void SAL_CALL PropertySetHelper::setPropertyValues( const Sequence< OUString >& rPropertyNames, const Sequence< Any >& rValues )
     135             :     throw (PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException, std::exception)
     136             : {
     137         472 :     const sal_Int32 nCount = rPropertyNames.getLength();
     138             : 
     139         472 :     if( nCount != rValues.getLength() )
     140           0 :         throw IllegalArgumentException();
     141             : 
     142         472 :     if( nCount )
     143             :     {
     144         419 :         boost::scoped_array<PropertyMapEntry const *> pEntries(new PropertyMapEntry const *[nCount+1]);
     145         419 :         pEntries[nCount] = NULL;
     146         419 :         const OUString* pNames = rPropertyNames.getConstArray();
     147             : 
     148         419 :         bool bUnknown = false;
     149             :         sal_Int32 n;
     150       14898 :         for( n = 0; !bUnknown && ( n < nCount ); n++, pNames++ )
     151             :         {
     152       14479 :             pEntries[n] = mp->find( *pNames );
     153       14479 :             bUnknown = NULL == pEntries[n];
     154             :         }
     155             : 
     156         419 :         if( !bUnknown )
     157         419 :             _setPropertyValues( pEntries.get(), rValues.getConstArray() );
     158             : 
     159         419 :         if( bUnknown )
     160           0 :             throw RuntimeException( *pNames, static_cast< XPropertySet* >( this ) );
     161             :     }
     162         472 : }
     163             : 
     164           0 : Sequence< Any > SAL_CALL PropertySetHelper::getPropertyValues(const Sequence< OUString >& rPropertyNames)
     165             :     throw (RuntimeException, std::exception)
     166             : {
     167           0 :     const sal_Int32 nCount = rPropertyNames.getLength();
     168             : 
     169           0 :     Sequence< Any > aValues;
     170           0 :     if( nCount )
     171             :     {
     172           0 :         boost::scoped_array<PropertyMapEntry const *> pEntries(new PropertyMapEntry const *[nCount+1]);
     173           0 :         pEntries[nCount] = NULL;
     174           0 :         const OUString* pNames = rPropertyNames.getConstArray();
     175             : 
     176           0 :         bool bUnknown = false;
     177             :         sal_Int32 n;
     178           0 :         for( n = 0; !bUnknown && ( n < nCount ); n++, pNames++ )
     179             :         {
     180           0 :             pEntries[n] = mp->find( *pNames );
     181           0 :             bUnknown = NULL == pEntries[n];
     182             :         }
     183             : 
     184           0 :         if( !bUnknown )
     185             :         {
     186           0 :             aValues.realloc(nCount);
     187           0 :             _getPropertyValues( pEntries.get(), aValues.getArray() );
     188             :         }
     189             : 
     190           0 :         if( bUnknown )
     191           0 :             throw RuntimeException( *pNames, static_cast< XPropertySet* >( this ) );
     192             :     }
     193             : 
     194           0 :     return aValues;
     195             : }
     196             : 
     197           0 : void SAL_CALL PropertySetHelper::addPropertiesChangeListener( const Sequence< OUString >&, const Reference< XPropertiesChangeListener >& ) throw(RuntimeException, std::exception)
     198             : {
     199             :     // todo
     200           0 : }
     201             : 
     202           0 : void SAL_CALL PropertySetHelper::removePropertiesChangeListener( const Reference< XPropertiesChangeListener >& ) throw(RuntimeException, std::exception)
     203             : {
     204             :     // todo
     205           0 : }
     206             : 
     207           0 : void SAL_CALL PropertySetHelper::firePropertiesChangeEvent( const Sequence< OUString >&, const Reference< XPropertiesChangeListener >& ) throw(RuntimeException, std::exception)
     208             : {
     209             :     // todo
     210           0 : }
     211             : 
     212             : // XPropertyState
     213           0 : PropertyState SAL_CALL PropertySetHelper::getPropertyState( const OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException, std::exception)
     214             : {
     215             :     PropertyMapEntry const * aEntries[2];
     216             : 
     217           0 :     aEntries[0] = mp->find( PropertyName );
     218           0 :     if( aEntries[0] == NULL )
     219           0 :         throw UnknownPropertyException( PropertyName, static_cast< XPropertySet* >( this ) );
     220             : 
     221           0 :     aEntries[1] = NULL;
     222             : 
     223           0 :     PropertyState aState(PropertyState_AMBIGUOUS_VALUE);
     224           0 :     _getPropertyStates( aEntries, &aState );
     225             : 
     226           0 :     return aState;
     227             : }
     228             : 
     229          99 : Sequence< PropertyState > SAL_CALL PropertySetHelper::getPropertyStates( const Sequence< OUString >& aPropertyName ) throw(UnknownPropertyException, RuntimeException, std::exception)
     230             : {
     231          99 :     const sal_Int32 nCount = aPropertyName.getLength();
     232             : 
     233          99 :     Sequence< PropertyState > aStates( nCount );
     234             : 
     235          99 :     if( nCount )
     236             :     {
     237          99 :         const OUString* pNames = aPropertyName.getConstArray();
     238             : 
     239          99 :         bool bUnknown = false;
     240             : 
     241          99 :         boost::scoped_array<PropertyMapEntry const *> pEntries(new PropertyMapEntry const *[nCount+1]);
     242             : 
     243             :         sal_Int32 n;
     244       14058 :         for( n = 0; !bUnknown && (n < nCount); n++, pNames++ )
     245             :         {
     246       13959 :             pEntries[n] = mp->find( *pNames );
     247       13959 :             bUnknown = NULL == pEntries[n];
     248             :         }
     249             : 
     250          99 :         pEntries[nCount] = NULL;
     251             : 
     252          99 :         if( !bUnknown )
     253          99 :             _getPropertyStates( pEntries.get(), aStates.getArray() );
     254             : 
     255          99 :         if( bUnknown )
     256           0 :             throw UnknownPropertyException( *pNames, static_cast< XPropertySet* >( this ) );
     257             :     }
     258             : 
     259          99 :     return aStates;
     260             : }
     261             : 
     262           0 : void SAL_CALL PropertySetHelper::setPropertyToDefault( const OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException, std::exception)
     263             : {
     264           0 :     PropertyMapEntry const *pEntry  = mp->find( PropertyName );
     265           0 :     if( NULL == pEntry )
     266           0 :         throw UnknownPropertyException( PropertyName, static_cast< XPropertySet* >( this ) );
     267             : 
     268           0 :     _setPropertyToDefault( pEntry );
     269           0 : }
     270             : 
     271           0 : Any SAL_CALL PropertySetHelper::getPropertyDefault( const OUString& aPropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
     272             : {
     273           0 :     PropertyMapEntry const * pEntry = mp->find( aPropertyName );
     274           0 :     if( NULL == pEntry )
     275           0 :         throw UnknownPropertyException( aPropertyName, static_cast< XPropertySet* >( this ) );
     276             : 
     277           0 :     return _getPropertyDefault( pEntry );
     278             : }
     279             : 
     280           0 : void PropertySetHelper::_getPropertyStates(
     281             :         const comphelper::PropertyMapEntry**, PropertyState*)
     282             : throw (UnknownPropertyException, RuntimeException)
     283             : {
     284             :     OSL_FAIL( "you have to implement this yourself!");
     285           0 : }
     286             : 
     287             : void
     288           0 : PropertySetHelper::_setPropertyToDefault(const comphelper::PropertyMapEntry*)
     289             : throw (UnknownPropertyException, RuntimeException)
     290             : {
     291             :     OSL_FAIL( "you have to implement this yourself!");
     292           0 : }
     293             : 
     294           0 : Any PropertySetHelper::_getPropertyDefault(const comphelper::PropertyMapEntry*)
     295             : throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
     296             : {
     297             :     OSL_FAIL( "you have to implement this yourself!");
     298             : 
     299           0 :     Any aAny;
     300           0 :     return aAny;
     301             : }
     302             : 
     303             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11