2 * \file math_iterator.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "math_iterator.h"
14 #include "math_inset.h"
15 #include "math_data.h"
17 #include <boost/assert.hpp>
20 MathIterator::MathIterator()
24 MathIterator::MathIterator(MathInset * p)
31 MathArray const & MathIterator::cell() const
33 CursorSlice const & top = back();
34 return top.asMathInset()->cell(top.idx_);
39 void MathIterator::push(MathInset * p)
41 //lyxerr << "push: " << p << endl;
42 push_back(CursorSlice(p));
46 void MathIterator::pop()
48 //lyxerr << "pop: " << endl;
54 void MathIterator::goEnd()
56 CursorSlice & top = back();
57 top.idx_ = top.asMathInset()->nargs() - 1;
58 top.pos_ = cell().size();
62 void MathIterator::operator++()
64 CursorSlice & top = back();
65 MathArray & ar = top.asMathInset()->cell(top.idx_);
67 // move into the current inset if possible
68 // it is impossible for pos() == size()!
70 if (top.pos_ != ar.size())
71 n = (ar.begin() + top.pos_)->nucleus();
72 if (n && n->isActive()) {
77 // otherwise move on one cell back if possible
78 if (top.pos_ < ar.size()) {
79 // pos() == size() is valid!
84 // otherwise try to move on one cell if possible
85 while (top.idx_ + 1 < top.asMathInset()->nargs()) {
86 // idx() == nargs() is _not_ valid!
88 if (top.asMathInset()->validCell(top.idx_)) {
94 // otherwise leave array, move on one back
95 // this might yield pos() == size(), but that's a ok.
97 // it certainly invalidates top
102 bool MathIterator::normal() const
104 return back().pos_ < cell().size();
108 void MathIterator::shrink(size_type i)
111 erase(begin() + i, end());
115 bool operator==(MathIterator const & it, MathIterator const & jt)
117 return MathIterator::base_type(it) == MathIterator::base_type(jt);
121 bool operator!=(MathIterator const & it, MathIterator const & jt)
123 return MathIterator::base_type(it) != MathIterator::base_type(jt);
127 MathIterator ibegin(MathInset * p)
129 return MathIterator(p);
133 MathIterator iend(MathInset * p)