LCOV - code coverage report
Current view: top level - include/comphelper - property.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 30 31 96.8 %
Date: 2015-06-13 12:38:46 Functions: 17 24 70.8 %
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             : #ifndef INCLUDED_COMPHELPER_PROPERTY_HXX
      21             : #define INCLUDED_COMPHELPER_PROPERTY_HXX
      22             : 
      23             : #include <cppuhelper/proptypehlp.hxx>
      24             : #include <comphelper/extract.hxx>
      25             : #include <com/sun/star/beans/Property.hpp>
      26             : #include <com/sun/star/beans/XPropertySet.hpp>
      27             : #include <functional>
      28             : #include <comphelper/comphelperdllapi.h>
      29             : #include <cppu/unotype.hxx>
      30             : 
      31             : namespace comphelper
      32             : {
      33             : 
      34             :     // comparing two property instances
      35             :     struct PropertyCompareByName : public ::std::binary_function< ::com::sun::star::beans::Property, ::com::sun::star::beans::Property, bool >
      36             :     {
      37     1247809 :         bool operator() (const ::com::sun::star::beans::Property& x, const ::com::sun::star::beans::Property& y) const
      38             :         {
      39     1247809 :             return x.Name.compareTo(y.Name) < 0;
      40             :         }
      41             :     };
      42             : 
      43             :     struct PropertyStringEqualFunctor : ::std::binary_function< ::com::sun::star::beans::Property, OUString, bool >
      44             :     {
      45             : 
      46             :         inline bool operator()( const ::com::sun::star::beans::Property& lhs, const OUString& rhs ) const
      47             :         {
      48             :             return lhs.Name == rhs ;
      49             :         }
      50             : 
      51             :         inline bool operator()( const OUString& lhs, const ::com::sun::star::beans::Property& rhs ) const
      52             :         {
      53             :             return lhs == rhs.Name ;
      54             :         }
      55             :     };
      56             : 
      57             :     struct PropertyEqualByName : public ::std::binary_function< ::com::sun::star::beans::Property, ::com::sun::star::beans::Property, bool >
      58             :     {
      59             :         bool operator() (const ::com::sun::star::beans::Property& x, const ::com::sun::star::beans::Property& y) const
      60             :         {
      61             :             return x.Name == y.Name ;
      62             :         }
      63             :     };
      64             : 
      65             : /// remove the property with the given name from the given sequence
      66             : COMPHELPER_DLLPUBLIC void RemoveProperty(css::uno::Sequence<css::beans::Property>& seqProps, const OUString& _rPropName);
      67             : 
      68             : /** within the given property sequence, modify attributes of a special property
      69             :     @param  _rProps         the sequence of properties to search in
      70             :     @param  _sPropName      the name of the property which's attributes should be modified
      71             :     @param  _nAddAttrib     the attributes which should be added
      72             :     @param  _nRemoveAttrib  the attributes which should be removed
      73             : */
      74             : COMPHELPER_DLLPUBLIC void ModifyPropertyAttributes(css::uno::Sequence<css::beans::Property>& _rProps, const OUString& _sPropName, sal_Int16 _nAddAttrib, sal_Int16 _nRemoveAttrib);
      75             : 
      76             : /** check if the given set has the given property.
      77             : */
      78             : COMPHELPER_DLLPUBLIC bool hasProperty(const OUString& _rName, const css::uno::Reference<css::beans::XPropertySet>& _rxSet);
      79             : 
      80             : /** copy properties between property sets, in compliance with the property
      81             :     attributes of the target object
      82             : */
      83             : COMPHELPER_DLLPUBLIC void copyProperties(const css::uno::Reference<css::beans::XPropertySet>& _rxSource,
      84             :                     const css::uno::Reference<css::beans::XPropertySet>& _rxDest);
      85             : 
      86             : /** helper for implementing ::cppu::OPropertySetHelper::convertFastPropertyValue
      87             :     @param          _rConvertedValue    the conversion result (if successful)
      88             :     @param          _rOldValue          the old value of the property, calculated from _rCurrentValue
      89             :     @param          _rValueToSet        the new value which is about to be set
      90             :     @param          _rCurrentValue      the current value of the property
      91             :     @return         sal_True, if the value could be converted and has changed
      92             :                     sal_False, if the value could be converted and has not changed
      93             :     @exception      InvalidArgumentException thrown if the value could not be converted to the requested type (which is the template argument)
      94             : */
      95             : template <typename T>
      96        7094 : bool tryPropertyValue(css::uno::Any& /*out*/_rConvertedValue, css::uno::Any& /*out*/_rOldValue, const css::uno::Any& _rValueToSet, const T& _rCurrentValue)
      97             : {
      98        7094 :     bool bModified(false);
      99        7094 :     T aNewValue = T();
     100        7094 :     ::cppu::convertPropertyValue(aNewValue, _rValueToSet);
     101        7092 :     if (aNewValue != _rCurrentValue)
     102             :     {
     103        2329 :         _rConvertedValue <<= aNewValue;
     104        2329 :         _rOldValue <<= _rCurrentValue;
     105        2329 :         bModified = true;
     106             :     }
     107        7092 :     return bModified;
     108             : }
     109             : 
     110             : /** helper for implementing ::cppu::OPropertySetHelper::convertFastPropertyValue for enum values
     111             :     @param          _rConvertedValue    the conversion result (if successful)
     112             :     @param          _rOldValue          the old value of the property, calculated from _rCurrentValue
     113             :     @param          _rValueToSet        the new value which is about to be set
     114             :     @param          _rCurrentValue      the current value of the property
     115             :     @return         sal_True, if the value could be converted and has changed
     116             :                     sal_False, if the value could be converted and has not changed
     117             :     @exception      InvalidArgumentException thrown if the value could not be converted to the requested type (which is the template argument)
     118             : */
     119             : template <class ENUMTYPE>
     120         165 : bool tryPropertyValueEnum(css::uno::Any& /*out*/_rConvertedValue, css::uno::Any& /*out*/_rOldValue, const css::uno::Any& _rValueToSet, const ENUMTYPE& _rCurrentValue)
     121             : {
     122         330 :     if (cppu::getTypeFavourUnsigned(&_rCurrentValue).getTypeClass()
     123         165 :         != css::uno::TypeClass_ENUM)
     124           0 :         return tryPropertyValue(_rConvertedValue, _rOldValue, _rValueToSet, _rCurrentValue);
     125             : 
     126         165 :     bool bModified(false);
     127             :     ENUMTYPE aNewValue;
     128         165 :     ::cppu::any2enum(aNewValue, _rValueToSet);
     129             :         // will throw an exception if not convertible
     130             : 
     131         165 :     if (aNewValue != _rCurrentValue)
     132             :     {
     133          45 :         _rConvertedValue <<= aNewValue;
     134          45 :         _rOldValue <<= _rCurrentValue;
     135          45 :         bModified = true;
     136             :     }
     137         165 :     return bModified;
     138             : }
     139             : 
     140             : /** helper for implementing ::cppu::OPropertySetHelper::convertFastPropertyValue for boolean properties
     141             :     @param          _rConvertedValue    the conversion result (if successful)
     142             :     @param          _rOldValue          the old value of the property, calculated from _rCurrentValue
     143             :     @param          _rValueToSet        the new value which is about to be set
     144             :     @param          _rCurrentValue      the current value of the property
     145             :     @return         sal_True, if the value could be converted and has changed
     146             :                     sal_False, if the value could be converted and has not changed
     147             :     @exception      InvalidArgumentException thrown if the value could not be converted to a boolean type
     148             : */
     149        1979 : inline bool tryPropertyValue(css::uno::Any& /*out*/_rConvertedValue, css::uno::Any& /*out*/_rOldValue, const css::uno::Any& _rValueToSet, bool _bCurrentValue)
     150             : {
     151        1979 :     bool bModified(false);
     152        1979 :     sal_Bool bNewValue(sal_False);
     153        1979 :     ::cppu::convertPropertyValue(bNewValue, _rValueToSet);
     154        1979 :     if (bool(bNewValue) != _bCurrentValue)
     155             :     {
     156         479 :         _rConvertedValue.setValue(&bNewValue, cppu::UnoType<bool>::get());
     157         479 :         _rOldValue.setValue(&_bCurrentValue, cppu::UnoType<bool>::get());
     158         479 :         bModified = true;
     159             :     }
     160        1979 :     return bModified;
     161             : }
     162             : 
     163             : /** helper for implementing ::cppu::OPropertySetHelper::convertFastPropertyValue
     164             :     @param          _rConvertedValue    the conversion result (if successful)
     165             :     @param          _rOldValue          the old value of the property, calculated from _rCurrentValue
     166             :     @param          _rValueToSet        the new value which is about to be set
     167             :     @param          _rCurrentValue      the current value of the property
     168             :     @param          _rExpectedType      the type which the property should have (if not void)
     169             :     @return         sal_True, if the value could be converted and has changed
     170             :                     sal_False, if the value could be converted and has not changed
     171             :     @exception      InvalidArgumentException thrown if the value could not be converted to the requested type (which is the template argument)
     172             : */
     173             : COMPHELPER_DLLPUBLIC bool tryPropertyValue(css::uno::Any& _rConvertedValue, css::uno::Any& _rOldValue, const css::uno::Any& _rValueToSet, const css::uno::Any& _rCurrentValue, const css::uno::Type& _rExpectedType);
     174             : 
     175             : }
     176             : 
     177             : #endif // INCLUDED_COMPHELPER_PROPERTY_HXX
     178             : 
     179             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11