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-27 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       16438 : PropertyMapEntry* PropertySetHelperImpl::find( const OUString& aName ) const throw()
      45             : {
      46       16438 :     PropertyMap::const_iterator aIter = mpInfo->getPropertyMap()->find( aName );
      47             : 
      48       16438 :     if( mpInfo->getPropertyMap()->end() != aIter )
      49             :     {
      50       16433 :         return (*aIter).second;
      51             :     }
      52             :     else
      53             :     {
      54           5 :         return NULL;
      55             :     }
      56             : }
      57             : 
      58             : ///////////////////////////////////////////////////////////////////////
      59             : 
      60         335 : PropertySetHelper::PropertySetHelper( comphelper::PropertySetInfo* pInfo ) throw()
      61             : {
      62         335 :     mp = new PropertySetHelperImpl;
      63         335 :     mp->mpInfo = pInfo;
      64         335 :     pInfo->acquire();
      65         335 : }
      66             : 
      67         132 : PropertySetHelper::PropertySetHelper( comphelper::PropertySetInfo* pInfo, __sal_NoAcquire ) throw()
      68             : {
      69         132 :     mp = new PropertySetHelperImpl;
      70         132 :     mp->mpInfo = pInfo;
      71         132 : }
      72             : 
      73         844 : PropertySetHelper::~PropertySetHelper() throw()
      74             : {
      75         422 :     mp->mpInfo->release();
      76         422 :     delete mp;
      77         422 : }
      78             : 
      79             : // XPropertySet
      80        2034 : Reference< XPropertySetInfo > SAL_CALL PropertySetHelper::getPropertySetInfo(  ) throw(RuntimeException)
      81             : {
      82        2034 :     return mp->mpInfo;
      83             : }
      84             : 
      85        1663 : void SAL_CALL PropertySetHelper::setPropertyValue( const ::rtl::OUString& aPropertyName, const Any& aValue ) throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
      86             : {
      87             :     PropertyMapEntry* aEntries[2];
      88        1663 :     aEntries[0] = mp->find( aPropertyName );
      89             : 
      90        1663 :     if( NULL == aEntries[0] )
      91           5 :         throw UnknownPropertyException( aPropertyName, static_cast< XPropertySet* >( this ) );
      92             : 
      93        1658 :     aEntries[1] = NULL;
      94             : 
      95        1658 :     _setPropertyValues( (const PropertyMapEntry**)aEntries, &aValue );
      96        1658 : }
      97             : 
      98       14088 : Any SAL_CALL PropertySetHelper::getPropertyValue( const ::rtl::OUString& PropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
      99             : {
     100             :     PropertyMapEntry* aEntries[2];
     101       14088 :     aEntries[0] = mp->find( PropertyName );
     102             : 
     103       14088 :     if( NULL == aEntries[0] )
     104           0 :         throw UnknownPropertyException( PropertyName, static_cast< XPropertySet* >( this ) );
     105             : 
     106       14088 :     aEntries[1] = NULL;
     107             : 
     108       14088 :     Any aAny;
     109       14088 :     _getPropertyValues( (const PropertyMapEntry**)aEntries, &aAny );
     110             : 
     111       14088 :     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          15 : void SAL_CALL PropertySetHelper::setPropertyValues( const Sequence< ::rtl::OUString >& aPropertyNames, const Sequence< Any >& aValues ) throw(PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
     136             : {
     137          15 :     const sal_Int32 nCount = aPropertyNames.getLength();
     138             : 
     139          15 :     if( nCount != aValues.getLength() )
     140           0 :         throw IllegalArgumentException();
     141             : 
     142          15 :     if( nCount )
     143             :     {
     144          15 :         PropertyMapEntry** pEntries = new PropertyMapEntry*[nCount+1];
     145          15 :         pEntries[nCount] = NULL;
     146          15 :         const OUString* pNames = aPropertyNames.getConstArray();
     147             : 
     148          15 :         sal_Bool bUnknown = sal_False;
     149             :         sal_Int32 n;
     150         426 :         for( n = 0; !bUnknown && ( n < nCount ); n++, pNames++ )
     151             :         {
     152         411 :             pEntries[n] = mp->find( *pNames );
     153         411 :             bUnknown = NULL == pEntries[n];
     154             :         }
     155             : 
     156          15 :         if( !bUnknown )
     157          15 :             _setPropertyValues( (const PropertyMapEntry**)pEntries, aValues.getConstArray() );
     158             : 
     159          15 :         delete[] pEntries;
     160             : 
     161          15 :         if( bUnknown )
     162           0 :             throw UnknownPropertyException( *pNames, static_cast< XPropertySet* >( this ) );
     163             :     }
     164          15 : }
     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           2 : Sequence< PropertyState > SAL_CALL PropertySetHelper::getPropertyStates( const Sequence< ::rtl::OUString >& aPropertyName ) throw(UnknownPropertyException, RuntimeException)
     233             : {
     234           2 :     const sal_Int32 nCount = aPropertyName.getLength();
     235             : 
     236           2 :     Sequence< PropertyState > aStates( nCount );
     237             : 
     238           2 :     if( nCount )
     239             :     {
     240           2 :         const OUString* pNames = aPropertyName.getConstArray();
     241             : 
     242           2 :         sal_Bool bUnknown = sal_False;
     243             : 
     244           2 :         PropertyMapEntry** pEntries = new PropertyMapEntry*[nCount+1];
     245             : 
     246             :         sal_Int32 n;
     247         278 :         for( n = 0; !bUnknown && (n < nCount); n++, pNames++ )
     248             :         {
     249         276 :             pEntries[n] = mp->find( *pNames );
     250         276 :             bUnknown = NULL == pEntries[n];
     251             :         }
     252             : 
     253           2 :         pEntries[nCount] = NULL;
     254             : 
     255           2 :         if( !bUnknown )
     256           2 :             _getPropertyStates( (const PropertyMapEntry**)pEntries, aStates.getArray() );
     257             : 
     258           2 :         delete[] pEntries;
     259             : 
     260           2 :         if( bUnknown )
     261           0 :             throw UnknownPropertyException( *pNames, static_cast< XPropertySet* >( this ) );
     262             :     }
     263             : 
     264           2 :     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