fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / include / comphelper / property.hxx
blob95fe122d51a657e4b689aaee25e6eb75b2e749ff
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef _COMPHELPER_PROPERTY_HXX_
21 #define _COMPHELPER_PROPERTY_HXX_
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"
31 //=========================================================================
32 //= property helper classes
33 //=========================================================================
35 //... namespace comphelper .......................................................
36 namespace comphelper
38 //.........................................................................
40 namespace starbeans = ::com::sun::star::beans;
41 namespace staruno = ::com::sun::star::uno;
43 /** compare two properties by name
45 //--------------------------------------------------------------------------
46 // comparing two property instances
47 struct PropertyCompareByName : public ::std::binary_function< ::com::sun::star::beans::Property, ::com::sun::star::beans::Property, bool >
49 bool operator() (const ::com::sun::star::beans::Property& x, const ::com::sun::star::beans::Property& y) const
51 return x.Name.compareTo(y.Name) < 0;// ? true : false;
55 //--------------------------------------------------------------------------
56 /** compare two properties by name
58 struct PropertyStringEqualFunctor : ::std::binary_function< ::com::sun::star::beans::Property, OUString, bool >
60 // ................................................................
61 inline bool operator()( const ::com::sun::star::beans::Property& lhs, const OUString& rhs ) const
63 return lhs.Name == rhs ;
65 // ................................................................
66 inline bool operator()( const OUString& lhs, const ::com::sun::star::beans::Property& rhs ) const
68 return lhs == rhs.Name ;
71 //--------------------------------------------------------------------------
72 // comparing two property instances
73 struct PropertyEqualByName : public ::std::binary_function< ::com::sun::star::beans::Property, ::com::sun::star::beans::Property, bool >
75 bool operator() (const ::com::sun::star::beans::Property& x, const ::com::sun::star::beans::Property& y) const
77 return x.Name == y.Name ;
81 //------------------------------------------------------------------
82 /// remove the property with the given name from the given sequence
83 COMPHELPER_DLLPUBLIC void RemoveProperty(staruno::Sequence<starbeans::Property>& seqProps, const OUString& _rPropName);
85 //------------------------------------------------------------------
86 /** within the given property sequence, modify attributes of a special property
87 @param _rProps the sequence of properties to search in
88 @param _sPropName the name of the property which's attributes should be modified
89 @param _nAddAttrib the attributes which should be added
90 @param _nRemoveAttrib the attributes which should be removed
92 COMPHELPER_DLLPUBLIC void ModifyPropertyAttributes(staruno::Sequence<starbeans::Property>& _rProps, const OUString& _sPropName, sal_Int16 _nAddAttrib, sal_Int16 _nRemoveAttrib);
94 //------------------------------------------------------------------
95 /** check if the given set has the given property.
97 COMPHELPER_DLLPUBLIC sal_Bool hasProperty(const OUString& _rName, const staruno::Reference<starbeans::XPropertySet>& _rxSet);
99 //------------------------------------------------------------------
100 /** copy properties between property sets, in compliance with the property
101 attributes of the target object
103 COMPHELPER_DLLPUBLIC void copyProperties(const staruno::Reference<starbeans::XPropertySet>& _rxSource,
104 const staruno::Reference<starbeans::XPropertySet>& _rxDest);
106 //==================================================================
107 //= property conversion helpers
108 //==================================================================
110 /** helper for implementing ::cppu::OPropertySetHelper::convertFastPropertyValue
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)
119 template <typename T>
120 sal_Bool tryPropertyValue(staruno::Any& /*out*/_rConvertedValue, staruno::Any& /*out*/_rOldValue, const staruno::Any& _rValueToSet, const T& _rCurrentValue)
122 sal_Bool bModified(sal_False);
123 T aNewValue = T();
124 ::cppu::convertPropertyValue(aNewValue, _rValueToSet);
125 if (aNewValue != _rCurrentValue)
127 _rConvertedValue <<= aNewValue;
128 _rOldValue <<= _rCurrentValue;
129 bModified = sal_True;
131 return bModified;
134 /** helper for implementing ::cppu::OPropertySetHelper::convertFastPropertyValue for enum values
135 @param _rConvertedValue the conversion result (if successful)
136 @param _rOldValue the old value of the property, calculated from _rCurrentValue
137 @param _rValueToSet the new value which is about to be set
138 @param _rCurrentValue the current value of the property
139 @return sal_True, if the value could be converted and has changed
140 sal_False, if the value could be converted and has not changed
141 @exception InvalidArgumentException thrown if the value could not be converted to the requested type (which is the template argument)
143 template <class ENUMTYPE>
144 sal_Bool tryPropertyValueEnum(staruno::Any& /*out*/_rConvertedValue, staruno::Any& /*out*/_rOldValue, const staruno::Any& _rValueToSet, const ENUMTYPE& _rCurrentValue)
146 if (cppu::getTypeFavourUnsigned(&_rCurrentValue).getTypeClass()
147 != staruno::TypeClass_ENUM)
148 return tryPropertyValue(_rConvertedValue, _rOldValue, _rValueToSet, _rCurrentValue);
150 sal_Bool bModified(sal_False);
151 ENUMTYPE aNewValue;
152 ::cppu::any2enum(aNewValue, _rValueToSet);
153 // will throw an exception if not convertible
155 if (aNewValue != _rCurrentValue)
157 _rConvertedValue <<= aNewValue;
158 _rOldValue <<= _rCurrentValue;
159 bModified = sal_True;
161 return bModified;
164 /** helper for implementing ::cppu::OPropertySetHelper::convertFastPropertyValue for boolean properties
165 @param _rConvertedValue the conversion result (if successful)
166 @param _rOldValue the old value of the property, calculated from _rCurrentValue
167 @param _rValueToSet the new value which is about to be set
168 @param _rCurrentValue the current value of the property
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 a boolean type
173 inline sal_Bool tryPropertyValue(staruno::Any& /*out*/_rConvertedValue, staruno::Any& /*out*/_rOldValue, const staruno::Any& _rValueToSet, sal_Bool _bCurrentValue)
175 sal_Bool bModified(sal_False);
176 sal_Bool bNewValue(sal_False);
177 ::cppu::convertPropertyValue(bNewValue, _rValueToSet);
178 if (bNewValue != _bCurrentValue)
180 _rConvertedValue.setValue(&bNewValue, ::getBooleanCppuType());
181 _rOldValue.setValue(&_bCurrentValue, ::getBooleanCppuType());
182 bModified = sal_True;
184 return bModified;
187 /** helper for implementing ::cppu::OPropertySetHelper::convertFastPropertyValue
188 @param _rConvertedValue the conversion result (if successful)
189 @param _rOldValue the old value of the property, calculated from _rCurrentValue
190 @param _rValueToSet the new value which is about to be set
191 @param _rCurrentValue the current value of the property
192 @param _rExpectedType the type which the property should have (if not void)
193 @return sal_True, if the value could be converted and has changed
194 sal_False, if the value could be converted and has not changed
195 @exception InvalidArgumentException thrown if the value could not be converted to the requested type (which is the template argument)
197 COMPHELPER_DLLPUBLIC sal_Bool tryPropertyValue(staruno::Any& _rConvertedValue, staruno::Any& _rOldValue, const staruno::Any& _rValueToSet, const staruno::Any& _rCurrentValue, const staruno::Type& _rExpectedType);
199 //.........................................................................
201 //... namespace comphelper .......................................................
203 #endif // _COMPHELPER_PROPERTY_HXX_
205 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */