[Libreoffice-commits] core.git: editeng/source
Mike Kaganski (via logerrit)
logerrit at kemper.freedesktop.org
Thu Jul 22 15:25:47 UTC 2021
editeng/source/editeng/editobj.cxx | 7 +++----
editeng/source/editeng/editobj2.hxx | 12 ++++++++++++
editeng/source/editeng/fieldupdater.cxx | 2 +-
editeng/source/editeng/impedit4.cxx | 2 +-
4 files changed, 17 insertions(+), 6 deletions(-)
New commits:
commit d1cbd25ebcf90b3302497987c0cf4a0b15163121
Author: Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Thu Jul 22 11:55:16 2021 +0300
Commit: Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Thu Jul 22 17:25:12 2021 +0200
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 at collabora.com>
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) )
More information about the Libreoffice-commits
mailing list