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>
43 struct PropertyDescriptionHandleCompare
45 bool operator() (
const PropertyDescription& x,
const PropertyDescription& y)
const
47 return x.aProperty.Handle < y.aProperty.Handle;
51 struct PropertyDescriptionNameMatch
54 explicit PropertyDescriptionNameMatch(
const OUString& _rCompare ) : m_rCompare( _rCompare ) { }
56 bool operator() (
const PropertyDescription& x )
const
74 sal_Int32 _nAttributes,
void* _pPointerToMember,
const Type& _rMemberType)
76 OSL_ENSURE((_nAttributes & PropertyAttribute::MAYBEVOID) == 0,
77 "OPropertyContainerHelper::registerProperty: don't use this for properties which may be void ! There is a method called \"registerMayBeVoidProperty\" for this !");
79 "OPropertyContainerHelper::registerProperty: don't give my the type of a uno::Any ! Really can't handle this !");
80 OSL_ENSURE(_pPointerToMember,
81 "OPropertyContainerHelper::registerProperty: you gave me nonsense : the pointer must be non-NULL");
84 aNewProp.
aProperty =
Property( _rName, _nHandle, _rMemberType, static_cast<sal_Int16>(_nAttributes) );
96 throw UnknownPropertyException(OUString::number(_nHandle));
102 Any* _pPointerToMember,
const Type& _rExpectedType)
104 OSL_ENSURE((_nAttributes & PropertyAttribute::MAYBEVOID) != 0,
105 "OPropertyContainerHelper::registerMayBeVoidProperty: why calling this when the attributes say nothing about may-be-void ?");
107 "OPropertyContainerHelper::registerMayBeVoidProperty: don't give my the type of a uno::Any ! Really can't handle this !");
108 OSL_ENSURE(_pPointerToMember,
109 "OPropertyContainerHelper::registerMayBeVoidProperty: you gave me nonsense : the pointer must be non-NULL");
111 _nAttributes |= PropertyAttribute::MAYBEVOID;
114 aNewProp.
aProperty =
Property( _rName, _nHandle, _rExpectedType, static_cast<sal_Int16>(_nAttributes) );
123 const Type& _rType, css::uno::Any
const & _pInitialValue)
126 "OPropertyContainerHelper::registerPropertyNoMember : don't give my the type of a uno::Any ! Really can't handle this !");
128 (_pInitialValue.isExtractableTo(_rType)
129 || (!_pInitialValue.hasValue()
130 && (_nAttributes & PropertyAttribute::MAYBEVOID) != 0)),
131 "bad initial value");
134 aNewProp.
aProperty =
Property( _rName, _nHandle, _rType, static_cast<sal_Int16>(_nAttributes) );
159 PropertyDescriptionNameMatch( _rName )
166 struct ComparePropertyHandles
181 OSL_ENSURE(checkConflicts.aProperty.Name != _rProp.
aProperty.Name,
"OPropertyContainerHelper::implPushBackProperty: name already exists!");
182 OSL_ENSURE(checkConflicts.aProperty.Handle != _rProp.
aProperty.Handle,
"OPropertyContainerHelper::implPushBackProperty: handle already exists!");
187 m_aProperties.begin(), m_aProperties.end(),
188 _rProp, ComparePropertyHandles() );
190 m_aProperties.insert( pos, _rProp );
196 void lcl_throwIllegalPropertyValueTypeException(
const PropertyDescription& _rProperty,
const Any& _rValue )
198 throw IllegalArgumentException(
199 "The given value cannot be converted to the required property type."
200 " (property name \"" + _rProperty.
aProperty.Name
201 +
"\", found value type \"" + _rValue.getValueType().getTypeName()
202 +
"\", required property type \"" + _rProperty.
aProperty.Type.getTypeName()
210 Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle,
const Any& _rValue )
212 bool bModified =
false;
218 OSL_FAIL(
"OPropertyContainerHelper::convertFastPropertyValue: unknown handle!" );
224 switch (aPos->eLocated)
230 bool bMayBeVoid = ((aPos->aProperty.Attributes & PropertyAttribute::MAYBEVOID) != 0);
234 Any aNewRequestedValue( _rValue );
238 if ( !aNewRequestedValue.getValueType().equals( aPos->aProperty.Type ) )
240 Any aProperlyTyped(
nullptr, aPos->aProperty.Type.getTypeLibType() );
243 const_cast< void* >( aProperlyTyped.getValue() ), aProperlyTyped.getValueType().getTypeLibType(),
244 const_cast< void*
>( aNewRequestedValue.getValue() ), aNewRequestedValue.getValueType().getTypeLibType(),
245 reinterpret_cast< uno_QueryInterfaceFunc
>( cpp_queryInterface ),
246 reinterpret_cast< uno_AcquireFunc >( cpp_acquire ),
247 reinterpret_cast< uno_ReleaseFunc
>( cpp_release )
253 aNewRequestedValue = aProperlyTyped;
258 if ( ! ( (bMayBeVoid && !aNewRequestedValue.hasValue())
259 || (aNewRequestedValue.getValueType().equals(aPos->aProperty.Type))
263 lcl_throwIllegalPropertyValueTypeException( *aPos, _rValue );
266 Any* pPropContainer =
nullptr;
272 OSL_ENSURE(aPos->aLocation.nOwnClassVectorIndex < static_cast<sal_Int32>(
m_aHoldProperties.size()),
273 "OPropertyContainerHelper::convertFastPropertyValue: invalid position !");
275 pPropContainer = &(*aIter);
278 pPropContainer =
static_cast<Any*
>(aPos->aLocation.pDerivedClassMember);
281 if (!pPropContainer->hasValue() || !aNewRequestedValue.hasValue())
282 bModified = pPropContainer->hasValue() != aNewRequestedValue.hasValue();
285 const_cast< void* >( pPropContainer->getValue() ), aPos->aProperty.Type.getTypeLibType(),
286 const_cast< void*
>( aNewRequestedValue.getValue() ), aPos->aProperty.Type.getTypeLibType(),
287 reinterpret_cast< uno_QueryInterfaceFunc
>( cpp_queryInterface ),
288 reinterpret_cast< uno_ReleaseFunc >( cpp_release )
293 _rOldValue = *pPropContainer;
294 _rConvertedValue = aNewRequestedValue;
305 const Any* pNewValue = &_rValue;
307 if (!_rValue.getValueType().equals(aPos->aProperty.Type))
309 bool bConverted =
false;
312 aProperlyTyped =
Any(
nullptr, aPos->aProperty.Type.getTypeLibType() );
316 const_cast<void*>(aProperlyTyped.getValue()), aProperlyTyped.getValueType().getTypeLibType(),
317 const_cast<void*
>(_rValue.getValue()), _rValue.getValueType().getTypeLibType(),
318 reinterpret_cast< uno_QueryInterfaceFunc
>( cpp_queryInterface ),
319 reinterpret_cast< uno_AcquireFunc >( cpp_acquire ),
320 reinterpret_cast< uno_ReleaseFunc
>( cpp_release )
326 pNewValue = &aProperlyTyped;
330 lcl_throwIllegalPropertyValueTypeException( *aPos, _rValue );
334 OSL_ENSURE( pNewValue->getValueType() == aPos->aProperty.Type,
335 "OPropertyContainerHelper::convertFastPropertyValue: conversion failed!" );
337 aPos->aLocation.pDerivedClassMember, aPos->aProperty.Type.getTypeLibType(),
338 const_cast<void*
>(pNewValue->getValue()), aPos->aProperty.Type.getTypeLibType(),
339 reinterpret_cast< uno_QueryInterfaceFunc
>( cpp_queryInterface ),
340 reinterpret_cast< uno_ReleaseFunc >( cpp_release )
345 _rOldValue.setValue(aPos->aLocation.pDerivedClassMember, aPos->aProperty.Type);
346 _rConvertedValue = *pNewValue;
361 OSL_FAIL(
"OPropertyContainerHelper::setFastPropertyValue: unknown handle!" );
367 bool bSuccess =
true;
369 switch (aPos->eLocated)
376 *
static_cast< Any*
>(aPos->aLocation.pDerivedClassMember) = _rValue;
382 aPos->aLocation.pDerivedClassMember, aPos->aProperty.Type.getTypeLibType(),
383 const_cast< void*
>( _rValue.getValue() ), _rValue.getValueType().getTypeLibType(),
384 reinterpret_cast< uno_QueryInterfaceFunc
>( cpp_queryInterface ),
385 reinterpret_cast< uno_AcquireFunc >( cpp_acquire ),
386 reinterpret_cast< uno_ReleaseFunc
>( cpp_release ) );
388 OSL_ENSURE( bSuccess,
389 "OPropertyContainerHelper::setFastPropertyValue: ooops... the value could not be assigned!");
401 OSL_FAIL(
"OPropertyContainerHelper::getFastPropertyValue: unknown handle!" );
407 switch (aPos->eLocated)
410 OSL_ENSURE(aPos->aLocation.nOwnClassVectorIndex < static_cast<sal_Int32>(
m_aHoldProperties.size()),
411 "OPropertyContainerHelper::convertFastPropertyValue: invalid position !");
415 _rValue = *
static_cast<Any*
>(aPos->aLocation.pDerivedClassMember);
418 _rValue.setValue(aPos->aLocation.pDerivedClassMember, aPos->aProperty.Type);
427 aHandlePropDesc.
aProperty.Handle = _nHandle;
433 PropertyDescriptionHandleCompare());
436 if ((aLowerBound !=
m_aProperties.end()) && aLowerBound->aProperty.Handle != _nHandle)
448 PropertyDescriptionNameMatch( _rName )
451 throw UnknownPropertyException( _rName );
453 return pos->aProperty;
460 Property* pOwnProps = aOwnProps.getArray();
464 pOwnProps->Name = rProp.aProperty.Name;
465 pOwnProps->Handle = rProp.aProperty.Handle;
466 pOwnProps->Attributes =
static_cast<sal_Int16
>(rProp.aProperty.Attributes);
467 pOwnProps->Type = rProp.aProperty.Type;
476 Sequence< Property > aOutput;
477 aOutput.realloc(_rProps.getLength() + aOwnProps.getLength());
479 std::merge( _rProps.begin(), _rProps.end(),
480 aOwnProps.begin(), aOwnProps.end(),
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()
void * pDerivedClassMember
void registerProperty(const OUString &_rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, void *_pPointerToMember, const css::uno::Type &_rMemberType)
register a property.
sal_Int32 nOwnClassVectorIndex
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...
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()
OPropertyContainerHelper()
COMPHELPER_DLLPRIVATE PropertiesIterator searchHandle(sal_Int32 _nHandle)
search the PropertyDescription for the given handle (within m_aProperties)
OUString const m_rCompare
css::beans::Property aProperty
const css::beans::Property & getProperty(const OUString &_rName) const
retrieves the description for a registered property
Properties::iterator PropertiesIterator
PropertyContainer m_aHoldProperties
helper class for managing property values, and implementing most of the X*Property* interfaces ...
bool isRegisteredProperty(sal_Int32 _nHandle) const
checks whether a property with the given handle has been registered
Properties::const_iterator ConstPropertiesIterator
COMPHELPER_DLLPRIVATE void implPushBackProperty(const PropertyDescription &_rProp)
insertion of _rProp into m_aProperties, keeping the sort order
~OPropertyContainerHelper()
void registerMayBeVoidProperty(const OUString &_rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, css::uno::Any *_pPointerToMember, const css::uno::Type &_rExpectedType)
register a property.
void revokeProperty(sal_Int32 _nHandle)
revokes a previously registered property
void getFastPropertyValue(css::uno::Any &rValue, sal_Int32 nHandle) const
void registerPropertyNoMember(const OUString &_rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, const css::uno::Type &_rType, css::uno::Any const &_pInitialValue)
register a property.
bool convertFastPropertyValue(css::uno::Any &rConvertedValue, css::uno::Any &rOldValue, sal_Int32 nHandle, const css::uno::Any &rValue)
void setFastPropertyValue(sal_Int32 nHandle, const css::uno::Any &rValue)