]> 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 ca65d4a3403fa5ef11f58e37fa8663d8ecf60188..3d6406c799c2faa4f9b33aafff4db283ff77a6e4 100644 (file)
 //{}
 
 
-MathIterator::MathIterator(MathAtom & t)
+MathIterator::MathIterator(MathInset * p)
 {
-       push(t);
+       push(p);
 }
 
 
-MathIterator::MathIterator(MathCursor::cursor_type const & c)
-       : cursor_(c)
-{}
+//MathIterator::MathIterator(MathCursor::cursor_type const & c)
+//     : cursor_(c)
+//{}
 
 
 MathCursorPos const & MathIterator::position() const
@@ -41,15 +41,15 @@ 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_;
 }
 
 
@@ -59,18 +59,24 @@ MathXArray const & MathIterator::xcell() const
 }
 
 
-MathAtom * MathIterator::nextInset() const
+MathArray const & MathIterator::cell() const
+{
+       return par()->xcell(position().idx_).data_;
+}
+
+
+MathInset * MathIterator::nextInset() const
 {
        if (position().pos_ == xcell().data_.size())
                return 0;
-       return const_cast<MathAtom *>(&*(xcell().begin() + position().pos_));
+       return (xcell().begin() + position().pos_)->nucleus();
 }
 
 
-void MathIterator::push(MathAtom & t)
+void MathIterator::push(MathInset * p)
 {
        //lyxerr << "push: " << p << endl;
-       cursor_.push_back(MathCursorPos(t));
+       cursor_.push_back(MathCursorPos(p));
 }
 
 
@@ -105,8 +111,8 @@ void MathIterator::operator++()
 {
        // move into the current inset if possible
        // it is impossible for pos() == size()!
-       if (nextInset() && nextInset()->nucleus()->isActive()) {
-               push(*nextInset());
+       if (nextInset() && nextInset()->isActive()) {
+               push(nextInset());
                return;
        }
 
@@ -132,6 +138,13 @@ void MathIterator::operator++()
 }
 
 
+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)
 {
@@ -151,16 +164,15 @@ bool operator!=(MathIterator const & it, MathIterator const & jt)
 }
 
 
-
-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;
 }