From ac8cbdbddb7cf17fc717203b3fd9b93b31a3ee32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Thu, 8 Mar 2001 11:51:35 +0000 Subject: [PATCH] mathed48.diff git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1709 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/ChangeLog | 6 ++++++ src/mathed/math_matrixinset.C | 2 +- src/mathed/math_parser.C | 4 ++-- src/mathed/math_rowst.h | 39 +++++++++++++++++------------------ src/mathed/math_xiter.C | 34 +++++++++++++++++------------- src/mathed/math_xiter.h | 4 +++- 6 files changed, 51 insertions(+), 38 deletions(-) diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index ef6f886649..86046e7be0 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,9 @@ +2001-03-08 André Pönitz + * math_rowst.h: give MathedRowContainer an 'insert' method. + + * math_xiter.C: new 'container()' method to encapsulated access to + the MathParInset's MathedRowContainer + 2001-03-06 André Pönitz * array.[Ch]: factor out deep_copy, remove third argument from raw_pointer_insert diff --git a/src/mathed/math_matrixinset.C b/src/mathed/math_matrixinset.C index ee3393d06a..d791c11fe1 100644 --- a/src/mathed/math_matrixinset.C +++ b/src/mathed/math_matrixinset.C @@ -52,7 +52,7 @@ MathMatrixInset::MathMatrixInset(MathMatrixInset const & mt) if (!ro) row_ = r; else - ro->setNext(r); + ro->next_ = r; mrow = mrow->next_; ro = r; ++nr_; diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index a4c33ef978..ea084cc494 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -603,8 +603,8 @@ void mathed_parse(MathedArray & array, unsigned flags = 0, if (mt && (flags & FLAG_END)) { if (mt->Permit(LMPF_ALLOW_CR)) { if (crow) { - crow->setNext(new MathedRowSt(mt->GetColumns() + 1)); // this leaks - crow = crow->getNext(); + crow->next_ = new MathedRowSt(mt->GetColumns() + 1); + crow = crow->next_; } data.insert('K', LM_TC_CR); } else diff --git a/src/mathed/math_rowst.h b/src/mathed/math_rowst.h index 602198d309..373aff6bca 100644 --- a/src/mathed/math_rowst.h +++ b/src/mathed/math_rowst.h @@ -69,11 +69,6 @@ public: explicit MathedRowSt(int n) : MathedRowStruct(n), next_(0) {} - /// Should be const but... - MathedRowSt * getNext() const; - /// ...we couldn't use this. - void setNext(MathedRowSt * n); -//private: /// MathedRowSt * next_; }; @@ -90,7 +85,7 @@ struct MathedRowContainer { iterator() : st_(0) {} /// explicit iterator(MathedRowSt * st) : st_(st) {} - /// "better" conversion to bool + /// explicit iterator(MathedRowContainer * m) : st_(m->data_) {} /// "better" conversion to bool operator void *() const { return st_; } @@ -122,26 +117,30 @@ struct MathedRowContainer { /// bool empty() const { return data_ == 0; } + /// insert 'item' before 'iterator' + void insert(iterator const & pos, MathedRowSt const & item) { + MathedRowSt * st = new MathedRowSt(item); + link_before(pos, st); + } + + void link_before(iterator const & it, MathedRowSt * r) { + if (data_ == it.st_) + data_ = r; + else { + MathedRowSt * pos = data_; + if (pos->next_ == it.st_) + pos->next_ = r; + } + r->next_ = it.st_; + } + + /// MathedRowSt * data_; }; -inline -MathedRowSt * MathedRowSt::getNext() const -{ - return next_; -} - - -inline -void MathedRowSt::setNext(MathedRowSt * n) -{ - next_ = n; -} - - inline string const & MathedRowStruct::getLabel() const { diff --git a/src/mathed/math_xiter.C b/src/mathed/math_xiter.C index bc91d0a1fd..9e54961bf7 100644 --- a/src/mathed/math_xiter.C +++ b/src/mathed/math_xiter.C @@ -36,6 +36,12 @@ MathParInset * MathedXIter::getPar() const return p_; } +MathedRowContainer & MathedXIter::container() +{ + Assert(p_); + return p_->getRowSt(); +} + void MathedXIter::GetPos(int & xx, int & yy) const { @@ -122,7 +128,7 @@ void MathedXIter::Clean(int pos2) MathedRowContainer::iterator r = crow_; ++r; if (r) { - crow_.st_->setNext(r.st_->getNext()); + crow_.st_->next_ = r.st_->next_; delete r.st_; } } @@ -160,10 +166,10 @@ void MathedXIter::Merge(MathedArray const & a) if (p_ && p_->Permit(LMPF_ALLOW_CR)) { MathedRowContainer::iterator r( new MathedRowSt(ncols + 1) ); if (crow_) { - r.st_->setNext(crow_.st_->getNext()); - crow_.st_->setNext(r.st_); + r.st_->next_ = crow_.st_->next_; + crow_.st_->next_ = r.st_; } else { - r.st_->setNext(0); + r.st_->next_ = 0; } crow_ = r; } else { @@ -186,7 +192,7 @@ void MathedXIter::SetData(MathParInset * pp) x_ = y_ = 0; array = &p_->GetData(); ncols = p_->GetColumns(); - crow_ = p_->getRowSt().begin(); + crow_ = container().begin(); if (p_->Permit(LMPF_ALLOW_CR)) flags |= MthIF_CR; if (p_->Permit(LMPF_ALLOW_TAB)) @@ -240,7 +246,7 @@ bool MathedXIter::Next() } else if (c == LM_TC_CR && p_) { x_ = 0; - if (crow_ && crow_.st_->getNext()) { + if (crow_ && crow_.st_->next_) { ++crow_; y_ = crow_->getBaseline(); w = crow_->getTab(0); @@ -272,7 +278,7 @@ void MathedXIter::GoBegin() x_ = y_ = 0; sw_ = sx_ = 0; if (p_) { - crow_ = p_->getRowSt().begin(); + crow_ = container().begin(); if (crow_) { x_ = crow_->getTab(0); y_ = crow_->getBaseline(); @@ -375,11 +381,11 @@ void MathedXIter::addRow() // Create new item for the structure MathedRowContainer::iterator r( new MathedRowSt(ncols + 1) ); if (crow_) { - r.st_->setNext(crow_.st_->getNext()); - crow_.st_->setNext(r.st_); + r.st_->next_ = crow_.st_->next_; + crow_.st_->next_ = r.st_; } else { crow_ = r; - r.st_->setNext(0); + r.st_->next_ = 0; } // Fill missed tabs in current row while (col < ncols - 1) @@ -419,9 +425,9 @@ void MathedXIter::delRow() if (line_empty) { - MathedRowContainer::iterator r( crow_.st_->getNext() ); + MathedRowContainer::iterator r( crow_.st_->next_ ); if (r) { - crow_.st_->setNext(r.st_->getNext()); + crow_.st_->next_ = r.st_->next_; delete r.st_; } join(p1); @@ -447,7 +453,7 @@ void MathedXIter::ipop() x_ = stck.x; y_ = stck.y; if (p_) { - crow_ = p_->getRowSt().begin(); + crow_ = container().begin(); if (crow_) for (int i = 0; i < row; ++i) ++crow_; @@ -599,7 +605,7 @@ MathedRowSt * MathedXIter::adjustVerticalSt() if (col >= ncols) ncols = col + 1; MathedRowSt * r = new MathedRowSt(ncols + 1); // this leaks // r->next = crow_->next; - crow_.st_->setNext(r); + crow_.st_->next_ = r; crow_.st_ = r; // lyxerr << " CX[" << crow_ << "]"; } diff --git a/src/mathed/math_xiter.h b/src/mathed/math_xiter.h index f9ecd8c129..fb5201aafb 100644 --- a/src/mathed/math_xiter.h +++ b/src/mathed/math_xiter.h @@ -4,6 +4,7 @@ #include "math_iter.h" #include "math_rowst.h" +#include "math_rowst.h" class MathParInset; @@ -86,6 +87,8 @@ public: } private: + /// + MathedRowContainer & container(); /// This function is not recursive, as MathPar::Metrics is void IMetrics(int, int &, int &, int &); /// Font size (display, text, script, script2) @@ -106,7 +109,6 @@ private: bool limits_; /// MathedRowContainer::iterator crow_; - /// //friend class MathedCursor; };