mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-25 19:07:45 +00:00
Remove some unnecessary static_casts and add two FIXMEs about casts that don't look safe.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35856 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
573500dd04
commit
07924ac300
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
@ -23,8 +23,8 @@ MathAtom::MathAtom()
|
||||
{}
|
||||
|
||||
|
||||
MathAtom::MathAtom(Inset * p)
|
||||
: nucleus_(static_cast<InsetMath *>(p))
|
||||
MathAtom::MathAtom(InsetMath * p)
|
||||
: nucleus_(p)
|
||||
{}
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user