LibreOffice Module comphelper (master)  1
property.hxx
Go to the documentation of this file.
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 
24 #include <comphelper/extract.hxx>
25 #include <com/sun/star/beans/Property.hpp>
26 #include <type_traits>
28 
29 namespace com { namespace sun { namespace star { namespace beans { class XPropertySet; } } } }
30 
31 namespace comphelper
32 {
33 
34  // comparing two property instances
36  {
37  bool operator() (const css::beans::Property& x, const css::beans::Property& y) const
38  {
39  return x.Name.compareTo(y.Name) < 0;
40  }
41  };
42 
44 COMPHELPER_DLLPUBLIC void RemoveProperty(css::uno::Sequence<css::beans::Property>& seqProps, const OUString& _rPropName);
45 
52 COMPHELPER_DLLPUBLIC void ModifyPropertyAttributes(css::uno::Sequence<css::beans::Property>& _rProps, const OUString& _sPropName, sal_Int16 _nAddAttrib, sal_Int16 _nRemoveAttrib);
53 
56 COMPHELPER_DLLPUBLIC bool hasProperty(const OUString& _rName, const css::uno::Reference<css::beans::XPropertySet>& _rxSet);
57 
61 COMPHELPER_DLLPUBLIC void copyProperties(const css::uno::Reference<css::beans::XPropertySet>& _rxSource,
62  const css::uno::Reference<css::beans::XPropertySet>& _rxDest);
63 
73 template <typename T>
74 bool tryPropertyValue(css::uno::Any& /*out*/_rConvertedValue, css::uno::Any& /*out*/_rOldValue, const css::uno::Any& _rValueToSet, const T& _rCurrentValue)
75 {
76  bool bModified(false);
77  T aNewValue = T();
78  ::cppu::convertPropertyValue(aNewValue, _rValueToSet);
79  if (aNewValue != _rCurrentValue)
80  {
81  _rConvertedValue <<= aNewValue;
82  _rOldValue <<= _rCurrentValue;
83  bModified = true;
84  }
85  return bModified;
86 }
87 
97 template <class ENUMTYPE>
98 typename std::enable_if<std::is_enum<ENUMTYPE>::value, bool>::type
99 tryPropertyValueEnum(css::uno::Any& /*out*/_rConvertedValue, css::uno::Any& /*out*/_rOldValue, const css::uno::Any& _rValueToSet, const ENUMTYPE& _rCurrentValue)
100 {
101  bool bModified(false);
102  ENUMTYPE aNewValue;
103  ::cppu::any2enum(aNewValue, _rValueToSet);
104  // will throw an exception if not convertible
105 
106  if (aNewValue != _rCurrentValue)
107  {
108  _rConvertedValue <<= aNewValue;
109  _rOldValue <<= _rCurrentValue;
110  bModified = true;
111  }
112  return bModified;
113 }
114 
125 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);
126 
127 }
128 
129 #endif // INCLUDED_COMPHELPER_PROPERTY_HXX
130 
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void ModifyPropertyAttributes(Sequence< Property > &seqProps, const OUString &sPropName, sal_Int16 nAddAttrib, sal_Int16 nRemoveAttrib)
Definition: property.cxx:156
bool operator()(const css::beans::Property &x, const css::beans::Property &y) const
Definition: property.hxx:37
std::enable_if< std::is_enum< ENUMTYPE >::value, bool >::type tryPropertyValueEnum(css::uno::Any &_rConvertedValue, css::uno::Any &_rOldValue, const css::uno::Any &_rValueToSet, const ENUMTYPE &_rCurrentValue)
helper for implementing cppu::OPropertySetHelper::convertFastPropertyValue for enum values ...
Definition: property.hxx:99
void any2enum(E &eRet, const css::uno::Any &rAny)
Sets int32 from enum or int in any with additional typecheck.
Definition: extract.hxx:76
void RemoveProperty(Sequence< Property > &_rProps, const OUString &_rPropName)
Definition: property.cxx:139
class SAL_NO_VTABLE XPropertySet
bool tryPropertyValue(Any &_rConvertedValue, Any &_rOldValue, const Any &_rValueToSet, const Any &_rCurrentValue, const Type &_rExpectedType)
Definition: property.cxx:173
bool hasProperty(const OUString &_rName, const Reference< XPropertySet > &_rxSet)
Definition: property.cxx:128
#define COMPHELPER_DLLPUBLIC
void copyProperties(const Reference< XPropertySet > &_rxSource, const Reference< XPropertySet > &_rxDest)
Definition: property.cxx:59