3 #include "math_iterator.h"
5 #include "support/LAssert.h"
8 //MathIterator::MathIterator()
12 MathIterator::MathIterator(MathInset * p)
18 //MathIterator::MathIterator(MathCursor::cursor_type const & c)
23 MathCursor::cursor_type const & MathIterator::cursor() const
29 MathInset const * MathIterator::par() const
31 return position().par_;
35 MathInset * MathIterator::par()
37 return position().par_;
41 MathArray const & MathIterator::cell() const
43 MathCursorPos const & top = position();
44 return top.par_->cell(top.idx_);
49 void MathIterator::push(MathInset * p)
51 //lyxerr << "push: " << p << endl;
52 cursor_.push_back(MathCursorPos(p));
56 void MathIterator::pop()
58 //lyxerr << "pop: " << endl;
59 lyx::Assert(cursor_.size());
64 MathCursorPos const & MathIterator::operator*() const
70 MathCursorPos const & MathIterator::operator->() const
76 void MathIterator::goEnd()
78 MathCursorPos & top = position();
79 top.idx_ = top.par_->nargs() - 1;
80 top.pos_ = cell().size();
84 void MathIterator::operator++()
86 MathCursorPos & top = position();
87 MathArray const & ar = top.par_->cell(top.idx_);
89 // move into the current inset if possible
90 // it is impossible for pos() == size()!
92 if (top.pos_ != ar.size())
93 n = (ar.begin() + top.pos_)->nucleus();
94 if (n && n->isActive()) {
99 // otherwise move on one cell position if possible
100 if (top.pos_ < ar.size()) {
101 // pos() == size() is valid!
106 // otherwise try to move on one cell if possible
107 while (top.idx_ + 1 < top.par_->nargs()) {
108 // idx() == nargs() is _not_ valid!
110 if (top.par_->validCell(top.idx_)) {
116 // otherwise leave array, move on one position
117 // this might yield pos() == size(), but that's a ok.
119 // it certainly invalidates top
124 void MathIterator::jump(MathInset::difference_type i)
126 position().pos_ += i;
127 //lyx::Assert(position().pos_ >= 0);
128 lyx::Assert(position().pos_ <= cell().size());
132 bool operator==(MathIterator const & it, MathIterator const & jt)
134 //lyxerr << "==: " << it.cursor().size() << " " << jt.cursor().size() << endl;
135 if (it.cursor().size() != jt.cursor().size())
137 return it.cursor() == jt.cursor();
141 bool operator!=(MathIterator const & it, MathIterator const & jt)
143 //lyxerr << "!=: " << it.cursor().size() << " " << jt.cursor().size() << endl;
144 if (it.cursor().size() != jt.cursor().size())
146 return it.cursor() != jt.cursor();
150 MathIterator ibegin(MathInset * p)
152 return MathIterator(p);
156 MathIterator iend(MathInset * p)