This removes MathIterator by shifting the remaining bits towards the
global cursor.

Both the global cursor and the math cursor now have two CursorSlice
stacks of the same shape...

Andre'

-- 
Those who desire to give up Freedom in order to gain Security, will not have,
nor do they deserve, either one.     (T. Jefferson or B. Franklin or both...)
? 1.diff
? 2.diff
? 3.diff
? fullredraw.diff
? par-row.diff
? qfont_loader.tar.bz2
? search.diff
? tabular-il.diff
? textcache.diff
? tmp.diff
? vspace.diff
? frontends/xforms/1.diff
? insets/1.diff
? mathed/.math_cursor.h.swp
? mathed/1.diff
? mathed/cursor.diff
? support/1.diff
Index: cursor_slice.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor_slice.C,v
retrieving revision 1.5
diff -u -p -r1.5 cursor_slice.C
--- cursor_slice.C      13 Jan 2004 18:08:07 -0000      1.5
+++ cursor_slice.C      14 Jan 2004 18:10:33 -0000
@@ -17,8 +17,11 @@
 #include "debug.h"
 
 #include "mathed/math_inset.h"
+#include "mathed/math_data.h"
+
 #include "insets/updatableinset.h"
 
+
 #include <boost/assert.hpp>
 
 using std::endl;
@@ -180,4 +183,65 @@ std::ostream & operator<<(std::ostream &
 //        << " y: " << item.inset_->y()
 ;
        return os;
+}
+
+
+
+
+void increment(CursorBase & it)
+{
+       CursorSlice & top = it.back();
+       MathArray   & ar  = top.asMathInset()->cell(top.idx_);
+
+       // move into the current inset if possible
+       // it is impossible for pos() == size()!
+       MathInset * n = 0;
+       if (top.pos_ != ar.size())
+               n = (ar.begin() + top.pos_)->nucleus();
+       if (n && n->isActive()) {
+               it.push_back(CursorSlice(n));
+               return;
+       }
+
+       // otherwise move on one cell back if possible
+       if (top.pos_ < ar.size()) {
+               // pos() == size() is valid!
+               ++top.pos_;
+               return;
+       }
+
+       // otherwise try to move on one cell if possible
+       while (top.idx_ + 1 < top.asMathInset()->nargs()) {
+               // idx() == nargs() is _not_ valid!
+               ++top.idx_;
+               if (top.asMathInset()->validCell(top.idx_)) {
+                       top.pos_ = 0;
+                       return;
+               }
+       }
+
+       // otherwise leave array, move on one back
+       // this might yield pos() == size(), but that's a ok.
+       it.pop_back();
+       // it certainly invalidates top
+       ++it.back().pos_;
+}
+
+
+CursorBase ibegin(MathInset * p)
+{
+       CursorBase it;
+       it.push_back(CursorSlice(p));
+       return it;
+}
+
+
+CursorBase iend(MathInset * p)
+{
+       CursorBase it;
+       it.push_back(CursorSlice(p));
+       CursorSlice & top = it.back();
+       top.idx_ = top.asMathInset()->nargs() - 1;
+       top.pos_ = top.asMathInset()->cell(top.idx_).size();
+       return it;
 }
