]> git.lyx.org Git - features.git/commitdiff
Remove some unnecessary static_casts and add two FIXMEs about casts that don't look...
authorVincent van Ravesteijn <vfr@lyx.org>
Tue, 26 Oct 2010 16:45:21 +0000 (16:45 +0000)
committerVincent van Ravesteijn <vfr@lyx.org>
Tue, 26 Oct 2010 16:45:21 +0000 (16:45 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35856 a592a061-630c-0410-9148-cb99ea01b6c8

src/Buffer.cpp
src/BufferView.cpp
src/Cursor.cpp
src/CutAndPaste.cpp
src/DocIterator.cpp
src/Paragraph.cpp
src/insets/InsetLabel.cpp
src/mathed/MathAtom.cpp
src/mathed/MathAtom.h

index 40e24b16d794473da2b1761bfdab6eb29d61acba..6115a4076285c1410473ec748bc6ba3bff69935b 100644 (file)
@@ -1707,15 +1707,13 @@ void Buffer::updateBibfilesCache(UpdateScope scope) const
        d->bibfiles_cache_.clear();
        for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) {
                if (it->lyxCode() == BIBTEX_CODE) {
-                       InsetBibtex const & inset =
-                               static_cast<InsetBibtex const &>(*it);
+                       InsetBibtex const & inset = static_cast<InsetBibtex const &>(*it);
                        support::FileNameList const bibfiles = inset.getBibFiles();
                        d->bibfiles_cache_.insert(d->bibfiles_cache_.end(),
                                bibfiles.begin(),
                                bibfiles.end());
                } else if (it->lyxCode() == INCLUDE_CODE) {
-                       InsetInclude & inset =
-                               static_cast<InsetInclude &>(*it);
+                       InsetInclude & inset = static_cast<InsetInclude &>(*it);
                        Buffer const * const incbuf = inset.getChildBuffer();
                        if (!incbuf)
                                continue;
@@ -2762,20 +2760,16 @@ void Buffer::Impl::updateMacros(DocIterator & it, DocIterator & scope)
                                continue;
                        }
 
-                       if (doing_export && iit->inset->asInsetMath()) {
-                               InsetMath * im = static_cast<InsetMath *>(iit->inset);
-                               if (im->asHullInset()) {
-                                       InsetMathHull * hull = static_cast<InsetMathHull *>(im);
-                                       hull->recordLocation(it);
-                               }
-                       }
+                       InsetMath * im = iit->inset->asInsetMath();
+                       if (doing_export && im)
+                               im->asHullInset()->recordLocation(it);
 
                        if (iit->inset->lyxCode() != MATHMACRO_CODE)
                                continue;
 
                        // get macro data
                        MathMacroTemplate & macroTemplate =
-                               static_cast<MathMacroTemplate &>(*iit->inset);
+                               *iit->inset->asInsetMath()->asMacroTemplate();
                        MacroContext mc(owner_, it);
                        macroTemplate.updateToContext(mc);
 
@@ -2999,10 +2993,12 @@ void Buffer::changeRefsIfUnique(docstring const & from, docstring const & to,
 
        for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) {
                if (it->lyxCode() == code) {
-                       InsetCommand & inset = static_cast<InsetCommand &>(*it);
-                       docstring const oldValue = inset.getParam(paramName);
+                       InsetCommand * inset = it->asInsetCommand();
+                       if (!inset)
+                               continue;
+                       docstring const oldValue = inset->getParam(paramName);
                        if (oldValue == from)
-                               inset.setParam(paramName, to);
+                               inset->setParam(paramName, to);
                }
        }
 }
