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"
16 #include <boost/assert.hpp>
19 MathIterator::MathIterator()
23 MathIterator::MathIterator(MathInset * p)
29 MathInset const * MathIterator::inset() const
35 MathInset * MathIterator::inset()
41 MathArray const & MathIterator::cell() const
43 CursorPos const & top = back();
44 return top.inset_->cell(top.idx_);
49 void MathIterator::push(MathInset * p)
51 //lyxerr << "push: " << p << endl;
52 push_back(CursorPos(p));
56 void MathIterator::pop()
58 //lyxerr << "pop: " << endl;
64 CursorPos const & MathIterator::operator*() const
70 CursorPos const & MathIterator::operator->() const
76 void MathIterator::goEnd()
78 CursorPos & top = back();
79 top.idx_ = top.inset_->nargs() - 1;
80 top.pos_ = cell().size();
84 void MathIterator::operator++()
86 CursorPos & top = back();
87 MathArray & ar = top.inset_->cell(top.idx_);
89 // move into the current inset if possible
90 // it is impossible for pos() == size()!
92 if (top.pos_ != ar.size())
93 n = (ar.begin() + top.pos_)->nucleus();
94 if (n && n->isActive()) {
99 // otherwise move on one cell back if possible
100 if (top.pos_ < ar.size()) {
101 // pos() == size() is valid!
106 // otherwise try to move on one cell if possible
107 while (top.idx_ + 1 < top.inset_->nargs()) {
108 // idx() == nargs() is _not_ valid!
110 if (top.inset_->validCell(top.idx_)) {
116 // otherwise leave array, move on one back
117 // this might yield pos() == size(), but that's a ok.
119 // it certainly invalidates top
124 void MathIterator::jump(difference_type i)
127 //BOOST_ASSERT(back().pos_ >= 0);
128 BOOST_ASSERT(back().pos_ <= cell().size());
132 bool MathIterator::normal() const
134 return back().pos_ < cell().size();
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)