From 27de8d9ee09052dc32a9ecae529780e0256cffab Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Fri, 23 May 2003 22:42:14 +0000 Subject: [PATCH] get rid of NO_NEXT add some NO_STD_LIST instead git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7035 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 15 +++++- src/ParagraphList.C | 125 ++------------------------------------------ src/ParagraphList.h | 17 +++++- src/paragraph.C | 58 +------------------- src/paragraph.h | 29 ++-------- 5 files changed, 39 insertions(+), 205 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 51bb95b09c..32208912a1 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,16 @@ +2003-05-24 Lars Gullik Bjønnes + + * 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. + + * ParagraphList.h: degenerate to std::list if NO_STD_LIST is not + set else use old code. + + * ParagraphList.C: remove all NO_NEXT code and only compile this + code of NO_STD_LIST is set. + 2003-05-23 Alfredo Braunstein * BufferView_pimpl.C: @@ -20,7 +33,7 @@ 2003-05-23 Lars Gullik Bjønnes - * ParagraphList.h (set): remove unused function. + * ParagraphList.h (set): remove unused function. 2003-05-23 André Pönitz diff --git a/src/ParagraphList.C b/src/ParagraphList.C index 86450c14ad..e375f0836f 100644 --- a/src/ParagraphList.C +++ b/src/ParagraphList.C @@ -4,6 +4,8 @@ #include "paragraph.h" +#ifdef NO_STD_LIST + ////////// The ParagraphList::iterator ParagraphList::iterator::iterator() @@ -33,11 +35,7 @@ ParagraphList::iterator::operator->() ParagraphList::iterator & ParagraphList::iterator::operator++() { -#ifndef NO_NEXT - ptr = ptr->next_; -#else ptr = ptr->next_par_; -#endif return *this; } @@ -54,11 +52,7 @@ ParagraphList::iterator::operator++(int) ParagraphList::iterator & ParagraphList::iterator::operator--() { -#ifndef NO_NEXT - ptr = ptr->previous_; -#else ptr = ptr->prev_par_; -#endif return *this; } @@ -118,25 +112,6 @@ ParagraphList & ParagraphList::operator=(ParagraphList const & rhs) ParagraphList::iterator ParagraphList::insert(ParagraphList::iterator it, Paragraph * par) { -#ifndef NO_NEXT - if (it != end()) { - Paragraph * prev = it->previous_; - par->next_ = &*it; - par->previous_ = prev; - prev->next_ = par; - it->previous_ = par; - } else if (parlist == 0) { - parlist = par; - } else { - // Find last par. - Paragraph * last = parlist; - while (last->next_) - last = last->next_; - last->next_ = par; - par->previous_ = last; - } - return iterator(par); -#else if (it != end()) { Paragraph * prev = it->prev_par_; par->next_par_ = &*it; @@ -154,7 +129,6 @@ ParagraphList::insert(ParagraphList::iterator it, Paragraph * par) par->prev_par_ = last; } return iterator(par); -#endif } @@ -183,33 +157,6 @@ void ParagraphList::splice(iterator pos, ParagraphList & pl) Paragraph * first = pl.parlist; Paragraph * last = first; -#ifndef NO_NEXT - while (last->next_) - last = last->next_; - - if (pos == end()) { - if (parlist == 0) { - parlist = first; - } else { - Paragraph * last_par = &back(); - last_par->next_ = first; - first->previous_ = last_par; - } - } else if (pos == begin()) { - last->next_ = parlist; - parlist->previous_ = last; - parlist = first; - } else { - Paragraph * pos_par = &*pos; - Paragraph * before_pos = pos_par->previous_; - - before_pos->next_ = first; - first->previous_ = before_pos; - last->next_ = pos_par; - pos_par->previous_ = last; - } - pl.parlist = 0; -#else while (last->next_par_) last = last->next_par_; @@ -235,47 +182,21 @@ void ParagraphList::splice(iterator pos, ParagraphList & pl) pos_par->prev_par_ = last; } pl.parlist = 0; -#endif } void ParagraphList::clear() { -#ifndef NO_NEXT - while (parlist) { - Paragraph * tmp = parlist->next_; - delete parlist; - parlist = tmp; - } -#else while (parlist) { Paragraph * tmp = parlist->next_par_; delete parlist; parlist = tmp; } -#endif } ParagraphList::iterator ParagraphList::erase(ParagraphList::iterator it) { -#ifndef NO_NEXT - Paragraph * prev = it->previous_; - Paragraph * next = it->next_; - - if (prev) - prev->next_ = next; - else - parlist = next; - - if (next) - next->previous_ = prev; - - it->previous_ = 0; - it->next_ = 0; - delete &*it; - return next; -#else Paragraph * prev = it->prev_par_; Paragraph * next = it->next_par_; @@ -289,7 +210,6 @@ ParagraphList::iterator ParagraphList::erase(ParagraphList::iterator it) delete &*it; return next; -#endif } @@ -341,50 +261,24 @@ Paragraph & ParagraphList::front() Paragraph const & ParagraphList::back() const { -#ifndef NO_NEXT - Paragraph * tmp = parlist; - while (tmp->next_) - tmp = tmp->next_; - return *tmp; -#else Paragraph * tmp = parlist; while (tmp->next_par_) tmp = tmp->next_par_; return *tmp; -#endif } Paragraph & ParagraphList::back() { -#ifndef NO_NEXT - Paragraph * tmp = parlist; - while (tmp->next_) - tmp = tmp->next_; - return *tmp; -#else Paragraph * tmp = parlist; while (tmp->next_par_) tmp = tmp->next_par_; return *tmp; -#endif } void ParagraphList::push_back(Paragraph * p) { -#ifndef NO_NEXT - if (!parlist) { - parlist = p; - return; - } - - Paragraph * pos = parlist; - while (pos->next_) - pos = pos->next_; - pos->next_ = p; - p->previous_ = pos; -#else if (!parlist) { parlist = p; return; @@ -395,23 +289,11 @@ void ParagraphList::push_back(Paragraph * p) pos = pos->next_par_; pos->next_par_ = p; p->prev_par_ = pos; -#endif } int ParagraphList::size() const { -#ifndef NO_NEXT - // When we switch to a std::container this will be O(1) - // instead of O(n). (Lgb) - Paragraph * tmp = parlist; - int c = 0; - while (tmp) { - ++c; - tmp = tmp->next_; - } - return c; -#else // When we switch to a std::container this will be O(1) // instead of O(n). (Lgb) Paragraph * tmp = parlist; @@ -421,7 +303,6 @@ int ParagraphList::size() const tmp = tmp->next_par_; } return c; -#endif } @@ -429,3 +310,5 @@ bool ParagraphList::empty() const { return parlist == 0; } + +#endif diff --git a/src/ParagraphList.h b/src/ParagraphList.h index 08f60640a5..38b6ede88b 100644 --- a/src/ParagraphList.h +++ b/src/ParagraphList.h @@ -3,11 +3,23 @@ #ifndef PARAGRAPH_LIST_H #define PARAGRAPH_LIST_H -#include -#include +#define NO_STD_LIST 1 + +#ifndef NO_STD_LIST + +#include "paragraph.h" + +#include + +typedef std::list ParagraphList; + +#else class Paragraph; +#include +#include + /// class ParagraphList { public: @@ -104,5 +116,6 @@ bool operator==(ParagraphList::iterator const & i1, bool operator!=(ParagraphList::iterator const & i1, ParagraphList::iterator const & i2); +#endif #endif diff --git a/src/paragraph.C b/src/paragraph.C index 4d87ad7ba8..605330f2ff 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -73,10 +73,7 @@ extern BufferView * current_view; Paragraph::Paragraph() : pimpl_(new Paragraph::Pimpl(this)) { -#ifndef NO_NEXT - next_ = 0; - previous_ = 0; -#else +#ifdef NO_STD_LIST next_par_ = 0; prev_par_ = 0; #endif @@ -91,10 +88,7 @@ Paragraph::Paragraph(Paragraph const & lp, bool same_ids) { enumdepth = 0; itemdepth = 0; -#ifndef NO_NEXT - next_ = 0; - previous_ = 0; -#else +#ifdef NO_STD_LIST next_par_ = 0; prev_par_ = 0; #endif @@ -118,13 +112,6 @@ Paragraph::Paragraph(Paragraph const & lp, bool same_ids) // the destructor removes the new paragraph from the list Paragraph::~Paragraph() { -#ifndef NO_NEXT - if (previous_) - previous_->next_ = next_; - if (next_) - next_->previous_ = previous_; -#endif - delete pimpl_; // //lyxerr << "Paragraph::paragraph_id = " @@ -612,47 +599,6 @@ void Paragraph::setFont(pos_type pos, LyXFont const & font) } -#ifndef NO_NEXT -void Paragraph::next(Paragraph * p) -{ - next_ = p; -} - - -// This function is able to hide closed footnotes. -Paragraph * Paragraph::next() -{ - return next_; -} - - -Paragraph const * Paragraph::next() const -{ - return next_; -} - - -void Paragraph::previous(Paragraph * p) -{ - previous_ = p; -} - - -// This function is able to hide closed footnotes. -Paragraph * Paragraph::previous() -{ - return previous_; -} - - -// This function is able to hide closed footnotes. -Paragraph const * Paragraph::previous() const -{ - return previous_; -} -#endif - - void Paragraph::makeSameLayout(Paragraph const & par) { layout(par.layout()); diff --git a/src/paragraph.h b/src/paragraph.h index 3b822aa561..31362d94c5 100644 --- a/src/paragraph.h +++ b/src/paragraph.h @@ -34,15 +34,16 @@ class TexRow; // Define this if you want to try out the new storage container for // paragraphs. (Lgb) // This is non working and far from finished. -#define NO_NEXT 1 +#define NO_STD_LIST 1 /// A Paragraph holds all text, attributes and insets in a text paragraph class Paragraph { public: +#ifdef NO_STD_LIST // Remove this whan ParagraphList transition is over. (Lgb) friend class ParagraphList; friend class ParagraphList::iterator; - +#endif /// enum META_KIND { /// Note that this is 1 right now to avoid @@ -140,23 +141,6 @@ public: /// InsetBibitem * bibitem(); // ale970302 -#ifndef NO_NEXT - /// - void next(Paragraph *); - /** these function are able to hide closed footnotes - */ - Paragraph * next(); - /// - Paragraph const * next() const; - - /// - void previous(Paragraph *); - /// - Paragraph * previous(); - /// - Paragraph const * previous() const; -#endif - /// initialise tracking for this par void trackChanges(Change::Type = Change::UNCHANGED); @@ -318,12 +302,7 @@ private: LyXLayout_ptr layout_; /// if anything uses this we don't want it to. Paragraph(Paragraph const &); -#ifndef NO_NEXT - /// - Paragraph * next_; - /// - Paragraph * previous_; -#else +#ifdef NO_STD_LIST Paragraph * next_par_; Paragraph * prev_par_; #endif -- 2.39.2