cppuhelper/source/propertysetmixin.cxx | 601 ++++++++++---------------------- include/cppuhelper/propertysetmixin.hxx | 27 - 2 files changed, 220 insertions(+), 408 deletions(-)
New commits: commit 04fe0cae207e6f0a1fe7e2bd6d980d8880ae1572 Author: Stephan Bergmann <[email protected]> Date: Sun Oct 20 18:49:48 2013 +0200 Some clean-up Change-Id: I8ab23a4b09f9d31ed49c98cdbbf1abc0e684358a diff --git a/cppuhelper/source/propertysetmixin.cxx b/cppuhelper/source/propertysetmixin.cxx index b928369..466b530 100644 --- a/cppuhelper/source/propertysetmixin.cxx +++ b/cppuhelper/source/propertysetmixin.cxx @@ -17,10 +17,14 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ - #include "sal/config.h" -#include "cppuhelper/propertysetmixin.hxx" +#include <algorithm> +#include <cassert> +#include <exception> +#include <map> +#include <set> +#include <vector> #include "com/sun/star/beans/Property.hpp" #include "com/sun/star/beans/PropertyChangeEvent.hpp" @@ -42,18 +46,16 @@ #include "com/sun/star/lang/IllegalArgumentException.hpp" #include "com/sun/star/lang/WrappedTargetException.hpp" #include "com/sun/star/lang/WrappedTargetRuntimeException.hpp" -#include "com/sun/star/lang/XComponent.hpp" -#include "com/sun/star/lang/XMultiComponentFactory.hpp" #include "com/sun/star/reflection/XCompoundTypeDescription.hpp" #include "com/sun/star/reflection/XIdlClass.hpp" #include "com/sun/star/reflection/XIdlField2.hpp" -#include "com/sun/star/reflection/XIdlReflection.hpp" #include "com/sun/star/reflection/XIndirectTypeDescription.hpp" #include "com/sun/star/reflection/XInterfaceAttributeTypeDescription2.hpp" #include "com/sun/star/reflection/XInterfaceMemberTypeDescription.hpp" #include "com/sun/star/reflection/XInterfaceTypeDescription2.hpp" #include "com/sun/star/reflection/XStructTypeDescription.hpp" #include "com/sun/star/reflection/XTypeDescription.hpp" +#include "com/sun/star/reflection/theCoreReflection.hpp" #include "com/sun/star/uno/Any.hxx" #include "com/sun/star/uno/DeploymentException.hpp" #include "com/sun/star/uno/Exception.hpp" @@ -65,51 +67,18 @@ #include "com/sun/star/uno/XComponentContext.hpp" #include "com/sun/star/uno/XInterface.hpp" #include "cppuhelper/implbase1.hxx" +#include "cppuhelper/propertysetmixin.hxx" #include "cppuhelper/weak.hxx" -#include "osl/diagnose.h" #include "osl/mutex.hxx" #include "rtl/ref.hxx" -#include "rtl/string.h" -#include "rtl/ustring.h" #include "rtl/ustring.hxx" #include "sal/types.h" #include "salhelper/simplereferenceobject.hxx" -#include <algorithm> -#include <exception> -#include <map> -#include <set> -#include <vector> - using cppu::PropertySetMixinImpl; namespace { -template< typename T > struct AutoDispose { - AutoDispose() {} - - ~AutoDispose() { - try { - dispose(); - } catch (...) {} - } - - void dispose() { - css::uno::Reference< css::lang::XComponent > comp( - ifc, css::uno::UNO_QUERY); - if (comp.is()) { - comp->dispose(); - } - ifc.clear(); - } - - css::uno::Reference< T > ifc; - -private: - AutoDispose(AutoDispose &); // not defined - void operator =(AutoDispose); // not defined -}; - struct PropertyData { explicit PropertyData( css::beans::Property const & theProperty, bool thePresent): @@ -234,19 +203,16 @@ void Data::initProperties( { t = resolveTypedefs(t); sal_Int16 n; - if (t->getName().matchAsciiL( - RTL_CONSTASCII_STRINGPARAM( - "com.sun.star.beans.Ambiguous<"))) + if (t->getName().startsWith( + "com.sun.star.beans.Ambiguous<")) { n = css::beans::PropertyAttribute::MAYBEAMBIGUOUS; - } else if (t->getName().matchAsciiL( - RTL_CONSTASCII_STRINGPARAM( - "com.sun.star.beans.Defaulted<"))) + } else if (t->getName().startsWith( + "com.sun.star.beans.Defaulted<")) { n = css::beans::PropertyAttribute::MAYBEDEFAULT; - } else if (t->getName().matchAsciiL( - RTL_CONSTASCII_STRINGPARAM( - "com.sun.star.beans.Optional<"))) + } else if (t->getName().startsWith( + "com.sun.star.beans.Optional<")) { n = css::beans::PropertyAttribute::MAYBEVOID; } else { @@ -261,12 +227,11 @@ void Data::initProperties( args( css::uno::Reference< css::reflection::XStructTypeDescription >( - t, - css::uno::UNO_QUERY_THROW)->getTypeArguments()); + t, css::uno::UNO_QUERY_THROW)-> + getTypeArguments()); if (args.getLength() != 1) { throw css::uno::RuntimeException( - rtl::OUString( - "inconsistent UNO type registry"), + "inconsistent UNO type registry", css::uno::Reference< css::uno::XInterface >()); } t = args[0]; @@ -275,8 +240,7 @@ void Data::initProperties( = handleNames->size(); if (handles > SAL_MAX_INT32) { throw css::uno::RuntimeException( - rtl::OUString( - "interface type has too many attributes"), + "interface type has too many attributes", css::uno::Reference< css::uno::XInterface >()); } rtl::OUString name(members[i]->getMemberName()); @@ -294,8 +258,7 @@ void Data::initProperties( second) { throw css::uno::RuntimeException( - rtl::OUString( - "inconsistent UNO type registry"), + "inconsistent UNO type registry", css::uno::Reference< css::uno::XInterface >()); } handleNames->push_back(name); @@ -337,7 +300,7 @@ private: css::uno::Sequence< css::beans::Property > Info::getProperties() throw (css::uno::RuntimeException, std::exception) { - OSL_ASSERT(m_data->properties.size() <= SAL_MAX_INT32); + assert(m_data->properties.size() <= SAL_MAX_INT32); css::uno::Sequence< css::beans::Property > s( static_cast< sal_Int32 >(m_data->properties.size())); sal_Int32 n = 0; @@ -466,36 +429,33 @@ PropertySetMixinImpl::Impl::Impl( implements(theImplements), disposed(false), m_context(context), m_absentOptional(absentOptional), m_type(type) { - OSL_ASSERT( - context.is() - && ((implements - & ~(IMPLEMENTS_PROPERTY_SET | IMPLEMENTS_FAST_PROPERTY_SET - | IMPLEMENTS_PROPERTY_ACCESS)) - == 0)); + assert(context.is()); + assert( + (implements + & ~(IMPLEMENTS_PROPERTY_SET | IMPLEMENTS_FAST_PROPERTY_SET + | IMPLEMENTS_PROPERTY_ACCESS)) + == 0); m_idlClass = getReflection(m_type.getTypeName()); css::uno::Reference< css::reflection::XTypeDescription > ifc; try { ifc = css::uno::Reference< css::reflection::XTypeDescription >( css::uno::Reference< css::container::XHierarchicalNameAccess >( m_context->getValueByName( - rtl::OUString( - "/singletons/com.sun.star.reflection." - "theTypeDescriptionManager")), + "/singletons/com.sun.star.reflection." + "theTypeDescriptionManager"), css::uno::UNO_QUERY_THROW)->getByHierarchicalName( m_type.getTypeName()), css::uno::UNO_QUERY_THROW); } catch (css::container::NoSuchElementException & e) { throw css::uno::RuntimeException( - (rtl::OUString( - "unexpected" - " com.sun.star.container.NoSuchElementException: ") + ("unexpected com.sun.star.container.NoSuchElementException: " + e.Message), css::uno::Reference< css::uno::XInterface >()); } std::vector< rtl::OUString > handleNames; initProperties(ifc, m_absentOptional, &handleNames); std::vector< rtl::OUString >::size_type size = handleNames.size(); - OSL_ASSERT(size <= SAL_MAX_INT32); + assert(size <= SAL_MAX_INT32); handleMap.realloc(static_cast< sal_Int32 >(size)); std::copy(handleNames.begin(), handleNames.end(), handleMap.getArray()); } @@ -506,9 +466,7 @@ rtl::OUString PropertySetMixinImpl::Impl::translateHandle( { if (handle < 0 || handle >= handleMap.getLength()) { throw css::beans::UnknownPropertyException( - (rtl::OUString("bad handle ") - + rtl::OUString::number(handle)), - object); + "bad handle " + rtl::OUString::number(handle), object); } return handleMap[handle]; } @@ -532,9 +490,7 @@ void PropertySetMixinImpl::Impl::setProperty( == 0))) { throw css::lang::IllegalArgumentException( - (rtl::OUString( - "flagging as ambiguous/defaulted non-ambiguous/defaulted" - " property ") + ("flagging as ambiguous/defaulted non-ambiguous/defaulted property " + name), object, illegalArgumentPosition); } @@ -566,9 +522,7 @@ void PropertySetMixinImpl::Impl::setProperty( e.Message, object, illegalArgumentPosition); } else { throw css::uno::RuntimeException( - (rtl::OUString( - "unexpected" - " com.sun.star.lang.IllegalArgumentException: ") + ("unexpected com.sun.star.lang.IllegalArgumentException: " + e.Message), object); } @@ -576,9 +530,7 @@ void PropertySetMixinImpl::Impl::setProperty( //TODO Clarify whether PropertyVetoException is the correct exception // to throw when trying to set a read-only property: throw css::beans::PropertyVetoException( - (rtl::OUString("cannot set read-only property ") - + name), - object); + "cannot set read-only property " + name, object); } catch (css::lang::WrappedTargetRuntimeException & e) { //FIXME A WrappedTargetRuntimeException from XIdlField2.get is not // guaranteed to originate directly within XIdlField2.get (and thus have @@ -628,8 +580,7 @@ css::uno::Any PropertySetMixinImpl::Impl::getProperty( value = field->get(object->queryInterface(m_type)); } catch (css::lang::IllegalArgumentException & e) { throw css::uno::RuntimeException( - (rtl::OUString( - "unexpected com.sun.star.lang.IllegalArgumentException: ") + ("unexpected com.sun.star.lang.IllegalArgumentException: " + e.Message), object); } catch (css::lang::WrappedTargetRuntimeException & e) { @@ -666,92 +617,76 @@ css::uno::Any PropertySetMixinImpl::Impl::getProperty( bool isDefaulted = false; while (undoAmbiguous || undoDefaulted || undoOptional) { if (undoAmbiguous - && value.getValueTypeName().matchAsciiL( - RTL_CONSTASCII_STRINGPARAM("com.sun.star.beans.Ambiguous<"))) + && value.getValueTypeName().startsWith( + "com.sun.star.beans.Ambiguous<")) { css::uno::Reference< css::reflection::XIdlClass > ambiguous( getReflection(value.getValueTypeName())); try { if (!(css::uno::Reference< css::reflection::XIdlField2 >( - ambiguous->getField( - rtl::OUString("IsAmbiguous")), + ambiguous->getField("IsAmbiguous"), css::uno::UNO_QUERY_THROW)->get(value) >>= isAmbiguous)) { throw css::uno::RuntimeException( - rtl::OUString( - "unexpected type of" - " com.sun.star.beans.Ambiguous IsAmbiguous" - " member"), + ("unexpected type of com.sun.star.beans.Ambiguous" + " IsAmbiguous member"), object); } value = css::uno::Reference< css::reflection::XIdlField2 >( - ambiguous->getField( - rtl::OUString("Value")), - css::uno::UNO_QUERY_THROW)->get(value); + ambiguous->getField("Value"), css::uno::UNO_QUERY_THROW)-> + get(value); } catch (css::lang::IllegalArgumentException & e) { throw css::uno::RuntimeException( - (rtl::OUString( - "unexpected com.sun.star.lang." - "IllegalArgumentException: ") + ("unexpected com.sun.star.lang.IllegalArgumentException: " + e.Message), object); } undoAmbiguous = false; } else if (undoDefaulted - && value.getValueTypeName().matchAsciiL( - RTL_CONSTASCII_STRINGPARAM( - "com.sun.star.beans.Defaulted<"))) + && value.getValueTypeName().startsWith( + "com.sun.star.beans.Defaulted<")) { css::uno::Reference< css::reflection::XIdlClass > defaulted( getReflection(value.getValueTypeName())); try { if (!(css::uno::Reference< css::reflection::XIdlField2 >( - defaulted->getField( - rtl::OUString("IsDefaulted")), + defaulted->getField("IsDefaulted"), css::uno::UNO_QUERY_THROW)->get(value) >>= isDefaulted)) { throw css::uno::RuntimeException( - rtl::OUString( - "unexpected type of" - " com.sun.star.beans.Defaulted IsDefaulted" - " member"), + ("unexpected type of com.sun.star.beans.Defaulted" + " IsDefaulted member"), object); } value = css::uno::Reference< css::reflection::XIdlField2 >( - defaulted->getField( - rtl::OUString("Value")), - css::uno::UNO_QUERY_THROW)->get(value); + defaulted->getField("Value"), css::uno::UNO_QUERY_THROW)-> + get(value); } catch (css::lang::IllegalArgumentException & e) { throw css::uno::RuntimeException( - (rtl::OUString( - "unexpected com.sun.star.lang." - "IllegalArgumentException: ") + ("unexpected com.sun.star.lang.IllegalArgumentException: " + e.Message), object); } undoDefaulted = false; } else if (undoOptional - && value.getValueTypeName().matchAsciiL( - RTL_CONSTASCII_STRINGPARAM( - "com.sun.star.beans.Optional<"))) + && value.getValueTypeName().startsWith( + "com.sun.star.beans.Optional<")) { css::uno::Reference< css::reflection::XIdlClass > optional( getReflection(value.getValueTypeName())); try { bool present = false; if (!(css::uno::Reference< css::reflection::XIdlField2 >( - optional->getField( - rtl::OUString("IsPresent")), + optional->getField("IsPresent"), css::uno::UNO_QUERY_THROW)->get(value) >>= present)) { throw css::uno::RuntimeException( - rtl::OUString( - "unexpected type of com.sun.star.beans.Optional" - " IsPresent member"), + ("unexpected type of com.sun.star.beans.Optional" + " IsPresent member"), object); } if (!present) { @@ -759,24 +694,18 @@ css::uno::Any PropertySetMixinImpl::Impl::getProperty( break; } value = css::uno::Reference< css::reflection::XIdlField2 >( - optional->getField( - rtl::OUString("Value")), - css::uno::UNO_QUERY_THROW)->get(value); + optional->getField("Value"), css::uno::UNO_QUERY_THROW)-> + get(value); } catch (css::lang::IllegalArgumentException & e) { throw css::uno::RuntimeException( - (rtl::OUString( - "unexpected com.sun.star.lang." - "IllegalArgumentException: ") + ("unexpected com.sun.star.lang.IllegalArgumentException: " + e.Message), object); } undoOptional = false; } else { throw css::uno::RuntimeException( - (rtl::OUString( - "unexpected type of attribute ") - + name), - object); + "unexpected type of attribute " + name, object); } } if (state != 0) { @@ -794,30 +723,9 @@ css::uno::Any PropertySetMixinImpl::Impl::getProperty( css::uno::Reference< css::reflection::XIdlClass > PropertySetMixinImpl::Impl::getReflection(rtl::OUString const & typeName) const { - css::uno::Reference< css::lang::XMultiComponentFactory > factory( - m_context->getServiceManager(), css::uno::UNO_QUERY_THROW); - AutoDispose< css::reflection::XIdlReflection > refl; - try { - refl.ifc = css::uno::Reference< css::reflection::XIdlReflection >( - factory->createInstanceWithContext( - rtl::OUString( - "com.sun.star.reflection.CoreReflection"), - m_context), - css::uno::UNO_QUERY_THROW); - } catch (css::uno::RuntimeException &) { - throw; - } catch (css::uno::Exception & e) { - throw css::uno::DeploymentException( - (rtl::OUString( - "component context fails to supply service" - " com.sun.star.reflection.CoreReflection: ") - + e.Message), - m_context); - } - css::uno::Reference< css::reflection::XIdlClass > idlClass( - refl.ifc->forName(typeName), css::uno::UNO_QUERY_THROW); - refl.dispose(); - return idlClass; + return css::uno::Reference< css::reflection::XIdlClass >( + css::reflection::theCoreReflection::get(m_context)->forName(typeName), + css::uno::UNO_SET_THROW); } css::uno::Any PropertySetMixinImpl::Impl::wrapValue( @@ -827,100 +735,77 @@ css::uno::Any PropertySetMixinImpl::Impl::wrapValue( bool wrapAmbiguous, bool isAmbiguous, bool wrapDefaulted, bool isDefaulted, bool wrapOptional) { - OSL_ASSERT( - (wrapAmbiguous || !isAmbiguous) && (wrapDefaulted || !isDefaulted)); + assert(wrapAmbiguous || !isAmbiguous); + assert(wrapDefaulted || !isDefaulted); if (wrapAmbiguous - && type->getName().matchAsciiL( - RTL_CONSTASCII_STRINGPARAM("com.sun.star.beans.Ambiguous<"))) + && type->getName().startsWith("com.sun.star.beans.Ambiguous<")) { css::uno::Any strct; type->createObject(strct); try { css::uno::Reference< css::reflection::XIdlField2 > field( - type->getField( - rtl::OUString("Value")), - css::uno::UNO_QUERY_THROW); + type->getField("Value"), css::uno::UNO_QUERY_THROW); field->set( strct, wrapValue( object, value, field->getType(), false, false, wrapDefaulted, isDefaulted, wrapOptional)); css::uno::Reference< css::reflection::XIdlField2 >( - type->getField( - rtl::OUString("IsAmbiguous")), - css::uno::UNO_QUERY_THROW)->set( + type->getField("IsAmbiguous"), css::uno::UNO_QUERY_THROW)->set( strct, css::uno::makeAny(isAmbiguous)); } catch (css::lang::IllegalArgumentException & e) { throw css::uno::RuntimeException( - (rtl::OUString( - "unexpected" - " com.sun.star.lang.IllegalArgumentException: ") + ("unexpected com.sun.star.lang.IllegalArgumentException: " + e.Message), object); } catch (css::lang::IllegalAccessException & e) { throw css::uno::RuntimeException( - (rtl::OUString( - "unexpected" - " com.sun.star.lang.IllegalAccessException: ") + ("unexpected com.sun.star.lang.IllegalAccessException: " + e.Message), object); } return strct; } else if (wrapDefaulted - && type->getName().matchAsciiL( - RTL_CONSTASCII_STRINGPARAM("com.sun.star.beans.Defaulted<"))) + && type->getName().startsWith("com.sun.star.beans.Defaulted<")) { css::uno::Any strct; type->createObject(strct); try { css::uno::Reference< css::reflection::XIdlField2 > field( - type->getField( - rtl::OUString("Value")), - css::uno::UNO_QUERY_THROW); + type->getField("Value"), css::uno::UNO_QUERY_THROW); field->set( strct, wrapValue( object, value, field->getType(), wrapAmbiguous, isAmbiguous, false, false, wrapOptional)); css::uno::Reference< css::reflection::XIdlField2 >( - type->getField( - rtl::OUString("IsDefaulted")), - css::uno::UNO_QUERY_THROW)->set( + type->getField("IsDefaulted"), css::uno::UNO_QUERY_THROW)->set( strct, css::uno::makeAny(isDefaulted)); } catch (css::lang::IllegalArgumentException & e) { throw css::uno::RuntimeException( - (rtl::OUString( - "unexpected" - " com.sun.star.lang.IllegalArgumentException: ") + ("unexpected com.sun.star.lang.IllegalArgumentException: " + e.Message), object); } catch (css::lang::IllegalAccessException & e) { throw css::uno::RuntimeException( - (rtl::OUString( - "unexpected" - " com.sun.star.lang.IllegalAccessException: ") + ("unexpected com.sun.star.lang.IllegalAccessException: " + e.Message), object); } return strct; } else if (wrapOptional - && type->getName().matchAsciiL( - RTL_CONSTASCII_STRINGPARAM("com.sun.star.beans.Optional<"))) + && type->getName().startsWith("com.sun.star.beans.Optional<")) { css::uno::Any strct; type->createObject(strct); bool present = value.hasValue(); try { css::uno::Reference< css::reflection::XIdlField2 >( - type->getField( - rtl::OUString("IsPresent")), - css::uno::UNO_QUERY_THROW)->set( + type->getField("IsPresent"), css::uno::UNO_QUERY_THROW)->set( strct, css::uno::makeAny(present)); if (present) { css::uno::Reference< css::reflection::XIdlField2 > field( - type->getField( - rtl::OUString("Value")), - css::uno::UNO_QUERY_THROW); + type->getField("Value"), css::uno::UNO_QUERY_THROW); field->set( strct, wrapValue( @@ -929,16 +814,12 @@ css::uno::Any PropertySetMixinImpl::Impl::wrapValue( } } catch (css::lang::IllegalArgumentException & e) { throw css::uno::RuntimeException( - (rtl::OUString( - "unexpected" - " com.sun.star.lang.IllegalArgumentException: ") + ("unexpected com.sun.star.lang.IllegalArgumentException: " + e.Message), object); } catch (css::lang::IllegalAccessException & e) { throw css::uno::RuntimeException( - (rtl::OUString( - "unexpected" - " com.sun.star.lang.IllegalAccessException: ") + ("unexpected com.sun.star.lang.IllegalAccessException: " + e.Message), object); } @@ -946,9 +827,7 @@ css::uno::Any PropertySetMixinImpl::Impl::wrapValue( } else { if (wrapAmbiguous || wrapDefaulted || wrapOptional) { throw css::uno::RuntimeException( - rtl::OUString( - "unexpected type of attribute"), - object); + "unexpected type of attribute", object); } return value; } @@ -980,15 +859,14 @@ void PropertySetMixinImpl::prepareSet( css::uno::Any const & newValue, BoundListeners * boundListeners) { Impl::PropertyMap::const_iterator it(m_impl->properties.find(propertyName)); - OSL_ASSERT(it != m_impl->properties.end()); + assert(it != m_impl->properties.end()); Impl::VetoListenerBag specificVeto; Impl::VetoListenerBag unspecificVeto; { osl::MutexGuard g(m_impl->mutex); if (m_impl->disposed) { throw css::lang::DisposedException( - rtl::OUString("disposed"), - static_cast< css::beans::XPropertySet * >(this)); + "disposed", static_cast< css::beans::XPropertySet * >(this)); } if ((it->second.property.Attributes & css::beans::PropertyAttribute::CONSTRAINED) @@ -999,7 +877,7 @@ void PropertySetMixinImpl::prepareSet( if (i != m_impl->vetoListeners.end()) { specificVeto = i->second; } - i = m_impl->vetoListeners.find(rtl::OUString()); + i = m_impl->vetoListeners.find(""); if (i != m_impl->vetoListeners.end()) { unspecificVeto = i->second; } @@ -1008,13 +886,13 @@ void PropertySetMixinImpl::prepareSet( & css::beans::PropertyAttribute::BOUND) != 0) { - OSL_ASSERT(boundListeners != 0); + assert(boundListeners != 0); Impl::BoundListenerMap::const_iterator i( m_impl->boundListeners.find(propertyName)); if (i != m_impl->boundListeners.end()) { boundListeners->m_impl->specificListeners = i->second; } - i = m_impl->boundListeners.find(rtl::OUString()); + i = m_impl->boundListeners.find(""); if (i != m_impl->boundListeners.end()) { boundListeners->m_impl->unspecificListeners = i->second; } @@ -1045,7 +923,7 @@ void PropertySetMixinImpl::prepareSet( if ((it->second.property.Attributes & css::beans::PropertyAttribute::BOUND) != 0) { - OSL_ASSERT(boundListeners != 0); + assert(boundListeners != 0); boundListeners->m_impl->event = css::beans::PropertyChangeEvent( static_cast< css::beans::XPropertySet * >(this), propertyName, false, it->second.property.Handle, oldValue, newValue); @@ -1146,7 +1024,7 @@ void PropertySetMixinImpl::addPropertyChangeListener( css::uno::RuntimeException, std::exception) { css::uno::Reference< css::beans::XPropertyChangeListener >( - listener, css::uno::UNO_QUERY_THROW); // reject NULL listener + listener, css::uno::UNO_SET_THROW); // reject NULL listener checkUnknown(propertyName); bool disposed; { @@ -1170,7 +1048,7 @@ void PropertySetMixinImpl::removePropertyChangeListener( css::beans::UnknownPropertyException, css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) { - OSL_ASSERT(listener.is()); + assert(listener.is()); checkUnknown(propertyName); osl::MutexGuard g(m_impl->mutex); Impl::BoundListenerMap::iterator i( @@ -1191,7 +1069,7 @@ void PropertySetMixinImpl::addVetoableChangeListener( css::uno::RuntimeException, std::exception) { css::uno::Reference< css::beans::XVetoableChangeListener >( - listener, css::uno::UNO_QUERY_THROW); // reject NULL listener + listener, css::uno::UNO_SET_THROW); // reject NULL listener checkUnknown(propertyName); bool disposed; { @@ -1215,7 +1093,7 @@ void PropertySetMixinImpl::removeVetoableChangeListener( css::beans::UnknownPropertyException, css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) { - OSL_ASSERT(listener.is()); + assert(listener.is()); checkUnknown(propertyName); osl::MutexGuard g(m_impl->mutex); Impl::VetoListenerMap::iterator i(m_impl->vetoListeners.find(propertyName)); @@ -1295,8 +1173,7 @@ void PropertySetMixinImpl::setPropertyValues( props[i].Handle))) { throw css::beans::UnknownPropertyException( - (rtl::OUString("name ") + props[i].Name - + rtl::OUString(" does not match handle ") + ("name " + props[i].Name + " does not match handle " + rtl::OUString::number(props[i].Handle)), static_cast< css::beans::XPropertySet * >(this)); } commit 615a69e33fdc4e97acefbc017cd6ee6d33edfaf2 Author: Stephan Bergmann <[email protected]> Date: Sun Oct 20 18:24:57 2013 +0200 Clean-up std::bad_alloc handling ...post 0bc89aac4c64bb833e387657f680e194c26aef97 "cppumaker: Allow UNO interface functions to throw std::exception." Change-Id: I232a1b266a45d39856d44a2f4e012b5df10fa880 diff --git a/cppuhelper/source/propertysetmixin.cxx b/cppuhelper/source/propertysetmixin.cxx index 65ddfa7..b928369 100644 --- a/cppuhelper/source/propertysetmixin.cxx +++ b/cppuhelper/source/propertysetmixin.cxx @@ -76,8 +76,8 @@ #include "salhelper/simplereferenceobject.hxx" #include <algorithm> +#include <exception> #include <map> -#include <new> #include <set> #include <vector> @@ -320,7 +320,7 @@ public: explicit Info(Data * data): m_data(data) {} virtual css::uno::Sequence< css::beans::Property > SAL_CALL getProperties() - throw (css::uno::RuntimeException); + throw (css::uno::RuntimeException, std::exception); virtual css::beans::Property SAL_CALL getPropertyByName( rtl::OUString const & name) @@ -335,27 +335,21 @@ private: }; css::uno::Sequence< css::beans::Property > Info::getProperties() - throw (css::uno::RuntimeException) + throw (css::uno::RuntimeException, std::exception) { - try { - OSL_ASSERT(m_data->properties.size() <= SAL_MAX_INT32); - css::uno::Sequence< css::beans::Property > s( - static_cast< sal_Int32 >(m_data->properties.size())); - sal_Int32 n = 0; - for (Data::PropertyMap::iterator i(m_data->properties.begin()); - i != m_data->properties.end(); ++i) - { - if (i->second.present) { - s[n++] = i->second.property; - } + OSL_ASSERT(m_data->properties.size() <= SAL_MAX_INT32); + css::uno::Sequence< css::beans::Property > s( + static_cast< sal_Int32 >(m_data->properties.size())); + sal_Int32 n = 0; + for (Data::PropertyMap::iterator i(m_data->properties.begin()); + i != m_data->properties.end(); ++i) + { + if (i->second.present) { + s[n++] = i->second.property; } - s.realloc(n); - return s; - } catch (std::bad_alloc &) { - //TODO OutOfMemoryException: - throw css::uno::RuntimeException( - rtl::OUString(), static_cast< cppu::OWeakObject * >(this)); } + s.realloc(n); + return s; } css::beans::Property Info::getPropertyByName(rtl::OUString const & name) @@ -1116,14 +1110,10 @@ css::uno::Any PropertySetMixinImpl::queryInterface(css::uno::Type const & type) } css::uno::Reference< css::beans::XPropertySetInfo > -PropertySetMixinImpl::getPropertySetInfo() throw (css::uno::RuntimeException) { - try { - return new Info(m_impl); - } catch (std::bad_alloc &) { - //TODO OutOfMemoryException: - throw css::uno::RuntimeException( - rtl::OUString(), static_cast< css::beans::XPropertySet * >(this)); - } +PropertySetMixinImpl::getPropertySetInfo() + throw (css::uno::RuntimeException, std::exception) +{ + return new Info(m_impl); } void PropertySetMixinImpl::setPropertyValue( @@ -1131,33 +1121,21 @@ void PropertySetMixinImpl::setPropertyValue( throw ( css::beans::UnknownPropertyException, css::beans::PropertyVetoException, css::lang::IllegalArgumentException, css::lang::WrappedTargetException, - css::uno::RuntimeException) + css::uno::RuntimeException, std::exception) { - try { - m_impl->setProperty( - static_cast< css::beans::XPropertySet * >(this), propertyName, - value, false, false, 1); - } catch (std::bad_alloc &) { - //TODO OutOfMemoryException: - throw css::uno::RuntimeException( - rtl::OUString(), static_cast< css::beans::XPropertySet * >(this)); - } + m_impl->setProperty( + static_cast< css::beans::XPropertySet * >(this), propertyName, value, + false, false, 1); } css::uno::Any PropertySetMixinImpl::getPropertyValue( rtl::OUString const & propertyName) throw ( css::beans::UnknownPropertyException, css::lang::WrappedTargetException, - css::uno::RuntimeException) + css::uno::RuntimeException, std::exception) { - try { - return m_impl->getProperty( - static_cast< css::beans::XPropertySet * >(this), propertyName, 0); - } catch (std::bad_alloc &) { - //TODO OutOfMemoryException: - throw css::uno::RuntimeException( - rtl::OUString(), static_cast< css::beans::XPropertySet * >(this)); - } + return m_impl->getProperty( + static_cast< css::beans::XPropertySet * >(this), propertyName, 0); } void PropertySetMixinImpl::addPropertyChangeListener( @@ -1165,29 +1143,23 @@ void PropertySetMixinImpl::addPropertyChangeListener( css::uno::Reference< css::beans::XPropertyChangeListener > const & listener) throw ( css::beans::UnknownPropertyException, css::lang::WrappedTargetException, - css::uno::RuntimeException) + css::uno::RuntimeException, std::exception) { css::uno::Reference< css::beans::XPropertyChangeListener >( listener, css::uno::UNO_QUERY_THROW); // reject NULL listener checkUnknown(propertyName); - try { - bool disposed; - { - osl::MutexGuard g(m_impl->mutex); - disposed = m_impl->disposed; - if (!disposed) { - m_impl->boundListeners[propertyName].insert(listener); - } - } - if (disposed) { - listener->disposing( - css::lang::EventObject( - static_cast< css::beans::XPropertySet * >(this))); + bool disposed; + { + osl::MutexGuard g(m_impl->mutex); + disposed = m_impl->disposed; + if (!disposed) { + m_impl->boundListeners[propertyName].insert(listener); } - } catch (std::bad_alloc &) { - //TODO OutOfMemoryException: - throw css::uno::RuntimeException( - rtl::OUString(), static_cast< css::beans::XPropertySet * >(this)); + } + if (disposed) { + listener->disposing( + css::lang::EventObject( + static_cast< css::beans::XPropertySet * >(this))); } } @@ -1196,24 +1168,18 @@ void PropertySetMixinImpl::removePropertyChangeListener( css::uno::Reference< css::beans::XPropertyChangeListener > const & listener) throw ( css::beans::UnknownPropertyException, css::lang::WrappedTargetException, - css::uno::RuntimeException) + css::uno::RuntimeException, std::exception) { OSL_ASSERT(listener.is()); checkUnknown(propertyName); - try { - osl::MutexGuard g(m_impl->mutex); - Impl::BoundListenerMap::iterator i( - m_impl->boundListeners.find(propertyName)); - if (i != m_impl->boundListeners.end()) { - BoundListenerBag::iterator j(i->second.find(listener)); - if (j != i->second.end()) { - i->second.erase(j); - } + osl::MutexGuard g(m_impl->mutex); + Impl::BoundListenerMap::iterator i( + m_impl->boundListeners.find(propertyName)); + if (i != m_impl->boundListeners.end()) { + BoundListenerBag::iterator j(i->second.find(listener)); + if (j != i->second.end()) { + i->second.erase(j); } - } catch (std::bad_alloc &) { - //TODO OutOfMemoryException: - throw css::uno::RuntimeException( - rtl::OUString(), static_cast< css::beans::XPropertySet * >(this)); } } @@ -1222,29 +1188,23 @@ void PropertySetMixinImpl::addVetoableChangeListener( css::uno::Reference< css::beans::XVetoableChangeListener > const & listener) throw ( css::beans::UnknownPropertyException, css::lang::WrappedTargetException, - css::uno::RuntimeException) + css::uno::RuntimeException, std::exception) { css::uno::Reference< css::beans::XVetoableChangeListener >( listener, css::uno::UNO_QUERY_THROW); // reject NULL listener checkUnknown(propertyName); - try { - bool disposed; - { - osl::MutexGuard g(m_impl->mutex); - disposed = m_impl->disposed; - if (!disposed) { - m_impl->vetoListeners[propertyName].insert(listener); - } - } - if (disposed) { - listener->disposing( - css::lang::EventObject( - static_cast< css::beans::XPropertySet * >(this))); + bool disposed; + { + osl::MutexGuard g(m_impl->mutex); + disposed = m_impl->disposed; + if (!disposed) { + m_impl->vetoListeners[propertyName].insert(listener); } - } catch (std::bad_alloc &) { - //TODO OutOfMemoryException: - throw css::uno::RuntimeException( - rtl::OUString(), static_cast< css::beans::XPropertySet * >(this)); + } + if (disposed) { + listener->disposing( + css::lang::EventObject( + static_cast< css::beans::XPropertySet * >(this))); } } @@ -1253,24 +1213,17 @@ void PropertySetMixinImpl::removeVetoableChangeListener( css::uno::Reference< css::beans::XVetoableChangeListener > const & listener) throw ( css::beans::UnknownPropertyException, css::lang::WrappedTargetException, - css::uno::RuntimeException) + css::uno::RuntimeException, std::exception) { OSL_ASSERT(listener.is()); checkUnknown(propertyName); - try { - osl::MutexGuard g(m_impl->mutex); - Impl::VetoListenerMap::iterator i( - m_impl->vetoListeners.find(propertyName)); - if (i != m_impl->vetoListeners.end()) { - Impl::VetoListenerBag::iterator j(i->second.find(listener)); - if (j != i->second.end()) { - i->second.erase(j); - } + osl::MutexGuard g(m_impl->mutex); + Impl::VetoListenerMap::iterator i(m_impl->vetoListeners.find(propertyName)); + if (i != m_impl->vetoListeners.end()) { + Impl::VetoListenerBag::iterator j(i->second.find(listener)); + if (j != i->second.end()) { + i->second.erase(j); } - } catch (std::bad_alloc &) { - //TODO OutOfMemoryException: - throw css::uno::RuntimeException( - rtl::OUString(), static_cast< css::beans::XPropertySet * >(this)); } } @@ -1279,68 +1232,52 @@ void PropertySetMixinImpl::setFastPropertyValue( throw ( css::beans::UnknownPropertyException, css::beans::PropertyVetoException, css::lang::IllegalArgumentException, css::lang::WrappedTargetException, - css::uno::RuntimeException) + css::uno::RuntimeException, std::exception) { - try { - m_impl->setProperty( - static_cast< css::beans::XPropertySet * >(this), - m_impl->translateHandle( - static_cast< css::beans::XPropertySet * >(this), handle), - value, false, false, 1); - } catch (std::bad_alloc &) { - //TODO OutOfMemoryException: - throw css::uno::RuntimeException( - rtl::OUString(), static_cast< css::beans::XPropertySet * >(this)); - } + m_impl->setProperty( + static_cast< css::beans::XPropertySet * >(this), + m_impl->translateHandle( + static_cast< css::beans::XPropertySet * >(this), handle), + value, false, false, 1); } css::uno::Any PropertySetMixinImpl::getFastPropertyValue(sal_Int32 handle) throw ( css::beans::UnknownPropertyException, css::lang::WrappedTargetException, - css::uno::RuntimeException) + css::uno::RuntimeException, std::exception) { - try { - return m_impl->getProperty( - static_cast< css::beans::XPropertySet * >(this), - m_impl->translateHandle( - static_cast< css::beans::XPropertySet * >(this), handle), - 0); - } catch (std::bad_alloc &) { - //TODO OutOfMemoryException: - throw css::uno::RuntimeException( - rtl::OUString(), static_cast< css::beans::XPropertySet * >(this)); - } + return m_impl->getProperty( + static_cast< css::beans::XPropertySet * >(this), + m_impl->translateHandle( + static_cast< css::beans::XPropertySet * >(this), handle), + 0); } css::uno::Sequence< css::beans::PropertyValue > -PropertySetMixinImpl::getPropertyValues() throw (css::uno::RuntimeException) { - try { - css::uno::Sequence< css::beans::PropertyValue > s( - m_impl->handleMap.getLength()); - sal_Int32 n = 0; - for (sal_Int32 i = 0; i < m_impl->handleMap.getLength(); ++i) { - try { - s[n].Value = m_impl->getProperty( - static_cast< css::beans::XPropertySet * >(this), - m_impl->handleMap[i], &s[n].State); - } catch (css::beans::UnknownPropertyException &) { - continue; - } catch (css::lang::WrappedTargetException & e) { - throw css::lang::WrappedTargetRuntimeException( - e.Message, static_cast< css::beans::XPropertySet * >(this), - e.TargetException); - } - s[n].Name = m_impl->handleMap[i]; - s[n].Handle = i; - ++n; +PropertySetMixinImpl::getPropertyValues() + throw (css::uno::RuntimeException, std::exception) +{ + css::uno::Sequence< css::beans::PropertyValue > s( + m_impl->handleMap.getLength()); + sal_Int32 n = 0; + for (sal_Int32 i = 0; i < m_impl->handleMap.getLength(); ++i) { + try { + s[n].Value = m_impl->getProperty( + static_cast< css::beans::XPropertySet * >(this), + m_impl->handleMap[i], &s[n].State); + } catch (css::beans::UnknownPropertyException &) { + continue; + } catch (css::lang::WrappedTargetException & e) { + throw css::lang::WrappedTargetRuntimeException( + e.Message, static_cast< css::beans::XPropertySet * >(this), + e.TargetException); } - s.realloc(n); - return s; - } catch (std::bad_alloc &) { - //TODO OutOfMemoryException: - throw css::uno::RuntimeException( - rtl::OUString(), static_cast< css::beans::XPropertySet * >(this)); + s[n].Name = m_impl->handleMap[i]; + s[n].Handle = i; + ++n; } + s.realloc(n); + return s; } void PropertySetMixinImpl::setPropertyValues( @@ -1348,33 +1285,26 @@ void PropertySetMixinImpl::setPropertyValues( throw ( css::beans::UnknownPropertyException, css::beans::PropertyVetoException, css::lang::IllegalArgumentException, css::lang::WrappedTargetException, - css::uno::RuntimeException) + css::uno::RuntimeException, std::exception) { - try { - for (sal_Int32 i = 0; i < props.getLength(); ++i) { - if (props[i].Handle != -1 - && (props[i].Name - != m_impl->translateHandle( - static_cast< css::beans::XPropertySet * >(this), - props[i].Handle))) - { - throw css::beans::UnknownPropertyException( - (rtl::OUString("name ") - + props[i].Name - + rtl::OUString(" does not match handle ") - + rtl::OUString::number(props[i].Handle)), - static_cast< css::beans::XPropertySet * >(this)); - } - m_impl->setProperty( - static_cast< css::beans::XPropertySet * >(this), props[i].Name, - props[i].Value, - props[i].State == css::beans::PropertyState_AMBIGUOUS_VALUE, - props[i].State == css::beans::PropertyState_DEFAULT_VALUE, 0); + for (sal_Int32 i = 0; i < props.getLength(); ++i) { + if (props[i].Handle != -1 + && (props[i].Name + != m_impl->translateHandle( + static_cast< css::beans::XPropertySet * >(this), + props[i].Handle))) + { + throw css::beans::UnknownPropertyException( + (rtl::OUString("name ") + props[i].Name + + rtl::OUString(" does not match handle ") + + rtl::OUString::number(props[i].Handle)), + static_cast< css::beans::XPropertySet * >(this)); } - } catch (std::bad_alloc &) { - //TODO OutOfMemoryException: - throw css::uno::RuntimeException( - rtl::OUString(), static_cast< css::beans::XPropertySet * >(this)); + m_impl->setProperty( + static_cast< css::beans::XPropertySet * >(this), props[i].Name, + props[i].Value, + props[i].State == css::beans::PropertyState_AMBIGUOUS_VALUE, + props[i].State == css::beans::PropertyState_DEFAULT_VALUE, 0); } } diff --git a/include/cppuhelper/propertysetmixin.hxx b/include/cppuhelper/propertysetmixin.hxx index 83f8531..bb01f28 100644 --- a/include/cppuhelper/propertysetmixin.hxx +++ b/include/cppuhelper/propertysetmixin.hxx @@ -21,6 +21,9 @@ #define INCLUDED_CPPUHELPER_PROPERTYSETMIXIN_HXX #include "sal/config.h" + +#include <exception> + #include "com/sun/star/beans/PropertyVetoException.hpp" #include "com/sun/star/beans/UnknownPropertyException.hpp" #include "com/sun/star/beans/XFastPropertySet.hpp" @@ -266,7 +269,8 @@ protected: // @see com::sun::star::beans::XPropertySet::getPropertySetInfo virtual com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo > - SAL_CALL getPropertySetInfo() throw (com::sun::star::uno::RuntimeException); + SAL_CALL getPropertySetInfo() + throw (com::sun::star::uno::RuntimeException, std::exception); // @see com::sun::star::beans::XPropertySet::setPropertyValue virtual void SAL_CALL setPropertyValue( @@ -277,7 +281,7 @@ protected: com::sun::star::beans::PropertyVetoException, com::sun::star::lang::IllegalArgumentException, com::sun::star::lang::WrappedTargetException, - com::sun::star::uno::RuntimeException); + com::sun::star::uno::RuntimeException, std::exception); // @see com::sun::star::beans::XPropertySet::getPropertyValue virtual com::sun::star::uno::Any SAL_CALL getPropertyValue( @@ -285,7 +289,7 @@ protected: throw ( com::sun::star::beans::UnknownPropertyException, com::sun::star::lang::WrappedTargetException, - com::sun::star::uno::RuntimeException); + com::sun::star::uno::RuntimeException, std::exception); /** @short Adds a @@ -303,7 +307,7 @@ protected: throw ( com::sun::star::beans::UnknownPropertyException, com::sun::star::lang::WrappedTargetException, - com::sun::star::uno::RuntimeException); + com::sun::star::uno::RuntimeException, std::exception); // @see com::sun::star::beans::XPropertySet::removePropertyChangeListener virtual void SAL_CALL removePropertyChangeListener( @@ -313,7 +317,7 @@ protected: throw ( com::sun::star::beans::UnknownPropertyException, com::sun::star::lang::WrappedTargetException, - com::sun::star::uno::RuntimeException); + com::sun::star::uno::RuntimeException, std::exception); /** @short Adds a @@ -331,7 +335,7 @@ protected: throw ( com::sun::star::beans::UnknownPropertyException, com::sun::star::lang::WrappedTargetException, - com::sun::star::uno::RuntimeException); + com::sun::star::uno::RuntimeException, std::exception); // @see com::sun::star::beans::XPropertySet::removeVetoableChangeListener virtual void SAL_CALL removeVetoableChangeListener( @@ -341,7 +345,7 @@ protected: throw ( com::sun::star::beans::UnknownPropertyException, com::sun::star::lang::WrappedTargetException, - com::sun::star::uno::RuntimeException); + com::sun::star::uno::RuntimeException, std::exception); // @see com::sun::star::beans::XFastPropertySet::setFastPropertyValue virtual void SAL_CALL setFastPropertyValue( @@ -351,7 +355,7 @@ protected: com::sun::star::beans::PropertyVetoException, com::sun::star::lang::IllegalArgumentException, com::sun::star::lang::WrappedTargetException, - com::sun::star::uno::RuntimeException); + com::sun::star::uno::RuntimeException, std::exception); // @see com::sun::star::beans::XFastPropertySet::getFastPropertyValue virtual com::sun::star::uno::Any SAL_CALL getFastPropertyValue( @@ -359,12 +363,13 @@ protected: throw ( com::sun::star::beans::UnknownPropertyException, com::sun::star::lang::WrappedTargetException, - com::sun::star::uno::RuntimeException); + com::sun::star::uno::RuntimeException, std::exception); // @see com::sun::star::beans::XPropertyAccess::getPropertyValues virtual com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > - SAL_CALL getPropertyValues() throw (com::sun::star::uno::RuntimeException); + SAL_CALL getPropertyValues() + throw (com::sun::star::uno::RuntimeException, std::exception); // @see com::sun::star::beans::XPropertyAccess::setPropertyValues virtual void SAL_CALL setPropertyValues( @@ -375,7 +380,7 @@ protected: com::sun::star::beans::PropertyVetoException, com::sun::star::lang::IllegalArgumentException, com::sun::star::lang::WrappedTargetException, - com::sun::star::uno::RuntimeException); + com::sun::star::uno::RuntimeException, std::exception); private: PropertySetMixinImpl( const PropertySetMixinImpl&); // not defined _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
