7 #include "math_iterator.h"
8 #include "math_inset.h"
10 #include "support/LAssert.h"
13 MathIterator::MathIterator()
17 MathIterator::MathIterator(MathInset * p)
23 MathInset const * MathIterator::par() const
29 MathInset * MathIterator::par()
35 MathArray const & MathIterator::cell() const
37 MathCursorPos const & top = back();
38 return top.par_->cell(top.idx_);
43 void MathIterator::push(MathInset * p)
45 //lyxerr << "push: " << p << endl;
46 push_back(MathCursorPos(p));
50 void MathIterator::pop()
52 //lyxerr << "pop: " << endl;
58 MathCursorPos const & MathIterator::operator*() const
64 MathCursorPos const & MathIterator::operator->() const
70 void MathIterator::goEnd()
72 MathCursorPos & top = back();
73 top.idx_ = top.par_->nargs() - 1;
74 top.pos_ = cell().size();
78 void MathIterator::operator++()
80 MathCursorPos & top = back();
81 MathArray & ar = top.par_->cell(top.idx_);
83 // move into the current inset if possible
84 // it is impossible for pos() == size()!
86 if (top.pos_ != ar.size())
87 n = (ar.begin() + top.pos_)->nucleus();
88 if (n && n->isActive()) {
93 // otherwise move on one cell back if possible
94 if (top.pos_ < ar.size()) {
95 // pos() == size() is valid!
100 // otherwise try to move on one cell if possible
101 while (top.idx_ + 1 < top.par_->nargs()) {
102 // idx() == nargs() is _not_ valid!
104 if (top.par_->validCell(top.idx_)) {
110 // otherwise leave array, move on one back
111 // this might yield pos() == size(), but that's a ok.
113 // it certainly invalidates top
118 void MathIterator::jump(difference_type i)
121 //lyx::Assert(back().pos_ >= 0);
122 lyx::Assert(back().pos_ <= cell().size());
126 bool MathIterator::normal() const
128 return back().pos_ < cell().size();
132 void MathIterator::shrink(size_type i)
135 erase(begin() + i, end());
139 bool operator==(MathIterator const & it, MathIterator const & jt)
141 return MathIterator::base_type(it) == MathIterator::base_type(jt);
145 bool operator!=(MathIterator const & it, MathIterator const & jt)
147 return MathIterator::base_type(it) != MathIterator::base_type(jt);
151 MathIterator ibegin(MathInset * p)
153 return MathIterator(p);
157 MathIterator iend(MathInset * p)