23 #include <com/sun/star/beans/IllegalTypeException.hpp>
24 #include <com/sun/star/beans/PropertyAttribute.hpp>
25 #include <com/sun/star/beans/Property.hpp>
38 extern "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(aTypes.begin(), aTypes.end());
87 m_bAutoAddProperties = AutomaticAddition;
93 m_aAllowedTypes.insert( aTypes.begin(), aTypes.end());
95 aArguments.
get_ensureType(
"AutomaticAddition", m_bAutoAddProperties );
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( OUString(), *
this, 1 );
209 throw IllegalArgumentException(OUString(), *
this, 1);
212 aProperty.Attributes);
225 throw NoSuchElementException( OUString(), *
this );
260 return m_aDynamicProperties.convertFastPropertyValue( _nHandle, _rValue, _rConvertedValue, _rOldValue );
275 m_pArrayHelper.reset( new ::cppu::OPropertyArrayHelper( aProperties ) );
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 );
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;
431 ComparePropertyValueByName()
440 TransformPropertyToName< PropertyValue >()
451 sal_Int32
nCount = aNames.getLength();
453 Sequence< sal_Int32 > aHandles( nCount );
454 sal_Int32* pHandle = aHandles.getArray();
455 const PropertyValue* pProperty = aProperties.getConstArray();
456 for (
const OUString*
pName = aNames.getConstArray();
457 pName != aNames.getConstArray() + aNames.getLength();
458 ++
pName, ++pHandle, ++pProperty
463 if ( *pHandle != -1 )
470 sal_Int16
const nAttributes = PropertyAttribute::BOUND | PropertyAttribute::REMOVABLE | PropertyAttribute::MAYBEDEFAULT;
476 throw UnknownPropertyException( *
pName, *
this );
480 Sequence< Any > aValues( aProperties.getLength() );
485 ExtractPropertyValue()
488 setFastPropertyValues( nCount, aHandles.getArray(), aValues.getConstArray(), nCount );
490 catch(
const PropertyVetoException& ) {
throw; }
491 catch(
const IllegalArgumentException& ) {
throw; }
492 catch(
const WrappedTargetException& ) {
throw; }
494 catch(
const UnknownPropertyException& ) {
throw; }
504 ::osl::MutexGuard aGuard(
m_aMutex );
521 if ( ( nAttributes & PropertyAttribute::MAYBEDEFAULT ) == 0 )
522 return PropertyState_DIRECT_VALUE;
524 return OPropertyBag_PBase::getPropertyStateByHandle( _nHandle );
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
virtual void SAL_CALL getFastPropertyValue(css::uno::Any &rValue, sal_Int32 nHandle) const override
virtual void SAL_CALL addProperty(const OUString &Name,::sal_Int16 Attributes, const css::uno::Any &DefaultValue) override
virtual void fireEvents(sal_Int32 *pnHandles, sal_Int32 nCount, sal_Bool bVetoable, bool bIgnoreRuntimeExceptionsWhileFiring) override
void notifyEach(void(SAL_CALL ListenerT::*NotificationMethod)(const EventT &), const EventT &Event)
Calls a UNO listener method for each contained listener.
void setModifiedImpl(bool bModified, bool bIgnoreRuntimeExceptionsWhileFiring)
::comphelper::OInterfaceContainerHelper2 m_NotifyListeners
for notification
virtual OUString SAL_CALL getImplementationName() override
sal_Int32 addInterface(const css::uno::Reference< css::uno::XInterface > &rxIFace)
Inserts an element into the container.
a collection of named values, packed in various formats.
#define IMPLEMENT_FORWARD_XTYPEPROVIDER2(classname, baseclass1, baseclass2)
virtual void SAL_CALL remove(const css::uno::Any &aElement) override
sal_Int32 removeInterface(const css::uno::Reference< css::uno::XInterface > &rxIFace)
Removes an element from the container.
::comphelper::OPropertyStateHelper OPropertyBag_PBase
::comphelper::PropertyBag m_aDynamicProperties
virtual css::uno::Any getPropertyDefaultByHandle(sal_Int32 _nHandle) const override
virtual ~OPropertyBag() override
virtual void SAL_CALL insert(const css::uno::Any &aElement) override
Sequence< PropertyValue > aArguments
PropertiesInfo aProperties
Any SAL_CALL getCaughtException()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
virtual void SAL_CALL addModifyListener(const css::uno::Reference< css::util::XModifyListener > &xListener) override
virtual void SAL_CALL setModified(sal_Bool bModified) override
std::unique_ptr< ::cppu::OPropertyArrayHelper > m_pArrayHelper
our IPropertyArrayHelper implementation
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void SAL_CALL removeProperty(const OUString &Name) override
virtual void SAL_CALL setPropertyValues(const css::uno::Sequence< css::beans::PropertyValue > &aProps) override
virtual sal_Bool SAL_CALL fillPropertyMembersByHandle(::rtl::OUString *pPropName, sal_Int16 *pAttributes, sal_Int32 nHandle)=0
bool get_ensureType(const char *_pAsciiValueName, VALUE_TYPE &_out_rValue) const
retrieves a value with a given name from the collection, if it is present
virtual sal_Bool SAL_CALL hasElements() override
virtual void SAL_CALL removeModifyListener(const css::uno::Reference< css::util::XModifyListener > &xListener) override
virtual css::beans::PropertyState getPropertyStateByHandle(sal_Int32 _nHandle) override
TypeBag m_aAllowedTypes
set of allowed property types
PropertyValueVector_t aPropertyValues
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
#define IMPLEMENT_FORWARD_XINTERFACE2(classname, refcountbase, baseclass2)
sal_Int32 findFreeHandle() const
finds a free property handle our mutex is locked
virtual sal_Bool SAL_CALL isModified() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual sal_Bool SAL_CALL convertFastPropertyValue(css::uno::Any &rConvertedValue, css::uno::Any &rOldValue, sal_Int32 nHandle, const css::uno::Any &rValue) override
void impl_setPropertyValues_throw(const css::uno::Sequence< css::beans::PropertyValue > &_rProps)
implements the setPropertyValues method
bool m_bAutoAddProperties
should we automatically add properties which are tried to set, if they don't exist previously...
virtual sal_Bool SAL_CALL has(const css::uno::Any &aElement) override
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_comphelper_OPropertyBag(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
bool m_isModified
modify flag
virtual css::uno::Type SAL_CALL getElementType() override
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
virtual sal_Int32 SAL_CALL getHandleByName(const ::rtl::OUString &rPropertyName)=0
virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getPropertyValues() override