22#include <osl/diagnose.h>
26#if OSL_DEBUG_LEVEL > 0
28 #include <com/sun/star/lang/XServiceInfo.hpp>
31#include <com/sun/star/beans/PropertyAttribute.hpp>
32#include <com/sun/star/beans/XPropertySet.hpp>
33#include <com/sun/star/lang/IllegalArgumentException.hpp>
34#include <rtl/ustrbuf.hxx>
41 using ::com::sun::star::uno::Reference;
42 using ::com::sun::star::beans::XPropertySet;
43 using ::com::sun::star::beans::XPropertySetInfo;
44 using ::com::sun::star::beans::Property;
45 using ::com::sun::star::uno::Sequence;
46 using ::com::sun::star::uno::Exception;
47 using ::com::sun::star::uno::Any;
48 using ::com::sun::star::uno::Type;
49 using ::com::sun::star::uno::cpp_queryInterface;
50 using ::com::sun::star::uno::cpp_acquire;
51 using ::com::sun::star::uno::cpp_release;
52#if OSL_DEBUG_LEVEL > 0
53 using ::com::sun::star::lang::XServiceInfo;
55 using ::com::sun::star::uno::UNO_QUERY;
57 namespace PropertyAttribute = ::com::sun::star::beans::PropertyAttribute;
61 const Reference<XPropertySet>& _rxDest)
63 if (!_rxSource.is() || !_rxDest.is())
65 OSL_FAIL(
"copyProperties: invalid arguments !");
69 Reference< XPropertySetInfo > xSourceProps = _rxSource->getPropertySetInfo();
70 Reference< XPropertySetInfo > xDestProps = _rxDest->getPropertySetInfo();
72 const Sequence< Property > aSourceProps = xSourceProps->getProperties();
74 for (
const Property& rSourceProp : aSourceProps)
76 if ( xDestProps->hasPropertyByName(rSourceProp.Name) )
80 aDestProp = xDestProps->getPropertyByName(rSourceProp.Name);
81 if (0 == (aDestProp.Attributes & PropertyAttribute::READONLY) )
83 const Any aSourceValue = _rxSource->getPropertyValue(rSourceProp.Name);
84 if ( 0 != (aDestProp.Attributes & PropertyAttribute::MAYBEVOID) || aSourceValue.hasValue() )
85 _rxDest->setPropertyValue(rSourceProp.Name, aSourceValue);
90#if OSL_DEBUG_LEVEL > 0
94 "::comphelper::copyProperties: could not copy property '"
96 +
"' to the destination set (a '" );
98 Reference< XServiceInfo > xSI( _rxDest, UNO_QUERY );
101 aBuffer.append( xSI->getImplementationName() );
105 aBuffer.appendAscii(
typeid( *_rxDest ).name() );
107 aBuffer.append(
"' implementation).\n" );
109 Any aException( ::cppu::getCaughtException() );
110 aBuffer.append(
"Caught an exception of type '"
111 + aException.getValueTypeName()
115 if ( ( aException >>= aBaseException ) && !aBaseException.Message.isEmpty() )
118 + aBaseException.Message
131bool hasProperty(
const OUString& _rName,
const Reference<XPropertySet>& _rxSet)
136 return _rxSet->getPropertySetInfo()->hasPropertyByName(_rName);
148 if ( pResult != std::cend(_rProps) && pResult->Name == _rPropName)
155void ModifyPropertyAttributes(Sequence<Property>& seqProps,
const OUString& sPropName, sal_Int16 nAddAttrib, sal_Int16 nRemoveAttrib)
158 auto [
begin,
end] = asNonConstRange(seqProps);
162 if ( (pResult !=
end) && (pResult->Name == sPropName) )
164 pResult->Attributes |= nAddAttrib;
165 pResult->Attributes &= ~nRemoveAttrib;
170bool tryPropertyValue(Any& _rConvertedValue, Any& _rOldValue,
const Any& _rValueToSet,
const Any& _rCurrentValue,
const Type& _rExpectedType)
172 bool bModified(
false);
173 if (_rCurrentValue.getValue() != _rValueToSet.getValue())
175 if ( _rValueToSet.hasValue() && ( !_rExpectedType.equals( _rValueToSet.getValueType() ) ) )
177 _rConvertedValue =
Any(
nullptr, _rExpectedType.getTypeLibType() );
180 const_cast< void*
>( _rConvertedValue.getValue() ), _rConvertedValue.getValueType().getTypeLibType(),
181 const_cast< void*
>( _rValueToSet.getValue() ), _rValueToSet.getValueType().getTypeLibType(),
182 reinterpret_cast< uno_QueryInterfaceFunc
>(
184 reinterpret_cast< uno_AcquireFunc
>(cpp_acquire),
185 reinterpret_cast< uno_ReleaseFunc
>(cpp_release)
188 throw css::lang::IllegalArgumentException();
191 _rConvertedValue = _rValueToSet;
193 if ( _rCurrentValue != _rConvertedValue )
195 _rOldValue = _rCurrentValue;
sal_Bool SAL_CALL uno_type_assignData(void *pDest, typelib_TypeDescriptionReference *pDestType, void *pSource, typelib_TypeDescriptionReference *pSourceType, uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release) SAL_THROW_EXTERN_C()
#define TOOLS_WARN_EXCEPTION(area, stream)
Logs an message along with a nicely formatted version of the current exception.
#define SAL_WARN(area, stream)
bool hasProperty(const OUString &_rName, const Reference< XPropertySet > &_rxSet)
bool tryPropertyValue(Any &_rConvertedValue, Any &_rOldValue, const Any &_rValueToSet, const Any &_rCurrentValue, const Type &_rExpectedType)
void ModifyPropertyAttributes(Sequence< Property > &seqProps, const OUString &sPropName, sal_Int16 nAddAttrib, sal_Int16 nRemoveAttrib)
void removeElementAt(css::uno::Sequence< T > &_rSeq, sal_Int32 _nPos)
remove a specified element from a sequences
void copyProperties(const Reference< XPropertySet > &_rxSource, const Reference< XPropertySet > &_rxDest)
void RemoveProperty(Sequence< Property > &_rProps, const OUString &_rPropName)
enumrange< T >::Iterator begin(enumrange< T >)
std::unique_ptr< char[]> aBuffer