From: Vincent van Ravesteijn Date: Tue, 26 Oct 2010 15:03:51 +0000 (+0000) Subject: Remove unneccessary uses of dynamic_cast from the code. X-Git-Tag: 2.0.0~2233 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=573500dd04f154f27318ac5ec469a337f97fe9f0;p=features.git Remove unneccessary uses of dynamic_cast from the code. A dynamic_cast is necessary when: - the object to be casted is from an external library because we can't add Qxxx::asXxxx() to Qt e.g.: * QAbstractListModel to GuiIdListModel, * QValidator to PathValidator, * QWidget to TabWorkArea, * QWidget to GuiWorkArea; - the object is to be casted from an interface to the implementing class, because the Interface does not know by whom it is implemented: * ProgressInterface to GuiProgress, * Application to GuiApplication. A dynamic_cast can be replaced by: - already existing as***Inset() functions, e.g.: * asHullInset(), * asInsetMath()->asMacro(), * asInsetText(); - a static_cast when we are sure this can't go wrong, e.g.: * we are sure that CellData::inset->clone() is an InsetTableCell, * in cases where we explicitly check it->lyxCode(). git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35855 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/Buffer.cpp b/src/Buffer.cpp index ad14807e10..40e24b16d7 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -2085,7 +2085,7 @@ void Buffer::dispatch(FuncRequest const & func, DispatchResult & dr) bool success = false; for (; it != end; ++it) { if (it->lyxCode() == BRANCH_CODE) { - InsetBranch & ins = dynamic_cast(*it); + InsetBranch & ins = static_cast(*it); if (ins.branch() == oldname) { undo().recordUndo(it); ins.rename(newname); @@ -2830,7 +2830,7 @@ void Buffer::getUsedBranches(std::list & result, bool const from_mast InsetIterator const end = inset_iterator_end(inset()); for (; it != end; ++it) { if (it->lyxCode() == BRANCH_CODE) { - InsetBranch & br = dynamic_cast(*it); + InsetBranch & br = static_cast(*it); docstring const name = br.branch(); if (!from_master && !params().branchlist().find(name)) result.push_back(name); diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp index e716cc3a81..3e8661c5fe 100644 --- a/src/CutAndPaste.cpp +++ b/src/CutAndPaste.cpp @@ -272,7 +272,7 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist, case LABEL_CODE: { // check for duplicates - InsetLabel & lab = dynamic_cast(*it); + InsetLabel & lab = static_cast(*it); docstring const oldname = lab.getParam("name"); lab.updateCommand(oldname, false); // We need to update the buffer reference cache. @@ -310,7 +310,7 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist, case BIBITEM_CODE: { // check for duplicates - InsetBibitem & bib = dynamic_cast(*it); + InsetBibitem & bib = static_cast(*it); docstring const oldkey = bib.getParam("key"); bib.updateCommand(oldkey, false); // We need to update the buffer reference cache. diff --git a/src/DocIterator.cpp b/src/DocIterator.cpp index f396ef5869..c0df50b446 100644 --- a/src/DocIterator.cpp +++ b/src/DocIterator.cpp @@ -91,7 +91,7 @@ DocIterator DocIterator::clone(Buffer * buffer) const bool DocIterator::inRegexped() const { - InsetMathHull * i = dynamic_cast(inset().asInsetMath()); + InsetMathHull * i = inset().asInsetMath()->asHullInset(); return i && i->getType() == hullRegexp; } diff --git a/src/Text3.cpp b/src/Text3.cpp index c132531bb7..9b4c6d9aff 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -268,10 +268,10 @@ static bool doInsertInset(Cursor & cur, Text * text, cur.buffer()->errors("Paste"); cur.clearSelection(); // bug 393 cur.finishUndo(); - InsetText * insetText = dynamic_cast(inset); - if (insetText) { - insetText->fixParagraphsFont(); - if (!insetText->allowMultiPar() || cur.lastpit() == 0) { + InsetText * inset_text = inset->asInsetText(); + if (inset_text) { + inset_text->fixParagraphsFont(); + if (!inset_text->allowMultiPar() || cur.lastpit() == 0) { // reset first par to default cur.text()->paragraphs().begin() ->setPlainOrDefaultLayout(bparams.documentClass()); diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index 0c1b2e280c..00a155d918 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -580,7 +580,7 @@ Tabular::CellData::CellData(CellData const & cs) rotate(cs.rotate), align_special(cs.align_special), p_width(cs.p_width), - inset(dynamic_cast(cs.inset->clone())) + inset(static_cast(cs.inset->clone())) { } diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp index 0b11be1308..d0c2397a2e 100644 --- a/src/mathed/InsetMathNest.cpp +++ b/src/mathed/InsetMathNest.cpp @@ -1011,7 +1011,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd) } case LFUN_REGEXP_MODE: { - InsetMathHull * i = dynamic_cast(cur.inset().asInsetMath()); + InsetMathHull * i = cur.inset().asInsetMath()->asHullInset(); if (i && i->getType() == hullRegexp) { cur.message(_("Already in regular expression mode")); break; diff --git a/src/mathed/MathMacro.cpp b/src/mathed/MathMacro.cpp index 6a232716dc..da398683b0 100644 --- a/src/mathed/MathMacro.cpp +++ b/src/mathed/MathMacro.cpp @@ -164,7 +164,7 @@ bool MathMacro::editMode(BufferView const * bv) const { // look if there is no other macro in edit mode above ++i; for (; i != cur.depth(); ++i) { - MathMacro const * macro = dynamic_cast(&cur[i].inset()); + MathMacro const * macro = cur[i].asInsetMath()->asMacro(); if (macro && macro->displayMode() == DISPLAY_NORMAL) return false; }