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 MathArray const & MathIterator::cell() const
64 return par()->xcell(position().idx_).data_;
68 MathInset * MathIterator::nextInset() const
70 if (position().pos_ == xcell().data_.size())
72 return (xcell().begin() + position().pos_)->nucleus();
76 void MathIterator::push(MathInset * p)
78 //lyxerr << "push: " << p << endl;
79 cursor_.push_back(MathCursorPos(p));
83 void MathIterator::pop()
85 //lyxerr << "pop: " << endl;
86 lyx::Assert(cursor_.size());
91 MathCursorPos const & MathIterator::operator*() const
97 MathCursorPos const & MathIterator::operator->() const
103 void MathIterator::goEnd()
105 position().idx_ = par()->nargs() - 1;
106 position().pos_ = xcell().data_.size();
110 void MathIterator::operator++()
112 // move into the current inset if possible
113 // it is impossible for pos() == size()!
114 if (nextInset() && nextInset()->isActive()) {
119 // otherwise move on one cell position if possible
120 if (position().pos_ < xcell().data_.size()) {
121 // pos() == size() is valid!
126 // otherwise move on one cell if possible
127 if (position().idx_ + 1 < par()->nargs()) {
128 // idx() == nargs() is _not_ valid!
134 // otherwise leave array, move on one position
135 // this might yield pos() == size(), but that's a ok.
141 void MathIterator::jump(MathInset::difference_type i)
143 position().pos_ += i;
144 //lyx::Assert(position().pos_ >= 0);
145 lyx::Assert(position().pos_ <= cell().size());
149 bool operator==(MathIterator const & it, MathIterator const & jt)
151 //lyxerr << "==: " << it.cursor().size() << " " << jt.cursor().size() << endl;
152 if (it.cursor().size() != jt.cursor().size())
154 return it.cursor() == jt.cursor();
158 bool operator!=(MathIterator const & it, MathIterator const & jt)
160 //lyxerr << "!=: " << it.cursor().size() << " " << jt.cursor().size() << endl;
161 if (it.cursor().size() != jt.cursor().size())
163 return it.cursor() != jt.cursor();
167 MathIterator ibegin(MathInset * p)
169 return MathIterator(p);
173 MathIterator iend(MathInset * p)