Files
libreoffice/cppuhelper/source/propshlp.cxx

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

1185 lines
38 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
2000-09-18 14:29:57 +00:00
#include <osl/diagnose.h>
#include <cppuhelper/implbase.hxx>
#include <cppuhelper/queryinterface.hxx>
#include <cppuhelper/propshlp.hxx>
#include <cppuhelper/exc_hlp.hxx>
#include <com/sun/star/beans/PropertyAttribute.hpp>
#include <com/sun/star/lang/DisposedException.hpp>
#include <memory>
#include <sal/log.hxx>
2000-09-18 14:29:57 +00:00
using namespace osl;
using namespace com::sun::star::uno;
using namespace com::sun::star::beans;
using namespace com::sun::star::lang;
using namespace cppu;
namespace cppu {
IPropertyArrayHelper::~IPropertyArrayHelper()
{
}
static const css::uno::Type & getPropertyTypeIdentifier( )
2000-09-18 14:29:57 +00:00
{
return cppu::UnoType<XPropertyChangeListener>::get();
2000-09-18 14:29:57 +00:00
}
static const css::uno::Type & getPropertiesTypeIdentifier()
2000-09-18 14:29:57 +00:00
{
return cppu::UnoType<XPropertiesChangeListener>::get();
2000-09-18 14:29:57 +00:00
}
static const css::uno::Type & getVetoableTypeIdentifier()
2000-09-18 14:29:57 +00:00
{
return cppu::UnoType<XVetoableChangeListener>::get();
2000-09-18 14:29:57 +00:00
}
extern "C" {
static int compare_OUString_Property_Impl( const void *arg1, const void *arg2 )
SAL_THROW_EXTERN_C()
2000-09-18 14:29:57 +00:00
{
return static_cast<OUString const *>(arg1)->compareTo( static_cast<Property const *>(arg2)->Name );
2000-09-18 14:29:57 +00:00
}
}
2000-09-18 14:29:57 +00:00
/**
* The class which implements the PropertySetInfo interface.
*/
Extend loplugin:external to warn about classes ...following up on 314f15bff08b76bf96acf99141776ef64d2f1355 "Extend loplugin:external to warn about enums". Cases where free functions were moved into an unnamed namespace along with a class, to not break ADL, are in: filter/source/svg/svgexport.cxx sc/source/filter/excel/xelink.cxx sc/source/filter/excel/xilink.cxx svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx All other free functions mentioning moved classes appear to be harmless and not give rise to (silent, even) ADL breakage. (One remaining TODO in compilerplugins/clang/external.cxx is that derived classes are not covered by computeAffectedTypes, even though they could also be affected by ADL-breakage--- but don't seem to be in any acutal case across the code base.) For friend declarations using elaborate type specifiers, like class C1 {}; class C2 { friend class C1; }; * If C2 (but not C1) is moved into an unnamed namespace, the friend declaration must be changed to not use an elaborate type specifier (i.e., "friend C1;"; see C++17 [namespace.memdef]/3: "If the name in a friend declaration is neither qualified nor a template-id and the declaration is a function or an elaborated-type-specifier, the lookup to determine whether the entity has been previously declared shall not consider any scopes outside the innermost enclosing namespace.") * If C1 (but not C2) is moved into an unnamed namespace, the friend declaration must be changed too, see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71882> "elaborated-type-specifier friend not looked up in unnamed namespace". Apart from that, to keep changes simple and mostly mechanical (which should help avoid regressions), out-of-line definitions of class members have been left in the enclosing (named) namespace. But explicit specializations of class templates had to be moved into the unnamed namespace to appease <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92598> "explicit specialization of template from unnamed namespace using unqualified-id in enclosing namespace". Also, accompanying declarations (of e.g. typedefs or static variables) that could arguably be moved into the unnamed namespace too have been left alone. And in some cases, mention of affected types in blacklists in other loplugins needed to be adapted. And sc/qa/unit/mark_test.cxx uses a hack of including other .cxx, one of which is sc/source/core/data/segmenttree.cxx where e.g. ScFlatUInt16SegmentsImpl is not moved into an unnamed namespace (because it is declared in sc/inc/segmenttree.hxx), but its base ScFlatSegmentsImpl is. GCC warns about such combinations with enabled-by-default -Wsubobject-linkage, but "The compiler doesn’t give this warning for types defined in the main .C file, as those are unlikely to have multiple definitions." (<https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html>) The warned-about classes also don't have multiple definitions in the given test, so disable the warning when including the .cxx. Change-Id: Ib694094c0d8168be68f8fe90dfd0acbb66a3f1e4 Reviewed-on: https://gerrit.libreoffice.org/83239 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-19 16:32:49 +01:00
namespace {
2000-09-18 14:29:57 +00:00
class OPropertySetHelperInfo_Impl
: public WeakImplHelper< css::beans::XPropertySetInfo >
2000-09-18 14:29:57 +00:00
{
Sequence < Property > aInfos;
public:
explicit OPropertySetHelperInfo_Impl( IPropertyArrayHelper & rHelper_ );
2000-09-18 14:29:57 +00:00
// XPropertySetInfo-methods
virtual Sequence< Property > SAL_CALL getProperties() override;
virtual Property SAL_CALL getPropertyByName(const OUString& PropertyName) override;
virtual sal_Bool SAL_CALL hasPropertyByName(const OUString& PropertyName) override;
2000-09-18 14:29:57 +00:00
};
Extend loplugin:external to warn about classes ...following up on 314f15bff08b76bf96acf99141776ef64d2f1355 "Extend loplugin:external to warn about enums". Cases where free functions were moved into an unnamed namespace along with a class, to not break ADL, are in: filter/source/svg/svgexport.cxx sc/source/filter/excel/xelink.cxx sc/source/filter/excel/xilink.cxx svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx All other free functions mentioning moved classes appear to be harmless and not give rise to (silent, even) ADL breakage. (One remaining TODO in compilerplugins/clang/external.cxx is that derived classes are not covered by computeAffectedTypes, even though they could also be affected by ADL-breakage--- but don't seem to be in any acutal case across the code base.) For friend declarations using elaborate type specifiers, like class C1 {}; class C2 { friend class C1; }; * If C2 (but not C1) is moved into an unnamed namespace, the friend declaration must be changed to not use an elaborate type specifier (i.e., "friend C1;"; see C++17 [namespace.memdef]/3: "If the name in a friend declaration is neither qualified nor a template-id and the declaration is a function or an elaborated-type-specifier, the lookup to determine whether the entity has been previously declared shall not consider any scopes outside the innermost enclosing namespace.") * If C1 (but not C2) is moved into an unnamed namespace, the friend declaration must be changed too, see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71882> "elaborated-type-specifier friend not looked up in unnamed namespace". Apart from that, to keep changes simple and mostly mechanical (which should help avoid regressions), out-of-line definitions of class members have been left in the enclosing (named) namespace. But explicit specializations of class templates had to be moved into the unnamed namespace to appease <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92598> "explicit specialization of template from unnamed namespace using unqualified-id in enclosing namespace". Also, accompanying declarations (of e.g. typedefs or static variables) that could arguably be moved into the unnamed namespace too have been left alone. And in some cases, mention of affected types in blacklists in other loplugins needed to be adapted. And sc/qa/unit/mark_test.cxx uses a hack of including other .cxx, one of which is sc/source/core/data/segmenttree.cxx where e.g. ScFlatUInt16SegmentsImpl is not moved into an unnamed namespace (because it is declared in sc/inc/segmenttree.hxx), but its base ScFlatSegmentsImpl is. GCC warns about such combinations with enabled-by-default -Wsubobject-linkage, but "The compiler doesn’t give this warning for types defined in the main .C file, as those are unlikely to have multiple definitions." (<https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html>) The warned-about classes also don't have multiple definitions in the given test, so disable the warning when including the .cxx. Change-Id: Ib694094c0d8168be68f8fe90dfd0acbb66a3f1e4 Reviewed-on: https://gerrit.libreoffice.org/83239 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-19 16:32:49 +01:00
}
2000-09-18 14:29:57 +00:00
/**
* Create an object that implements XPropertySetInfo IPropertyArrayHelper.
*/
OPropertySetHelperInfo_Impl::OPropertySetHelperInfo_Impl(
IPropertyArrayHelper & rHelper_ )
:aInfos( rHelper_.getProperties() )
2000-09-18 14:29:57 +00:00
{
}
/**
* Return the sequence of properties, which are provided through the constructor.
2000-09-18 14:29:57 +00:00
*/
Sequence< Property > OPropertySetHelperInfo_Impl::getProperties()
2000-09-18 14:29:57 +00:00
{
return aInfos;
}
/**
* Return the sequence of properties, which are provided through the constructor.
2000-09-18 14:29:57 +00:00
*/
Property OPropertySetHelperInfo_Impl::getPropertyByName( const OUString & PropertyName )
2000-09-18 14:29:57 +00:00
{
Property * pR;
pR = static_cast<Property *>(bsearch( &PropertyName, aInfos.getConstArray(), aInfos.getLength(),
2000-09-18 14:29:57 +00:00
sizeof( Property ),
compare_OUString_Property_Impl ));
2000-09-18 14:29:57 +00:00
if( !pR ) {
throw UnknownPropertyException(PropertyName);
2000-09-18 14:29:57 +00:00
}
return *pR;
}
/**
* Return the sequence of properties, which are provided through the constructor.
2000-09-18 14:29:57 +00:00
*/
sal_Bool OPropertySetHelperInfo_Impl::hasPropertyByName( const OUString & PropertyName )
2000-09-18 14:29:57 +00:00
{
Property * pR;
pR = static_cast<Property *>(bsearch( &PropertyName, aInfos.getConstArray(), aInfos.getLength(),
2000-09-18 14:29:57 +00:00
sizeof( Property ),
compare_OUString_Property_Impl ));
return pR != nullptr;
2000-09-18 14:29:57 +00:00
}
class OPropertySetHelper::Impl {
public:
Impl( bool i_bIgnoreRuntimeExceptionsWhileFiring,
IEventNotificationHook *i_pFireEvents
)
:m_bIgnoreRuntimeExceptionsWhileFiring( i_bIgnoreRuntimeExceptionsWhileFiring )
,m_bFireEvents(true)
,m_pFireEvents( i_pFireEvents )
{
}
bool m_bIgnoreRuntimeExceptionsWhileFiring;
bool m_bFireEvents;
class IEventNotificationHook * const m_pFireEvents;
std::vector< sal_Int32 > m_handles;
std::vector< Any > m_newValues;
std::vector< Any > m_oldValues;
};
2000-09-18 14:29:57 +00:00
OPropertySetHelper::OPropertySetHelper(
OBroadcastHelper & rBHelper_ )
: rBHelper( rBHelper_ ),
aBoundLC( rBHelper_.rMutex ),
aVetoableLC( rBHelper_.rMutex ),
m_pReserved( new Impl(false, nullptr) )
{
}
OPropertySetHelper::OPropertySetHelper(
OBroadcastHelper & rBHelper_, bool bIgnoreRuntimeExceptionsWhileFiring )
: rBHelper( rBHelper_ ),
aBoundLC( rBHelper_.rMutex ),
aVetoableLC( rBHelper_.rMutex ),
m_pReserved( new Impl( bIgnoreRuntimeExceptionsWhileFiring, nullptr ) )
{
}
OPropertySetHelper::OPropertySetHelper(
OBroadcastHelper & rBHelper_, IEventNotificationHook * i_pFireEvents,
bool bIgnoreRuntimeExceptionsWhileFiring)
: rBHelper( rBHelper_ ),
aBoundLC( rBHelper_.rMutex ),
aVetoableLC( rBHelper_.rMutex ),
m_pReserved(
new Impl( bIgnoreRuntimeExceptionsWhileFiring, i_pFireEvents) )
2000-09-18 14:29:57 +00:00
{
}
OPropertySetHelper2::OPropertySetHelper2(
OBroadcastHelper & irBHelper,
IEventNotificationHook *i_pFireEvents,
bool bIgnoreRuntimeExceptionsWhileFiring)
:OPropertySetHelper( irBHelper, i_pFireEvents, bIgnoreRuntimeExceptionsWhileFiring )
{
}
2000-09-18 14:29:57 +00:00
/**
* You must call disposing before.
*/
OPropertySetHelper::~OPropertySetHelper()
2000-09-18 14:29:57 +00:00
{
delete m_pReserved;
2000-09-18 14:29:57 +00:00
}
OPropertySetHelper2::~OPropertySetHelper2()
{
}
2000-09-18 14:29:57 +00:00
// XInterface
Any OPropertySetHelper::queryInterface( const css::uno::Type & rType )
2000-09-18 14:29:57 +00:00
{
return ::cppu::queryInterface(
rType,
static_cast< XPropertySet * >( this ),
static_cast< XMultiPropertySet * >( this ),
static_cast< XFastPropertySet * >( this ) );
2000-09-18 14:29:57 +00:00
}
Any OPropertySetHelper2::queryInterface( const css::uno::Type & rType )
{
Any cnd(cppu::queryInterface(rType, static_cast< XPropertySetOption * >(this)));
if ( cnd.hasValue() )
return cnd;
return OPropertySetHelper::queryInterface(rType);
}
/**
* called from the derivee's XTypeProvider::getTypes implementation
*/
css::uno::Sequence< css::uno::Type > OPropertySetHelper::getTypes()
{
return {
UnoType<css::beans::XPropertySet>::get(),
UnoType<css::beans::XMultiPropertySet>::get(),
UnoType<css::beans::XFastPropertySet>::get()};
}
2000-09-18 14:29:57 +00:00
// ComponentHelper
void OPropertySetHelper::disposing()
2000-09-18 14:29:57 +00:00
{
// Create an event with this as sender
Reference < XPropertySet > rSource = this;
2000-09-18 14:29:57 +00:00
EventObject aEvt;
aEvt.Source = rSource;
// inform all listeners to release this object
// The listener containers are automatically cleared
2000-09-18 14:29:57 +00:00
aBoundLC.disposeAndClear( aEvt );
aVetoableLC.disposeAndClear( aEvt );
}
Reference < XPropertySetInfo > OPropertySetHelper::createPropertySetInfo(
IPropertyArrayHelper & rProperties )
2000-09-18 14:29:57 +00:00
{
return new OPropertySetHelperInfo_Impl(rProperties);
2000-09-18 14:29:57 +00:00
}
// XPropertySet
void OPropertySetHelper::setPropertyValue(
const OUString& rPropertyName, const Any& rValue )
2000-09-18 14:29:57 +00:00
{
// get the map table
IPropertyArrayHelper & rPH = getInfoHelper();
// map the name to the handle
sal_Int32 nHandle = rPH.getHandleByName( rPropertyName );
// call the method of the XFastPropertySet interface
setFastPropertyValue( nHandle, rValue );
}
// XPropertySet
Any OPropertySetHelper::getPropertyValue(
const OUString& rPropertyName )
2000-09-18 14:29:57 +00:00
{
// get the map table
IPropertyArrayHelper & rPH = getInfoHelper();
// map the name to the handle
sal_Int32 nHandle = rPH.getHandleByName( rPropertyName );
// call the method of the XFastPropertySet interface
return getFastPropertyValue( nHandle );
}
// XPropertySet
void OPropertySetHelper::addPropertyChangeListener(
const OUString& rPropertyName,
const Reference < XPropertyChangeListener > & rxListener )
2000-09-18 14:29:57 +00:00
{
MutexGuard aGuard( rBHelper.rMutex );
2001-03-12 12:39:32 +00:00
OSL_ENSURE( !rBHelper.bInDispose, "do not addPropertyChangeListener in the dispose call" );
OSL_ENSURE( !rBHelper.bDisposed, "object is disposed" );
if( rBHelper.bInDispose || rBHelper.bDisposed )
return;
2000-09-18 14:29:57 +00:00
// only add listeners if you are not disposed
// a listener with no name means all properties
if( !rPropertyName.isEmpty() )
{
// get the map table
IPropertyArrayHelper & rPH = getInfoHelper();
// map the name to the handle
sal_Int32 nHandle = rPH.getHandleByName( rPropertyName );
if( nHandle == -1 ) {
// property not known throw exception
throw UnknownPropertyException(rPropertyName);
}
2000-09-18 14:29:57 +00:00
sal_Int16 nAttributes;
rPH.fillPropertyMembersByHandle( nullptr, &nAttributes, nHandle );
if( !(nAttributes & css::beans::PropertyAttribute::BOUND) )
{
OSL_FAIL( "add listener to an unbound property" );
// silent ignore this
return;
2000-09-18 14:29:57 +00:00
}
// add the change listener to the helper container
aBoundLC.addInterface( nHandle, rxListener );
2000-09-18 14:29:57 +00:00
}
else
// add the change listener to the helper container
rBHelper.aLC.addInterface(
getPropertyTypeIdentifier( ),
rxListener
);
2000-09-18 14:29:57 +00:00
}
// XPropertySet
void OPropertySetHelper::removePropertyChangeListener(
const OUString& rPropertyName,
const Reference < XPropertyChangeListener >& rxListener )
2000-09-18 14:29:57 +00:00
{
MutexGuard aGuard( rBHelper.rMutex );
2001-03-12 12:39:32 +00:00
OSL_ENSURE( !rBHelper.bDisposed, "object is disposed" );
// all listeners are automatically released in a dispose call
if( rBHelper.bInDispose || rBHelper.bDisposed )
return;
if( !rPropertyName.isEmpty() )
2000-09-18 14:29:57 +00:00
{
// get the map table
IPropertyArrayHelper & rPH = getInfoHelper();
// map the name to the handle
sal_Int32 nHandle = rPH.getHandleByName( rPropertyName );
if( nHandle == -1 )
// property not known throw exception
throw UnknownPropertyException(rPropertyName);
aBoundLC.removeInterface( nHandle, rxListener );
}
else {
// remove the change listener to the helper container
rBHelper.aLC.removeInterface(
getPropertyTypeIdentifier( ),
rxListener
);
2000-09-18 14:29:57 +00:00
}
}
// XPropertySet
void OPropertySetHelper::addVetoableChangeListener(
2000-09-18 14:29:57 +00:00
const OUString& rPropertyName,
const Reference< XVetoableChangeListener > & rxListener )
2000-09-18 14:29:57 +00:00
{
MutexGuard aGuard( rBHelper.rMutex );
2001-03-12 12:39:32 +00:00
OSL_ENSURE( !rBHelper.bInDispose, "do not addVetoableChangeListener in the dispose call" );
OSL_ENSURE( !rBHelper.bDisposed, "object is disposed" );
if( rBHelper.bInDispose || rBHelper.bDisposed )
return;
// only add listeners if you are not disposed
// a listener with no name means all properties
if( !rPropertyName.isEmpty() )
2000-09-18 14:29:57 +00:00
{
// get the map table
IPropertyArrayHelper & rPH = getInfoHelper();
// map the name to the handle
sal_Int32 nHandle = rPH.getHandleByName( rPropertyName );
if( nHandle == -1 ) {
// property not known throw exception
throw UnknownPropertyException(rPropertyName);
}
2000-09-18 14:29:57 +00:00
sal_Int16 nAttributes;
rPH.fillPropertyMembersByHandle( nullptr, &nAttributes, nHandle );
if( !(nAttributes & PropertyAttribute::CONSTRAINED) )
{
OSL_FAIL( "addVetoableChangeListener, and property is not constrained" );
// silent ignore this
return;
2000-09-18 14:29:57 +00:00
}
// add the vetoable listener to the helper container
aVetoableLC.addInterface( nHandle, rxListener );
2000-09-18 14:29:57 +00:00
}
else
// add the vetoable listener to the helper container
rBHelper.aLC.addInterface(
getVetoableTypeIdentifier( ),
rxListener
);
2000-09-18 14:29:57 +00:00
}
// XPropertySet
void OPropertySetHelper::removeVetoableChangeListener(
2000-09-18 14:29:57 +00:00
const OUString& rPropertyName,
const Reference < XVetoableChangeListener > & rxListener )
2000-09-18 14:29:57 +00:00
{
MutexGuard aGuard( rBHelper.rMutex );
2001-03-12 12:39:32 +00:00
OSL_ENSURE( !rBHelper.bDisposed, "object is disposed" );
// all listeners are automatically released in a dispose call
if( rBHelper.bInDispose || rBHelper.bDisposed )
return;
if( !rPropertyName.isEmpty() )
2000-09-18 14:29:57 +00:00
{
// get the map table
IPropertyArrayHelper & rPH = getInfoHelper();
// map the name to the handle
sal_Int32 nHandle = rPH.getHandleByName( rPropertyName );
if( nHandle == -1 ) {
// property not known throw exception
throw UnknownPropertyException(rPropertyName);
2000-09-18 14:29:57 +00:00
}
// remove the vetoable listener to the helper container
aVetoableLC.removeInterface( nHandle, rxListener );
2000-09-18 14:29:57 +00:00
}
else
// add the vetoable listener to the helper container
rBHelper.aLC.removeInterface(
getVetoableTypeIdentifier( ),
rxListener
);
2000-09-18 14:29:57 +00:00
}
void OPropertySetHelper::setDependentFastPropertyValue( sal_Int32 i_handle, const css::uno::Any& i_value )
{
//OSL_PRECOND( rBHelper.rMutex.isAcquired(), "OPropertySetHelper::setDependentFastPropertyValue: to be called with a locked mutex only!" );
// there is no such thing as Mutex.isAcquired, sadly ...
sal_Int16 nAttributes(0);
IPropertyArrayHelper& rInfo = getInfoHelper();
if ( !rInfo.fillPropertyMembersByHandle( nullptr, &nAttributes, i_handle ) )
// unknown property
throw UnknownPropertyException(OUString::number(i_handle));
// no need to check for READONLY-ness of the property. The method is intended to be called internally, which
// implies it might be invoked for properties which are read-only to the instance's clients, but well allowed
// to change their value.
Any aConverted, aOld;
bool bChanged = convertFastPropertyValue( aConverted, aOld, i_handle, i_value );
if ( !bChanged )
return;
// don't fire vetoable events. This method is called with our mutex locked, so calling into listeners would not be
// a good idea. The caller is responsible for not invoking this for constrained properties.
OSL_ENSURE( ( nAttributes & PropertyAttribute::CONSTRAINED ) == 0,
"OPropertySetHelper::setDependentFastPropertyValue: not to be used for constrained properties!" );
// actually set the new value
try
{
setFastPropertyValue_NoBroadcast( i_handle, aConverted );
}
catch (const UnknownPropertyException& ) { throw; /* allowed to leave */ }
catch (const PropertyVetoException& ) { throw; /* allowed to leave */ }
catch (const IllegalArgumentException& ) { throw; /* allowed to leave */ }
catch (const WrappedTargetException& ) { throw; /* allowed to leave */ }
catch (const RuntimeException& ) { throw; /* allowed to leave */ }
catch (const Exception& )
{
// not allowed to leave this method
WrappedTargetException aWrapped;
aWrapped.TargetException = ::cppu::getCaughtException();
aWrapped.Context = static_cast< XPropertySet* >( this );
throw aWrapped;
}
// remember the handle/values, for the events to be fired later
m_pReserved->m_handles.push_back( i_handle );
m_pReserved->m_newValues.push_back( aConverted ); // TODO: setFastPropertyValue notifies the unconverted value here ...?
m_pReserved->m_oldValues.push_back( aOld );
}
2000-09-18 14:29:57 +00:00
// XFastPropertySet
void OPropertySetHelper::setFastPropertyValue( sal_Int32 nHandle, const Any& rValue )
{
2001-03-12 12:39:32 +00:00
OSL_ENSURE( !rBHelper.bInDispose, "do not setFastPropertyValue in the dispose call" );
OSL_ENSURE( !rBHelper.bDisposed, "object is disposed" );
2000-09-18 14:29:57 +00:00
IPropertyArrayHelper & rInfo = getInfoHelper();
sal_Int16 nAttributes;
if( !rInfo.fillPropertyMembersByHandle( nullptr, &nAttributes, nHandle ) ) {
2000-09-18 14:29:57 +00:00
// unknown property
throw UnknownPropertyException(OUString::number(nHandle));
2000-09-18 14:29:57 +00:00
}
if( nAttributes & PropertyAttribute::READONLY )
throw PropertyVetoException();
Any aConvertedVal;
Any aOldVal;
// Will the property change?
bool bChanged;
2000-09-18 14:29:57 +00:00
{
MutexGuard aGuard( rBHelper.rMutex );
bChanged = convertFastPropertyValue( aConvertedVal, aOldVal, nHandle, rValue );
// release guard to fire events
}
if( !bChanged )
return;
// Is it a constrained property?
if( nAttributes & PropertyAttribute::CONSTRAINED )
{
// In aValue is the converted rValue
// fire a constrained event
// second parameter NULL means constrained
fire( &nHandle, &rValue, &aOldVal, 1, true );
}
2000-09-18 14:29:57 +00:00
{
MutexGuard aGuard( rBHelper.rMutex );
try
2000-09-18 14:29:57 +00:00
{
// set the property to the new value
setFastPropertyValue_NoBroadcast( nHandle, aConvertedVal );
2000-09-18 14:29:57 +00:00
}
catch (const css::beans::UnknownPropertyException& ) { throw; /* allowed to leave */ }
catch (const css::beans::PropertyVetoException& ) { throw; /* allowed to leave */ }
catch (const css::lang::IllegalArgumentException& ) { throw; /* allowed to leave */ }
catch (const css::lang::WrappedTargetException& ) { throw; /* allowed to leave */ }
catch (const css::uno::RuntimeException& ) { throw; /* allowed to leave */ }
catch (const css::uno::Exception& e )
2000-09-18 14:29:57 +00:00
{
// not allowed to leave this method
css::lang::WrappedTargetException aWrap;
aWrap.Context = static_cast< css::beans::XPropertySet* >( this );
aWrap.TargetException <<= e;
throw aWrap;
2000-09-18 14:29:57 +00:00
}
// release guard to fire events
2000-09-18 14:29:57 +00:00
}
// file a change event, if the value changed
impl_fireAll( &nHandle, &rValue, &aOldVal, 1 );
2000-09-18 14:29:57 +00:00
}
// XFastPropertySet
Any OPropertySetHelper::getFastPropertyValue( sal_Int32 nHandle )
{
IPropertyArrayHelper & rInfo = getInfoHelper();
if( !rInfo.fillPropertyMembersByHandle( nullptr, nullptr, nHandle ) )
2000-09-18 14:29:57 +00:00
// unknown property
throw UnknownPropertyException(OUString::number(nHandle));
2000-09-18 14:29:57 +00:00
Any aRet;
MutexGuard aGuard( rBHelper.rMutex );
getFastPropertyValue( aRet, nHandle );
return aRet;
}
void OPropertySetHelper::impl_fireAll( sal_Int32* i_handles, const Any* i_newValues, const Any* i_oldValues, sal_Int32 i_count )
{
ClearableMutexGuard aGuard( rBHelper.rMutex );
if ( m_pReserved->m_handles.empty() )
{
aGuard.clear();
fire( i_handles, i_newValues, i_oldValues, i_count, false );
return;
}
const size_t additionalEvents = m_pReserved->m_handles.size();
OSL_ENSURE( additionalEvents == m_pReserved->m_newValues.size()
&& additionalEvents == m_pReserved->m_oldValues.size(),
"OPropertySetHelper::impl_fireAll: inconsistency!" );
std::vector< sal_Int32 > allHandles( additionalEvents + i_count );
std::copy( m_pReserved->m_handles.begin(), m_pReserved->m_handles.end(), allHandles.begin() );
std::copy( i_handles, i_handles + i_count, allHandles.begin() + additionalEvents );
std::vector< Any > allNewValues( additionalEvents + i_count );
std::copy( m_pReserved->m_newValues.begin(), m_pReserved->m_newValues.end(), allNewValues.begin() );
std::copy( i_newValues, i_newValues + i_count, allNewValues.begin() + additionalEvents );
std::vector< Any > allOldValues( additionalEvents + i_count );
std::copy( m_pReserved->m_oldValues.begin(), m_pReserved->m_oldValues.end(), allOldValues.begin() );
std::copy( i_oldValues, i_oldValues + i_count, allOldValues.begin() + additionalEvents );
m_pReserved->m_handles.clear();
m_pReserved->m_newValues.clear();
m_pReserved->m_oldValues.clear();
aGuard.clear();
fire( allHandles.data(), allNewValues.data(), allOldValues.data(), additionalEvents + i_count, false );
}
2000-09-18 14:29:57 +00:00
void OPropertySetHelper::fire
(
sal_Int32 * pnHandles,
const Any * pNewValues,
const Any * pOldValues,
sal_Int32 nHandles, // This is the Count of the array
2000-09-18 14:29:57 +00:00
sal_Bool bVetoable
)
{
if (! m_pReserved->m_bFireEvents)
return;
if (m_pReserved->m_pFireEvents) {
m_pReserved->m_pFireEvents->fireEvents(
pnHandles, nHandles, bVetoable,
m_pReserved->m_bIgnoreRuntimeExceptionsWhileFiring);
}
2000-09-18 14:29:57 +00:00
// Only fire, if one or more properties changed
if( !nHandles )
return;
// create the event sequence of all changed properties
Sequence< PropertyChangeEvent > aEvts( nHandles );
PropertyChangeEvent * pEvts = aEvts.getArray();
Reference < XInterface > xSource( static_cast<XPropertySet *>(this), UNO_QUERY );
sal_Int32 i;
sal_Int32 nChangesLen = 0;
// Loop over all changed properties to fill the event struct
for( i = 0; i < nHandles; i++ )
2000-09-18 14:29:57 +00:00
{
// Vetoable fire and constrained attribute set or
// Change fire and Changed and bound attribute set
IPropertyArrayHelper & rInfo = getInfoHelper();
sal_Int16 nAttributes;
OUString aPropName;
rInfo.fillPropertyMembersByHandle( &aPropName, &nAttributes, pnHandles[i] );
if(
(bVetoable && (nAttributes & PropertyAttribute::CONSTRAINED)) ||
(!bVetoable && (nAttributes & PropertyAttribute::BOUND))
)
2000-09-18 14:29:57 +00:00
{
pEvts[nChangesLen].Source = xSource;
pEvts[nChangesLen].PropertyName = aPropName;
pEvts[nChangesLen].PropertyHandle = pnHandles[i];
pEvts[nChangesLen].OldValue = pOldValues[i];
pEvts[nChangesLen].NewValue = pNewValues[i];
nChangesLen++;
2000-09-18 14:29:57 +00:00
}
}
2000-09-18 14:29:57 +00:00
bool bIgnoreRuntimeExceptionsWhileFiring =
m_pReserved->m_bIgnoreRuntimeExceptionsWhileFiring;
// fire the events for all changed properties
for( i = 0; i < nChangesLen; i++ )
{
// get the listener container for the property name
OInterfaceContainerHelper * pLC;
if( bVetoable ) // fire change Events?
pLC = aVetoableLC.getContainer( pEvts[i].PropertyHandle );
else
pLC = aBoundLC.getContainer( pEvts[i].PropertyHandle );
if( pLC )
2000-09-18 14:29:57 +00:00
{
// Iterate over all listeners and send events
OInterfaceIteratorHelper aIt( *pLC);
while( aIt.hasMoreElements() )
2000-09-18 14:29:57 +00:00
{
XInterface * pL = aIt.next();
try
2000-09-18 14:29:57 +00:00
{
try
{
if( bVetoable ) // fire change Events?
{
static_cast<XVetoableChangeListener *>(pL)->vetoableChange(
pEvts[i] );
}
else
{
static_cast<XPropertyChangeListener *>(pL)->propertyChange(
pEvts[i] );
}
}
catch (DisposedException & exc)
{
OSL_ENSURE( exc.Context.is(),
"DisposedException without Context!" );
if (exc.Context == pL)
aIt.remove();
else
throw;
}
2000-09-18 14:29:57 +00:00
}
catch (RuntimeException & exc)
{
SAL_INFO("cppuhelper", "caught RuntimeException while firing listeners: " << exc);
if (! bIgnoreRuntimeExceptionsWhileFiring)
throw;
}
2000-09-18 14:29:57 +00:00
}
}
// broadcast to all listeners with "" property name
if( bVetoable ){
// fire change Events?
pLC = rBHelper.aLC.getContainer(
getVetoableTypeIdentifier()
);
}
else {
pLC = rBHelper.aLC.getContainer(
getPropertyTypeIdentifier( )
);
}
if( pLC )
{
// Iterate over all listeners and send events.
OInterfaceIteratorHelper aIt( *pLC);
while( aIt.hasMoreElements() )
2000-09-18 14:29:57 +00:00
{
XInterface * pL = aIt.next();
try
2000-09-18 14:29:57 +00:00
{
try
{
if( bVetoable ) // fire change Events?
{
static_cast<XVetoableChangeListener *>(pL)->vetoableChange(
pEvts[i] );
}
else
{
static_cast<XPropertyChangeListener *>(pL)->propertyChange(
pEvts[i] );
}
}
catch (DisposedException & exc)
{
OSL_ENSURE( exc.Context.is(),
"DisposedException without Context!" );
if (exc.Context == pL)
aIt.remove();
else
throw;
}
2000-09-18 14:29:57 +00:00
}
catch (RuntimeException & exc)
{
SAL_INFO("cppuhelper", "caught RuntimeException while firing listeners: " << exc);
if (! bIgnoreRuntimeExceptionsWhileFiring)
throw;
}
2000-09-18 14:29:57 +00:00
}
}
}
// reduce array to changed properties
aEvts.realloc( nChangesLen );
if( bVetoable )
return;
2000-09-18 14:29:57 +00:00
auto pCont = rBHelper.aLC.getContainer(getPropertiesTypeIdentifier());
if (!pCont)
return;
2000-09-18 14:29:57 +00:00
// Here is a Bug, unbound properties are also fired
OInterfaceIteratorHelper aIt( *pCont );
while( aIt.hasMoreElements() )
{
XPropertiesChangeListener * pL =
static_cast<XPropertiesChangeListener *>(aIt.next());
try
2000-09-18 14:29:57 +00:00
{
try
2000-09-18 14:29:57 +00:00
{
// fire the whole event sequence to the
// XPropertiesChangeListener's
pL->propertiesChange( aEvts );
}
catch (DisposedException & exc)
{
OSL_ENSURE( exc.Context.is(),
"DisposedException without Context!" );
if (exc.Context == pL)
aIt.remove();
else
throw;
2000-09-18 14:29:57 +00:00
}
}
catch (RuntimeException & exc)
{
SAL_INFO("cppuhelper", "caught RuntimeException while firing listeners: " << exc);
if (! bIgnoreRuntimeExceptionsWhileFiring)
throw;
}
2000-09-18 14:29:57 +00:00
}
}
// OPropertySetHelper
void OPropertySetHelper::setFastPropertyValues(
2000-09-18 14:29:57 +00:00
sal_Int32 nSeqLen,
sal_Int32 * pHandles,
const Any * pValues,
sal_Int32 nHitCount )
2000-09-18 14:29:57 +00:00
{
2001-03-12 12:39:32 +00:00
OSL_ENSURE( !rBHelper.bInDispose, "do not getFastPropertyValue in the dispose call" );
OSL_ENSURE( !rBHelper.bDisposed, "object is disposed" );
2000-09-18 14:29:57 +00:00
// get the map table
IPropertyArrayHelper & rPH = getInfoHelper();
2000-09-18 14:29:57 +00:00
std::unique_ptr<Any[]> pConvertedValues(new Any[ nHitCount ]);
std::unique_ptr<Any[]> pOldValues(new Any[ nHitCount ]);
sal_Int32 n = 0;
sal_Int32 i;
2000-09-18 14:29:57 +00:00
{
2000-09-18 14:29:57 +00:00
// must lock the mutex outside the loop. So all values are consistent.
MutexGuard aGuard( rBHelper.rMutex );
for( i = 0; i < nSeqLen; i++ )
{
if( pHandles[i] != -1 )
{
sal_Int16 nAttributes;
rPH.fillPropertyMembersByHandle( nullptr, &nAttributes, pHandles[i] );
2000-09-18 14:29:57 +00:00
if( nAttributes & PropertyAttribute::READONLY ) {
throw PropertyVetoException();
}
// Will the property change?
if( convertFastPropertyValue( pConvertedValues[ n ], pOldValues[n],
2000-09-18 14:29:57 +00:00
pHandles[i], pValues[i] ) )
{
// only increment if the property really change
pHandles[n] = pHandles[i];
n++;
2000-09-18 14:29:57 +00:00
}
}
}
// release guard to fire events
}
2000-09-18 14:29:57 +00:00
// fire vetoable events
fire( pHandles, pConvertedValues.get(), pOldValues.get(), n, true );
2000-09-18 14:29:57 +00:00
{
2000-09-18 14:29:57 +00:00
// must lock the mutex outside the loop.
MutexGuard aGuard( rBHelper.rMutex );
// Loop over all changed properties
for( i = 0; i < n; i++ )
2000-09-18 14:29:57 +00:00
{
// Will the property change?
setFastPropertyValue_NoBroadcast( pHandles[i], pConvertedValues[i] );
}
// release guard to fire events
}
2000-09-18 14:29:57 +00:00
// fire change events
impl_fireAll( pHandles, pConvertedValues.get(), pOldValues.get(), n );
2000-09-18 14:29:57 +00:00
}
// XMultiPropertySet
/**
* The sequence may be contain not known properties. The implementation
2000-09-18 14:29:57 +00:00
* must ignore these properties.
*/
void OPropertySetHelper::setPropertyValues(
2000-09-18 14:29:57 +00:00
const Sequence<OUString>& rPropertyNames,
const Sequence<Any>& rValues )
2000-09-18 14:29:57 +00:00
{
sal_Int32 nSeqLen = rPropertyNames.getLength();
std::unique_ptr<sal_Int32[]> pHandles(new sal_Int32[ nSeqLen ]);
2000-09-18 14:29:57 +00:00
// get the map table
IPropertyArrayHelper & rPH = getInfoHelper();
// fill the handle array
sal_Int32 nHitCount = rPH.fillHandles( pHandles.get(), rPropertyNames );
2000-09-18 14:29:57 +00:00
if( nHitCount != 0 )
setFastPropertyValues( nSeqLen, pHandles.get(), rValues.getConstArray(), nHitCount );
2000-09-18 14:29:57 +00:00
}
// XMultiPropertySet
Sequence<Any> OPropertySetHelper::getPropertyValues( const Sequence<OUString>& rPropertyNames )
{
sal_Int32 nSeqLen = rPropertyNames.getLength();
std::unique_ptr<sal_Int32[]> pHandles(new sal_Int32[ nSeqLen ]);
2000-09-18 14:29:57 +00:00
Sequence< Any > aValues( nSeqLen );
// get the map table
IPropertyArrayHelper & rPH = getInfoHelper();
// fill the handle array
rPH.fillHandles( pHandles.get(), rPropertyNames );
2000-09-18 14:29:57 +00:00
Any * pValues = aValues.getArray();
MutexGuard aGuard( rBHelper.rMutex );
// fill the sequence with the values
for( sal_Int32 i = 0; i < nSeqLen; i++ )
getFastPropertyValue( pValues[i], pHandles[i] );
return aValues;
}
// XMultiPropertySet
void OPropertySetHelper::addPropertiesChangeListener(
const Sequence<OUString> & ,
const Reference < XPropertiesChangeListener > & rListener )
2000-09-18 14:29:57 +00:00
{
rBHelper.addListener( cppu::UnoType<decltype(rListener)>::get(), rListener );
2000-09-18 14:29:57 +00:00
}
// XMultiPropertySet
void OPropertySetHelper::removePropertiesChangeListener(
const Reference < XPropertiesChangeListener > & rListener )
2000-09-18 14:29:57 +00:00
{
rBHelper.removeListener( cppu::UnoType<decltype(rListener)>::get(), rListener );
2000-09-18 14:29:57 +00:00
}
// XMultiPropertySet
void OPropertySetHelper::firePropertiesChangeEvent(
2000-09-18 14:29:57 +00:00
const Sequence<OUString>& rPropertyNames,
const Reference < XPropertiesChangeListener >& rListener )
2000-09-18 14:29:57 +00:00
{
sal_Int32 nLen = rPropertyNames.getLength();
std::unique_ptr<sal_Int32[]> pHandles(new sal_Int32[nLen]);
2000-09-18 14:29:57 +00:00
IPropertyArrayHelper & rPH = getInfoHelper();
rPH.fillHandles( pHandles.get(), rPropertyNames );
2000-09-18 14:29:57 +00:00
const OUString* pNames = rPropertyNames.getConstArray();
// get the count of matching properties
sal_Int32 nFireLen = 0;
sal_Int32 i;
for( i = 0; i < nLen; i++ )
if( pHandles[i] != -1 )
nFireLen++;
Sequence<PropertyChangeEvent> aChanges( nFireLen );
PropertyChangeEvent* pChanges = aChanges.getArray();
{
// must lock the mutex outside the loop. So all values are consistent.
MutexGuard aGuard( rBHelper.rMutex );
Reference < XInterface > xSource( static_cast<XPropertySet *>(this), UNO_QUERY );
2011-01-12 12:54:06 +00:00
sal_Int32 nFirePos = 0;
2000-09-18 14:29:57 +00:00
for( i = 0; i < nLen; i++ )
{
if( pHandles[i] != -1 )
{
pChanges[nFirePos].Source = xSource;
pChanges[nFirePos].PropertyName = pNames[i];
pChanges[nFirePos].PropertyHandle = pHandles[i];
getFastPropertyValue( pChanges[nFirePos].OldValue, pHandles[i] );
pChanges[nFirePos].NewValue = pChanges[nFirePos].OldValue;
nFirePos++;
}
}
// release guard to fire events
}
if( nFireLen )
rListener->propertiesChange( aChanges );
}
void OPropertySetHelper2::enableChangeListenerNotification( sal_Bool bEnable )
{
m_pReserved->m_bFireEvents = bEnable;
}
extern "C" {
static int compare_Property_Impl( const void *arg1, const void *arg2 )
SAL_THROW_EXTERN_C()
2000-09-18 14:29:57 +00:00
{
return static_cast<Property const *>(arg1)->Name.compareTo( static_cast<Property const *>(arg2)->Name );
2000-09-18 14:29:57 +00:00
}
}
void OPropertyArrayHelper::init( sal_Bool bSorted )
2000-09-18 14:29:57 +00:00
{
sal_Int32 i, nElements = aInfos.getLength();
const Property* pProperties = aInfos.getConstArray();
for( i = 1; i < nElements; i++ )
{
if( pProperties[i-1].Name > pProperties[i].Name )
2000-09-18 14:29:57 +00:00
{
if (bSorted) {
OSL_FAIL( "Property array is not sorted" );
}
2000-09-18 14:29:57 +00:00
// not sorted
qsort( aInfos.getArray(), nElements, sizeof( Property ),
compare_Property_Impl );
pProperties = aInfos.getConstArray();
2000-09-18 14:29:57 +00:00
break;
}
}
for( i = 0; i < nElements; i++ )
if( pProperties[i].Handle != i )
return;
// The handle is the index
bRightOrdered = true;
2000-09-18 14:29:57 +00:00
}
OPropertyArrayHelper::OPropertyArrayHelper(
2000-09-18 14:29:57 +00:00
Property * pProps,
sal_Int32 nEle,
sal_Bool bSorted )
: m_pReserved(nullptr)
, aInfos(pProps, nEle)
, bRightOrdered( false )
2000-09-18 14:29:57 +00:00
{
init( bSorted );
}
OPropertyArrayHelper::OPropertyArrayHelper(
2000-09-18 14:29:57 +00:00
const Sequence< Property > & aProps,
sal_Bool bSorted )
: m_pReserved(nullptr)
, aInfos(aProps)
, bRightOrdered( false )
2000-09-18 14:29:57 +00:00
{
init( bSorted );
}
2000-09-18 14:29:57 +00:00
sal_Int32 OPropertyArrayHelper::getCount() const
{
return aInfos.getLength();
}
2000-09-18 14:29:57 +00:00
sal_Bool OPropertyArrayHelper::fillPropertyMembersByHandle
(
OUString * pPropName,
sal_Int16 * pAttributes,
sal_Int32 nHandle
)
{
const Property* pProperties = aInfos.getConstArray();
sal_Int32 nElements = aInfos.getLength();
if( bRightOrdered )
{
if( nHandle < 0 || nHandle >= nElements )
return false;
2000-09-18 14:29:57 +00:00
if( pPropName )
*pPropName = pProperties[ nHandle ].Name;
if( pAttributes )
*pAttributes = pProperties[ nHandle ].Attributes;
return true;
2000-09-18 14:29:57 +00:00
}
// normally the array is sorted
for( sal_Int32 i = 0; i < nElements; i++ )
2000-09-18 14:29:57 +00:00
{
if( pProperties[i].Handle == nHandle )
2000-09-18 14:29:57 +00:00
{
if( pPropName )
*pPropName = pProperties[ i ].Name;
if( pAttributes )
*pAttributes = pProperties[ i ].Attributes;
return true;
2000-09-18 14:29:57 +00:00
}
}
return false;
2000-09-18 14:29:57 +00:00
}
Sequence< Property > OPropertyArrayHelper::getProperties()
2000-09-18 14:29:57 +00:00
{
return aInfos;
}
2000-09-18 14:29:57 +00:00
Property OPropertyArrayHelper::getPropertyByName(const OUString& aPropertyName)
{
Property * pR;
pR = static_cast<Property *>(bsearch( &aPropertyName, aInfos.getConstArray(), aInfos.getLength(),
2000-09-18 14:29:57 +00:00
sizeof( Property ),
compare_OUString_Property_Impl ));
2000-09-18 14:29:57 +00:00
if( !pR ) {
throw UnknownPropertyException(aPropertyName);
2000-09-18 14:29:57 +00:00
}
return *pR;
}
2000-09-18 14:29:57 +00:00
sal_Bool OPropertyArrayHelper::hasPropertyByName(const OUString& aPropertyName)
{
Property * pR;
pR = static_cast<Property *>(bsearch( &aPropertyName, aInfos.getConstArray(), aInfos.getLength(),
2000-09-18 14:29:57 +00:00
sizeof( Property ),
compare_OUString_Property_Impl ));
return pR != nullptr;
2000-09-18 14:29:57 +00:00
}
2000-09-18 14:29:57 +00:00
sal_Int32 OPropertyArrayHelper::getHandleByName( const OUString & rPropName )
{
Property * pR;
pR = static_cast<Property *>(bsearch( &rPropName, aInfos.getConstArray(), aInfos.getLength(),
2000-09-18 14:29:57 +00:00
sizeof( Property ),
compare_OUString_Property_Impl ));
2000-09-18 14:29:57 +00:00
return pR ? pR->Handle : -1;
}
2000-09-18 14:29:57 +00:00
sal_Int32 OPropertyArrayHelper::fillHandles( sal_Int32 * pHandles, const Sequence< OUString > & rPropNames )
{
sal_Int32 nHitCount = 0;
const OUString * pReqProps = rPropNames.getConstArray();
sal_Int32 nReqLen = rPropNames.getLength();
const Property * pCur = aInfos.getConstArray();
const Property * pEnd = pCur + aInfos.getLength();
for( sal_Int32 i = 0; i < nReqLen; i++ )
{
// Calculate logarithm
sal_Int32 n = static_cast<sal_Int32>(pEnd - pCur);
2000-09-18 14:29:57 +00:00
sal_Int32 nLog = 0;
while( n )
{
nLog += 1;
n = n >> 1;
}
// Number of properties to search for * Log2 of the number of remaining
// properties to search in.
2000-09-18 14:29:57 +00:00
if( (nReqLen - i) * nLog >= pEnd - pCur )
{
// linear search is better
while( pCur < pEnd && pReqProps[i] > pCur->Name )
{
pCur++;
}
if( pCur < pEnd && pReqProps[i] == pCur->Name )
{
pHandles[i] = pCur->Handle;
nHitCount++;
}
else
pHandles[i] = -1;
}
else
{
// binary search is better
sal_Int32 nCompVal = 1;
const Property * pOldEnd = pEnd--;
const Property * pMid = pCur;
while( nCompVal != 0 && pCur <= pEnd )
{
pMid = (pEnd - pCur) / 2 + pCur;
nCompVal = pReqProps[i].compareTo( pMid->Name );
if( nCompVal > 0 )
pCur = pMid + 1;
else
pEnd = pMid - 1;
}
if( nCompVal == 0 )
{
pHandles[i] = pMid->Handle;
nHitCount++;
pCur = pMid +1;
}
else if( nCompVal > 0 )
{
pHandles[i] = -1;
pCur = pMid +1;
}
else
{
pHandles[i] = -1;
pCur = pMid;
}
pEnd = pOldEnd;
}
}
return nHitCount;
}
} // end namespace cppu
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */