-
#include <config.h>
#include "math_iterator.h"
}
-MathXArray const & MathIterator::xcell() const
-{
- return par()->xcell(position().idx_);
-}
-
-
MathArray const & MathIterator::cell() const
{
- return par()->xcell(position().idx_).data_;
+ MathCursorPos const & top = position();
+ return top.par_->cell(top.idx_);
}
-MathInset * MathIterator::nextInset() const
-{
- if (position().pos_ == xcell().data_.size())
- return 0;
- return (xcell().begin() + position().pos_)->nucleus();
-}
-
void MathIterator::push(MathInset * p)
{
void MathIterator::goEnd()
{
- position().idx_ = par()->nargs() - 1;
- position().pos_ = xcell().data_.size();
+ MathCursorPos & top = position();
+ top.idx_ = top.par_->nargs() - 1;
+ top.pos_ = cell().size();
}
void MathIterator::operator++()
{
+ MathCursorPos & top = position();
+ MathArray const & ar = top.par_->cell(top.idx_);
+
// move into the current inset if possible
// it is impossible for pos() == size()!
- MathInset * n = nextInset();
+ MathInset * n = 0;
+ if (top.pos_ != ar.size())
+ n = (ar.begin() + top.pos_)->nucleus();
if (n && n->isActive()) {
push(n);
return;
}
// otherwise move on one cell position if possible
- MathCursorPos & top = position();
- if (top.pos_ < top.par_->cell(top.idx_).size()) {
+ if (top.pos_ < ar.size()) {
// pos() == size() is valid!
++top.pos_;
return;
}
- // otherwise move on one cell if possible
- if (top.idx_ + 1 < top.par_->nargs()) {
+ // otherwise try to move on one cell if possible
+ while (top.idx_ + 1 < top.par_->nargs()) {
// idx() == nargs() is _not_ valid!
++top.idx_;
- top.pos_ = 0;
- return;
+ if (top.par_->validCell(top.idx_)) {
+ top.pos_ = 0;
+ return;
+ }
}
// otherwise leave array, move on one position
// this might yield pos() == size(), but that's a ok.
+ pop();
// it certainly invalidates top
- pop();
++position().pos_;
}
//lyxerr << "==: " << it.cursor().size() << " " << jt.cursor().size() << endl;
if (it.cursor().size() != jt.cursor().size())
return false;
- return it.cursor() == jt.cursor();
+ return it.cursor() == jt.cursor();
}
//lyxerr << "!=: " << it.cursor().size() << " " << jt.cursor().size() << endl;
if (it.cursor().size() != jt.cursor().size())
return true;
- return it.cursor() != jt.cursor();
+ return it.cursor() != jt.cursor();
}