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 MathArray const & MathIterator::cell() const
22 CursorSlice const & top = back();
23 return top.asMathInset()->cell(top.idx_);
27 void MathIterator::operator++()
29 CursorSlice & top = back();
30 MathArray & ar = top.asMathInset()->cell(top.idx_);
32 // move into the current inset if possible
33 // it is impossible for pos() == size()!
35 if (top.pos_ != ar.size())
36 n = (ar.begin() + top.pos_)->nucleus();
37 if (n && n->isActive()) {
38 push_back(CursorSlice(n));
42 // otherwise move on one cell back if possible
43 if (top.pos_ < ar.size()) {
44 // pos() == size() is valid!
49 // otherwise try to move on one cell if possible
50 while (top.idx_ + 1 < top.asMathInset()->nargs()) {
51 // idx() == nargs() is _not_ valid!
53 if (top.asMathInset()->validCell(top.idx_)) {
59 // otherwise leave array, move on one back
60 // this might yield pos() == size(), but that's a ok.
62 // it certainly invalidates top
67 bool operator==(MathIterator const & it, MathIterator const & jt)
69 return MathIterator::base_type(it) == MathIterator::base_type(jt);
73 bool operator!=(MathIterator const & it, MathIterator const & jt)
75 return MathIterator::base_type(it) != MathIterator::base_type(jt);
79 MathIterator ibegin(MathInset * p)
82 it.push_back(CursorSlice(p));
87 MathIterator iend(MathInset * p)
90 it.push_back(CursorSlice(p));
92 CursorSlice & top = it.back();
93 top.idx_ = top.asMathInset()->nargs() - 1;
94 top.pos_ = it.cell().size();