Convert SV_DECL_PTRARR(SbPropertyValueArr_Impl) to std::vector

Change-Id: I3e072c165d83e9ade06caf2508031b473ef7691d
This commit is contained in:
Noel Grandin 2012-06-09 18:07:07 +02:00 committed by Michael Stahl
parent 6d0961d194
commit 8de787a266
2 changed files with 30 additions and 28 deletions

View file

@ -59,12 +59,17 @@ int CDECL SbCompare_PropertyValues_Impl( const void *arg1, const void *arg2 )
return ((PropertyValue*)arg1)->Name.compareTo( ((PropertyValue*)arg2)->Name ); return ((PropertyValue*)arg1)->Name.compareTo( ((PropertyValue*)arg2)->Name );
} }
extern "C" int CDECL SbCompare_UString_PropertyValue_Impl( const void *arg1, const void *arg2 ) struct SbCompare_UString_PropertyValue_Impl
{ {
const ::rtl::OUString *pArg1 = (::rtl::OUString*) arg1; bool operator() ( const ::rtl::OUString& lhs, PropertyValue* const & rhs )
const PropertyValue **pArg2 = (const PropertyValue**) arg2; {
return pArg1->compareTo( (*pArg2)->Name ); return lhs.compareTo( rhs->Name );
} }
bool operator() ( PropertyValue* const & lhs, const ::rtl::OUString& rhs )
{
return !rhs.compareTo( lhs->Name );
}
};
int CDECL SbCompare_Properties_Impl( const void *arg1, const void *arg2 ) int CDECL SbCompare_Properties_Impl( const void *arg1, const void *arg2 )
{ {
@ -90,8 +95,8 @@ SbPropertyValues::~SbPropertyValues()
{ {
_xInfo = Reference< XPropertySetInfo >(); _xInfo = Reference< XPropertySetInfo >();
for ( sal_uInt16 n = 0; n < _aPropVals.Count(); ++n ) for ( sal_uInt16 n = 0; n < _aPropVals.size(); ++n )
delete _aPropVals.GetObject( n ); delete _aPropVals[ n ];
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -111,12 +116,10 @@ Reference< XPropertySetInfo > SbPropertyValues::getPropertySetInfo(void) throw(
sal_Int32 SbPropertyValues::GetIndex_Impl( const ::rtl::OUString &rPropName ) const sal_Int32 SbPropertyValues::GetIndex_Impl( const ::rtl::OUString &rPropName ) const
{ {
PropertyValue **ppPV; SbPropertyValueArr_Impl::const_iterator it = std::lower_bound(
ppPV = (PropertyValue **) _aPropVals.begin(), _aPropVals.end(), rPropName,
bsearch( &rPropName, _aPropVals.GetData(), _aPropVals.Count(), SbCompare_UString_PropertyValue_Impl() );
sizeof( PropertyValue* ), return it != _aPropVals.end() ? it - _aPropVals.begin() : USHRT_MAX;
SbCompare_UString_PropertyValue_Impl );
return ppPV ? ppPV - _aPropVals.GetData() : USHRT_MAX;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -131,8 +134,8 @@ void SbPropertyValues::setPropertyValue(
::com::sun::star::uno::RuntimeException) ::com::sun::star::uno::RuntimeException)
{ {
sal_Int32 nIndex = GetIndex_Impl( aPropertyName ); sal_Int32 nIndex = GetIndex_Impl( aPropertyName );
PropertyValue *pPropVal = _aPropVals.GetObject( PropertyValue *pPropVal = _aPropVals[
sal::static_int_cast< sal_uInt16 >(nIndex)); sal::static_int_cast< sal_uInt16 >(nIndex)];
pPropVal->Value = aValue; pPropVal->Value = aValue;
} }
@ -146,8 +149,8 @@ Any SbPropertyValues::getPropertyValue(
{ {
sal_Int32 nIndex = GetIndex_Impl( aPropertyName ); sal_Int32 nIndex = GetIndex_Impl( aPropertyName );
if ( nIndex != USHRT_MAX ) if ( nIndex != USHRT_MAX )
return _aPropVals.GetObject( return _aPropVals[
sal::static_int_cast< sal_uInt16 >(nIndex))->Value; sal::static_int_cast< sal_uInt16 >(nIndex)]->Value;
return Any(); return Any();
} }
@ -195,9 +198,9 @@ void SbPropertyValues::removeVetoableChangeListener(
Sequence< PropertyValue > SbPropertyValues::getPropertyValues(void) throw (::com::sun::star::uno::RuntimeException) Sequence< PropertyValue > SbPropertyValues::getPropertyValues(void) throw (::com::sun::star::uno::RuntimeException)
{ {
Sequence<PropertyValue> aRet( _aPropVals.Count()); Sequence<PropertyValue> aRet( _aPropVals.size() );
for ( sal_uInt16 n = 0; n < _aPropVals.Count(); ++n ) for ( sal_uInt16 n = 0; n < _aPropVals.size(); ++n )
aRet.getArray()[n] = *_aPropVals.GetObject(n); aRet.getArray()[n] = *_aPropVals[n];
return aRet; return aRet;
} }
@ -210,14 +213,14 @@ void SbPropertyValues::setPropertyValues(const Sequence< PropertyValue >& rPrope
::com::sun::star::lang::WrappedTargetException, ::com::sun::star::lang::WrappedTargetException,
::com::sun::star::uno::RuntimeException) ::com::sun::star::uno::RuntimeException)
{ {
if ( _aPropVals.Count() ) if ( !_aPropVals.empty() )
throw PropertyExistException(); throw PropertyExistException();
const PropertyValue *pPropVals = rPropertyValues.getConstArray(); const PropertyValue *pPropVals = rPropertyValues.getConstArray();
for ( sal_Int16 n = 0; n < rPropertyValues.getLength(); ++n ) for ( sal_Int16 n = 0; n < rPropertyValues.getLength(); ++n )
{ {
PropertyValue *pPropVal = new PropertyValue(pPropVals[n]); PropertyValue *pPropVal = new PropertyValue(pPropVals[n]);
_aPropVals.Insert( pPropVal, n ); _aPropVals.push_back( pPropVal );
} }
} }
@ -262,11 +265,11 @@ sal_Bool PropertySetInfoImpl::hasPropertyByName(const ::rtl::OUString& Name) thr
SbPropertySetInfo::SbPropertySetInfo( const SbPropertyValueArr_Impl &rPropVals ) SbPropertySetInfo::SbPropertySetInfo( const SbPropertyValueArr_Impl &rPropVals )
{ {
aImpl._aProps.realloc( rPropVals.Count() ); aImpl._aProps.realloc( rPropVals.size() );
for ( sal_uInt16 n = 0; n < rPropVals.Count(); ++n ) for ( sal_uInt16 n = 0; n < rPropVals.size(); ++n )
{ {
Property &rProp = aImpl._aProps.getArray()[n]; Property &rProp = aImpl._aProps.getArray()[n];
const PropertyValue &rPropVal = *rPropVals.GetObject(n); const PropertyValue &rPropVal = *rPropVals[n];
rProp.Name = rPropVal.Name; rProp.Name = rPropVal.Name;
rProp.Handle = rPropVal.Handle; rProp.Handle = rPropVal.Handle;
rProp.Type = getCppuVoidType(); rProp.Type = getCppuVoidType();

View file

@ -28,7 +28,6 @@
#ifndef _SFX_PROPBAG_HXX #ifndef _SFX_PROPBAG_HXX
#define _SFX_PROPBAG_HXX #define _SFX_PROPBAG_HXX
#include <svl/svarray.hxx>
#include <com/sun/star/beans/PropertyValue.hpp> #include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/beans/XPropertySetInfo.hpp> #include <com/sun/star/beans/XPropertySetInfo.hpp>
@ -36,9 +35,9 @@
#include <com/sun/star/beans/XPropertyContainer.hpp> #include <com/sun/star/beans/XPropertyContainer.hpp>
#include <cppuhelper/implbase1.hxx> #include <cppuhelper/implbase1.hxx>
#include <cppuhelper/implbase2.hxx> #include <cppuhelper/implbase2.hxx>
#include <vector>
typedef ::com::sun::star::beans::PropertyValue* SbPropertyValuePtr; typedef std::vector< ::com::sun::star::beans::PropertyValue* > SbPropertyValueArr_Impl;
SV_DECL_PTRARR( SbPropertyValueArr_Impl, SbPropertyValuePtr, 4 )
typedef ::cppu::WeakImplHelper2< ::com::sun::star::beans::XPropertySet, typedef ::cppu::WeakImplHelper2< ::com::sun::star::beans::XPropertySet,
::com::sun::star::beans::XPropertyAccess > SbPropertyValuesHelper; ::com::sun::star::beans::XPropertyAccess > SbPropertyValuesHelper;