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 CursorSlice const & MathIterator::operator*() const
60 CursorSlice const & MathIterator::operator->() const
66 void MathIterator::goEnd()
68 CursorSlice & top = back();
69 top.idx_ = top.asMathInset()->nargs() - 1;
70 top.pos_ = cell().size();
74 void MathIterator::operator++()
76 CursorSlice & top = back();
77 MathArray & ar = top.asMathInset()->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.asMathInset()->nargs()) {
98 // idx() == nargs() is _not_ valid!
100 if (top.asMathInset()->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 //BOOST_ASSERT(back().pos_ >= 0);
118 BOOST_ASSERT(back().pos_ <= cell().size());
122 bool MathIterator::normal() const
124 return back().pos_ < cell().size();
128 void MathIterator::shrink(size_type i)
131 erase(begin() + i, end());
135 bool operator==(MathIterator const & it, MathIterator const & jt)
137 return MathIterator::base_type(it) == MathIterator::base_type(jt);
141 bool operator!=(MathIterator const & it, MathIterator const & jt)
143 return MathIterator::base_type(it) != MathIterator::base_type(jt);
147 MathIterator ibegin(MathInset * p)
149 return MathIterator(p);
153 MathIterator iend(MathInset * p)