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 void MathIterator::operator++()
22 CursorSlice & top = back();
23 MathArray & ar = top.asMathInset()->cell(top.idx_);
25 // move into the current inset if possible
26 // it is impossible for pos() == size()!
28 if (top.pos_ != ar.size())
29 n = (ar.begin() + top.pos_)->nucleus();
30 if (n && n->isActive()) {
31 push_back(CursorSlice(n));
35 // otherwise move on one cell back if possible
36 if (top.pos_ < ar.size()) {
37 // pos() == size() is valid!
42 // otherwise try to move on one cell if possible
43 while (top.idx_ + 1 < top.asMathInset()->nargs()) {
44 // idx() == nargs() is _not_ valid!
46 if (top.asMathInset()->validCell(top.idx_)) {
52 // otherwise leave array, move on one back
53 // this might yield pos() == size(), but that's a ok.
55 // it certainly invalidates top
60 bool operator==(MathIterator const & it, MathIterator const & jt)
62 return MathIterator::base_type(it) == MathIterator::base_type(jt);
66 bool operator!=(MathIterator const & it, MathIterator const & jt)
68 return MathIterator::base_type(it) != MathIterator::base_type(jt);
72 MathIterator ibegin(MathInset * p)
75 it.push_back(CursorSlice(p));
80 MathIterator iend(MathInset * p)
83 it.push_back(CursorSlice(p));
84 CursorSlice & top = it.back();
85 top.idx_ = top.asMathInset()->nargs() - 1;
86 top.pos_ = top.asMathInset()->cell(top.idx_).size();