4 #include "math_iterator.h"
5 #include "math_inset.h"
7 #include "support/LAssert.h"
10 MathIterator::MathIterator()
14 MathIterator::MathIterator(MathInset * p)
20 MathInset const * MathIterator::par() const
26 MathInset * MathIterator::par()
32 MathArray const & MathIterator::cell() const
34 MathCursorPos const & top = back();
35 return top.par_->cell(top.idx_);
40 void MathIterator::push(MathInset * p)
42 //lyxerr << "push: " << p << endl;
43 push_back(MathCursorPos(p));
47 void MathIterator::pop()
49 //lyxerr << "pop: " << endl;
55 MathCursorPos const & MathIterator::operator*() const
61 MathCursorPos const & MathIterator::operator->() const
67 void MathIterator::goEnd()
69 MathCursorPos & top = back();
70 top.idx_ = top.par_->nargs() - 1;
71 top.pos_ = cell().size();
75 void MathIterator::operator++()
77 MathCursorPos & top = back();
78 MathArray & ar = top.par_->cell(top.idx_);
80 // move into the current inset if possible
81 // it is impossible for pos() == size()!
83 if (top.pos_ != ar.size())
84 n = (ar.begin() + top.pos_)->nucleus();
85 if (n && n->isActive()) {
90 // otherwise move on one cell back if possible
91 if (top.pos_ < ar.size()) {
92 // pos() == size() is valid!
97 // otherwise try to move on one cell if possible
98 while (top.idx_ + 1 < top.par_->nargs()) {
99 // idx() == nargs() is _not_ valid!
101 if (top.par_->validCell(top.idx_)) {
107 // otherwise leave array, move on one back
108 // this might yield pos() == size(), but that's a ok.
110 // it certainly invalidates top
115 void MathIterator::jump(difference_type i)
118 //lyx::Assert(back().pos_ >= 0);
119 lyx::Assert(back().pos_ <= cell().size());
123 bool MathIterator::normal() const
125 return back().pos_ < cell().size();
129 void MathIterator::shrink(size_type i)
132 erase(begin() + i, end());
136 bool operator==(MathIterator const & it, MathIterator const & jt)
138 return MathIterator::base_type(it) == MathIterator::base_type(jt);
142 bool operator!=(MathIterator const & it, MathIterator const & jt)
144 return MathIterator::base_type(it) != MathIterator::base_type(jt);
148 MathIterator ibegin(MathInset * p)
150 return MathIterator(p);
154 MathIterator iend(MathInset * p)