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

Generated by: LCOV version 1.10