3 #include "math_iterator.h"
4 #include "math_inset.h"
6 #include "support/LAssert.h"
9 MathIterator::MathIterator()
13 MathIterator::MathIterator(MathInset * p)
19 MathInset const * MathIterator::par() const
25 MathInset * MathIterator::par()
31 MathArray const & MathIterator::cell() const
33 MathCursorPos const & top = back();
34 return top.par_->cell(top.idx_);
39 void MathIterator::push(MathInset * p)
41 //lyxerr << "push: " << p << endl;
42 push_back(MathCursorPos(p));
46 void MathIterator::pop()
48 //lyxerr << "pop: " << endl;
54 MathCursorPos const & MathIterator::operator*() const
60 MathCursorPos const & MathIterator::operator->() const
66 void MathIterator::goEnd()
68 MathCursorPos & top = back();
69 top.idx_ = top.par_->nargs() - 1;
70 top.pos_ = cell().size();
74 void MathIterator::operator++()
76 MathCursorPos & top = back();
77 MathArray & ar = top.par_->cell(top.idx_);
79 // move into the current inset if possible
80 // it is impossible for pos() == size()!
82 if (top.pos_ != ar.size())
83 n = (ar.begin() + top.pos_)->nucleus();
84 if (n && n->isActive()) {
89 // otherwise move on one cell back if possible
90 if (top.pos_ < ar.size()) {
91 // pos() == size() is valid!
96 // otherwise try to move on one cell if possible
97 while (top.idx_ + 1 < top.par_->nargs()) {
98 // idx() == nargs() is _not_ valid!
100 if (top.par_->validCell(top.idx_)) {
106 // otherwise leave array, move on one back
107 // this might yield pos() == size(), but that's a ok.
109 // it certainly invalidates top
114 void MathIterator::jump(difference_type i)
117 //lyx::Assert(back().pos_ >= 0);
118 lyx::Assert(back().pos_ <= cell().size());
123 void MathIterator::shrink(size_type i)
126 erase(begin() + i, end());
130 void MathIterator::shrink(size_type i)
133 erase(begin() + i, end());
138 void MathIterator::shrink(size_type i)
141 erase(begin() + i, end());
145 bool operator==(MathIterator const & it, MathIterator const & jt)
147 return MathIterator::base_type(it) == MathIterator::base_type(jt);
151 bool operator!=(MathIterator const & it, MathIterator const & jt)
153 return MathIterator::base_type(it) != MathIterator::base_type(jt);
157 MathIterator ibegin(MathInset * p)
159 return MathIterator(p);
163 MathIterator iend(MathInset * p)