LCOV - code coverage report
Current view: top level - comphelper/source/property - propstate.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 77 92 83.7 %
Date: 2014-11-03 Functions: 15 21 71.4 %
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/propstate.hxx>
      21             : #include <com/sun/star/uno/genfunc.h>
      22             : #include <cppuhelper/queryinterface.hxx>
      23             : #include <comphelper/sequence.hxx>
      24             : 
      25             : namespace comphelper
      26             : {
      27             : 
      28             : 
      29             :     using ::com::sun::star::uno::Reference;
      30             :     using ::com::sun::star::uno::Type;
      31             :     using ::com::sun::star::uno::RuntimeException;
      32             :     using ::com::sun::star::uno::Sequence;
      33             :     using ::com::sun::star::lang::XTypeProvider;
      34             :     using ::com::sun::star::uno::Any;
      35             :     using ::com::sun::star::uno::cpp_queryInterface;
      36             :     using ::com::sun::star::uno::cpp_release;
      37             :     using ::com::sun::star::beans::PropertyState_DEFAULT_VALUE;
      38             :     using ::com::sun::star::beans::PropertyState_DIRECT_VALUE;
      39             : 
      40             : 
      41             :     // OPropertyStateHelper
      42             : 
      43             : 
      44             : 
      45      175271 :     ::com::sun::star::uno::Any SAL_CALL OPropertyStateHelper::queryInterface(const  ::com::sun::star::uno::Type& _rType) throw( ::com::sun::star::uno::RuntimeException, std::exception)
      46             :     {
      47      175271 :         ::com::sun::star::uno::Any aReturn = OPropertySetHelper2::queryInterface(_rType);
      48             :         // our own ifaces
      49      175271 :         if ( !aReturn.hasValue() )
      50      106803 :             aReturn = ::cppu::queryInterface(_rType, static_cast< ::com::sun::star::beans::XPropertyState*>(this));
      51             : 
      52      175271 :         return aReturn;
      53             :     }
      54             : 
      55             : 
      56         480 :     css::uno::Sequence<css::uno::Type> OPropertyStateHelper::getTypes()
      57             :     {
      58         480 :         ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> aTypes(4);
      59         480 :         ::com::sun::star::uno::Type* pTypes = aTypes.getArray();
      60             :         // base class types
      61         480 :         pTypes[0] = cppu::UnoType<com::sun::star::beans::XPropertySet>::get();
      62         480 :         pTypes[1] = cppu::UnoType<com::sun::star::beans::XMultiPropertySet>::get();
      63         480 :         pTypes[2] = cppu::UnoType<com::sun::star::beans::XFastPropertySet>::get();
      64             :         // my own type
      65         480 :         pTypes[3] = cppu::UnoType<com::sun::star::beans::XPropertyState>::get();
      66         480 :         return aTypes;
      67             :     }
      68             : 
      69        4876 :     OPropertyStateHelper::OPropertyStateHelper(
      70             :         ::cppu::OBroadcastHelper& rBHlp,
      71             :         ::cppu::IEventNotificationHook *i_pFireEvents)
      72        4876 :         :   ::cppu::OPropertySetHelper2(rBHlp, i_pFireEvents) { }
      73             : 
      74        6611 :     OPropertyStateHelper::~OPropertyStateHelper() {}
      75             : 
      76             : 
      77           0 :     void OPropertyStateHelper::firePropertyChange(sal_Int32 nHandle, const  ::com::sun::star::uno::Any& aNewValue, const  ::com::sun::star::uno::Any& aOldValue)
      78             :     {
      79           0 :         fire(&nHandle, &aNewValue, &aOldValue, 1, sal_False);
      80           0 :     }
      81             : 
      82             :     // XPropertyState
      83             : 
      84        7728 :     ::com::sun::star::beans::PropertyState SAL_CALL OPropertyStateHelper::getPropertyState(const OUString& _rsName) throw( ::com::sun::star::beans::UnknownPropertyException,  ::com::sun::star::uno::RuntimeException, std::exception)
      85             :     {
      86        7728 :         cppu::IPropertyArrayHelper& rPH = getInfoHelper();
      87        7728 :         sal_Int32 nHandle = rPH.getHandleByName(_rsName);
      88             : 
      89        7728 :         if (nHandle == -1)
      90           0 :             throw  ::com::sun::star::beans::UnknownPropertyException();
      91             : 
      92        7728 :         return getPropertyStateByHandle(nHandle);
      93             :     }
      94             : 
      95             : 
      96        1514 :     void SAL_CALL OPropertyStateHelper::setPropertyToDefault(const OUString& _rsName) throw( ::com::sun::star::beans::UnknownPropertyException,  ::com::sun::star::uno::RuntimeException, std::exception)
      97             :     {
      98        1514 :         cppu::IPropertyArrayHelper& rPH = getInfoHelper();
      99        1514 :         sal_Int32 nHandle = rPH.getHandleByName(_rsName);
     100             : 
     101        1514 :         if (nHandle == -1)
     102           0 :             throw  ::com::sun::star::beans::UnknownPropertyException();
     103             : 
     104        1514 :         setPropertyToDefaultByHandle(nHandle);
     105        1514 :     }
     106             : 
     107             : 
     108         736 :     ::com::sun::star::uno::Any SAL_CALL OPropertyStateHelper::getPropertyDefault(const OUString& _rsName) throw( ::com::sun::star::beans::UnknownPropertyException,  ::com::sun::star::lang::WrappedTargetException,  ::com::sun::star::uno::RuntimeException, std::exception)
     109             :     {
     110         736 :         cppu::IPropertyArrayHelper& rPH = getInfoHelper();
     111         736 :         sal_Int32 nHandle = rPH.getHandleByName(_rsName);
     112             : 
     113         736 :         if (nHandle == -1)
     114           0 :             throw  ::com::sun::star::beans::UnknownPropertyException();
     115             : 
     116         736 :         return getPropertyDefaultByHandle(nHandle);
     117             :     }
     118             : 
     119             : 
     120          36 :     ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyState> SAL_CALL OPropertyStateHelper::getPropertyStates(const  ::com::sun::star::uno::Sequence< OUString >& _rPropertyNames) throw( ::com::sun::star::beans::UnknownPropertyException,  ::com::sun::star::uno::RuntimeException, std::exception)
     121             :     {
     122          36 :         sal_Int32 nLen = _rPropertyNames.getLength();
     123          36 :         ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyState> aRet(nLen);
     124          36 :         ::com::sun::star::beans::PropertyState* pValues = aRet.getArray();
     125          36 :         const OUString* pNames = _rPropertyNames.getConstArray();
     126             : 
     127          36 :         cppu::IPropertyArrayHelper& rHelper = getInfoHelper();
     128             : 
     129          72 :         ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property> aProps = rHelper.getProperties();
     130          36 :         const  ::com::sun::star::beans::Property* pProps = aProps.getConstArray();
     131          36 :         sal_Int32 nPropCount       = aProps.getLength();
     132             : 
     133          72 :         osl::MutexGuard aGuard(rBHelper.rMutex);
     134          74 :         for (sal_Int32 i=0, j=0; i<nPropCount && j<nLen; ++i, ++pProps)
     135             :         {
     136             :             // get the values only for valid properties
     137          38 :             if (pProps->Name.equals(*pNames))
     138             :             {
     139          36 :                 *pValues = getPropertyState(*pNames);
     140          36 :                 ++pValues;
     141          36 :                 ++pNames;
     142          36 :                 ++j;
     143             :             }
     144             :         }
     145             : 
     146          72 :         return aRet;
     147             :     }
     148             : 
     149             : 
     150       25430 :     ::com::sun::star::beans::PropertyState OPropertyStateHelper::getPropertyStateByHandle( sal_Int32 _nHandle )
     151             :     {
     152             :         // simply compare the current and the default value
     153       25430 :         Any aCurrentValue = getPropertyDefaultByHandle( _nHandle );
     154       50860 :         Any aDefaultValue;  getFastPropertyValue( aDefaultValue, _nHandle );
     155             : 
     156             :         bool bEqual = uno_type_equalData(
     157       50860 :                 const_cast< void* >( aCurrentValue.getValue() ), aCurrentValue.getValueType().getTypeLibType(),
     158       50860 :                 const_cast< void* >( aDefaultValue.getValue() ), aDefaultValue.getValueType().getTypeLibType(),
     159             :                 reinterpret_cast< uno_QueryInterfaceFunc >(cpp_queryInterface),
     160             :                 reinterpret_cast< uno_ReleaseFunc >(cpp_release)
     161       76290 :             );
     162       50860 :         return bEqual ? PropertyState_DEFAULT_VALUE : PropertyState_DIRECT_VALUE;
     163             :     }
     164             : 
     165             : 
     166        1514 :     void OPropertyStateHelper::setPropertyToDefaultByHandle( sal_Int32 _nHandle )
     167             :     {
     168        1514 :         setFastPropertyValue( _nHandle, getPropertyDefaultByHandle( _nHandle ) );
     169        1514 :     }
     170             : 
     171             : 
     172           0 :     ::com::sun::star::uno::Any OPropertyStateHelper::getPropertyDefaultByHandle( sal_Int32 ) const
     173             :     {
     174           0 :         return  ::com::sun::star::uno::Any();
     175             :     }
     176             : 
     177             : 
     178             :     // OStatefulPropertySet
     179             : 
     180             : 
     181           2 :     OStatefulPropertySet::OStatefulPropertySet()
     182           2 :         :OPropertyStateHelper( GetBroadcastHelper() )
     183             :     {
     184           2 :     }
     185             : 
     186             : 
     187           2 :     OStatefulPropertySet::~OStatefulPropertySet()
     188             :     {
     189           2 :     }
     190             : 
     191             : 
     192           0 :     Sequence< Type > SAL_CALL OStatefulPropertySet::getTypes() throw(RuntimeException, std::exception)
     193             :     {
     194           0 :         Sequence< Type > aOwnTypes( 2 );
     195           0 :         aOwnTypes[0] = cppu::UnoType<XWeak>::get();
     196           0 :         aOwnTypes[1] = cppu::UnoType<XTypeProvider>::get();
     197             : 
     198             :         return concatSequences(
     199             :             aOwnTypes,
     200             :             OPropertyStateHelper::getTypes()
     201           0 :         );
     202             :     }
     203             : 
     204           0 :     Sequence< sal_Int8 > SAL_CALL OStatefulPropertySet::getImplementationId() throw(RuntimeException, std::exception)
     205             :     {
     206           0 :         return css::uno::Sequence<sal_Int8>();
     207             :     }
     208             : 
     209             : 
     210           2 :     Any SAL_CALL OStatefulPropertySet::queryInterface( const Type& _rType ) throw(RuntimeException, std::exception)
     211             :     {
     212           2 :         Any aReturn = OWeakObject::queryInterface( _rType );
     213           2 :         if ( !aReturn.hasValue() )
     214           2 :             aReturn = ::cppu::queryInterface( _rType, static_cast< XTypeProvider* >( this ) );
     215           2 :         if ( !aReturn.hasValue() )
     216           2 :             aReturn = OPropertyStateHelper::queryInterface( _rType );
     217           2 :         return aReturn;
     218             :     }
     219             : 
     220             : 
     221           6 :     void SAL_CALL OStatefulPropertySet::acquire() throw()
     222             :     {
     223           6 :         ::cppu::OWeakObject::acquire();
     224           6 :     }
     225             : 
     226             : 
     227           6 :     void SAL_CALL OStatefulPropertySet::release() throw()
     228             :     {
     229           6 :         ::cppu::OWeakObject::release();
     230           6 :     }
     231             : 
     232             : 
     233             : }
     234             : 
     235             : 
     236             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10