4 #include "math_iterator.h"
6 #include "support/LAssert.h"
9 //MathIterator::MathIterator()
13 MathIterator::MathIterator(MathInset * p)
19 //MathIterator::MathIterator(MathCursor::cursor_type const & c)
24 MathCursorPos const & MathIterator::position() const
26 lyx::Assert(cursor_.size());
27 return cursor_.back();
31 MathCursorPos & MathIterator::position()
33 lyx::Assert(cursor_.size());
34 return cursor_.back();
38 MathCursor::cursor_type const & MathIterator::cursor() const
44 MathInset const * MathIterator::par() const
46 return position().par_;
50 MathInset * MathIterator::par()
52 return position().par_;
56 MathXArray const & MathIterator::xcell() const
58 return par()->xcell(position().idx_);
62 MathInset * MathIterator::nextInset() const
64 if (position().pos_ == xcell().data_.size())
66 return (xcell().begin() + position().pos_)->nucleus();
70 void MathIterator::push(MathInset * p)
72 //lyxerr << "push: " << p << endl;
73 cursor_.push_back(MathCursorPos(p));
77 void MathIterator::pop()
79 //lyxerr << "pop: " << endl;
80 lyx::Assert(cursor_.size());
85 MathCursorPos const & MathIterator::operator*() const
91 MathCursorPos const & MathIterator::operator->() const
97 void MathIterator::goEnd()
99 position().idx_ = par()->nargs() - 1;
100 position().pos_ = xcell().data_.size();
104 void MathIterator::operator++()
106 // move into the current inset if possible
107 // it is impossible for pos() == size()!
108 if (nextInset() && nextInset()->isActive()) {
113 // otherwise move on one cell position if possible
114 if (position().pos_ < xcell().data_.size()) {
115 // pos() == size() is valid!
120 // otherwise move on one cell if possible
121 if (position().idx_ + 1 < par()->nargs()) {
122 // idx() == nargs() is _not_ valid!
128 // otherwise leave array, move on one position
129 // this might yield pos() == size(), but that's a ok.
136 bool operator==(MathIterator const & it, MathIterator const & jt)
138 //lyxerr << "==: " << it.cursor().size() << " " << jt.cursor().size() << endl;
139 if (it.cursor().size() != jt.cursor().size())
141 return it.cursor() == jt.cursor();
145 bool operator!=(MathIterator const & it, MathIterator const & jt)
147 //lyxerr << "!=: " << it.cursor().size() << " " << jt.cursor().size() << endl;
148 if (it.cursor().size() != jt.cursor().size())
150 return it.cursor() != jt.cursor();
155 MathIterator ibegin(MathInset * p)
157 return MathIterator(p);
161 MathIterator iend(MathInset * p)