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 "support/LAssert.h"
18 using namespace lyx::support;
20 MathIterator::MathIterator()
24 MathIterator::MathIterator(MathInset * p)
30 MathInset const * MathIterator::inset() const
36 MathInset * MathIterator::inset()
42 MathArray const & MathIterator::cell() const
44 CursorPos const & top = back();
45 return top.inset_->cell(top.idx_);
50 void MathIterator::push(MathInset * p)
52 //lyxerr << "push: " << p << endl;
53 push_back(CursorPos(p));
57 void MathIterator::pop()
59 //lyxerr << "pop: " << endl;
65 CursorPos const & MathIterator::operator*() const
71 CursorPos const & MathIterator::operator->() const
77 void MathIterator::goEnd()
79 CursorPos & top = back();
80 top.idx_ = top.inset_->nargs() - 1;
81 top.pos_ = cell().size();
85 void MathIterator::operator++()
87 CursorPos & top = back();
88 MathArray & ar = top.inset_->cell(top.idx_);
90 // move into the current inset if possible
91 // it is impossible for pos() == size()!
93 if (top.pos_ != ar.size())
94 n = (ar.begin() + top.pos_)->nucleus();
95 if (n && n->isActive()) {
100 // otherwise move on one cell back if possible
101 if (top.pos_ < ar.size()) {
102 // pos() == size() is valid!
107 // otherwise try to move on one cell if possible
108 while (top.idx_ + 1 < top.inset_->nargs()) {
109 // idx() == nargs() is _not_ valid!
111 if (top.inset_->validCell(top.idx_)) {
117 // otherwise leave array, move on one back
118 // this might yield pos() == size(), but that's a ok.
120 // it certainly invalidates top
125 void MathIterator::jump(difference_type i)
128 //Assert(back().pos_ >= 0);
129 Assert(back().pos_ <= cell().size());
133 bool MathIterator::normal() const
135 return back().pos_ < cell().size();
139 void MathIterator::shrink(size_type i)
142 erase(begin() + i, end());
146 bool operator==(MathIterator const & it, MathIterator const & jt)
148 return MathIterator::base_type(it) == MathIterator::base_type(jt);
152 bool operator!=(MathIterator const & it, MathIterator const & jt)
154 return MathIterator::base_type(it) != MathIterator::base_type(jt);
158 MathIterator ibegin(MathInset * p)
160 return MathIterator(p);
164 MathIterator iend(MathInset * p)