4 #include "math_iterator.h"
6 #include "support/LAssert.h"
9 //MathIterator::MathIterator()
13 MathIterator::MathIterator(MathInset * p)
19 //MathIterator::MathIterator(MathCursor::cursor_type const & c)
24 MathCursor::cursor_type const & MathIterator::cursor() const
30 MathInset const * MathIterator::par() const
32 return position().par_;
36 MathInset * MathIterator::par()
38 return position().par_;
42 MathArray const & MathIterator::cell() const
44 MathCursorPos const & top = position();
45 return top.par_->cell(top.idx_);
50 void MathIterator::push(MathInset * p)
52 //lyxerr << "push: " << p << endl;
53 cursor_.push_back(MathCursorPos(p));
57 void MathIterator::pop()
59 //lyxerr << "pop: " << endl;
60 lyx::Assert(cursor_.size());
65 MathCursorPos const & MathIterator::operator*() const
71 MathCursorPos const & MathIterator::operator->() const
77 void MathIterator::goEnd()
79 MathCursorPos & top = position();
80 top.idx_ = top.par_->nargs() - 1;
81 top.pos_ = cell().size();
85 void MathIterator::operator++()
87 MathCursorPos & top = position();
88 MathArray const & ar = top.par_->cell(top.idx_);
90 // move into the current inset if possible
91 // it is impossible for pos() == size()!
93 if (top.pos_ != ar.size())
94 n = (ar.begin() + top.pos_)->nucleus();
95 if (n && n->isActive()) {
100 // otherwise move on one cell position if possible
101 if (top.pos_ < ar.size()) {
102 // pos() == size() is valid!
107 // otherwise try to move on one cell if possible
108 while (top.idx_ + 1 < top.par_->nargs()) {
109 // idx() == nargs() is _not_ valid!
111 if (top.par_->validCell(top.idx_)) {
117 // otherwise leave array, move on one position
118 // this might yield pos() == size(), but that's a ok.
120 // it certainly invalidates top
125 void MathIterator::jump(MathInset::difference_type i)
127 position().pos_ += i;
128 //lyx::Assert(position().pos_ >= 0);
129 lyx::Assert(position().pos_ <= cell().size());
133 bool operator==(MathIterator const & it, MathIterator const & jt)
135 //lyxerr << "==: " << it.cursor().size() << " " << jt.cursor().size() << endl;
136 if (it.cursor().size() != jt.cursor().size())
138 return it.cursor() == jt.cursor();
142 bool operator!=(MathIterator const & it, MathIterator const & jt)
144 //lyxerr << "!=: " << it.cursor().size() << " " << jt.cursor().size() << endl;
145 if (it.cursor().size() != jt.cursor().size())
147 return it.cursor() != jt.cursor();
151 MathIterator ibegin(MathInset * p)
153 return MathIterator(p);
157 MathIterator iend(MathInset * p)