]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_iterator.C
fix typo that put too many include paths for most people
[lyx.git] / src / mathed / math_iterator.C
index c0841de2bd1cc9f9fc5f32107b136b71f45447ec..628ead5cab346f3afc8ceaf414ea822801c93676 100644 (file)
@@ -1,4 +1,3 @@
-
 #include <config.h>
 
 #include "math_iterator.h"
 //{}
 
 
-MathIterator::MathIterator(MathAtom & t)
+MathIterator::MathIterator(MathInset * p)
 {
-       push(t);
+       push(p);
 }
 
 
-MathIterator::MathIterator(MathCursor::cursor_type const & c)
-       : cursor_(c)
-{}
-
-
-MathCursorPos const & MathIterator::position() const
-{
-       lyx::Assert(cursor_.size());
-       return cursor_.back();
-}
-
-
-MathCursorPos & MathIterator::position()
-{
-       lyx::Assert(cursor_.size());
-       return cursor_.back();
-}
+//MathIterator::MathIterator(MathCursor::cursor_type const & c)
+//     : cursor_(c)
+//{}
 
 
 MathCursor::cursor_type const & MathIterator::cursor() const
@@ -41,36 +26,30 @@ MathCursor::cursor_type const & MathIterator::cursor() const
 }
 
 
-MathAtom const & MathIterator::par() const
+MathInset const * MathIterator::par() const
 {
-       return *(position().par_);
+       return position().par_;
 }
 
 
-MathAtom & MathIterator::par()
+MathInset * MathIterator::par()
 {
-       return *(position().par_);
+       return position().par_;
 }
 
 
-MathXArray const & MathIterator::xcell() const
+MathArray const & MathIterator::cell() const
 {
-       return par()->xcell(position().idx_);
+       MathCursorPos const & top = position();
+       return top.par_->cell(top.idx_);
 }
 
 
-MathAtom * MathIterator::nextInset() const
-{
-       if (position().pos_ == xcell().data_.size())
-               return 0;
-       return const_cast<MathAtom *>(xcell().begin() + position().pos_);
-}
 
-
-void MathIterator::push(MathAtom & t)
+void MathIterator::push(MathInset * p)
 {
        //lyxerr << "push: " << p << endl;
-       cursor_.push_back(MathCursorPos(t));
+       cursor_.push_back(MathCursorPos(p));
 }
 
 
@@ -96,49 +75,66 @@ MathCursorPos const & MathIterator::operator->() const
 
 void MathIterator::goEnd()
 {
-       position().idx_ = par()->nargs() - 1;
-       position().pos_ = xcell().data_.size();
+       MathCursorPos & top = position();
+       top.idx_ = top.par_->nargs() - 1;
+       top.pos_ = cell().size();
 }
 
 
 void MathIterator::operator++()
 {
+       MathCursorPos   & top = position();
+       MathArray const & ar  = top.par_->cell(top.idx_);
+
        // move into the current inset if possible
        // it is impossible for pos() == size()!
-       if (nextInset() && nextInset()->nucleus()->isActive()) {
-               push(*nextInset());
+       MathInset * n = 0;
+       if (top.pos_ != ar.size())
+               n = (ar.begin() + top.pos_)->nucleus();
+       if (n && n->isActive()) {
+               push(n);
                return;
        }
 
        // otherwise move on one cell position if possible
-       if (position().pos_ < xcell().data_.size()) {
+       if (top.pos_ < ar.size()) {
                // pos() == size() is valid!
-               ++position().pos_;
+               ++top.pos_;
                return;
        }
 
-       // otherwise move on one cell if possible
-       if (position().idx_ + 1 < par()->nargs()) {
+       // otherwise try to move on one cell if possible
+       while (top.idx_ + 1 < top.par_->nargs()) {
                // idx() == nargs() is _not_ valid!
-               ++position().idx_;
-               position().pos_ = 0;
-               return;
+               ++top.idx_;
+               if (top.par_->validCell(top.idx_)) {
+                       top.pos_ = 0;
+                       return;
+               }
        }
 
        // otherwise leave array, move on one position
        // this might yield pos() == size(), but that's a ok.
        pop();
+       // it certainly invalidates top
        ++position().pos_;
 }
 
 
+void MathIterator::jump(MathInset::difference_type i)
+{
+       position().pos_ += i;
+       //lyx::Assert(position().pos_ >= 0);
+       lyx::Assert(position().pos_ <= cell().size());
+}
+
 
 bool operator==(MathIterator const & it, MathIterator const & jt)
 {
        //lyxerr << "==: " << it.cursor().size() << " " << jt.cursor().size() << endl;
        if (it.cursor().size() != jt.cursor().size())
                return false;
-       return it.cursor() == jt.cursor();      
+       return it.cursor() == jt.cursor();
 }
 
 
@@ -147,20 +143,19 @@ bool operator!=(MathIterator const & it, MathIterator const & jt)
        //lyxerr << "!=: " << it.cursor().size() << " " << jt.cursor().size() << endl;
        if (it.cursor().size() != jt.cursor().size())
                return true;
-       return it.cursor() != jt.cursor();      
+       return it.cursor() != jt.cursor();
 }
 
 
-
-MathIterator ibegin(MathAtom & t)
+MathIterator ibegin(MathInset * p)
 {
-       return MathIterator(t);
+       return MathIterator(p);
 }
 
 
-MathIterator iend(MathAtom & t)
+MathIterator iend(MathInset * p)
 {
-       MathIterator it(t);
+       MathIterator it(p);
        it.goEnd();
        return it;
 }