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