]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_iterator.C
make \newcommand{\bb}[1]{\mathbf{#1}} work for read/write/display.
[lyx.git] / src / mathed / math_iterator.C
index 0ea88d50987c367e389434e00eff43df30d236ba..3d6406c799c2faa4f9b33aafff4db283ff77a6e4 100644 (file)
@@ -1,12 +1,13 @@
 
 #include <config.h>
 
-#include "debug.h"
 #include "math_iterator.h"
+#include "debug.h"
+#include "support/LAssert.h"
 
 
-MathIterator::MathIterator()
-{}
+//MathIterator::MathIterator()
+//{}
 
 
 MathIterator::MathIterator(MathInset * p)
@@ -15,19 +16,21 @@ MathIterator::MathIterator(MathInset * p)
 }
 
 
-MathIterator::MathIterator(MathCursor::cursor_type const & c)
-       : cursor_(c)
-{}
+//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();
 }
 
@@ -38,20 +41,30 @@ MathCursor::cursor_type const & MathIterator::cursor() const
 }
 
 
-MathInset * MathIterator::par() const
+MathInset const * MathIterator::par() const
+{
+       return position().par_;
+}
+
+
+MathInset * MathIterator::par()
 {
-       return cursor_.size() ? cursor_.back().par_ : 0;
+       return position().par_;
 }
 
 
 MathXArray const & MathIterator::xcell() const
 {
-       if (!par())
-               lyxerr << "MathIterator::xcell: no cell\n";
        return par()->xcell(position().idx_);
 }
 
 
+MathArray const & MathIterator::cell() const
+{
+       return par()->xcell(position().idx_).data_;
+}
+
+
 MathInset * MathIterator::nextInset() const
 {
        if (position().pos_ == xcell().data_.size())
@@ -70,6 +83,7 @@ void MathIterator::push(MathInset * p)
 void MathIterator::pop()
 {
        //lyxerr << "pop: " << endl;
+       lyx::Assert(cursor_.size());
        cursor_.pop_back();
 }
 
@@ -86,6 +100,13 @@ MathCursorPos const & MathIterator::operator->() const
 }
 
 
+void MathIterator::goEnd()
+{
+       position().idx_ = par()->nargs() - 1;
+       position().pos_ = xcell().data_.size();
+}
+
+
 void MathIterator::operator++()
 {
        // move into the current inset if possible
@@ -110,13 +131,20 @@ void MathIterator::operator++()
                return;
        }
 
-       // otherwise leave array, move on one cell
+       // otherwise leave array, move on one position
        // this might yield pos() == size(), but that's a ok.
        pop();
        ++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)
 {
@@ -135,3 +163,16 @@ bool operator!=(MathIterator const & it, MathIterator const & jt)
        return it.cursor() != jt.cursor();      
 }
 
+
+MathIterator ibegin(MathInset * p)
+{
+       return MathIterator(p);
+}
+
+
+MathIterator iend(MathInset * p)
+{
+       MathIterator it(p);
+       it.goEnd();
+       return it;
+}