X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2Fmath_iterator.C;h=2f949af5fda80cb362ba445df61446cbeda2ec30;hb=04076d27acff102a78e785841d05146f1135eed8;hp=8f508907e8bbed52a78ce3fe1d2307141bb078f0;hpb=a37064c0ac3b1e67b04a9480852f5c9e701fb4d9;p=lyx.git diff --git a/src/mathed/math_iterator.C b/src/mathed/math_iterator.C index 8f508907e8..2f949af5fd 100644 --- a/src/mathed/math_iterator.C +++ b/src/mathed/math_iterator.C @@ -1,84 +1,26 @@ -#ifdef __GNUG__ -#pragma implementation -#endif +/** + * \file math_iterator.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author André Pönitz + * + * Full author contact details are available in file CREDITS. + */ #include #include "math_iterator.h" #include "math_inset.h" -#include "debug.h" -#include "support/LAssert.h" +#include "math_data.h" - -MathIterator::MathIterator() -{} - - -MathIterator::MathIterator(MathInset * p) -{ - push(p); -} - - -MathInset const * MathIterator::par() const -{ - return back().par_; -} - - -MathInset * MathIterator::par() -{ - return back().par_; -} - - -MathArray const & MathIterator::cell() const -{ - MathCursorPos const & top = back(); - return top.par_->cell(top.idx_); -} - - - -void MathIterator::push(MathInset * p) -{ - //lyxerr << "push: " << p << endl; - push_back(MathCursorPos(p)); -} - - -void MathIterator::pop() -{ - //lyxerr << "pop: " << endl; - lyx::Assert(size()); - pop_back(); -} - - -MathCursorPos const & MathIterator::operator*() const -{ - return back(); -} - - -MathCursorPos const & MathIterator::operator->() const -{ - return back(); -} - - -void MathIterator::goEnd() -{ - MathCursorPos & top = back(); - top.idx_ = top.par_->nargs() - 1; - top.pos_ = cell().size(); -} +#include void MathIterator::operator++() { - MathCursorPos & top = back(); - MathArray & ar = top.par_->cell(top.idx_); + CursorSlice & top = back(); + MathArray & ar = top.asMathInset()->cell(top.idx_); // move into the current inset if possible // it is impossible for pos() == size()! @@ -86,7 +28,7 @@ void MathIterator::operator++() if (top.pos_ != ar.size()) n = (ar.begin() + top.pos_)->nucleus(); if (n && n->isActive()) { - push(n); + push_back(CursorSlice(n)); return; } @@ -98,10 +40,10 @@ void MathIterator::operator++() } // otherwise try to move on one cell if possible - while (top.idx_ + 1 < top.par_->nargs()) { + while (top.idx_ + 1 < top.asMathInset()->nargs()) { // idx() == nargs() is _not_ valid! ++top.idx_; - if (top.par_->validCell(top.idx_)) { + if (top.asMathInset()->validCell(top.idx_)) { top.pos_ = 0; return; } @@ -109,43 +51,12 @@ void MathIterator::operator++() // otherwise leave array, move on one back // this might yield pos() == size(), but that's a ok. - pop(); + pop_back(); // it certainly invalidates top ++back().pos_; } -void MathIterator::jump(difference_type i) -{ - back().pos_ += i; - //lyx::Assert(back().pos_ >= 0); - lyx::Assert(back().pos_ <= cell().size()); -} - - -/* -void MathIterator::shrink(size_type i) -{ - if (i < size()) - erase(begin() + i, end()); -} - - -void MathIterator::shrink(size_type i) -{ - if (i < size()) - erase(begin() + i, end()); -} -*/ - - -void MathIterator::shrink(size_type i) -{ - if (i < size()) - erase(begin() + i, end()); -} - - bool operator==(MathIterator const & it, MathIterator const & jt) { return MathIterator::base_type(it) == MathIterator::base_type(jt); @@ -160,13 +71,18 @@ bool operator!=(MathIterator const & it, MathIterator const & jt) MathIterator ibegin(MathInset * p) { - return MathIterator(p); + MathIterator it; + it.push_back(CursorSlice(p)); + return it; } MathIterator iend(MathInset * p) { - MathIterator it(p); - it.goEnd(); + MathIterator it; + it.push_back(CursorSlice(p)); + CursorSlice & top = it.back(); + top.idx_ = top.asMathInset()->nargs() - 1; + top.pos_ = top.asMathInset()->cell(top.idx_).size(); return it; }