Index: cursor_slice.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor_slice.h,v
retrieving revision 1.3
diff -u -p -r1.3 cursor_slice.h
--- cursor_slice.h      13 Jan 2004 18:08:07 -0000      1.3
+++ cursor_slice.h      14 Jan 2004 18:10:33 -0000
@@ -127,4 +127,17 @@ bool operator<(CursorSlice const &, Curs
 /// test for order
 bool operator>(CursorSlice const &, CursorSlice const &);
 
+#include <vector>
+
+
+// this is used for traversing math insets
+typedef std::vector<CursorSlice> CursorBase;
+/// move on one step
+void increment(CursorBase &);
+///
+CursorBase ibegin(InsetBase * p);
+///
+CursorBase iend(InsetBase * p);
+
+
 #endif
Index: mathed/Makefile.am
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/Makefile.am,v
retrieving revision 1.123
diff -u -p -r1.123 Makefile.am
--- mathed/Makefile.am  15 Dec 2003 11:36:19 -0000      1.123
+++ mathed/Makefile.am  14 Jan 2004 18:10:33 -0000
@@ -86,8 +86,6 @@ libmathed_la_SOURCES = \
        math_hullinset.h \
        math_inset.C \
        math_inset.h \
-       math_iterator.C \
-       math_iterator.h \
        math_kerninset.C \
        math_kerninset.h \
        math_lefteqninset.C \
Index: mathed/formulabase.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/formulabase.C,v
retrieving revision 1.320
diff -u -p -r1.320 formulabase.C
--- mathed/formulabase.C        14 Jan 2004 17:58:07 -0000      1.320
+++ mathed/formulabase.C        14 Jan 2004 18:10:33 -0000
@@ -830,7 +830,7 @@ bool InsetFormulaBase::searchForward(Buf
 #warning pretty ugly
 #endif
        static InsetFormulaBase * lastformula = 0;
-       static MathIterator current = MathIterator(ibegin(par().nucleus()));
+       static CursorBase current = CursorBase(ibegin(par().nucleus()));
        static MathArray ar;
        static string laststr;
 
@@ -842,11 +842,11 @@ bool InsetFormulaBase::searchForward(Buf
                ar.clear();
                mathed_parse_cell(ar, str);
        } else {
-               ++current;
+               increment(current);
        }
        //lyxerr << "searching '" << str << "' in " << this << ar << endl;
 
-       for (MathIterator it = current; it != iend(par().nucleus()); ++it) {
+       for (CursorBase it = current; it != iend(par().nucleus()); increment(it)) {
                CursorSlice & top = it.back();
                MathArray const & a = top.asMathInset()->cell(top.idx_);
                if (a.matchpart(ar, top.pos_)) {
Index: mathed/math_cursor.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_cursor.C,v
retrieving revision 1.375
diff -u -p -r1.375 math_cursor.C
--- mathed/math_cursor.C        14 Jan 2004 17:58:07 -0000      1.375
+++ mathed/math_cursor.C        14 Jan 2004 18:10:33 -0000
@@ -246,14 +246,14 @@ void MathCursor::last()
 
 
 bool positionable
-       (MathIterator const & cursor, MathIterator const & anchor)
+       (CursorBase const & cursor, CursorBase const & anchor)
 {
        // avoid deeper nested insets when selecting
        if (cursor.size() > anchor.size())
                return false;
 
        // anchor might be deeper, should have same path then
-       for (MathIterator::size_type i = 0; i < cursor.size(); ++i)
+       for (CursorBase::size_type i = 0; i < cursor.size(); ++i)
                if (cursor[i].asMathInset() != anchor[i].asMathInset())
                        return false;
 
@@ -491,7 +491,7 @@ bool MathCursor::up(bool sel)
        dump("up 1");
        macroModeClose();
        selHandle(sel);
-       MathIterator save = Cursor_;
+       CursorBase save = Cursor_;
        if (goUpDown(true))
                return true;
        Cursor_ = save;
@@ -505,7 +505,7 @@ bool MathCursor::down(bool sel)
        dump("down 1");
        macroModeClose();
        selHandle(sel);
-       MathIterator save = Cursor_;
+       CursorBase save = Cursor_;
        if (goUpDown(false))
                return true;
        Cursor_ = save;
@@ -788,8 +788,8 @@ void MathCursor::pullArg()
 
 void MathCursor::touch()
 {
-       MathIterator::const_iterator it = Cursor_.begin();
-       MathIterator::const_iterator et = Cursor_.end();
+       CursorBase::const_iterator it = Cursor_.begin();
+       CursorBase::const_iterator et = Cursor_.end();
        for ( ; it != et; ++it)
                it->cell().touch();
 }
@@ -1028,11 +1028,11 @@ bool MathCursor::goUpDown(bool up)
 bool MathCursor::bruteFind
        (int x, int y, int xlow, int xhigh, int ylow, int yhigh)
 {
-       MathIterator best_cursor;
+       CursorBase best_cursor;
        double best_dist = 1e10;
 
-       MathIterator it = ibegin(formula()->par().nucleus());
-       MathIterator et = iend(formula()->par().nucleus());
+       CursorBase it = ibegin(formula()->par().nucleus());
+       CursorBase et = iend(formula()->par().nucleus());
        while (1) {
                // avoid invalid nesting when selecting
                if (!selection_ || positionable(it, Anchor_)) {
@@ -1052,7 +1052,7 @@ bool MathCursor::bruteFind
 
                if (it == et)
                        break;
-               ++it;
+               increment(it);
        }
 
        if (best_dist < 1e10)
@@ -1065,9 +1065,9 @@ void MathCursor::bruteFind2(int x, int y
 {
        double best_dist = 1e10;
 
-       MathIterator it = Cursor_;
+       CursorBase it = Cursor_;
        it.back().setPos(0);
-       MathIterator et = Cursor_;
+       CursorBase et = Cursor_;
        int n = et.back().asMathInset()->cell(et.back().idx_).size();
        et.back().setPos(n);
        for (int i = 0; ; ++i) {
@@ -1083,7 +1083,7 @@ void MathCursor::bruteFind2(int x, int y
                }
                if (it == et)
                        break;
-               ++it;
+               increment(it);
        }
 }
 
@@ -1286,7 +1286,7 @@ bool MathCursor::interpret(char c)
 }
 
 
-void MathCursor::setSelection(MathIterator const & where, size_type n)
+void MathCursor::setSelection(CursorBase const & where, size_type n)
 {
        selection_ = true;
        Anchor_ = where;
Index: mathed/math_cursor.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_cursor.h,v
retrieving revision 1.155
diff -u -p -r1.155 math_cursor.h
--- mathed/math_cursor.h        13 Jan 2004 12:28:35 -0000      1.155
+++ mathed/math_cursor.h        14 Jan 2004 18:10:33 -0000
@@ -13,10 +13,9 @@
 #ifndef MATH_CURSOR
 #define MATH_CURSOR
 
+#include "cursor_slice.h"
 #include "math_inset.h"
 #include "math_data.h"
-#include "math_iterator.h"
-#include "support/types.h"
 
 #include <string>
 
@@ -225,7 +224,7 @@ public:
        /// dump selection information for debugging
        void dump(char const * str) const;
        /// moves on
-       void setSelection(MathIterator const & where, size_type n);
+       void setSelection(CursorBase const & where, size_type n);
        /// grab selection marked by anchor and current cursor
        std::string grabSelection() const;
        /// guess what
@@ -282,9 +281,9 @@ private:
        idx_type & idx();
 
        /// path of positions the cursor had to go if it were leaving each inset
-       MathIterator Cursor_;
+       CursorBase Cursor_;
        /// path of positions the anchor had to go if it were leaving each inset
-       mutable MathIterator Anchor_;
+       mutable CursorBase Anchor_;
        /// pointer to enclsing LyX inset
        InsetFormulaBase * formula_;
        // Selection stuff
Index: mathed/math_iterator.C
===================================================================
RCS file: mathed/math_iterator.C
diff -N mathed/math_iterator.C
--- mathed/math_iterator.C      14 Jan 2004 17:58:07 -0000      1.29
+++ /dev/null   1 Jan 1970 00:00:00 -0000
@@ -1,88 +0,0 @@
-/**
- * \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 "math_inset.h"
-#include "math_data.h"
-
-#include <boost/assert.hpp>
-
-
-void MathIterator::operator++()
-{
-       CursorSlice & top = back();
-       MathArray   & ar  = top.asMathInset()->cell(top.idx_);
-
-       // move into the current inset if possible
-       // it is impossible for pos() == size()!
-       MathInset * n = 0;
-       if (top.pos_ != ar.size())
-               n = (ar.begin() + top.pos_)->nucleus();
-       if (n && n->isActive()) {
-               push_back(CursorSlice(n));
-               return;
-       }
-
-       // otherwise move on one cell back if possible
-       if (top.pos_ < ar.size()) {
-               // pos() == size() is valid!
-               ++top.pos_;
-               return;
-       }
-
-       // otherwise try to move on one cell if possible
-       while (top.idx_ + 1 < top.asMathInset()->nargs()) {
-               // idx() == nargs() is _not_ valid!
-               ++top.idx_;
-               if (top.asMathInset()->validCell(top.idx_)) {
-                       top.pos_ = 0;
-                       return;
-               }
-       }
-
-       // otherwise leave array, move on one back
-       // this might yield pos() == size(), but that's a ok.
-       pop_back();
-       // it certainly invalidates top
-       ++back().pos_;
-}
-
-
-bool operator==(MathIterator const & it, MathIterator const & jt)
-{
-       return MathIterator::base_type(it) == MathIterator::base_type(jt);
-}
-
-
-bool operator!=(MathIterator const & it, MathIterator const & jt)
-{
-       return MathIterator::base_type(it) != MathIterator::base_type(jt);
-}
-
-
-MathIterator ibegin(MathInset * p)
-{
-       MathIterator it;
-       it.push_back(CursorSlice(p));
-       return it;
-}
-
-
-MathIterator iend(MathInset * p)
-{
-       MathIterator it;
-       it.push_back(CursorSlice(p));
-       CursorSlice & top = it.back();
-       top.idx_ = top.asMathInset()->nargs() - 1;
-       top.pos_ = top.asMathInset()->cell(top.idx_).size();
-       return it;
-}
Index: mathed/math_iterator.h
===================================================================
RCS file: mathed/math_iterator.h
diff -N mathed/math_iterator.h
--- mathed/math_iterator.h      14 Jan 2004 17:46:46 -0000      1.21
+++ /dev/null   1 Jan 1970 00:00:00 -0000
@@ -1,57 +0,0 @@
-// -*- C++ -*-
-/**
- * \file math_iterator.h
- * 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.
- */
-
-#ifndef MATH_ITERATOR_H
-#define MATH_ITERATOR_H
-
-#include "cursor_slice.h"
-
-#include <vector>
-
-
-// this is used for traversing math insets
-
-class MathIterator : private std::vector<CursorSlice> {
-public:
-       // re-use inherited stuff
-       typedef std::vector<CursorSlice> base_type;
-       using base_type::clear;
-       using base_type::size;
-       using base_type::push_back;
-       using base_type::pop_back;
-       using base_type::back;
-       using base_type::begin;
-       using base_type::end;
-       using base_type::erase;
-       using base_type::operator[];
-       using base_type::size_type;
-       using base_type::difference_type;
-       using base_type::const_iterator;
-       friend bool operator!=(MathIterator const &, MathIterator const &);
-       friend bool operator==(MathIterator const &, MathIterator const &);
-
-       /// move on one step
-       void operator++();
-       /// read access to top most item
-       MathArray const & cell() const;
-};
-
-///
-bool operator==(MathIterator const &, MathIterator const &);
-///
-bool operator!=(MathIterator const &, MathIterator const &);
-
-///
-MathIterator ibegin(MathInset * p);
-///
-MathIterator iend(MathInset * p);
-
-#endif

Reply via email to