From 297b40c7259a552b8f6b164a6e5557820f0fcab7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Sat, 24 May 2003 11:54:10 +0000 Subject: [PATCH 1/1] make ParagraphList::push_back take a reference instead of a pointer. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7036 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 10 ++++- src/ParagraphList.C | 8 ++-- src/ParagraphList.h | 2 +- src/bufferlist.C | 6 +-- src/converter.C | 2 +- src/frontends/controllers/ChangeLog | 4 ++ src/frontends/controllers/ControlDocument.C | 4 +- src/insets/ChangeLog | 6 +++ src/insets/insettext.C | 41 ++++++++++++++++----- src/paragraph.C | 6 +++ src/paragraph.h | 2 + src/undo_funcs.C | 4 +- 12 files changed, 72 insertions(+), 23 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 32208912a1..7986fda635 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,9 +1,17 @@ 2003-05-24 Lars Gullik Bjønnes + * paragraph.[Ch] (id): new function + + * bufferlist.C (newFile): adjust + + * ParagraphList.C (ParagraphList): adjust + (assign): adjust + (push_back): take a reference instead of a pointer. + * paragraph.h: add NO_STD_LIST define, remove NO_NEXT define. * paragraph.C: remove all NO_NEXT node add some NO_STD_LIST parts - instead. + instead. * ParagraphList.h: degenerate to std::list if NO_STD_LIST is not set else use old code. diff --git a/src/ParagraphList.C b/src/ParagraphList.C index e375f0836f..9ebcdebe61 100644 --- a/src/ParagraphList.C +++ b/src/ParagraphList.C @@ -96,7 +96,7 @@ ParagraphList::ParagraphList(ParagraphList const & pl) ParagraphList::iterator it = pl.begin(); ParagraphList::iterator end = pl.end(); for (; it != end; ++it) { - push_back(new Paragraph(*it, false)); + push_back(*it); } } @@ -145,7 +145,7 @@ void ParagraphList::assign(iterator beg, iterator end) { clear(); for (; beg != end; ++beg) { - push_back(new Paragraph(*beg, false)); + push_back(*beg); } } @@ -277,8 +277,10 @@ Paragraph & ParagraphList::back() } -void ParagraphList::push_back(Paragraph * p) +void ParagraphList::push_back(Paragraph const & pr) { + Paragraph * p = new Paragraph(pr, false); + if (!parlist) { parlist = p; return; diff --git a/src/ParagraphList.h b/src/ParagraphList.h index 38b6ede88b..2251875ac9 100644 --- a/src/ParagraphList.h +++ b/src/ParagraphList.h @@ -85,7 +85,7 @@ public: /// iterator end() const; /// - void push_back(Paragraph *); + void push_back(Paragraph const &); /// Paragraph const & front() const; /// diff --git a/src/bufferlist.C b/src/bufferlist.C index 52928050f6..25faf205fb 100644 --- a/src/bufferlist.C +++ b/src/bufferlist.C @@ -362,7 +362,7 @@ Buffer * BufferList::readFile(string const & s, bool ronly) if (fileInfoA.getModificationTime() > fileInfo2.getModificationTime()) { string const file = MakeDisplayPath(s, 20); - string text = bformat(_("The backup of the document %1$s is newer.\n\n" + string text = bformat(_("The backup of the document %1$s is newer.\n\n" "Load the backup instead?"), file); int const ret = Alert::prompt(_("Load backup?"), text, 0, 1, _("&Load backup"), _("Load &original")); @@ -442,11 +442,11 @@ Buffer * BufferList::newFile(string const & name, string tname, bool isNamed) "could not be read."), file); Alert::error(_("Could not read template"), text); // no template, start with empty buffer - b->paragraphs.push_back(new Paragraph); + b->paragraphs.push_back(Paragraph()); b->paragraphs.begin()->layout(b->params.getLyXTextClass().defaultLayout()); } } else { // start with empty buffer - b->paragraphs.push_back(new Paragraph); + b->paragraphs.push_back(Paragraph()); b->paragraphs.begin()->layout(b->params.getLyXTextClass().defaultLayout()); } diff --git a/src/converter.C b/src/converter.C index 6ed16425ff..cd8a7ae10e 100644 --- a/src/converter.C +++ b/src/converter.C @@ -463,7 +463,7 @@ bool Converters::formatIsUsed(string const & format) } -bool Converters::scanLog(Buffer const * buffer, string const & command, +bool Converters::scanLog(Buffer const * buffer, string const & /*command*/, string const & filename) { if (!buffer) diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index 94e167e1cc..b6c83d3401 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,7 @@ +2003-05-24 Lars Gullik Bjønnes + + * ControlDocument.C (saveAsDefault): adjust + 2003-05-21 Alfredo Braunstein * ViewBase.h: diff --git a/src/frontends/controllers/ControlDocument.C b/src/frontends/controllers/ControlDocument.C index 1edecf88c6..58b6877adf 100644 --- a/src/frontends/controllers/ControlDocument.C +++ b/src/frontends/controllers/ControlDocument.C @@ -162,8 +162,8 @@ void ControlDocument::saveAsDefault() defaults.params = params(); // add an empty paragraph. Is this enough? - Paragraph * par = new Paragraph; - par->layout(params().getLyXTextClass().defaultLayout()); + Paragraph par; + par.layout(params().getLyXTextClass().defaultLayout()); defaults.paragraphs.push_back(par); defaults.writeFile(defaults.fileName()); diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 53ceb43519..807ade6e34 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,9 @@ +2003-05-24 Lars Gullik Bjønnes + + * insettext.C (InsetText): adjust + (clear): adjust + (setParagraphData): separate same_id cases, adjust + (appendParagraphs): adjust 2003-05-23 André Pönitz diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 383597720f..d74aea11de 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -139,7 +139,7 @@ InsetText::InsetText(BufferParams const & bp) : UpdatableInset(), lt(0), in_update(false), do_resize(0), do_reinit(false) { - paragraphs.push_back(new Paragraph); + paragraphs.push_back(Paragraph()); paragraphs.begin()->layout(bp.getLyXTextClass().defaultLayout()); if (bp.tracking_changes) paragraphs.begin()->trackChanges(); @@ -217,7 +217,7 @@ void InsetText::clear(bool just_mark_erased) LyXLayout_ptr old_layout = paragraphs.begin()->layout(); paragraphs.clear(); - paragraphs.push_back(new Paragraph); + paragraphs.push_back(Paragraph()); paragraphs.begin()->setInsetOwner(this); paragraphs.begin()->layout(old_layout); @@ -1945,13 +1945,34 @@ void InsetText::setParagraphData(ParagraphList const & plist, bool same_id) // we have to unlock any locked inset otherwise we're in troubles the_locking_inset = 0; - paragraphs.clear(); - ParagraphList::iterator pit = plist.begin(); - ParagraphList::iterator pend = plist.end(); - for (; pit != pend; ++pit) { - Paragraph * new_par = new Paragraph(*pit, same_id); - new_par->setInsetOwner(this); - paragraphs.push_back(new_par); + #warning CHECK not adhering to same_id here might wreck havoc (Lgb) + // But it it makes no difference that is a lot better. + if (same_id) { + lyxerr << "Same_id called with 'true'" << endl; + lyxerr << "Please report this to the list." << endl; + + paragraphs.clear(); + ParagraphList::iterator it = plist.begin(); + ParagraphList::iterator end = plist.end(); + for (; it != end; ++it) { + int const id = it->id(); + paragraphs.push_back(*it); + Paragraph & tmp = paragraphs.back(); + tmp.setInsetOwner(this); + tmp.id(id); + } + } else { +#warning FIXME. + // See if this can be simplified when std::list is in effect. + paragraphs.clear(); + + ParagraphList::iterator it = plist.begin(); + ParagraphList::iterator end = plist.end(); + for (; it != end; ++it) { + paragraphs.push_back(*it); + Paragraph & tmp = paragraphs.back(); + tmp.setInsetOwner(this); + } } reinitLyXText(); @@ -2635,7 +2656,7 @@ void InsetText::appendParagraphs(Buffer * buffer, ParagraphList & plist) ParagraphList::iterator pend = plist.end(); for (; pit != pend; ++pit) { - paragraphs.push_back(new Paragraph(*pit, false)); + paragraphs.push_back(*pit); } #endif diff --git a/src/paragraph.C b/src/paragraph.C index 605330f2ff..f5c2694036 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -1341,6 +1341,12 @@ int Paragraph::id() const } +void Paragraph::id(int i) +{ + pimpl_->id_ = i; +} + + LyXLayout_ptr const & Paragraph::layout() const { Inset * inset = inInset(); diff --git a/src/paragraph.h b/src/paragraph.h index 31362d94c5..c426e34132 100644 --- a/src/paragraph.h +++ b/src/paragraph.h @@ -90,6 +90,8 @@ public: /// return the unique ID of this paragraph int id() const; + /// Set the Id of this paragraph. + void id(int); /// int startTeXParParams(BufferParams const &, std::ostream &, bool) const; diff --git a/src/undo_funcs.C b/src/undo_funcs.C index f820005ebc..a352978977 100644 --- a/src/undo_funcs.C +++ b/src/undo_funcs.C @@ -168,7 +168,7 @@ bool textHandleUndo(BufferView * bv, Undo & undo) } */ } - + // Set the cursor for redoing // if we have a par before the first. if (before != null) { @@ -295,7 +295,7 @@ bool createUndo(BufferView * bv, Undo::undo_kind kind, // Create a new Undo. std::vector undo_pars; - for (ParagraphList::iterator it = *first; it != *last; ++it) + for (ParagraphList::iterator it = *first; it != *last; ++it) undo_pars.push_back(new Paragraph(*it, true)); undo_pars.push_back(new Paragraph(**last, true)); -- 2.39.5