2001-12-05 17:50:18 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "math_iterator.h"
|
2001-12-10 10:09:00 +00:00
|
|
|
#include "debug.h"
|
|
|
|
#include "support/LAssert.h"
|
2001-12-05 17:50:18 +00:00
|
|
|
|
|
|
|
|
2001-12-10 10:09:00 +00:00
|
|
|
//MathIterator::MathIterator()
|
|
|
|
//{}
|
2001-12-05 17:50:18 +00:00
|
|
|
|
|
|
|
|
2001-12-11 15:35:18 +00:00
|
|
|
MathIterator::MathIterator(MathInset * p)
|
2001-12-05 17:50:18 +00:00
|
|
|
{
|
2001-12-11 15:35:18 +00:00
|
|
|
push(p);
|
2001-12-05 17:50:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-11 15:35:18 +00:00
|
|
|
//MathIterator::MathIterator(MathCursor::cursor_type const & c)
|
|
|
|
// : cursor_(c)
|
|
|
|
//{}
|
2001-12-05 17:50:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
MathCursor::cursor_type const & MathIterator::cursor() const
|
|
|
|
{
|
|
|
|
return cursor_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-11 15:35:18 +00:00
|
|
|
MathInset const * MathIterator::par() const
|
2001-12-10 10:09:00 +00:00
|
|
|
{
|
2001-12-11 15:35:18 +00:00
|
|
|
return position().par_;
|
2001-12-10 10:09:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-11 15:35:18 +00:00
|
|
|
MathInset * MathIterator::par()
|
2001-12-05 17:50:18 +00:00
|
|
|
{
|
2001-12-11 15:35:18 +00:00
|
|
|
return position().par_;
|
2001-12-05 17:50:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-03 09:41:26 +00:00
|
|
|
MathArray const & MathIterator::cell() const
|
|
|
|
{
|
2002-03-12 16:11:51 +00:00
|
|
|
MathCursorPos const & top = position();
|
|
|
|
return top.par_->cell(top.idx_);
|
2002-01-03 09:41:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-05 17:50:18 +00:00
|
|
|
|
2001-12-11 15:35:18 +00:00
|
|
|
void MathIterator::push(MathInset * p)
|
2001-12-05 17:50:18 +00:00
|
|
|
{
|
|
|
|
//lyxerr << "push: " << p << endl;
|
2001-12-11 15:35:18 +00:00
|
|
|
cursor_.push_back(MathCursorPos(p));
|
2001-12-05 17:50:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathIterator::pop()
|
|
|
|
{
|
|
|
|
//lyxerr << "pop: " << endl;
|
2001-12-10 10:09:00 +00:00
|
|
|
lyx::Assert(cursor_.size());
|
2001-12-05 17:50:18 +00:00
|
|
|
cursor_.pop_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathCursorPos const & MathIterator::operator*() const
|
|
|
|
{
|
|
|
|
return position();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathCursorPos const & MathIterator::operator->() const
|
|
|
|
{
|
|
|
|
return position();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-10 10:09:00 +00:00
|
|
|
void MathIterator::goEnd()
|
|
|
|
{
|
2002-03-12 16:11:51 +00:00
|
|
|
MathCursorPos & top = position();
|
|
|
|
top.idx_ = top.par_->nargs() - 1;
|
|
|
|
top.pos_ = cell().size();
|
2001-12-10 10:09:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-05 17:50:18 +00:00
|
|
|
void MathIterator::operator++()
|
|
|
|
{
|
2002-03-12 16:11:51 +00:00
|
|
|
MathCursorPos & top = position();
|
|
|
|
MathArray const & ar = top.par_->cell(top.idx_);
|
|
|
|
|
2001-12-05 17:50:18 +00:00
|
|
|
// move into the current inset if possible
|
|
|
|
// it is impossible for pos() == size()!
|
2002-03-12 16:11:51 +00:00
|
|
|
MathInset * n = 0;
|
|
|
|
if (top.pos_ != ar.size())
|
|
|
|
n = (ar.begin() + top.pos_)->nucleus();
|
2002-03-12 14:59:08 +00:00
|
|
|
if (n && n->isActive()) {
|
|
|
|
push(n);
|
2001-12-05 17:50:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// otherwise move on one cell position if possible
|
2002-03-12 16:11:51 +00:00
|
|
|
if (top.pos_ < ar.size()) {
|
2001-12-05 17:50:18 +00:00
|
|
|
// pos() == size() is valid!
|
2002-03-12 14:59:08 +00:00
|
|
|
++top.pos_;
|
2001-12-05 17:50:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-03-18 11:45:53 +00:00
|
|
|
// otherwise try to move on one cell if possible
|
|
|
|
while (top.idx_ + 1 < top.par_->nargs()) {
|
2001-12-05 17:50:18 +00:00
|
|
|
// idx() == nargs() is _not_ valid!
|
2002-03-12 14:59:08 +00:00
|
|
|
++top.idx_;
|
2002-03-18 11:45:53 +00:00
|
|
|
if (top.par_->validCell(top.idx_)) {
|
|
|
|
top.pos_ = 0;
|
|
|
|
return;
|
|
|
|
}
|
2001-12-05 17:50:18 +00:00
|
|
|
}
|
|
|
|
|
2001-12-10 10:09:00 +00:00
|
|
|
// otherwise leave array, move on one position
|
2001-12-05 17:50:18 +00:00
|
|
|
// this might yield pos() == size(), but that's a ok.
|
2002-03-12 14:59:08 +00:00
|
|
|
pop();
|
2002-03-12 16:11:51 +00:00
|
|
|
// it certainly invalidates top
|
2001-12-05 17:50:18 +00:00
|
|
|
++position().pos_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-08 11:03:34 +00:00
|
|
|
void MathIterator::jump(MathInset::difference_type i)
|
2002-01-03 09:41:26 +00:00
|
|
|
{
|
|
|
|
position().pos_ += i;
|
2002-01-08 11:03:34 +00:00
|
|
|
//lyx::Assert(position().pos_ >= 0);
|
2002-01-03 09:41:26 +00:00
|
|
|
lyx::Assert(position().pos_ <= cell().size());
|
|
|
|
}
|
|
|
|
|
2001-12-05 17:50:18 +00:00
|
|
|
|
|
|
|
bool operator==(MathIterator const & it, MathIterator const & jt)
|
|
|
|
{
|
|
|
|
//lyxerr << "==: " << it.cursor().size() << " " << jt.cursor().size() << endl;
|
|
|
|
if (it.cursor().size() != jt.cursor().size())
|
|
|
|
return false;
|
|
|
|
return it.cursor() == jt.cursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool operator!=(MathIterator const & it, MathIterator const & jt)
|
|
|
|
{
|
|
|
|
//lyxerr << "!=: " << it.cursor().size() << " " << jt.cursor().size() << endl;
|
|
|
|
if (it.cursor().size() != jt.cursor().size())
|
|
|
|
return true;
|
|
|
|
return it.cursor() != jt.cursor();
|
|
|
|
}
|
|
|
|
|
2001-12-10 10:09:00 +00:00
|
|
|
|
2001-12-11 15:35:18 +00:00
|
|
|
MathIterator ibegin(MathInset * p)
|
2001-12-10 10:09:00 +00:00
|
|
|
{
|
2001-12-11 15:35:18 +00:00
|
|
|
return MathIterator(p);
|
2001-12-10 10:09:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-11 15:35:18 +00:00
|
|
|
MathIterator iend(MathInset * p)
|
2001-12-10 10:09:00 +00:00
|
|
|
{
|
2001-12-11 15:35:18 +00:00
|
|
|
MathIterator it(p);
|
2001-12-10 10:09:00 +00:00
|
|
|
it.goEnd();
|
|
|
|
return it;
|
|
|
|
}
|