index 338a55aa5c3f9a1ce7e7fdeba159fec447ab9e83..4c57dfd479683af405ca5c8d00ae274a0289c758 100644 (file)
@@ -121,6 +121,9 @@ bool findNextInset(DocIterator & dit, vector<InsetCode> const & codes,
                if (inset
                    && std::find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end()
                    && (contents.empty() ||
+                       //FIXME: This static_cast seems very dangerous. Does this
+                       // mean that if contents is not empty, we must only be
+                       // looking for InsetCommand's ??
                    static_cast<InsetCommand const *>(inset)->getFirstNonOptParam() == contents)) {
                        dit = tmpdit;
                        return true;
@@ -146,6 +149,9 @@ bool findInset(DocIterator & dit, vector<InsetCode> const & codes,
                Inset const * inset = tmpdit.nextInset();
                if (inset
                    && std::find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end()) {
+                       //FIXME: This static_cast seems very dangerous. Does this
+                       // mean that if contents is not empty, we must only be
+                       // looking for InsetCommand's ??
                        contents = static_cast<InsetCommand const *>(inset)->getFirstNonOptParam();
                }
        }
index 45745798da27f3314bdb61266c65fc3cf2407497..f6d10cbc972ab2ca43f0180943e645f791c933c3 100644 (file)
@@ -1315,7 +1315,7 @@ void Cursor::insert(Inset * inset0)
 {
        LASSERT(inset0, /**/);
        if (inMathed())
-               insert(MathAtom(inset0));
+               insert(MathAtom(inset0->asInsetMath()));
        else {
                text()->insertInset(*this, inset0);
                inset0->setBuffer(bv_->buffer());
index 3e8661c5fe3637ca8827a4523b825134548178b9..364e1e9d034e5eaf06cc5515a5a7695719d9ccf3 100644 (file)
@@ -234,8 +234,8 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist,
 
                case MATH_HULL_CODE: {
                        // check for equation labels and resolve duplicates
-                       InsetMathHull & ins = static_cast<InsetMathHull &>(*it);
-                       std::vector<InsetLabel *> labels = ins.getLabels();
+                       InsetMathHull * ins = it->asInsetMath()->asHullInset();
+                       std::vector<InsetLabel *> labels = ins->getLabels();
                        for (size_t i = 0; i != labels.size(); ++i) {
                                if (!labels[i])
                                        continue;
@@ -251,19 +251,17 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist,
                                for (InsetIterator itt = inset_iterator_begin(in);
                                      itt != i_end; ++itt) {
                                        if (itt->lyxCode() == REF_CODE) {
-                                               InsetCommand & ref =
-                                                       static_cast<InsetCommand &>(*itt);
-                                               if (ref.getParam("reference") == oldname)
-                                                       ref.setParam("reference", newname);
+                                               InsetCommand * ref = itt->asInsetCommand();
+                                               if (ref->getParam("reference") == oldname)
+                                                       ref->setParam("reference", newname);
                                        } else if (itt->lyxCode() == MATH_REF_CODE) {
-                                               InsetMathHull & mi =
-                                                       static_cast<InsetMathHull &>(*itt);
+                                               InsetMathHull * mi = itt->asInsetMath()->asHullInset();
                                                // this is necessary to prevent an uninitialized
                                                // buffer when the RefInset is in a MathBox.
                                                // FIXME audit setBuffer calls
-                                               mi.setBuffer(const_cast<Buffer &>(buffer));
-                                               if (mi.asRefInset()->getTarget() == oldname)
-                                                       mi.asRefInset()->changeTarget(newname);
+                                               mi->setBuffer(const_cast<Buffer &>(buffer));
+                                               if (mi->asRefInset()->getTarget() == oldname)
+                                                       mi->asRefInset()->changeTarget(newname);
                                        }
                                }
                        }
@@ -322,10 +320,9 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist,
                        for (InsetIterator itt = inset_iterator_begin(in);
                             itt != i_end; ++itt) {
                                if (itt->lyxCode() == CITE_CODE) {
-                                       InsetCommand & ref =
-                                               static_cast<InsetCommand &>(*itt);
-                                       if (ref.getParam("key") == oldkey)
-                                               ref.setParam("key", newkey);
+                                       InsetCommand * ref = itt->asInsetCommand();
+                                       if (ref->getParam("key") == oldkey)
+                                               ref->setParam("key", newkey);
                                }
                        }
                        break;
index c0df50b446f8fc61f2b84eb5f37c1fdf22842602..2c244ae2e11c224f20429b8eb764927084eeb404 100644 (file)
@@ -142,8 +142,8 @@ Inset * DocIterator::realInset() const
        LASSERT(inTexted(), /**/);
        // if we are in a tabular, we need the cell
        if (inset().lyxCode() == TABULAR_CODE) {
-               InsetTabular & tabular = static_cast<InsetTabular&>(inset());
-               return tabular.cell(idx()).get();
+               InsetTabular * tabular = inset().asInsetTabular();
+               return tabular->cell(idx()).get();
        }
        return &inset();
 }
index d96ddaeefea3d282cfab127f0add726f1b00e116..1e90a95cb1462cb618019b1486b62b032cae799e 100644 (file)
@@ -3096,8 +3096,8 @@ int Paragraph::checkBiblio(Buffer const & buffer)
        InsetList::iterator end = d->insetlist_.end();
        for (; it != end; ++it)
                if (it->inset->lyxCode() == BIBITEM_CODE
-                   && it->pos > 0) {
-                       InsetBibitem * olditem = static_cast<InsetBibitem *>(it->inset);
+                     && it->pos > 0) {
+                       InsetCommand * olditem = it->inset->asInsetCommand();
                        oldkey = olditem->getParam("key");
                        oldlabel = olditem->getParam("label");
                        erasedInsetPosition = it->pos;
@@ -3113,8 +3113,7 @@ int Paragraph::checkBiblio(Buffer const & buffer)
        // There was an InsetBibitem at the beginning and we did have to
        // erase one. So we give its properties to the beginning inset.
        if (hasbibitem) {
-               InsetBibitem * inset =
-                       static_cast<InsetBibitem *>(d->insetlist_.begin()->inset);
+               InsetCommand * inset = d->insetlist_.begin()->inset->asInsetCommand();
                if (!oldkey.empty())
                        inset->setParam("key", oldkey);
                inset->setParam("label", oldlabel);
@@ -3129,7 +3128,7 @@ int Paragraph::checkBiblio(Buffer const & buffer)
        if (!oldkey.empty())
                inset->setParam("key", oldkey);
        inset->setParam("label", oldlabel);
-       insertInset(0, static_cast<Inset *>(inset),
+       insertInset(0, inset,
                    Change(track_changes ? Change::INSERTED : Change::UNCHANGED));
 
        return 1;
index 5217dffd1aad3d0aae47b6a1c41457d7ed5e3e26..ce97f3a84c4dc144c70620ea0341b066095cbe25 100644 (file)
@@ -86,12 +86,10 @@ void InsetLabel::updateCommand(docstring const & new_label, bool updaterefs)
                for (; it != end; ++it) {
                        buffer().undo().recordUndo(it->second);
                        if (it->first->lyxCode() == MATH_REF_CODE) {
-                               InsetMathHull * mi =
-                                       static_cast<InsetMathHull *>(it->first);
+                               InsetMathHull * mi = it->first->asInsetMath()->asHullInset();
                                mi->asRefInset()->changeTarget(label);
                        } else {
-                               InsetCommand * ref =
-                                       static_cast<InsetCommand *>(it->first);
+                               InsetCommand * ref = it->first->asInsetCommand();
                                ref->setParam("reference", label);
                        }
                }
@@ -160,7 +158,7 @@ void InsetLabel::addToToc(DocIterator const & cpit)
                DocIterator const ref_pit(it->second);
                if (it->first->lyxCode() == MATH_REF_CODE)
                        toc.push_back(TocItem(ref_pit, 1,
-                               static_cast<InsetMathHull *>(it->first)->asRefInset()
+                               it->first->asInsetMath()->asHullInset()->asRefInset()
                                        ->screenLabel()));
                else
                        toc.push_back(TocItem(ref_pit, 1,
index e8b799db532bc9f2987e189864709124cf6a9289..a8483ea212cd0b07e91840dbfd05420282dc93e5 100644 (file)
@@ -23,8 +23,8 @@ MathAtom::MathAtom()
 {}
 
 
-MathAtom::MathAtom(Inset * p)
-       : nucleus_(static_cast<InsetMath *>(p))
+MathAtom::MathAtom(InsetMath * p)
+       : nucleus_(p)
 {}
 
 
index 3b3201db0c1847ed4366d127ee33a287e761e443..b11d75da182b3da122fae03dfbee869d0411773f 100644 (file)
@@ -51,7 +51,7 @@ public:
        /// std::containers
        MathAtom();
        /// the "real constructor"
-       explicit MathAtom(Inset * p);
+       explicit MathAtom(InsetMath * p);
        /// copy constructor, invokes nucleus_->clone()
        MathAtom(MathAtom const &);
        /// we really need to clean up