5 #include "math_iterator.h"
8 MathIterator::MathIterator()
12 MathIterator::MathIterator(MathInset * p)
18 MathIterator::MathIterator(MathCursor::cursor_type const & c)
23 MathCursorPos const & MathIterator::position() const
25 return cursor_.back();
29 MathCursorPos & MathIterator::position()
31 return cursor_.back();
35 MathCursor::cursor_type const & MathIterator::cursor() const
41 MathInset * MathIterator::par() const
43 return cursor_.size() ? cursor_.back().par_ : 0;
47 MathXArray const & MathIterator::xcell() const
50 lyxerr << "MathIterator::xcell: no cell\n";
51 return par()->xcell(position().idx_);
55 MathInset * MathIterator::nextInset() const
57 if (position().pos_ == xcell().data_.size())
59 return (xcell().begin() + position().pos_)->nucleus();
63 void MathIterator::push(MathInset * p)
65 //lyxerr << "push: " << p << endl;
66 cursor_.push_back(MathCursorPos(p));
70 void MathIterator::pop()
72 //lyxerr << "pop: " << endl;
77 MathCursorPos const & MathIterator::operator*() const
83 MathCursorPos const & MathIterator::operator->() const
89 void MathIterator::operator++()
91 // move into the current inset if possible
92 // it is impossible for pos() == size()!
93 if (nextInset() && nextInset()->isActive()) {
98 // otherwise move on one cell position if possible
99 if (position().pos_ < xcell().data_.size()) {
100 // pos() == size() is valid!
105 // otherwise move on one cell if possible
106 if (position().idx_ + 1 < par()->nargs()) {
107 // idx() == nargs() is _not_ valid!
113 // otherwise leave array, move on one cell
114 // this might yield pos() == size(), but that's a ok.
121 bool operator==(MathIterator const & it, MathIterator const & jt)
123 //lyxerr << "==: " << it.cursor().size() << " " << jt.cursor().size() << endl;
124 if (it.cursor().size() != jt.cursor().size())
126 return it.cursor() == jt.cursor();
130 bool operator!=(MathIterator const & it, MathIterator const & jt)
132 //lyxerr << "!=: " << it.cursor().size() << " " << jt.cursor().size() << endl;
133 if (it.cursor().size() != jt.cursor().size())
135 return it.cursor() != jt.cursor();