/src/libreoffice/include/comphelper/property.hxx
Line | Count | Source |
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 <type_traits> |
27 | | #include <comphelper/comphelperdllapi.h> |
28 | | |
29 | | namespace com::sun::star::beans { class XPropertySet; } |
30 | | |
31 | | namespace comphelper |
32 | | { |
33 | | |
34 | | // comparing two property instances |
35 | | struct PropertyCompareByName |
36 | | { |
37 | | bool operator() (const css::beans::Property& x, const css::beans::Property& y) const |
38 | 10.7M | { |
39 | 10.7M | return x.Name.compareTo(y.Name) < 0; |
40 | 10.7M | } |
41 | | }; |
42 | | |
43 | | /// remove the property with the given name from the given sequence |
44 | | COMPHELPER_DLLPUBLIC void RemoveProperty(css::uno::Sequence<css::beans::Property>& seqProps, const OUString& _rPropName); |
45 | | |
46 | | /** within the given property sequence, modify attributes of a special property |
47 | | @param _rProps the sequence of properties to search in |
48 | | @param _sPropName the name of the property which's attributes should be modified |
49 | | @param _nAddAttrib the attributes which should be added |
50 | | @param _nRemoveAttrib the attributes which should be removed |
51 | | */ |
52 | | COMPHELPER_DLLPUBLIC void ModifyPropertyAttributes(css::uno::Sequence<css::beans::Property>& _rProps, const OUString& _sPropName, sal_Int16 _nAddAttrib, sal_Int16 _nRemoveAttrib); |
53 | | |
54 | | /** check if the given set has the given property. |
55 | | */ |
56 | | COMPHELPER_DLLPUBLIC bool hasProperty(const OUString& _rName, const css::uno::Reference<css::beans::XPropertySet>& _rxSet); |
57 | | |
58 | | /** copy properties between property sets, in compliance with the property |
59 | | attributes of the target object |
60 | | */ |
61 | | COMPHELPER_DLLPUBLIC void copyProperties(const css::uno::Reference<css::beans::XPropertySet>& _rxSource, |
62 | | const css::uno::Reference<css::beans::XPropertySet>& _rxDest); |
63 | | |
64 | | /** helper for implementing ::cppu::OPropertySetHelper::convertFastPropertyValue |
65 | | @param _rConvertedValue the conversion result (if successful) |
66 | | @param _rOldValue the old value of the property, calculated from _rCurrentValue |
67 | | @param _rValueToSet the new value which is about to be set |
68 | | @param _rCurrentValue the current value of the property |
69 | | @return sal_True, if the value could be converted and has changed |
70 | | sal_False, if the value could be converted and has not changed |
71 | | @exception InvalidArgumentException thrown if the value could not be converted to the requested type (which is the template argument) |
72 | | */ |
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 | 0 | { |
76 | 0 | bool bModified(false); |
77 | 0 | T aNewValue = T(); |
78 | 0 | ::cppu::convertPropertyValue(aNewValue, _rValueToSet); |
79 | 0 | if (aNewValue != _rCurrentValue) |
80 | 0 | { |
81 | 0 | _rConvertedValue <<= aNewValue; |
82 | 0 | _rOldValue <<= _rCurrentValue; |
83 | 0 | bModified = true; |
84 | 0 | } |
85 | 0 | return bModified; |
86 | 0 | } Unexecuted instantiation: bool comphelper::tryPropertyValue<com::sun::star::uno::Sequence<rtl::OUString> >(com::sun::star::uno::Any&, com::sun::star::uno::Any&, com::sun::star::uno::Any const&, com::sun::star::uno::Sequence<rtl::OUString> const&) Unexecuted instantiation: bool comphelper::tryPropertyValue<rtl::OUString>(com::sun::star::uno::Any&, com::sun::star::uno::Any&, com::sun::star::uno::Any const&, rtl::OUString const&) Unexecuted instantiation: bool comphelper::tryPropertyValue<bool>(com::sun::star::uno::Any&, com::sun::star::uno::Any&, com::sun::star::uno::Any const&, bool const&) Unexecuted instantiation: bool comphelper::tryPropertyValue<com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> >(com::sun::star::uno::Any&, com::sun::star::uno::Any&, com::sun::star::uno::Any const&, com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> const&) |
87 | | |
88 | | /** helper for implementing ::cppu::OPropertySetHelper::convertFastPropertyValue for enum values |
89 | | @param _rConvertedValue the conversion result (if successful) |
90 | | @param _rOldValue the old value of the property, calculated from _rCurrentValue |
91 | | @param _rValueToSet the new value which is about to be set |
92 | | @param _rCurrentValue the current value of the property |
93 | | @return sal_True, if the value could be converted and has changed |
94 | | sal_False, if the value could be converted and has not changed |
95 | | @exception InvalidArgumentException thrown if the value could not be converted to the requested type (which is the template argument) |
96 | | */ |
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 | | |
115 | | /** helper for implementing ::cppu::OPropertySetHelper::convertFastPropertyValue |
116 | | @param _rConvertedValue the conversion result (if successful) |
117 | | @param _rOldValue the old value of the property, calculated from _rCurrentValue |
118 | | @param _rValueToSet the new value which is about to be set |
119 | | @param _rCurrentValue the current value of the property |
120 | | @param _rExpectedType the type which the property should have (if not void) |
121 | | @return sal_True, if the value could be converted and has changed |
122 | | sal_False, if the value could be converted and has not changed |
123 | | @exception InvalidArgumentException thrown if the value could not be converted to the requested type (which is the template argument) |
124 | | */ |
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: */ |