]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_iterator.C
remove unneeded inset() member function
[lyx.git] / src / mathed / math_iterator.C
index 91e022bae4e232e1d4fa666b68249e0c23ddc331..180de4602ff5daea747bc8b85a6bdfd8bd45a585 100644 (file)
@@ -1,13 +1,24 @@
+/**
+ * \file math_iterator.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author André Pönitz
+ *
+ * Full author contact details are available in file CREDITS.
+ */
 
 #include <config.h>
 
 #include "math_iterator.h"
-#include "debug.h"
-#include "support/LAssert.h"
+#include "math_inset.h"
+#include "math_data.h"
 
+#include <boost/assert.hpp>
 
-//MathIterator::MathIterator()
-//{}
+
+MathIterator::MathIterator()
+{}
 
 
 MathIterator::MathIterator(MathInset * p)
@@ -16,33 +27,11 @@ MathIterator::MathIterator(MathInset * p)
 }
 
 
-//MathIterator::MathIterator(MathCursor::cursor_type const & c)
-//     : cursor_(c)
-//{}
-
-
-MathCursor::cursor_type const & MathIterator::cursor() const
-{
-       return cursor_;
-}
-
-
-MathInset const * MathIterator::par() const
-{
-       return position().par_;
-}
-
-
-MathInset * MathIterator::par()
-{
-       return position().par_;
-}
-
 
 MathArray const & MathIterator::cell() const
 {
-       MathCursorPos const & top = position();
-       return top.par_->cell(top.idx_);
+       CursorSlice const & top = back();
+       return top.asMathInset()->cell(top.idx_);
 }
 
 
@@ -50,42 +39,42 @@ MathArray const & MathIterator::cell() const
 void MathIterator::push(MathInset * p)
 {
        //lyxerr << "push: " << p << endl;
-       cursor_.push_back(MathCursorPos(p));
+       push_back(CursorSlice(p));
 }
 
 
 void MathIterator::pop()
 {
        //lyxerr << "pop: " << endl;
-       lyx::Assert(cursor_.size());
-       cursor_.pop_back();
+       BOOST_ASSERT(size());
+       pop_back();
 }
 
 
-MathCursorPos const & MathIterator::operator*() const
+CursorSlice const & MathIterator::operator*() const
 {
-       return position();
+       return back();
 }
 
 
-MathCursorPos const & MathIterator::operator->() const
+CursorSlice const & MathIterator::operator->() const
 {
-       return position();
+       return back();
 }
 
 
 void MathIterator::goEnd()
 {
-       MathCursorPos & top = position();
-       top.idx_ = top.par_->nargs() - 1;
+       CursorSlice & top = back();
+       top.idx_ = top.asMathInset()->nargs() - 1;
        top.pos_ = cell().size();
 }
 
 
 void MathIterator::operator++()
 {
-       MathCursorPos   & top = position();
-       MathArray const & ar  = top.par_->cell(top.idx_);
+       CursorSlice & top = back();
+       MathArray   & ar  = top.asMathInset()->cell(top.idx_);
 
        // move into the current inset if possible
        // it is impossible for pos() == size()!
@@ -97,52 +86,61 @@ void MathIterator::operator++()
                return;
        }
 
-       // otherwise move on one cell position if possible
+       // otherwise move on one cell back if possible
        if (top.pos_ < ar.size()) {
                // pos() == size() is valid!
                ++top.pos_;
                return;
        }
 
-       // otherwise move on one cell if possible
-       if (top.idx_ + 1 < top.par_->nargs()) {
+       // otherwise try to move on one cell if possible
+       while (top.idx_ + 1 < top.asMathInset()->nargs()) {
                // idx() == nargs() is _not_ valid!
                ++top.idx_;
-               top.pos_ = 0;
-               return;
+               if (top.asMathInset()->validCell(top.idx_)) {
+                       top.pos_ = 0;
+                       return;
+               }
        }
 
-       // otherwise leave array, move on one position
+       // otherwise leave array, move on one back
        // this might yield pos() == size(), but that's a ok.
-       pop(); 
+       pop();
        // it certainly invalidates top
-       ++position().pos_;
+       ++back().pos_;
+}
+
+
+void MathIterator::jump(difference_type i)
+{
+       back().pos_ += i;
+       //BOOST_ASSERT(back().pos_ >= 0);
+       BOOST_ASSERT(back().pos_ <= cell().size());
+}
+
+
+bool MathIterator::normal() const
+{
+       return back().pos_ < cell().size();
 }
 
 
-void MathIterator::jump(MathInset::difference_type i)
+void MathIterator::shrink(size_type i)
 {
-       position().pos_ += i;
-       //lyx::Assert(position().pos_ >= 0);
-       lyx::Assert(position().pos_ <= cell().size());
+       if (i < size())
+               erase(begin() + i, end());
 }
 
 
 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 MathIterator::base_type(it) == MathIterator::base_type(jt);
 }
 
 
 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 MathIterator::base_type(it) != MathIterator::base_type(jt);
 }