From 6a789e617ed07bfddc516c8fc0cf94cd6dfe7250 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Sat, 5 Oct 2019 13:32:10 +0200 Subject: improve SfxPoolItem operator== implementations (*) make them all call the superclass operator== (*) make the base class check which and typeid to ensure we are only comparing the safe subclasses together (*) remove a couple of operator== that were not doing anything useful Change-Id: Ia6234aed42df04157a5d6a323dc951916a9cb316 Reviewed-on: https://gerrit.libreoffice.org/80308 Tested-by: Jenkins Reviewed-by: Noel Grandin --- editeng/source/items/bulitem.cxx | 2 +- editeng/source/items/numitem.cxx | 3 ++- editeng/source/items/paraitem.cxx | 7 ------- editeng/source/items/textitem.cxx | 9 +-------- editeng/source/items/writingmodeitem.cxx | 7 ------- editeng/source/items/xmlcnitm.cxx | 5 ++--- 6 files changed, 6 insertions(+), 27 deletions(-) (limited to 'editeng') diff --git a/editeng/source/items/bulitem.cxx b/editeng/source/items/bulitem.cxx index 9518cf4abbe9..46f6271f2c33 100644 --- a/editeng/source/items/bulitem.cxx +++ b/editeng/source/items/bulitem.cxx @@ -87,7 +87,7 @@ void SvxBulletItem::CopyValidProperties( const SvxBulletItem& rCopyFrom ) bool SvxBulletItem::operator==( const SfxPoolItem& rItem ) const { - DBG_ASSERT(dynamic_cast< const SvxBulletItem* >(&rItem) != nullptr,"operator==Types not matching"); + assert(SfxPoolItem::operator==(rItem)); const SvxBulletItem& rBullet = static_cast(rItem); // Compare with ValidMask, otherwise no put possible in an AttrSet if the // item differs only in terms of the ValidMask from an existing one. diff --git a/editeng/source/items/numitem.cxx b/editeng/source/items/numitem.cxx index e35682e04fbe..67cf0373cc37 100644 --- a/editeng/source/items/numitem.cxx +++ b/editeng/source/items/numitem.cxx @@ -938,7 +938,8 @@ SvxNumBulletItem::~SvxNumBulletItem() bool SvxNumBulletItem::operator==( const SfxPoolItem& rCopy) const { - return *pNumRule == *static_cast(rCopy).pNumRule; + return SfxPoolItem::operator==(rCopy) && + *pNumRule == *static_cast(rCopy).pNumRule; } SfxPoolItem* SvxNumBulletItem::Clone( SfxItemPool * ) const diff --git a/editeng/source/items/paraitem.cxx b/editeng/source/items/paraitem.cxx index 2194b3ed9e5a..ed159e14ed08 100644 --- a/editeng/source/items/paraitem.cxx +++ b/editeng/source/items/paraitem.cxx @@ -1061,8 +1061,6 @@ bool SvxPageModelItem::PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId bool SvxPageModelItem::operator==( const SfxPoolItem& rAttr ) const { - assert(SfxPoolItem::operator==(rAttr)); - return SfxStringItem::operator==(rAttr) && bAuto == static_cast( rAttr ).bAuto; } @@ -1217,11 +1215,6 @@ bool SvxParaVertAlignItem::PutValue( const css::uno::Any& rVal, return false; } -bool SvxParaVertAlignItem::operator==( const SfxPoolItem& rItem ) const -{ - assert(SfxPoolItem::operator==(rItem)); - return SfxUInt16Item::operator==( rItem ); -} SvxParaGridItem::SvxParaGridItem( bool bOn, const sal_uInt16 nId ) diff --git a/editeng/source/items/textitem.cxx b/editeng/source/items/textitem.cxx index e4ce386c68c9..ffb4e63e2e21 100644 --- a/editeng/source/items/textitem.cxx +++ b/editeng/source/items/textitem.cxx @@ -1040,8 +1040,7 @@ bool SvxTextLineItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) bool SvxTextLineItem::operator==( const SfxPoolItem& rItem ) const { - assert(SfxPoolItem::operator==(rItem)); - return SfxEnumItem::operator==( static_cast&>(rItem) ) && + return SfxEnumItem::operator==( rItem ) && GetColor() == static_cast(rItem).GetColor(); } @@ -2241,12 +2240,6 @@ bool SvxTextRotateItem::PutValue(const css::uno::Any& rVal, sal_uInt8 nMemberId) return bRet; } -bool SvxTextRotateItem::operator==(const SfxPoolItem& rItem) const -{ - assert(SfxPoolItem::operator==(rItem)); - return SfxUInt16Item::operator==(rItem); -} - void SvxTextRotateItem::dumpAsXml(xmlTextWriterPtr pWriter) const { xmlTextWriterStartElement(pWriter, BAD_CAST("SvxTextRotateItem")); diff --git a/editeng/source/items/writingmodeitem.cxx b/editeng/source/items/writingmodeitem.cxx index dfa2df0de9cd..2fa4ce5ebbd4 100644 --- a/editeng/source/items/writingmodeitem.cxx +++ b/editeng/source/items/writingmodeitem.cxx @@ -38,13 +38,6 @@ SvxWritingModeItem::~SvxWritingModeItem() { } -bool SvxWritingModeItem::operator==( const SfxPoolItem& rCmp ) const -{ - assert(SfxPoolItem::operator==(rCmp)); - - return GetValue() == static_cast(rCmp).GetValue(); -} - SfxPoolItem* SvxWritingModeItem::Clone( SfxItemPool * ) const { return new SvxWritingModeItem( *this ); diff --git a/editeng/source/items/xmlcnitm.cxx b/editeng/source/items/xmlcnitm.cxx index 4e0c25c9c239..be38d75ab5f4 100644 --- a/editeng/source/items/xmlcnitm.cxx +++ b/editeng/source/items/xmlcnitm.cxx @@ -53,9 +53,8 @@ SvXMLAttrContainerItem::~SvXMLAttrContainerItem() bool SvXMLAttrContainerItem::operator==( const SfxPoolItem& rItem ) const { - DBG_ASSERT( dynamic_cast< const SvXMLAttrContainerItem* >(&rItem) != nullptr, - "SvXMLAttrContainerItem::operator ==(): Bad type"); - return *pImpl == *static_cast(rItem).pImpl; + return SfxPoolItem::operator==(rItem) && + *pImpl == *static_cast(rItem).pImpl; } bool SvXMLAttrContainerItem::GetPresentation( -- cgit v1.2.3