2002-09-11 09:14:57 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2001-12-05 17:50:18 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "math_iterator.h"
|
2002-07-26 14:11:19 +00:00
|
|
|
#include "math_inset.h"
|
2001-12-10 10:09:00 +00:00
|
|
|
#include "debug.h"
|
|
|
|
#include "support/LAssert.h"
|
2001-12-05 17:50:18 +00:00
|
|
|
|
|
|
|
|
2002-07-26 14:11:19 +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
|
|
|
MathInset const * MathIterator::par() const
|
2001-12-10 10:09:00 +00:00
|
|
|
{
|
2002-07-26 14:11:19 +00:00
|
|
|
return back().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
|
|
|
{
|
2002-07-26 14:11:19 +00:00
|
|
|
return back().par_;
|
2001-12-05 17:50:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-03 09:41:26 +00:00
|
|
|
MathArray const & MathIterator::cell() const
|
|
|
|
{
|
2002-07-26 14:11:19 +00:00
|
|
|
MathCursorPos const & top = back();
|
2002-03-12 16:11:51 +00:00
|
|
|
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;
|
2002-07-26 14:11:19 +00:00
|
|
|
push_back(MathCursorPos(p));
|
2001-12-05 17:50:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathIterator::pop()
|
|
|
|
{
|
|
|
|
//lyxerr << "pop: " << endl;
|
2002-07-26 14:11:19 +00:00
|
|
|
lyx::Assert(size());
|
|
|
|
pop_back();
|
2001-12-05 17:50:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathCursorPos const & MathIterator::operator*() const
|
|
|
|
{
|
2002-07-26 14:11:19 +00:00
|
|
|
return back();
|
2001-12-05 17:50:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathCursorPos const & MathIterator::operator->() const
|
|
|
|
{
|
2002-07-26 14:11:19 +00:00
|
|
|
return back();
|
2001-12-05 17:50:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-10 10:09:00 +00:00
|
|
|
void MathIterator::goEnd()
|
|
|
|
{
|
2002-07-26 14:11:19 +00:00
|
|
|
MathCursorPos & top = back();
|
2002-03-12 16:11:51 +00:00
|
|
|
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-07-26 14:11:19 +00:00
|
|
|
MathCursorPos & top = back();
|
2002-08-08 16:08:11 +00:00
|
|
|
MathArray & ar = top.par_->cell(top.idx_);
|
2002-03-12 16:11:51 +00:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2002-07-26 14:11:19 +00:00
|
|
|
// otherwise move on one cell back 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
|
|
|
}
|
|
|
|
|
2002-07-26 14:11:19 +00:00
|
|
|
// otherwise leave array, move on one back
|
2001-12-05 17:50:18 +00:00
|
|
|
// this might yield pos() == size(), but that's a ok.
|
2002-03-21 17:42:56 +00:00
|
|
|
pop();
|
2002-03-12 16:11:51 +00:00
|
|
|
// it certainly invalidates top
|
2002-07-26 14:11:19 +00:00
|
|
|
++back().pos_;
|
2001-12-05 17:50:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-26 14:11:19 +00:00
|
|
|
void MathIterator::jump(difference_type i)
|
2002-01-03 09:41:26 +00:00
|
|
|
{
|
2002-07-26 14:11:19 +00:00
|
|
|
back().pos_ += i;
|
|
|
|
//lyx::Assert(back().pos_ >= 0);
|
|
|
|
lyx::Assert(back().pos_ <= cell().size());
|
2002-01-03 09:41:26 +00:00
|
|
|
}
|
|
|
|
|
2001-12-05 17:50:18 +00:00
|
|
|
|
2002-08-13 17:43:40 +00:00
|
|
|
/*
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-05 17:50:18 +00:00
|
|
|
bool operator==(MathIterator const & it, MathIterator const & jt)
|
|
|
|
{
|
2002-07-26 14:11:19 +00:00
|
|
|
return MathIterator::base_type(it) == MathIterator::base_type(jt);
|
2001-12-05 17:50:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool operator!=(MathIterator const & it, MathIterator const & jt)
|
|
|
|
{
|
2002-07-26 14:11:19 +00:00
|
|
|
return MathIterator::base_type(it) != MathIterator::base_type(jt);
|
2001-12-05 17:50:18 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|