22#include <osl/diagnose.h>
24#include <com/sun/star/uno/Sequence.hxx>
25#include <com/sun/star/beans/PropertyAttribute.hpp>
26#include <com/sun/star/beans/UnknownPropertyException.hpp>
44 struct PropertyDescriptionHandleCompare
46 bool operator() (
const PropertyDescription& x,
const PropertyDescription& y)
const
48 return x.aProperty.Handle <
y.aProperty.Handle;
52 struct PropertyDescriptionNameMatch
55 explicit PropertyDescriptionNameMatch( OUString _aCompare ) :
m_rCompare(
std::move( _aCompare )) { }
57 bool operator() (
const PropertyDescription& x )
const
75 sal_Int32 _nAttributes,
void* _pPointerToMember,
const Type& _rMemberType)
77 OSL_ENSURE((_nAttributes & PropertyAttribute::MAYBEVOID) == 0,
78 "OPropertyContainerHelper::registerProperty: don't use this for properties which may be void ! There is a method called \"registerMayBeVoidProperty\" for this !");
80 "OPropertyContainerHelper::registerProperty: don't give my the type of a uno::Any ! Really can't handle this !");
81 OSL_ENSURE(_pPointerToMember,
82 "OPropertyContainerHelper::registerProperty: you gave me nonsense : the pointer must be non-NULL");
85 aNewProp.
aProperty =
Property( _rName, _nHandle, _rMemberType,
static_cast<sal_Int16
>(_nAttributes) );
97 throw UnknownPropertyException(OUString::number(_nHandle));
103 Any* _pPointerToMember,
const Type& _rExpectedType)
105 OSL_ENSURE((_nAttributes & PropertyAttribute::MAYBEVOID) != 0,
106 "OPropertyContainerHelper::registerMayBeVoidProperty: why calling this when the attributes say nothing about may-be-void ?");
108 "OPropertyContainerHelper::registerMayBeVoidProperty: don't give my the type of a uno::Any ! Really can't handle this !");
109 OSL_ENSURE(_pPointerToMember,
110 "OPropertyContainerHelper::registerMayBeVoidProperty: you gave me nonsense : the pointer must be non-NULL");
112 _nAttributes |= PropertyAttribute::MAYBEVOID;
115 aNewProp.
aProperty =
Property( _rName, _nHandle, _rExpectedType,
static_cast<sal_Int16
>(_nAttributes) );
124 const Type& _rType, css::uno::Any
const & _pInitialValue)
127 "OPropertyContainerHelper::registerPropertyNoMember : don't give my the type of a uno::Any ! Really can't handle this !");
129 (_pInitialValue.isExtractableTo(_rType)
130 || (!_pInitialValue.hasValue()
131 && (_nAttributes & PropertyAttribute::MAYBEVOID) != 0)),
132 "bad initial value");
135 aNewProp.
aProperty =
Property( _rName, _nHandle, _rType,
static_cast<sal_Int16
>(_nAttributes) );
160 PropertyDescriptionNameMatch( _rName )
167 struct ComparePropertyHandles
182 OSL_ENSURE(checkConflicts.aProperty.Name != _rProp.
aProperty.Name,
"OPropertyContainerHelper::implPushBackProperty: name already exists!");
183 OSL_ENSURE(checkConflicts.aProperty.Handle != _rProp.
aProperty.Handle,
"OPropertyContainerHelper::implPushBackProperty: handle already exists!");
189 _rProp, ComparePropertyHandles() );
197 void lcl_throwIllegalPropertyValueTypeException(
const PropertyDescription& _rProperty,
const Any& _rValue )
199 throw IllegalArgumentException(
200 "The given value cannot be converted to the required property type."
201 " (property name \"" + _rProperty.
aProperty.Name
202 +
"\", found value type \"" + _rValue.getValueType().getTypeName()
203 +
"\", required property type \"" + _rProperty.
aProperty.Type.getTypeName()
211 Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle,
const Any& _rValue )
213 bool bModified =
false;
219 OSL_FAIL(
"OPropertyContainerHelper::convertFastPropertyValue: unknown handle!" );
225 switch (aPos->eLocated)
231 bool bMayBeVoid = ((aPos->aProperty.Attributes & PropertyAttribute::MAYBEVOID) != 0);
235 Any aNewRequestedValue( _rValue );
239 if ( !aNewRequestedValue.getValueType().equals( aPos->aProperty.Type ) )
241 Any aProperlyTyped(
nullptr, aPos->aProperty.Type.getTypeLibType() );
244 const_cast< void*
>( aProperlyTyped.getValue() ), aProperlyTyped.getValueType().getTypeLibType(),
245 const_cast< void*
>( aNewRequestedValue.getValue() ), aNewRequestedValue.getValueType().getTypeLibType(),
246 reinterpret_cast< uno_QueryInterfaceFunc
>( cpp_queryInterface ),
247 reinterpret_cast< uno_AcquireFunc
>( cpp_acquire ),
248 reinterpret_cast< uno_ReleaseFunc
>( cpp_release )
254 aNewRequestedValue = aProperlyTyped;
259 if ( ! ( (bMayBeVoid && !aNewRequestedValue.hasValue())
260 || (aNewRequestedValue.getValueType().equals(aPos->aProperty.Type))
264 lcl_throwIllegalPropertyValueTypeException( *aPos, _rValue );
267 Any* pPropContainer =
nullptr;
274 "OPropertyContainerHelper::convertFastPropertyValue: invalid position !");
276 pPropContainer = &(*aIter);
279 pPropContainer =
static_cast<Any*
>(aPos->aLocation.pDerivedClassMember);
282 if (!pPropContainer->hasValue() || !aNewRequestedValue.hasValue())
283 bModified = pPropContainer->hasValue() != aNewRequestedValue.hasValue();
286 const_cast< void*
>( pPropContainer->getValue() ), aPos->aProperty.Type.getTypeLibType(),
287 const_cast< void*
>( aNewRequestedValue.getValue() ), aPos->aProperty.Type.getTypeLibType(),
288 reinterpret_cast< uno_QueryInterfaceFunc
>( cpp_queryInterface ),
289 reinterpret_cast< uno_ReleaseFunc
>( cpp_release )
294 _rOldValue = *pPropContainer;
295 _rConvertedValue = aNewRequestedValue;
306 const Any* pNewValue = &_rValue;
308 if (!_rValue.getValueType().equals(aPos->aProperty.Type))
310 bool bConverted =
false;
313 aProperlyTyped =
Any(
nullptr, aPos->aProperty.Type.getTypeLibType() );
317 const_cast<void*
>(aProperlyTyped.getValue()), aProperlyTyped.getValueType().getTypeLibType(),
318 const_cast<void*
>(_rValue.getValue()), _rValue.getValueType().getTypeLibType(),
319 reinterpret_cast< uno_QueryInterfaceFunc
>( cpp_queryInterface ),
320 reinterpret_cast< uno_AcquireFunc
>( cpp_acquire ),
321 reinterpret_cast< uno_ReleaseFunc
>( cpp_release )
327 pNewValue = &aProperlyTyped;
331 lcl_throwIllegalPropertyValueTypeException( *aPos, _rValue );
335 OSL_ENSURE( pNewValue->getValueType() == aPos->aProperty.Type,
336 "OPropertyContainerHelper::convertFastPropertyValue: conversion failed!" );
338 aPos->aLocation.pDerivedClassMember, aPos->aProperty.Type.getTypeLibType(),
339 const_cast<void*
>(pNewValue->getValue()), aPos->aProperty.Type.getTypeLibType(),
340 reinterpret_cast< uno_QueryInterfaceFunc
>( cpp_queryInterface ),
341 reinterpret_cast< uno_ReleaseFunc
>( cpp_release )
346 _rOldValue.setValue(aPos->aLocation.pDerivedClassMember, aPos->aProperty.Type);
347 _rConvertedValue = *pNewValue;
362 OSL_FAIL(
"OPropertyContainerHelper::setFastPropertyValue: unknown handle!" );
368 bool bSuccess =
true;
370 switch (aPos->eLocated)
377 *
static_cast< Any*
>(aPos->aLocation.pDerivedClassMember) = _rValue;
383 aPos->aLocation.pDerivedClassMember, aPos->aProperty.Type.getTypeLibType(),
384 const_cast< void*
>( _rValue.getValue() ), _rValue.getValueType().getTypeLibType(),
385 reinterpret_cast< uno_QueryInterfaceFunc
>( cpp_queryInterface ),
386 reinterpret_cast< uno_AcquireFunc
>( cpp_acquire ),
387 reinterpret_cast< uno_ReleaseFunc
>( cpp_release ) );
389 OSL_ENSURE( bSuccess,
390 "OPropertyContainerHelper::setFastPropertyValue: ooops... the value could not be assigned!");
402 OSL_FAIL(
"OPropertyContainerHelper::getFastPropertyValue: unknown handle!" );
408 switch (aPos->eLocated)
412 "OPropertyContainerHelper::convertFastPropertyValue: invalid position !");
416 _rValue = *
static_cast<Any*
>(aPos->aLocation.pDerivedClassMember);
419 _rValue.setValue(aPos->aLocation.pDerivedClassMember, aPos->aProperty.Type);
428 aHandlePropDesc.
aProperty.Handle = _nHandle;
434 PropertyDescriptionHandleCompare());
437 if ((aLowerBound !=
m_aProperties.end()) && aLowerBound->aProperty.Handle != _nHandle)
449 PropertyDescriptionNameMatch( _rName )
452 throw UnknownPropertyException( _rName );
454 return pos->aProperty;
461 Property* pOwnProps = aOwnProps.getArray();
465 pOwnProps->Name = rProp.aProperty.Name;
466 pOwnProps->Handle = rProp.aProperty.Handle;
467 pOwnProps->Attributes = rProp.aProperty.Attributes;
468 pOwnProps->Type = rProp.aProperty.Type;
473 auto [
begin,
end] = asNonConstRange(aOwnProps);
478 Sequence< Property > aOutput(_rProps.getLength() + aOwnProps.getLength());
480 std::merge( std::cbegin(_rProps), std::cend(_rProps),
481 std::cbegin(aOwnProps), std::cend(aOwnProps),
helper class for managing property values, and implementing most of the X*Property* interfaces
COMPHELPER_DLLPRIVATE void implPushBackProperty(const PropertyDescription &_rProp)
insertion of _rProp into m_aProperties, keeping the sort order
Properties::const_iterator ConstPropertiesIterator
void getFastPropertyValue(css::uno::Any &rValue, sal_Int32 nHandle) const
OPropertyContainerHelper()
void registerPropertyNoMember(const OUString &_rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, const css::uno::Type &_rType, css::uno::Any const &_pInitialValue)
register a property.
Properties::iterator PropertiesIterator
bool convertFastPropertyValue(css::uno::Any &rConvertedValue, css::uno::Any &rOldValue, sal_Int32 nHandle, const css::uno::Any &rValue)
const css::beans::Property & getProperty(const OUString &_rName) const
retrieves the description for a registered property
void describeProperties(css::uno::Sequence< css::beans::Property > &_rProps) const
appends the descriptions of all properties which were registered 'til that moment to the given sequen...
void registerProperty(const OUString &_rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, void *_pPointerToMember, const css::uno::Type &_rMemberType)
register a property.
bool isRegisteredProperty(sal_Int32 _nHandle) const
checks whether a property with the given handle has been registered
void revokeProperty(sal_Int32 _nHandle)
revokes a previously registered property
COMPHELPER_DLLPRIVATE PropertiesIterator searchHandle(sal_Int32 _nHandle)
search the PropertyDescription for the given handle (within m_aProperties)
void setFastPropertyValue(sal_Int32 nHandle, const css::uno::Any &rValue)
~OPropertyContainerHelper()
PropertyContainer m_aHoldProperties
void registerMayBeVoidProperty(const OUString &_rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, css::uno::Any *_pPointerToMember, const css::uno::Type &_rExpectedType)
register a property.
sal_Bool SAL_CALL uno_type_equalData(void *pVal1, typelib_TypeDescriptionReference *pVal1Type, void *pVal2, typelib_TypeDescriptionReference *pVal2Type, uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release) SAL_THROW_EXTERN_C()
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()
enumrange< T >::Iterator begin(enumrange< T >)
OUString const m_rCompare
css::beans::Property aProperty
std::size_t nOwnClassVectorIndex
void * pDerivedClassMember