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 move on one cell if possible
108 if (top.idx_ + 1 < top.par_->nargs()) {
109 // idx() == nargs() is _not_ valid!
115 // otherwise leave array, move on one position
116 // this might yield pos() == size(), but that's a ok.
118 // it certainly invalidates top
123 void MathIterator::jump(MathInset::difference_type i)
125 position().pos_ += i;
126 //lyx::Assert(position().pos_ >= 0);
127 lyx::Assert(position().pos_ <= cell().size());
131 bool operator==(MathIterator const & it, MathIterator const & jt)
133 //lyxerr << "==: " << it.cursor().size() << " " << jt.cursor().size() << endl;
134 if (it.cursor().size() != jt.cursor().size())
136 return it.cursor() == jt.cursor();
140 bool operator!=(MathIterator const & it, MathIterator const & jt)
142 //lyxerr << "!=: " << it.cursor().size() << " " << jt.cursor().size() << endl;
143 if (it.cursor().size() != jt.cursor().size())
145 return it.cursor() != jt.cursor();
149 MathIterator ibegin(MathInset * p)
151 return MathIterator(p);
155 MathIterator iend(MathInset * p)