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
25#include <com/sun/star/beans/Property.hpp>
26#include <type_traits>
28
29namespace com::sun::star::beans { class XPropertySet; }
30
31namespace 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
44COMPHELPER_DLLPUBLIC void RemoveProperty(css::uno::Sequence<css::beans::Property>& seqProps, const OUString& _rPropName);
45
52COMPHELPER_DLLPUBLIC void ModifyPropertyAttributes(css::uno::Sequence<css::beans::Property>& _rProps, const OUString& _sPropName, sal_Int16 _nAddAttrib, sal_Int16 _nRemoveAttrib);
53
56COMPHELPER_DLLPUBLIC bool hasProperty(const OUString& _rName, const css::uno::Reference<css::beans::XPropertySet>& _rxSet);
57
61COMPHELPER_DLLPUBLIC void copyProperties(const css::uno::Reference<css::beans::XPropertySet>& _rxSource,
62 const css::uno::Reference<css::beans::XPropertySet>& _rxDest);
63
73template <typename T>
74bool 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
97template <class ENUMTYPE>
98typename std::enable_if<std::is_enum<ENUMTYPE>::value, bool>::type
99tryPropertyValueEnum(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
125COMPHELPER_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: */
#define COMPHELPER_DLLPUBLIC
float y
float x
class SAL_NO_VTABLE XPropertySet
bool hasProperty(const OUString &_rName, const Reference< XPropertySet > &_rxSet)
Definition: property.cxx:131
bool tryPropertyValue(Any &_rConvertedValue, Any &_rOldValue, const Any &_rValueToSet, const Any &_rCurrentValue, const Type &_rExpectedType)
Definition: property.cxx:170
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 ModifyPropertyAttributes(Sequence< Property > &seqProps, const OUString &sPropName, sal_Int16 nAddAttrib, sal_Int16 nRemoveAttrib)
Definition: property.cxx:155
void copyProperties(const Reference< XPropertySet > &_rxSource, const Reference< XPropertySet > &_rxDest)
Definition: property.cxx:60
void RemoveProperty(Sequence< Property > &_rProps, const OUString &_rPropName)
Definition: property.cxx:142
void any2enum(E &eRet, const css::uno::Any &rAny)
Sets int32 from enum or int in any with additional typecheck.
Definition: extract.hxx:73
bool operator()(const css::beans::Property &x, const css::beans::Property &y) const
Definition: property.hxx:37