From db707dab045d01f186a07c7da75d5b22de4e87c3 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Mon, 17 May 2004 11:28:31 +0000 Subject: [PATCH] remove now unnecessary const casts git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8757 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 14 +++++++++ src/CutAndPaste.C | 2 +- src/insets/ChangeLog | 4 +++ src/insets/insettabular.C | 2 +- src/insets/insettabular.h | 2 +- src/output_docbook.C | 6 ++-- src/output_latex.C | 60 +++++++++++++++++++-------------------- src/output_linuxdoc.C | 8 +++--- src/output_plaintext.C | 9 +++--- src/paragraph.C | 4 +-- src/paragraph.h | 2 +- src/paragraph_funcs.C | 4 +-- src/paragraph_pimpl.C | 4 +-- src/text.C | 4 +-- 14 files changed, 71 insertions(+), 54 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index b71e3d6c2d..52fb677a22 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,17 @@ +2004-05-17 Georg Baum + + * paragraph.C (startTeXParParams): correct column count + * CutAndPaste.C (pasteSelection): remove const_cast + * output_docbook.C (docbookParagraphs): remove const_cast + * output_latex.C (TeXEnvironment, TeXOnePar, TeXDeeper): remove + const_cast and return ParagraphList::const_iterator + * output_linuxdoc.C (linuxdocParagraphs): remove const_cast + * output_plaintext.C (writeFileAscii): remove const_cast + * paragraph.[Ch] (simpleTeXOnePar): make const + * paragraph_funcs.C (outerPar): use const iterators + * paragraph_pimpl.C (validate): use const iterators + * text.C (setHeightOfRow): use const iterators + 2004-05-17 Angus Leeming * lfuns.h: diff --git a/src/CutAndPaste.C b/src/CutAndPaste.C index 76bb471f82..dd9affac06 100644 --- a/src/CutAndPaste.C +++ b/src/CutAndPaste.C @@ -170,7 +170,7 @@ pasteSelectionHelper(Buffer const & buffer, ParagraphList & pars, switch (lit->inset->lyxCode()) { case InsetOld::TABULAR_CODE: { InsetTabular * it = static_cast(lit->inset); - it->buffer(const_cast(&buffer)); + it->buffer(&buffer); break; } diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index a9ee2c7ab7..c082574b2a 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,7 @@ +2004-05-15 Georg Baum + + * insettabular.[Ch] (buffer): make Buffer * argument const + 2004-05-17 Angus Leeming * insetcommand.C (priv_dispatch): act on receipt of LFUN_INSET_REFRESH diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 770d259e7f..edbe8a6277 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -183,7 +183,7 @@ Buffer const & InsetTabular::buffer() const } -void InsetTabular::buffer(Buffer * b) +void InsetTabular::buffer(Buffer const * b) { buffer_ = b; } diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index a12205c7d1..1e01bb7bd0 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -133,7 +133,7 @@ public: Buffer const & buffer() const; /// set the owning buffer - void buffer(Buffer * buf); + void buffer(Buffer const * buf); /// lock cell with given index void edit(LCursor & cur, bool left); /// diff --git a/src/output_docbook.C b/src/output_docbook.C index 77faddc5b1..de47d99b0f 100644 --- a/src/output_docbook.C +++ b/src/output_docbook.C @@ -64,8 +64,8 @@ void docbookParagraphs(Buffer const & buf, string item_tag; - ParagraphList::iterator par = const_cast(paragraphs).begin(); - ParagraphList::iterator pend = const_cast(paragraphs).end(); + ParagraphList::const_iterator par = paragraphs.begin(); + ParagraphList::const_iterator pend = paragraphs.end(); Counters & counters = buf.params().getLyXTextClass().counters(); @@ -219,7 +219,7 @@ void docbookParagraphs(Buffer const & buf, } par->simpleDocBookOnePar(buf, os, - outerFont(par - const_cast(paragraphs).begin(), paragraphs), + outerFont(par - paragraphs.begin(), paragraphs), runparams, depth + 1 + command_depth); // write closing SGML tags diff --git a/src/output_latex.C b/src/output_latex.C index 2a8b460249..cc4a7fb921 100644 --- a/src/output_latex.C +++ b/src/output_latex.C @@ -42,33 +42,33 @@ extern string bibitemWidest(Buffer const &); namespace { -ParagraphList::iterator +ParagraphList::const_iterator TeXEnvironment(Buffer const & buf, ParagraphList const & paragraphs, - ParagraphList::iterator pit, + ParagraphList::const_iterator pit, ostream & os, TexRow & texrow, OutputParams const & runparams); -ParagraphList::iterator +ParagraphList::const_iterator TeXOnePar(Buffer const & buf, ParagraphList const & paragraphs, - ParagraphList::iterator pit, + ParagraphList::const_iterator pit, ostream & os, TexRow & texrow, OutputParams const & runparams, string const & everypar = string()); -ParagraphList::iterator +ParagraphList::const_iterator TeXDeeper(Buffer const & buf, ParagraphList const & paragraphs, - ParagraphList::iterator pit, + ParagraphList::const_iterator pit, ostream & os, TexRow & texrow, OutputParams const & runparams) { lyxerr[Debug::LATEX] << "TeXDeeper... " << &*pit << endl; - ParagraphList::iterator par = pit; + ParagraphList::const_iterator par = pit; - while (par != const_cast(paragraphs).end() && + while (par != paragraphs.end() && par->params().depth() == pit->params().depth()) { if (par->layout()->isEnvironment()) { par = TeXEnvironment(buf, paragraphs, par, @@ -84,10 +84,10 @@ TeXDeeper(Buffer const & buf, } -ParagraphList::iterator +ParagraphList::const_iterator TeXEnvironment(Buffer const & buf, ParagraphList const & paragraphs, - ParagraphList::iterator pit, + ParagraphList::const_iterator pit, ostream & os, TexRow & texrow, OutputParams const & runparams) { @@ -100,7 +100,7 @@ TeXEnvironment(Buffer const & buf, Language const * language = pit->getParLanguage(bparams); Language const * doc_language = bparams.language; Language const * previous_language = - (pit != const_cast(paragraphs).begin()) + (pit != paragraphs.begin()) ? boost::prior(pit)->getParLanguage(bparams) : doc_language; if (language->babel() != previous_language->babel()) { @@ -141,11 +141,11 @@ TeXEnvironment(Buffer const & buf, os << style->latexparam() << '\n'; texrow.newline(); } - ParagraphList::iterator par = pit; + ParagraphList::const_iterator par = pit; do { par = TeXOnePar(buf, paragraphs, par, os, texrow, runparams); - if (par == const_cast(paragraphs).end()) { + if (par == paragraphs.end()) { // Make sure that the last paragraph is // correctly terminated (because TeXOnePar does // not add a \n in this case) @@ -174,7 +174,7 @@ TeXEnvironment(Buffer const & buf, par = TeXDeeper(buf, paragraphs, par, os, texrow, runparams); } - } while (par != const_cast(paragraphs).end() + } while (par != paragraphs.end() && par->layout() == pit->layout() && par->params().depth() == pit->params().depth() && par->params().leftIndent() == pit->params().leftIndent()); @@ -209,10 +209,10 @@ InsetOptArg * optArgInset(Paragraph const & par) } -ParagraphList::iterator +ParagraphList::const_iterator TeXOnePar(Buffer const & buf, ParagraphList const & paragraphs, - ParagraphList::iterator pit, + ParagraphList::const_iterator pit, ostream & os, TexRow & texrow, OutputParams const & runparams, string const & everypar) @@ -236,7 +236,7 @@ TeXOnePar(Buffer const & buf, } if (!pit->params().spacing().isDefault() - && (pit == const_cast(paragraphs).begin() + && (pit == paragraphs.begin() || !boost::prior(pit)->hasSameLayout(*pit))) { os << pit->params().spacing().writeEnvirBegin() << '\n'; @@ -259,14 +259,14 @@ TeXOnePar(Buffer const & buf, Language const * language = pit->getParLanguage(bparams); Language const * doc_language = bparams.language; Language const * previous_language = - (pit != const_cast(paragraphs).begin()) + (pit != paragraphs.begin()) ? boost::prior(pit)->getParLanguage(bparams) : doc_language; if (language->babel() != previous_language->babel() // check if we already put language command in TeXEnvironment() && !(style->isEnvironment() - && (pit == const_cast(paragraphs).begin() || + && (pit == paragraphs.begin() || (boost::prior(pit)->layout() != pit->layout() && boost::prior(pit)->getDepth() <= pit->getDepth()) || boost::prior(pit)->getDepth() < pit->getDepth()))) @@ -324,7 +324,7 @@ TeXOnePar(Buffer const & buf, os << everypar; bool need_par = pit->simpleTeXOnePar(buf, bparams, - outerFont(pit - const_cast(paragraphs).begin(), paragraphs), + outerFont(pit - paragraphs.begin(), paragraphs), os, texrow, runparams); // Make sure that \\par is done with the font of the last @@ -337,7 +337,7 @@ TeXOnePar(Buffer const & buf, // We do not need to use to change the font for the last paragraph // or for a command. LyXFont const outerfont = - outerFont(pit - const_cast(paragraphs).begin(), + outerFont(pit - paragraphs.begin(), paragraphs); LyXFont const font = @@ -348,7 +348,7 @@ paragraphs); bool is_command = style->isCommand(); if (style->resfont.size() != font.size() - && boost::next(pit) != const_cast(paragraphs).end() + && boost::next(pit) != paragraphs.end() && !is_command) { if (!need_par) os << '{'; @@ -361,7 +361,7 @@ paragraphs); switch (style->latextype) { case LATEX_ITEM_ENVIRONMENT: case LATEX_LIST_ENVIRONMENT: - if (boost::next(pit) != const_cast(paragraphs).end() + if (boost::next(pit) != paragraphs.end() && (pit->params().depth() < boost::next(pit)->params().depth())) { os << '\n'; texrow.newline(); @@ -370,9 +370,9 @@ paragraphs); case LATEX_ENVIRONMENT: { // if its the last paragraph of the current environment // skip it otherwise fall through - ParagraphList::iterator next = boost::next(pit); + ParagraphList::const_iterator next = boost::next(pit); - if (next != const_cast(paragraphs).end() + if (next != paragraphs.end() && (next->layout() != pit->layout() || next->params().depth() != pit->params().depth())) break; @@ -381,7 +381,7 @@ paragraphs); // fall through possible default: // we don't need it for the last paragraph!!! - if (boost::next(pit) != const_cast(paragraphs).end()) { + if (boost::next(pit) != paragraphs.end()) { os << '\n'; texrow.newline(); } @@ -415,7 +415,7 @@ paragraphs); } if (!pit->params().spacing().isDefault() - && (boost::next(pit) == const_cast(paragraphs).end() + && (boost::next(pit) == paragraphs.end() || !boost::next(pit)->hasSameLayout(*pit))) { os << pit->params().spacing().writeEnvirEnd() << '\n'; @@ -426,7 +426,7 @@ paragraphs); // we don't need it for the last paragraph!!! // Note from JMarc: we will re-add a \n explicitely in // TeXEnvironment, because it is needed in this case - if (boost::next(pit) != const_cast(paragraphs).end()) { + if (boost::next(pit) != paragraphs.end()) { os << '\n'; texrow.newline(); } @@ -449,8 +449,8 @@ void latexParagraphs(Buffer const & buf, bool was_title = false; bool already_title = false; LyXTextClass const & tclass = buf.params().getLyXTextClass(); - ParagraphList::iterator par = const_cast(paragraphs).begin(); - ParagraphList::iterator endpar = const_cast(paragraphs).end(); + ParagraphList::const_iterator par = paragraphs.begin(); + ParagraphList::const_iterator endpar = paragraphs.end(); // if only_body while (par != endpar) { diff --git a/src/output_linuxdoc.C b/src/output_linuxdoc.C index c51f2f2c63..44e1cd6ee9 100644 --- a/src/output_linuxdoc.C +++ b/src/output_linuxdoc.C @@ -41,13 +41,13 @@ void linuxdocParagraphs(Buffer const & buf, string item_name; vector environment_stack(5); - ParagraphList::iterator pit = const_cast(paragraphs).begin(); - ParagraphList::iterator pend = const_cast(paragraphs).end(); + ParagraphList::const_iterator pit = paragraphs.begin(); + ParagraphList::const_iterator pend = paragraphs.end(); for (; pit != pend; ++pit) { LyXLayout_ptr const & style = pit->layout(); // treat as a special case for compatibility with old code if (pit->isInset(0)) { - InsetBase * inset = pit->getInset(0); + InsetBase const * inset = pit->getInset(0); if (inset->lyxCode() == InsetOld::TOC_CODE) { string const temp = "toc"; sgml::openTag(os, depth, false, temp); @@ -136,7 +136,7 @@ void linuxdocParagraphs(Buffer const & buf, } pit->simpleLinuxDocOnePar(buf, os, - outerFont(pit - const_cast(paragraphs).begin(), paragraphs), + outerFont(pit - paragraphs.begin(), paragraphs), runparams, depth); os << "\n"; diff --git a/src/output_plaintext.C b/src/output_plaintext.C index a3f23e9d68..09329d20b5 100644 --- a/src/output_plaintext.C +++ b/src/output_plaintext.C @@ -55,11 +55,10 @@ void writeFileAscii(Buffer const & buf, void writeFileAscii(Buffer const & buf, ostream & os, OutputParams const & runparams) { - Buffer & tmp = const_cast(buf); - ParagraphList par = const_cast(tmp.paragraphs()); - ParagraphList::iterator beg = par.begin(); - ParagraphList::iterator end = par.end(); - ParagraphList::iterator it = beg; + ParagraphList const par = buf.paragraphs(); + ParagraphList::const_iterator beg = par.begin(); + ParagraphList::const_iterator end = par.end(); + ParagraphList::const_iterator it = beg; for (; it != end; ++it) { asciiParagraph(buf, *it, os, runparams, it == beg); } diff --git a/src/paragraph.C b/src/paragraph.C index ede6729f74..ac356aa78b 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -784,7 +784,7 @@ int Paragraph::startTeXParParams(BufferParams const & bparams, case LYX_ALIGN_CENTER: if (moving_arg) { os << "\\protect"; - column = 8; + column += 8; } break; } @@ -890,7 +890,7 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf, BufferParams const & bparams, LyXFont const & outerfont, ostream & os, TexRow & texrow, - OutputParams const & runparams) + OutputParams const & runparams) const { lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl; diff --git a/src/paragraph.h b/src/paragraph.h index ec25e15222..8968fb2abf 100644 --- a/src/paragraph.h +++ b/src/paragraph.h @@ -118,7 +118,7 @@ public: /// bool simpleTeXOnePar(Buffer const &, BufferParams const &, LyXFont const & outerfont, std::ostream &, - TexRow & texrow, OutputParams const &); + TexRow & texrow, OutputParams const &) const; /// void simpleLinuxDocOnePar(Buffer const & buf, diff --git a/src/paragraph_funcs.C b/src/paragraph_funcs.C index 09072f861b..86db8b948b 100644 --- a/src/paragraph_funcs.C +++ b/src/paragraph_funcs.C @@ -306,8 +306,8 @@ par_type outerPar(Buffer const & buf, InsetBase const * inset) if (&text->paragraphs() == &pit.plist()) return pit.outerPar(); - InsetList::iterator ii = pit->insetlist.begin(); - InsetList::iterator iend = pit->insetlist.end(); + InsetList::const_iterator ii = pit->insetlist.begin(); + InsetList::const_iterator iend = pit->insetlist.end(); for ( ; ii != iend; ++ii) if (ii->inset == inset) return pit.outerPar(); diff --git a/src/paragraph_pimpl.C b/src/paragraph_pimpl.C index d12f6b491e..10460fcaa8 100644 --- a/src/paragraph_pimpl.C +++ b/src/paragraph_pimpl.C @@ -780,8 +780,8 @@ void Paragraph::Pimpl::validate(LaTeXFeatures & features, features.require("ParagraphLeftIndent"); // then the insets - InsetList::iterator icit = owner_->insetlist.begin(); - InsetList::iterator iend = owner_->insetlist.end(); + InsetList::const_iterator icit = owner_->insetlist.begin(); + InsetList::const_iterator iend = owner_->insetlist.end(); for (; icit != iend; ++icit) { if (icit->inset) { icit->inset->validate(features); diff --git a/src/text.C b/src/text.C index 797f796823..4e5e5ef7df 100644 --- a/src/text.C +++ b/src/text.C @@ -917,8 +917,8 @@ void LyXText::setHeightOfRow(par_type pit, Row & row) int maxdesc = int(font_metrics::maxDescent(font) * spacing_val); // insets may be taller - InsetList::iterator ii = pars_[pit].insetlist.begin(); - InsetList::iterator iend = pars_[pit].insetlist.end(); + InsetList::const_iterator ii = pars_[pit].insetlist.begin(); + InsetList::const_iterator iend = pars_[pit].insetlist.end(); for ( ; ii != iend; ++ii) { if (ii->pos >= row.pos() && ii->pos < row.endpos()) { maxasc = max(maxasc, ii->inset->ascent()); -- 2.39.2