diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2021-07-22 11:55:16 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2021-07-22 17:25:12 +0200 |
commit | d1cbd25ebcf90b3302497987c0cf4a0b15163121 (patch) | |
tree | 275c263a1c3eb2d350121a2021f1021d1d5c020f /editeng | |
parent | 689b5a4862ead541e54e83cb14067cfaa691e2ab (diff) |
Make static_casting to the only derived class less verbose
... and assert on correct derived type in debug builds.
Change-Id: Iedd37b3ad4139ab1eb1a0a321e3ebd0018ecde99
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119360
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'editeng')
-rw-r--r-- | editeng/source/editeng/editobj.cxx | 7 | ||||
-rw-r--r-- | editeng/source/editeng/editobj2.hxx | 12 | ||||
-rw-r--r-- | editeng/source/editeng/fieldupdater.cxx | 2 | ||||
-rw-r--r-- | editeng/source/editeng/impedit4.cxx | 2 |
4 files changed, 17 insertions, 6 deletions
diff --git a/editeng/source/editeng/editobj.cxx b/editeng/source/editeng/editobj.cxx index 5f14386c4ccb..39e2bcbd22d8 100644 --- a/editeng/source/editeng/editobj.cxx +++ b/editeng/source/editeng/editobj.cxx @@ -215,8 +215,7 @@ std::unique_ptr<EditTextObject> EditTextObjectImpl::Clone() const bool EditTextObject::Equals( const EditTextObject& rCompare ) const { - return static_cast<const EditTextObjectImpl*>(this)->Equals( - static_cast<const EditTextObjectImpl&>(rCompare), false /*bComparePool*/); + return toImpl(*this).Equals(toImpl(rCompare), false /*bComparePool*/); } void EditTextObjectImpl::dumpAsXml(xmlTextWriterPtr pWriter) const @@ -743,7 +742,7 @@ void EditTextObjectImpl::ChangeStyleSheetName( SfxStyleFamily eFamily, bool EditTextObjectImpl::operator==( const EditTextObject& rCompare ) const { - return Equals( static_cast<const EditTextObjectImpl&>(rCompare), true); + return Equals(toImpl(rCompare), true); } bool EditTextObjectImpl::Equals( const EditTextObjectImpl& rCompare, bool bComparePool ) const @@ -767,7 +766,7 @@ bool EditTextObjectImpl::Equals( const EditTextObjectImpl& rCompare, bool bCompa // #i102062# bool EditTextObjectImpl::isWrongListEqual(const EditTextObject& rComp) const { - const EditTextObjectImpl& rCompare = static_cast<const EditTextObjectImpl&>(rComp); + const EditTextObjectImpl& rCompare = toImpl(rComp); return std::equal( maContents.begin(), maContents.end(), rCompare.maContents.begin(), rCompare.maContents.end(), [](const auto& c1, const auto& c2) { return c1->isWrongListEqual(*c2); }); diff --git a/editeng/source/editeng/editobj2.hxx b/editeng/source/editeng/editobj2.hxx index 818ea0fbaf75..005624ede6e6 100644 --- a/editeng/source/editeng/editobj2.hxx +++ b/editeng/source/editeng/editobj2.hxx @@ -266,4 +266,16 @@ public: virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override; }; +inline EditTextObjectImpl& toImpl(EditTextObject& rObj) +{ + assert(dynamic_cast<EditTextObjectImpl*>(&rObj)); + return static_cast<EditTextObjectImpl&>(rObj); +} + +inline const EditTextObjectImpl& toImpl(const EditTextObject& rObj) +{ + assert(dynamic_cast<const EditTextObjectImpl*>(&rObj)); + return static_cast<const EditTextObjectImpl&>(rObj); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/editeng/source/editeng/fieldupdater.cxx b/editeng/source/editeng/fieldupdater.cxx index 78891dac499b..41d9be7aeee7 100644 --- a/editeng/source/editeng/fieldupdater.cxx +++ b/editeng/source/editeng/fieldupdater.cxx @@ -22,7 +22,7 @@ class FieldUpdaterImpl { EditTextObjectImpl& mrObj; public: - explicit FieldUpdaterImpl(EditTextObject& rObj) : mrObj(static_cast<EditTextObjectImpl&>(rObj)) {} + explicit FieldUpdaterImpl(EditTextObject& rObj) : mrObj(toImpl(rObj)) {} void updateTableFields(int nTab) { diff --git a/editeng/source/editeng/impedit4.cxx b/editeng/source/editeng/impedit4.cxx index de36a316de83..5c08141e9979 100644 --- a/editeng/source/editeng/impedit4.cxx +++ b/editeng/source/editeng/impedit4.cxx @@ -1169,7 +1169,7 @@ EditSelection ImpEditEngine::InsertTextObject( const EditTextObject& rTextObject DBG_ASSERT( !aSel.DbgIsBuggy( aEditDoc ), "InsertBibTextObject: Selection broken!(1)" ); bool bUsePortionInfo = false; - const EditTextObjectImpl& rTextObjectImpl = static_cast<const EditTextObjectImpl&>(rTextObject); + const EditTextObjectImpl& rTextObjectImpl = toImpl(rTextObject); XParaPortionList* pPortionInfo = rTextObjectImpl.GetPortionInfo(); if ( pPortionInfo && ( static_cast<tools::Long>(pPortionInfo->GetPaperWidth()) == GetColumnWidth(aPaperSize) ) |