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

Generated by: LCOV version 1.11