23#include <com/sun/star/beans/IllegalTypeException.hpp>
24#include <com/sun/star/beans/PropertyAttribute.hpp>
25#include <com/sun/star/beans/Property.hpp>
38extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
40 css::uno::XComponentContext *,
41 css::uno::Sequence<css::uno::Any>
const &)
58 ,::
cppu::IEventNotificationHook()
59 ,m_bAutoAddProperties( false )
75 void SAL_CALL
OPropertyBag::initialize( const Sequence< Any >& _rArguments )
78 bool AllowEmptyPropertyName(
false);
79 bool AutomaticAddition(
false);
81 if (_rArguments.getLength() == 3
82 && (_rArguments[0] >>=
aTypes)
83 && (_rArguments[1] >>= AllowEmptyPropertyName)
84 && (_rArguments[2] >>= AutomaticAddition))
86 m_aAllowedTypes.insert(std::cbegin(
aTypes), std::cend(
aTypes));
87 m_bAutoAddProperties = AutomaticAddition;
93 m_aAllowedTypes.insert(std::cbegin(
aTypes), std::cend(
aTypes));
95 aArguments.get_ensureType(
"AutomaticAddition", m_bAutoAddProperties );
96 aArguments.get_ensureType(
"AllowEmptyPropertyName",
97 AllowEmptyPropertyName );
99 if (AllowEmptyPropertyName) {
100 m_aDynamicProperties.setAllowEmptyPropertyName(
101 AllowEmptyPropertyName);
107 return "com.sun.star.comp.comphelper.OPropertyBag";
117 return {
"com.sun.star.beans.PropertyBag" };
124 bool bIgnoreRuntimeExceptionsWhileFiring)
126 if (
nCount && !bVetoable) {
132 bool bIgnoreRuntimeExceptionsWhileFiring)
135 ::osl::MutexGuard aGuard(
m_aMutex );
142 Reference<XInterface> xThis(*
this);
143 EventObject event(xThis);
145 &XModifyListener::modified, event);
147 if (!bIgnoreRuntimeExceptionsWhileFiring) {
158 ::osl::MutexGuard aGuard(
m_aMutex );
168 const Reference< XModifyListener > & xListener)
174 const Reference< XModifyListener > & xListener)
199 if ( !( _element >>= aProperty ) )
200 throw IllegalArgumentException(
"element is not Property", *
this, 1 );
209 throw IllegalArgumentException(
"not in list of allowed types", *
this, 1);
212 aProperty.Attributes);
225 throw NoSuchElementException( OUString(), *
this );
260 return m_aDynamicProperties.convertFastPropertyValue( _nHandle, _rValue, _rConvertedValue, _rOldValue );
284 const sal_Int32 nPrime = 1009;
285 const sal_Int32 nSeed = 11;
287 sal_Int32 nCheck = nSeed;
290 nCheck = ( nCheck * nSeed ) % nPrime;
311 const Type& aPropertyType = _rInitialValue.getValueType();
314 throw IllegalTypeException(OUString(), *
this);
342 struct ComparePropertyValueByName
344 bool operator()(
const PropertyValue& _rLHS,
const PropertyValue& _rRHS )
346 return _rLHS.Name < _rRHS.Name;
350 template<
typename CLASS >
351 struct TransformPropertyToName
353 const OUString& operator()(
const CLASS& _rProp )
359 struct ExtractPropertyValue
361 const Any& operator()(
const PropertyValue& _rProp )
371 ::osl::MutexGuard aGuard(
m_aMutex );
378 Sequence< OUString > aNames(
aProperties.getLength() );
383 TransformPropertyToName< Property >()
387 Sequence< Any > aValues;
390 aValues = OPropertyBag_PBase::getPropertyValues( aNames );
391 if ( aValues.getLength() != aNames.getLength() )
407 const OUString*
pName = aNames.getConstArray();
408 const OUString* pNamesEnd = aNames.getConstArray() + aNames.getLength();
409 const Any* pValue = aValues.getArray();
412 for ( ;
pName != pNamesEnd; ++
pName, ++pValue, ++pPropertyValue )
414 pPropertyValue->Name = *
pName;
416 pPropertyValue->Value = *pValue;
432 ComparePropertyValueByName()
436 Sequence< OUString > aNames(
aProperties.getLength() );
441 TransformPropertyToName< PropertyValue >()
452 sal_Int32
nCount = aNames.getLength();
454 Sequence< sal_Int32 > aHandles(
nCount );
455 sal_Int32* pHandle = aHandles.getArray();
456 const PropertyValue* pProperty =
aProperties.getConstArray();
457 for (
const OUString*
pName = aNames.getConstArray();
458 pName != aNames.getConstArray() + aNames.getLength();
459 ++
pName, ++pHandle, ++pProperty
464 if ( *pHandle != -1 )
471 sal_Int16
const nAttributes = PropertyAttribute::BOUND | PropertyAttribute::REMOVABLE | PropertyAttribute::MAYBEDEFAULT;
477 throw UnknownPropertyException( *
pName, *
this );
481 Sequence< Any > aValues(
aProperties.getLength() );
486 ExtractPropertyValue()
489 setFastPropertyValues(
nCount, aHandles.getArray(), aValues.getConstArray(),
nCount );
491 catch(
const PropertyVetoException& ) {
throw; }
492 catch(
const IllegalArgumentException& ) {
throw; }
493 catch(
const WrappedTargetException& ) {
throw; }
495 catch(
const UnknownPropertyException& ) {
throw; }
498 throw WrappedTargetException( OUString(), *
this, ::cppu::getCaughtException() );
505 ::osl::MutexGuard aGuard(
m_aMutex );
522 if ( (
nAttributes & PropertyAttribute::MAYBEDEFAULT ) == 0 )
523 return PropertyState_DIRECT_VALUE;
525 return OPropertyBag_PBase::getPropertyStateByHandle( _nHandle );
PropertyValueVector_t aPropertyValues
PropertiesInfo aProperties
a collection of named values, packed in various formats.
sal_Int32 addInterface(const css::uno::Reference< ListenerT > &rxIFace)
Inserts an element into the container.
sal_Int32 removeInterface(const css::uno::Reference< ListenerT > &rxIFace)
Removes an element from the container.
void notifyEach(void(SAL_CALL ListenerT::*NotificationMethod)(const EventT &), const EventT &Event)
Calls a UNO listener method for each contained listener.
virtual sal_Bool SAL_CALL convertFastPropertyValue(css::uno::Any &rConvertedValue, css::uno::Any &rOldValue, sal_Int32 nHandle, const css::uno::Any &rValue) override
void setModifiedImpl(bool bModified, bool bIgnoreRuntimeExceptionsWhileFiring)
virtual void SAL_CALL remove(const css::uno::Any &aElement) override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
virtual void SAL_CALL removeProperty(const OUString &Name) override
bool m_bAutoAddProperties
should we automatically add properties which are tried to set, if they don't exist previously?
::comphelper::PropertyBag m_aDynamicProperties
TypeBag m_aAllowedTypes
set of allowed property types
virtual css::uno::Any getPropertyDefaultByHandle(sal_Int32 _nHandle) const override
virtual OUString SAL_CALL getImplementationName() override
virtual void SAL_CALL addModifyListener(const css::uno::Reference< css::util::XModifyListener > &xListener) override
virtual void SAL_CALL setPropertyValues(const css::uno::Sequence< css::beans::PropertyValue > &aProps) override
virtual css::uno::Type SAL_CALL getElementType() override
virtual void fireEvents(sal_Int32 *pnHandles, sal_Int32 nCount, sal_Bool bVetoable, bool bIgnoreRuntimeExceptionsWhileFiring) override
virtual void SAL_CALL setModified(sal_Bool bModified) override
bool m_isModified
modify flag
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
virtual css::beans::PropertyState getPropertyStateByHandle(sal_Int32 _nHandle) override
virtual ~OPropertyBag() override
virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getPropertyValues() override
virtual void SAL_CALL getFastPropertyValue(css::uno::Any &rValue, sal_Int32 nHandle) const override
std::unique_ptr< ::cppu::OPropertyArrayHelper > m_pArrayHelper
our IPropertyArrayHelper implementation
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
virtual void SAL_CALL removeModifyListener(const css::uno::Reference< css::util::XModifyListener > &xListener) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
::comphelper::OInterfaceContainerHelper3< css::util::XModifyListener > m_NotifyListeners
for notification
virtual void SAL_CALL addProperty(const OUString &Name, ::sal_Int16 Attributes, const css::uno::Any &DefaultValue) override
virtual sal_Bool SAL_CALL isModified() override
virtual sal_Bool SAL_CALL has(const css::uno::Any &aElement) override
sal_Int32 findFreeHandle() const
finds a free property handle @precond our mutex is locked
void impl_setPropertyValues_throw(const css::uno::Sequence< css::beans::PropertyValue > &_rProps)
implements the setPropertyValues method
virtual sal_Bool SAL_CALL hasElements() override
virtual void SAL_CALL insert(const css::uno::Any &aElement) override
virtual sal_Bool SAL_CALL fillPropertyMembersByHandle(::rtl::OUString *pPropName, sal_Int16 *pAttributes, sal_Int32 nHandle)=0
virtual sal_Int32 SAL_CALL getHandleByName(const ::rtl::OUString &rPropertyName)=0
Sequence< PropertyValue > aArguments
::cppu::WeakImplHelper< css::beans::XPropertyBag, css::util::XModifiable, css::lang::XServiceInfo, css::lang::XInitialization, css::container::XSet > OPropertyBag_Base
::comphelper::OPropertyStateHelper OPropertyBag_PBase
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
enumrange< T >::Iterator begin(enumrange< T >)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_comphelper_OPropertyBag(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
#define IMPLEMENT_FORWARD_XTYPEPROVIDER2(classname, baseclass1, baseclass2)
#define IMPLEMENT_FORWARD_XINTERFACE2(classname, refcountbase, baseclass2)