]> git.lyx.org Git - lyx.git/commitdiff
more IU
authorAndré Pönitz <poenitz@gmx.net>
Wed, 14 Jan 2004 18:17:02 +0000 (18:17 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Wed, 14 Jan 2004 18:17:02 +0000 (18:17 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8351 a592a061-630c-0410-9148-cb99ea01b6c8

src/cursor_slice.C
src/cursor_slice.h
src/mathed/Makefile.am
src/mathed/formulabase.C
src/mathed/math_cursor.C
src/mathed/math_cursor.h
src/mathed/math_iterator.C [deleted file]
src/mathed/math_iterator.h [deleted file]

index 7094014d89c1cd6cc1a50256ca38ab9f313bc13f..4427fc3984f0647fe7b2644f306e475d1b8996e3 100644 (file)
 #include "debug.h"
 
 #include "mathed/math_inset.h"
+#include "mathed/math_data.h"
+
 #include "insets/updatableinset.h"
 
+
 #include <boost/assert.hpp>
 
 using std::endl;
@@ -181,3 +184,64 @@ std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
 ;
        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(InsetBase * p)
+{
+       CursorBase it;
+       it.push_back(CursorSlice(p));
+       return it;
+}
+
+
+CursorBase iend(InsetBase * 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 5655a8fa7b3c85c560130f78f726d9391bc7ee5c..48a850b98f48345763d5ec001e866fc74540f27f 100644 (file)
@@ -127,4 +127,17 @@ bool operator<(CursorSlice const &, CursorSlice const &);
 /// 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 40edab9de390a57a12e1571e3ffa1f7acbe8b7c2..c400caeb2545b46f75898816660aa1528170b947 100644 (file)
@@ -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 eba3876d0c218b8f602a4ef20121bbfc2d901a06..3ff6ba7d170f9a37c827a6342223ded13313fdfd 100644 (file)
@@ -830,7 +830,7 @@ bool InsetFormulaBase::searchForward(BufferView * bv, string const & str,
 #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(BufferView * bv, string const & str,
                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 7dcaedbe19bc940b0e98c8e23993b8b078468b31..f652c33f3c7c529dfcacf3614a5a968efd51ad70 100644 (file)
@@ -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 e6a98291e58be5c9062f2a252cb583cc71b8db68..55efa1e017fb4adf7f02062d2b72516b4bc7e4f8 100644 (file)
 #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
diff --git a/src/mathed/math_iterator.C b/src/mathed/math_iterator.C
deleted file mode 100644 (file)
index 2f949af..0000000
+++ /dev/null
@@ -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;
-}
diff --git a/src/mathed/math_iterator.h b/src/mathed/math_iterator.h
deleted file mode 100644 (file)
index 8a98fc6..0000000
+++ /dev/null
@@ -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