]> git.lyx.org Git - features.git/commitdiff
patch from Andre and more array changes by me
authorLars Gullik Bjønnes <larsbj@gullik.org>
Mon, 12 Feb 2001 08:55:14 +0000 (08:55 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Mon, 12 Feb 2001 08:55:14 +0000 (08:55 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1483 a592a061-630c-0410-9148-cb99ea01b6c8

17 files changed:
src/mathed/ChangeLog
src/mathed/Makefile.am
src/mathed/array.C [new file with mode: 0644]
src/mathed/array.h
src/mathed/formulamacro.C
src/mathed/math_cursor.C
src/mathed/math_cursor.h
src/mathed/math_defs.h
src/mathed/math_inset.C
src/mathed/math_inset.h
src/mathed/math_iter.C
src/mathed/math_iter.h
src/mathed/math_macro.C
src/mathed/math_macro.h
src/mathed/math_parser.C
src/mathed/math_root.C
src/mathed/math_root.h

index f71d92ee99edd3deaccf592ac7b32631176061f2..ff985aa5f188eb9adf5c024677151e6c8ba1b448 100644 (file)
@@ -1,3 +1,16 @@
+2001-02-09  Lars Gullik Bjønnes  <larsbj@lyx.org>
+
+       * array.h: made all variables private, removed friend, added new
+       methods: raw_pointer_insert, raw_pointer_copy, strange_copy, added
+       non const operator[] added setter for last and getter for maxsize.
+       changed name from LyxArrayBase to MathedArray.
+       changed name of some methods to start with lowerchar.
+       moved inline methods to array.C
+       
+       * math_iter.C + several file: changes because of the above.
+
+       * array.C: new file with the prev inline methods.
+       
 2001-02-10  Dekel Tsur  <dekelts@tau.ac.il>
 
        * Many files: add support for the align environment from amsmath.
index 2ed45838b75a5a9102bc4470f20f41aa34b0096e..d84ec6ca445935b51523ec14615c877b5ac83de4 100644 (file)
@@ -7,7 +7,9 @@ ETAGS_ARGS = --lang=c++
 BOOST_INCLUDES = -I$(top_srcdir)/boost
 INCLUDES = -I${top_srcdir}/images -I${srcdir}/../ $(SIGC_CFLAGS) $(BOOST_INCLUDES)
 
-libmathed_la_SOURCES = array.h \
+libmathed_la_SOURCES = \
+       array.C \
+       array.h \
        formula.C \
        formula.h \
        formulamacro.C \
diff --git a/src/mathed/array.C b/src/mathed/array.C
new file mode 100644 (file)
index 0000000..6c7b9a5
--- /dev/null
@@ -0,0 +1,125 @@
+
+#include <config.h>
+
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include "array.h"
+#include "math_defs.h"
+
+
+// Is this still needed? (Lgb)
+static inline
+void * my_memcpy(void * ps_in, void const * pt_in, size_t n)
+{
+       char * ps = static_cast<char *>(ps_in);
+       char const * pt = static_cast<char const *>(pt_in);
+       while (n--) *ps++ = *pt++;
+       return ps_in;
+}
+
+
+int MathedArray::empty() const
+{
+       return (last_ == 0);
+}
+   
+
+int MathedArray::last() const
+{
+       return last_;
+}
+
+
+void MathedArray::last(int l)
+{
+       last_ = l;
+}
+
+
+int MathedArray::maxsize() const
+{
+       return maxsize_;
+}
+
+
+void MathedArray::resize(int newsize)
+{
+       if (newsize < ARRAY_MIN_SIZE)
+               newsize = ARRAY_MIN_SIZE;
+       newsize += ARRAY_STEP - (newsize % ARRAY_STEP);
+       bf_.resize(newsize);
+       if (last_ >= newsize) last_ = newsize - 1;
+       maxsize_ = newsize;
+       bf_[last_] = 0;
+}
+
+
+MathedArray::MathedArray(int size) 
+{
+       maxsize_ = (size < ARRAY_MIN_SIZE) ? ARRAY_MIN_SIZE : size;
+       bf_.resize(maxsize_);
+       last_ = 0;
+}
+
+
+void MathedArray::move(int p, int shift)
+{
+       if (p <= last_) {
+               if (last_ + shift >= maxsize_) { 
+                   resize(last_ + shift);
+               }
+               memmove(&bf_[p + shift], &bf_[p], last_ - p);
+               last_ += shift;
+               bf_[last_] = 0;
+       }
+}
+
+
+void MathedArray::mergeF(MathedArray * a, int p, int dx)
+{
+       my_memcpy(&bf_[p], &a->bf_[0], dx);
+}
+
+
+void MathedArray::raw_pointer_copy(MathedInset ** p, int pos) const
+{
+       my_memcpy(p, &bf_[pos], sizeof(MathedInset*));
+}
+
+
+void MathedArray::raw_pointer_insert(void * p, int pos, int len)
+{
+       my_memcpy(&bf_[pos], &p, len);
+}
+
+
+void MathedArray::strange_copy(MathedArray * dest, int dpos,
+                               int spos, int len)
+{
+       my_memcpy(&dest[dpos], &bf_[spos], len);
+}
+
+
+byte MathedArray::operator[](int i) const
+{
+       return bf_[i];
+}
+
+
+byte & MathedArray::operator[](int i)
+{
+       return bf_[i];
+}
+
+
+void MathedArray::insert(int pos, byte c)
+{
+       if (pos < 0) pos = last_;
+       if (pos >= maxsize_) 
+               resize(maxsize_ + ARRAY_STEP);
+       bf_[pos] = c;
+       if (pos >= last_)
+               last_ = pos + 1;
+}
index 9f9bdd36f09111c042d31b486ef9737a48177e71..def0ffd18586626f6eadc71505ee317e30c51a5c 100644 (file)
@@ -1,6 +1,5 @@
 // -*- C++ -*-
 /*
- *  File:        array.h
  *  Purpose:     A general purpose resizable array.  
  *  Author:      Alejandro Aguilar Sierra <asierra@servidor.unam.mx> 
  *  Created:     January 1996
  *   the GNU General Public Licence version 2 or later.
  */
 
+#ifndef MATHEDARRAY_H
+#define MATHEDARRAY_H
+
 #include <vector>
 
+
+class MathedInset;
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
 #ifndef byte
 #define byte unsigned char
 #endif
 
-/** A resizable array.
+/** \class MathedArray
+    \brief A resizable array.
+    
     A general purpose resizable array.
-    @author Alejandro Aguilar Sierra
-    @version January 1996
+    
+    \author Alejandro Aguilar Sierra
+    \author André Pönitz
+    \author Lars Gullik Bjønnes
+    \version February 2001
   */
-class LyxArrayBase  {
+class MathedArray  {
 public:
        ///
-       typedef std::vector<byte> buffer_type;
+       typedef std::vector<byte>         buffer_type;
+       typedef byte                      value_type;
+       typedef buffer_type::size_type    size_type;
        ///
        enum {
                ///
@@ -41,148 +57,47 @@ public:
 
        ///
        explicit
-       LyxArrayBase(int size = ARRAY_STEP);
+       MathedArray(int size = ARRAY_STEP);
 
        ///
-       int empty() const { return (last == 0); }
+       int empty() const;
    
        ///
-       int Last() { return last; }
+       int last() const;
+       ///
+       void last(int l);
    
-       /// Make the allocated memory fit the needed size
-       void Fit();     
-
-       /// Remove dx elements from position pos. Don't changes the size
-       void Remove(int pos, int dx);   
-
-       /// Merge dx elements from array a at pos. Changes the size if necessary.
-       void Merge(LyxArrayBase * a, int pos, int dx); 
-
-       /// Same as Merge but doesn't changes the size (dangerous)
-       void MergeF(LyxArrayBase * a, int pos, int dx); 
+       /// Merge \a dx elements from array \a a at \apos.
+       /// This doesn't changes the size (dangerous)
+       void mergeF(MathedArray * a, int pos, int dx); 
 
-       /// Copy dx byts from an array at position pos
-       void Copy(void *, int pos, int dx); 
+       /// Insert a character at position \a pos
+       void insert(int pos, byte);
 
-       /// Constructs a new array with dx elements starting at pos 
-       LyxArrayBase * Extract(int pos, int dx); 
-
-       /// Insert a character at position pos
-       void Insert(int pos, byte);
-
-       /// Constructs a new array with dx elements starting at pos 
-       byte operator[](const int);
-
-protected:
        ///
-       void Resize(int newsize);
+       void raw_pointer_copy(MathedInset ** p, int pos) const;
+       ///
+       void raw_pointer_insert(void * p, int pos, int len);
+       ///
+       void strange_copy(MathedArray * dest, int dpos, int spos, int len);
+       ///
+       byte operator[](int) const;
+       ///
+       byte & operator[](int i);
+       
+       ///
+       void move(int p, int shift);
        ///
-       bool Move(int p, int shift);
+       void resize(int newsize);
+       ///
+       int maxsize() const;
+private:
 
        /// Buffer
-       buffer_type bf;
+       buffer_type bf_;
        /// Last position inserted.
-       int last;
+       int last_;
        /// Max size of the array.
-       int maxsize;
-private:
-       ///
-       friend class MathedIter;
+       int maxsize_;
 };
-   
-
-
-/************************ Inline functions *****************************/
-
-inline // Hmmm, Hp-UX's CC can't handle this inline. Asger.
-void LyxArrayBase::Resize(int newsize)
-{
-       if (newsize<ARRAY_MIN_SIZE)
-               newsize = ARRAY_MIN_SIZE;
-       newsize += ARRAY_STEP - (newsize % ARRAY_STEP);
-       bf.resize(newsize);
-       if (last >= newsize) last = newsize-1;
-       maxsize = newsize;
-       bf[last] = 0;
-}
-
-inline
-LyxArrayBase::LyxArrayBase(int size) 
-{
-       maxsize = (size<ARRAY_MIN_SIZE) ? ARRAY_MIN_SIZE: size;
-       bf.resize(maxsize);
-       last = 0;
-}
-
-inline   
-bool LyxArrayBase::Move(int p, int shift) 
-{
-       bool result = false;
-       if (p <= last) {
-               if (last + shift >= maxsize) { 
-                   Resize(last + shift);
-               }
-               memmove(&bf[p + shift], &bf[p], last - p);
-               last += shift;
-               bf[last] = 0;
-               result = true;
-       }
-       return result;
-}
-
-inline
-void LyxArrayBase::Fit()
-{
-       Resize(last);
-}
-
-inline
-void LyxArrayBase::Remove(int pos, int dx)
-{
-       Move(pos + dx, -dx);
-}    
-
-inline
-void LyxArrayBase::Merge(LyxArrayBase * a, int p, int dx)
-{
-       Move(p, dx);
-       memcpy(&bf[p], &a->bf[0], dx);
-}
-inline
-void LyxArrayBase::MergeF(LyxArrayBase * a, int p, int dx)
-{
-       memcpy(&bf[p], &a->bf[0], dx);
-}
-inline
-void LyxArrayBase::Copy(void * a, int p, int dx)
-{
-       memcpy(&bf[p], a, dx);
-}
-
-inline
-LyxArrayBase * LyxArrayBase::Extract(int, int dx)
-{
-       LyxArrayBase * a = new LyxArrayBase(dx);
-       a->Merge(this, 0, dx);
-       return a;
-}
-inline
-byte LyxArrayBase::operator[](const int i)
-{
-       return bf[i];
-}
-
-
-inline
-void LyxArrayBase::Insert(int pos, byte c)
-{
-       if (pos < 0) pos = last;
-       if (pos >= maxsize) 
-               Resize(maxsize + ARRAY_STEP);
-       bf[pos] = c;
-       if (pos >= last)
-               last = pos + 1;
-}
+#endif
index 5504ab93a04f5e969df23016246542d1b28d216a..5c9dbc16a309cc628b8ec2132d400568364926e1 100644 (file)
@@ -193,7 +193,7 @@ void InsetFormulaMacro::Edit(BufferView * bv, int x, int y,unsigned int button)
 void InsetFormulaMacro::InsetUnlock(BufferView * bv)
 {
     opened = false;
-    LyxArrayBase * tarray = tmacro->GetData();
+    MathedArray * tarray = tmacro->GetData();
     MathedIter it(tarray);
     it.Clear();
     tmacro->SetData(par->GetData());
index 5d6895338571cda4d550dc5a73e3483104ed1834..e8d48803a2ed35764403d9b12bdef97d4333890e 100644 (file)
@@ -31,7 +31,7 @@
 #include "LColor.h"
 #include "Painter.h"
 
-static LyxArrayBase * selarray = 0;
+static MathedArray * selarray = 0;
 
 using std::endl;
 
@@ -776,7 +776,7 @@ bool MathedCursor::pullArg()
        if (!p) { 
            return false;
        }
-       LyxArrayBase * a = p->GetData();
+       MathedArray * a = p->GetData();
        p->SetData(0);
        Delete();
        if (a) {
index 5bc6df4683499d851f8790d93dd00258ddd8a048..0ca9ffdf14574198dae025e2b06b0492b96135e8 100644 (file)
@@ -147,7 +147,7 @@ class MathedCursor {
     ///
     MathedXIter cursel, * anchor;
     ///
-//    LyxArrayBase *selarray; 
+//    MathedArray *selarray; 
     ///
     bool is_visible;
     ///
index 0d1901d5d6b9e0b255bdc12993c6a0a7097fcfa3..2a01d91fd23ab47645e2af7da3fa1fbb04ed41e7 100644 (file)
@@ -337,9 +337,9 @@ class MathParInset: public MathedInset  {
     virtual void UserSetSize(short);
  
     /// Data is stored in a LyXArray
-    virtual void SetData(LyxArrayBase *);
+    virtual void SetData(MathedArray *);
     ///
-    virtual LyxArrayBase * GetData() { return array; }
+    virtual MathedArray * GetData() { return array; }
 
     /// Paragraph position
     virtual void GetXY(int &, int &) const;
@@ -379,7 +379,7 @@ class MathParInset: public MathedInset  {
     
  protected:
     /// Paragraph data is stored here
-    LyxArrayBase * array;
+    MathedArray * array;
     /// Cursor start position
     int xo;
     ///
@@ -397,8 +397,8 @@ class MathParInset: public MathedInset  {
     ///
     friend class MathedCursor;
     ///
-    friend LyxArrayBase * mathed_parse(unsigned flags = 0,
-                                      LyxArrayBase * a = 0,
+    friend MathedArray * mathed_parse(unsigned flags = 0,
+                                      MathedArray * a = 0,
                                       MathParInset ** p = 0);
 };
 
@@ -488,7 +488,7 @@ class MathMatrixInset: public MathParInset {
     ///
     void Metrics();
     ///
-    void SetData(LyxArrayBase *);
+    void SetData(MathedArray *);
     ///
     void SetAlign(char, string const &);
     ///
@@ -523,7 +523,7 @@ class MathMatrixInset: public MathParInset {
 
 /*************************  Prototypes  **********************************/
 /// 
-LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * data,
+MathedArray * mathed_parse(unsigned flags, MathedArray * data,
                            MathParInset ** mt);
 ///
 void mathed_write(MathParInset *, std::ostream &, int *, bool fragile,
index 491a9d0d396c54554d3fc3eaa9d49361029ba526..d09a80d01e14eab62cb9f98288bde72842a166f3 100644 (file)
@@ -115,7 +115,7 @@ MathedInset * MathParInset::Clone()
 }
 
 
-void MathParInset::SetData(LyxArrayBase * a)
+void MathParInset::SetData(MathedArray * a)
 {
     array = a;
    
@@ -236,14 +236,14 @@ void MathFracInset::SetStyle(short st)
 }
 
 
-void MathFracInset::SetData(LyxArrayBase * n, LyxArrayBase * d)
+void MathFracInset::SetData(MathedArray * n, MathedArray * d)
 {
    den->SetData(d);
    MathParInset::SetData(n);
 }
 
 
-void MathFracInset::SetData(LyxArrayBase * d)
+void MathFracInset::SetData(MathedArray * d)
 {
    if (idx == 0)
      MathParInset::SetData(d);
@@ -262,7 +262,7 @@ void MathFracInset::GetXY(int & x, int & y) const
 }
 
 
-LyxArrayBase * MathFracInset::GetData()
+MathedArray * MathFracInset::GetData()
 {
    if (idx == 0)
      return array;
@@ -368,7 +368,7 @@ void MathMatrixInset::SetAlign(char vv, string const & hh)
 
 
 // Check the number of tabs and crs
-void MathMatrixInset::SetData(LyxArrayBase * a)
+void MathMatrixInset::SetData(MathedArray * a)
 {
     if (!a) return;
     MathedIter it(a);
index 2c3bc54bbdb23af4282530d44c48636d7ae0cff7..618c42601ce7a63e3388c3c2493686325098c684 100644 (file)
@@ -201,12 +201,12 @@ public:
        ///
        void Metrics();
        
-       /** This does the same that SetData(LyxArrayBase*) but for both
+       /** This does the same that SetData(MathedArray*) but for both
            numerator and denominator at once.
        */
-       void SetData(LyxArrayBase *, LyxArrayBase *);
+       void SetData(MathedArray *, MathedArray *);
        ///
-       void SetData(LyxArrayBase *);
+       void SetData(MathedArray *);
        ///
        void GetXY(int & x, int & y) const;
        ///
@@ -214,7 +214,7 @@ public:
        ///
        bool Inside(int, int);
        ///
-       LyxArrayBase * GetData();
+       MathedArray * GetData();
        ///
        bool setArgumentIdx(int i); // was bool Up/down(void);
        ///
index 0a1bff2d1755cf40a945772fcbcf2e114fcc8b10..b7a12f7cd33440e4652d522a72832d433736f991 100644 (file)
@@ -35,25 +35,11 @@ extern int mathed_char_width(short type, int style, byte c);
 extern int mathed_string_width(short type, int style, string const & s);
 extern int mathed_char_height(short, int, byte, int &, int &);
 
-// the builtin memcpy() is broken in egcs and gcc 2.95.x on alpha
-// stations. We provide a hand-made version instead. 
-static inline
-void my_memcpy( void * ps_in, void const * pt_in, size_t n )
-{
-    char * ps = static_cast<char *>(ps_in);
-    char const * pt = static_cast<char const *>(pt_in);
-    /*
-    for (size_t i = n; i--;)
-       *ps++ = *pt++;
-       */
-    while (n--) *ps++ = *pt++;
-}
-
 
 void MathedIter::Reset()
 {
-    if (array->last > 0 && MathIsFont(array->bf[0])) {
-       fcode = array->bf[0];
+    if (array->last() > 0 && MathIsFont((*array)[0])) {
+       fcode = (*array)[0];
        pos = 1;
     } else {
        fcode = -1;
@@ -66,39 +52,41 @@ void MathedIter::Reset()
 byte MathedIter::GetChar() const
 {
     if (IsFont()) { 
-       fcode = array->bf[pos];
+       fcode = (*array)[pos];
        ++pos;
     }
-    return array->bf[pos];
+    return (*array)[pos];
 }
 
 
 string const MathedIter::GetString() const
 {
        if (IsFont()) { 
-               fcode = array->bf[++pos];
+               fcode = (*array)[++pos];
                ++pos;
        }
        string s;
-       for ( ; array->bf[pos] >= ' ' && pos < array->last; ++pos)
-               s += array->bf[pos];
+       for (; (*array)[pos] >= ' ' && pos < array->last(); ++pos)
+               s += (*array)[pos];
 
        return s;
 }
-       
+
+
 MathedInset * MathedIter::GetInset() const
 {
    if (IsInset()) {
       MathedInset * p;
-      my_memcpy(&p, &array->bf[pos + 1], sizeof(p));
+      array->raw_pointer_copy(&p, pos + 1);
       return p;
    } else {
           lyxerr << "Math Error: This is not an inset["
-                 << array->bf[pos] << "]" << endl;
+                 << (*array)[pos] << "]" << endl;
      return 0;
    }
 }
 
+
 // An active math inset MUST be derived from MathParInset because it 
 // must have at least one paragraph to edit
 MathParInset * MathedIter::GetActiveInset() const
@@ -111,11 +99,12 @@ MathParInset * MathedIter::GetActiveInset() const
     return 0;
 }
 
+
 bool MathedIter::Next()
 {  
     if (!OK()) return false;
    
-    if (array->bf[pos] < ' ') {
+    if ((*array)[pos] < ' ') {
        fcode = -1;     
        if (IsTab()) ++col;
        if (IsCR())  {
@@ -130,7 +119,7 @@ bool MathedIter::Next()
       ++pos;
     
     if (IsFont()) {
-       fcode = array->bf[pos++];
+       fcode = (*array)[pos++];
     }
 
     return true;   
@@ -140,7 +129,7 @@ bool MathedIter::Next()
 bool MathedIter::goNextCode(MathedTextCodes code)
 {  
     while (Next()) {
-       if (array->bf[pos] == code) 
+       if ((*array)[pos] == code) 
          return true;
     }
     
@@ -176,20 +165,20 @@ void MathedIter::Insert(byte c, MathedTextCodes t)
     // Never more than one space // array->bf[pos-1] gives error from purify:
     //       Reading 1 byte from 0x47b857 in the heap.
     //  Address 0x47b857 is 1 byte before start of malloc'd block at 0x47b858 of 16 bytes.
-    if (c == ' ' && (array->bf[pos] == ' ' || array->bf[pos - 1] == ' ')) 
+    if (c == ' ' && ((*array)[pos] == ' ' || (*array)[pos - 1] == ' ')) 
       return;
        
-    if (IsFont() && array->bf[pos] == t) {
+    if (IsFont() && (*array)[pos] == t) {
        fcode = t;
        ++pos;
     } else
-      if (t != fcode && pos > 0 && MathIsFont(array->bf[pos - 1])) {
+      if (t != fcode && pos > 0 && MathIsFont((*array)[pos - 1])) {
          --pos;
          int k = pos - 1;
-         for (; k >= 0 && array->bf[k] >= ' '; --k);
-         fcode = (k >= 0 && MathIsFont(array->bf[k])) ? array->bf[k] : -1;
+         for (; k >= 0 && (*array)[k] >= ' '; --k);
+         fcode = (k >= 0 && MathIsFont((*array)[k])) ? (*array)[k] : -1;
       }
-    short const f = (array->bf[pos] < ' ') ? 0 : fcode;
+    short const f = ((*array)[pos] < ' ') ? 0 : fcode;
     int shift = (t == fcode) ? 1 : ((f) ? 3 : 2);
     
     if (t == LM_TC_TAB || t == LM_TC_CR) {
@@ -202,90 +191,91 @@ void MathedIter::Insert(byte c, MathedTextCodes t)
          ++col;
     }
  
-    if (pos < array->last)
-        array->Move(pos, shift);
+    if (pos < array->last())
+        array->move(pos, shift);
     else {
-       if (array->last+shift >= array->maxsize) {
-           array->Resize(array->last+shift);
+       if (array->last() + shift >= array->maxsize()) {
+           array->resize(array->last() + shift);
        }
-       array->last += shift;
-       array->bf[array->last] = '\0';
+       array->last(array->last() + shift);
+       (*array)[array->last()] = '\0';
     }
     if (t != fcode) {
        if (f)  
-         array->bf[pos + shift - 1] = fcode;
+         (*array)[pos + shift - 1] = fcode;
        if (c >= ' ') {
-           array->bf[pos++] = t;
+           (*array)[pos++] = t;
            fcode = t;
        } else {
            fcode = 0;
        }
-    }      
-    array->bf[pos++] = c;
+    }
+    (*array)[pos++] = c;
 }
 
 
 // Prepare to insert a non-char object
 void MathedIter::split(int shift)
 {
-   if (pos < array->last) {
+   if (pos < array->last()) {
       bool fg = false;
-      if (array->bf[pos] >= ' ') {
-        if (pos> 0 && MathIsFont(array->bf[pos - 1]))
+      if ((*array)[pos] >= ' ') {
+        if (pos> 0 && MathIsFont((*array)[pos - 1]))
           --pos;
         else { 
-           fg = true; 
+           fg = true;
            ++shift;
         }
       }      
-      array->Move(pos, shift);
-      if (fg) array->bf[pos + shift - 1] = fcode;
+      array->move(pos, shift);
+      if (fg) (*array)[pos + shift - 1] = fcode;
    } else {
-      if (array->last + shift >= array->maxsize) {
-         array->Resize(array->last + shift);
+      if (array->last() + shift >= array->maxsize()) {
+         array->resize(array->last() + shift);
       }
-      array->last += shift;
+      array->last(array->last() + shift);
    }
-   array->bf[array->last] = '\0';
+   (*array)[array->last()] = '\0';
 }
 
 
 // I assume that both pos and pos2 are legal positions
 void MathedIter::join(int pos2)
 {   
-    if (!OK() || pos2<= pos)
+    if (!OK() || pos2 <= pos)
       return;    
 
     short f = fcode;
-    if (pos > 0 && array->bf[pos] >= ' ' && MathIsFont(array->bf[pos - 1]))
+    if (pos > 0 && (*array)[pos] >= ' ' && MathIsFont((*array)[pos - 1]))
       --pos;   
            
-    if (MathIsFont(array->bf[pos2 - 1]))
+    if (MathIsFont((*array)[pos2 - 1]))
       --pos2;
     
-    if (array->bf[pos2] >= ' ') {
+    if ((*array)[pos2] >= ' ') {
        for (int p = pos2; p > 0; --p) 
-         if (MathIsFont(array->bf[p])) {
-             f = array->bf[p];
+         if (MathIsFont((*array)[p])) {
+             f = (*array)[p];
              break;
          }
-       array->bf[pos++] = f;
+       (*array)[pos++] = f;
     }    
 
-    array->Move(pos2, pos - pos2);
+    array->move(pos2, pos - pos2);
 }
 
+
 void MathedIter::Insert(MathedInset * p, int type)
 {
     int const shift = SizeInset;
     if (!MathIsInset(type))
       type = LM_TC_INSET;
     split(shift);
-    array->bf[pos] = type;
-    my_memcpy(&array->bf[pos + 1], &p, sizeof(p));
+    (*array)[pos] = type;
+    array->raw_pointer_insert(p, pos + 1, sizeof(p));
     pos += SizeInset;
-    array->bf[pos - 1] = type;
-    array->bf[array->last] = '\0';
+    (*array)[pos - 1] = type;
+    (*array)[array->last()] = '\0';
     fcode = -1;
 }
 
@@ -297,18 +287,18 @@ bool MathedIter::Delete()
    
    int shift = 0;
    byte c = GetChar();
-   if (c >= ' ') { 
-      if (MathIsFont(array->bf[pos - 1]) && array->bf[pos + 1] < ' ') {
+   if (c >= ' ') {
+      if (MathIsFont((*array)[pos - 1]) && (*array)[pos + 1] < ' ') {
         shift = 2;
         pos--;
         int i = pos - 1;
-        for (; i > 0 && !MathIsFont(array->bf[i]); --i);
-        if (i > 0 && MathIsFont(array->bf[i]))
-          fcode = array->bf[i];
+        for (; i > 0 && !MathIsFont((*array)[i]); --i);
+        if (i > 0 && MathIsFont((*array)[i]))
+          fcode = (*array)[i];
       } else
-       shift = 1;      
+       shift = 1;
    } else {
-      if (MathIsInset(array->bf[pos]))
+      if (MathIsInset((*array)[pos]))
        shift = sizeof(char*) + 2;
      else if (c == LM_TC_TAB || c == LM_TC_CR) {
         ++shift;
@@ -319,65 +309,64 @@ bool MathedIter::Delete()
    } 
     
    if (shift != 0) {
-      array->Move(pos + shift, -shift);
-      if (pos >= array->last) 
-        pos = (array->last > 0) ? array->last : 0;
+      array->move(pos + shift, -shift);
+      if (pos >= array->last()
+        pos = (array->last() > 0) ? array->last() : 0;
        return true;
    } else
      return false;
 }
 
 
-LyxArrayBase * MathedIter::Copy(int pos1, int pos2)
+MathedArray * MathedIter::Copy(int pos1, int pos2)
 {
    if (!array) {
 //      lyxerr << "Math error: Attempting to copy a void array." << endl;
       return 0;
    }
       
-//   int posx = pos;
    ipush(); 
-   LyxArrayBase * t = array, * a;
+   MathedArray * t = array;
+   MathedArray * a;
     
-   if (pos1 > 0 || pos2 <= array->last) {       
+   if (pos1 > 0 || pos2 <= array->last()) {       
        short fc = 0;
-       if (pos1 > 0 && array->bf[pos1] > ' ') {
+       if (pos1 > 0 && (*array)[pos1] > ' ') {
           for (int p = pos1; p >= 0; --p) 
-            if (MathIsFont(array->bf[p])) {
+            if (MathIsFont((*array)[p])) {
                 if (p != pos1 - 1)
-                  fc = array->bf[p];
+                  fc = (*array)[p];
                 else
                   --pos1;
                 break;
             }
        }
 
-       if (pos2 > 0 && array->bf[pos2] >= ' '
-          && MathIsFont(array->bf[pos2 - 1])) 
+       if (pos2 > 0 && (*array)[pos2] >= ' '
+          && MathIsFont((*array)[pos2 - 1])) 
         --pos2;
 
        int dx = pos2 - pos1;
-       a = new LyxArrayBase(dx + LyxArrayBase::ARRAY_MIN_SIZE);
+       a = new MathedArray(dx + MathedArray::ARRAY_MIN_SIZE);
 //       lyxerr << "VA " << pos2 << " " << pos2 << " " << dx << endl;
-       my_memcpy(&a->bf[(fc) ? 1 : 0], &array->bf[pos1], dx);
+       array->strange_copy(a, (fc) ? 1 : 0, pos1, dx);
        if (fc) {
-          a->bf[0] = fc;
+          (*a)[0] = fc;
           ++dx;
        }
-       a->last = dx;
-       a->bf[dx] = '\0';
+       a->last(dx);
+       (*a)[dx] = '\0';
    }  else   
-      a = new LyxArrayBase(*array);
+      a = new MathedArray(*array);
    SetData(a);
    while (OK()) {
       if (IsInset()) {
         MathedInset * inset = GetInset();
         inset = inset->Clone();
-        my_memcpy(&array->bf[pos + 1], &inset, sizeof(inset));
+        array->raw_pointer_insert(inset, pos + 1, sizeof(inset));
       }
       Next();
    }
-//   pos = posx;
    array = t;
    ipop(); 
    return a;
@@ -389,7 +378,7 @@ void MathedIter::Clear()
    if (!array) {
           lyxerr << "Math error: Attempting to clean a void array." << endl;
       return;
-   }   
+   }
    Reset();  
    while (OK()) {
       if (IsInset()) {
@@ -477,7 +466,7 @@ void MathedXIter::Clean(int pos2)
     }    
     ipop();
     
-    if (pos2 <= array->Last()) {
+    if (pos2 <= array->last()) {
        pos = pos1;
        join(pos2);
        checkTabs();
@@ -485,7 +474,7 @@ void MathedXIter::Clean(int pos2)
 }
 
 
-void MathedXIter::Merge(LyxArrayBase * a0)
+void MathedXIter::Merge(MathedArray * a0)
 {
     if (!a0) {
            lyxerr[Debug::MATHED]
@@ -495,15 +484,14 @@ void MathedXIter::Merge(LyxArrayBase * a0)
     }
     // All insets must be clonned
     MathedIter it(a0);
-    LyxArrayBase * a = it.Copy();
+    MathedArray * a = it.Copy();
     
     // make room for the data 
-    split(a->Last());
-    array->MergeF(a, pos, a->Last());
+    split(a->last());
+    array->mergeF(a, pos, a->last());
 
     int pos1 = pos;
-    int pos2 = pos + a->Last();
-    // int pos3 = 0;
+    int pos2 = pos + a->last();
 
     goPosAbs(pos1);
     
@@ -553,6 +541,7 @@ MathedXIter::MathedXIter(MathParInset * pp)
     }
 }
 
+
 void MathedXIter::SetData(MathParInset * pp)
 {
     p = pp;
@@ -570,7 +559,7 @@ void MathedXIter::SetData(MathParInset * pp)
        y = crow->getBaseline();
     } 
     if (!array) {
-           array = new LyxArrayBase; // this leaks
+           array = new MathedArray; // this leaks
        p->SetData(array);
     }
     size = p->GetStyle();
@@ -653,6 +642,7 @@ void MathedXIter::GoBegin()
    }
 }
 
+
 void MathedXIter::GoLast()
 {
    while (Next());
@@ -699,7 +689,7 @@ bool MathedXIter::Up()
     if (row == 0) return false;
     int xp = x;
     int rowp = row;
-    int colp= col;
+    int colp = col;
     GoBegin();
     while (row < rowp - 1) Next();
     while (x < xp && OK() && !IsCR()) {
@@ -803,6 +793,7 @@ void MathedXIter::delRow()
     checkTabs();    
 }
 
+
 void MathedXIter::ipush()
 { 
     MathedIter::ipush();
index dc19a7f43c01d84f2eb45cca0a75412ecc288064..f790f667ef633598256233424951b66d13e434f4 100644 (file)
@@ -50,7 +50,7 @@ class MathedIter {
     }
     ///
     explicit
-    MathedIter(LyxArrayBase *);
+    MathedIter(MathedArray *);
     ///
     virtual ~MathedIter() {}
     ///
@@ -60,9 +60,9 @@ class MathedIter {
     ///
     void goPosAbs(int);
     ///
-    int Empty() const { return array->Last()<= 1; }
+    int Empty() const { return array->last() <= 1; }
     ///
-    int OK() const { return array && (pos < array->Last()); }
+    int OK() const { return array && (pos < array->last()); }
     ///
     int IsFirst() const { return (pos == 0); }
     ///
@@ -110,12 +110,12 @@ class MathedIter {
     ///
     void setNumCols(int n) { ncols = n; }
     ///
-    void SetData(LyxArrayBase * a) { array = a; Reset(); }
+    void SetData(MathedArray * a) { array = a; Reset(); }
     ///
-    LyxArrayBase * GetData() const { return array; }
+    MathedArray * GetData() const { return array; }
     
     /// Copy every object from position p1 to p2
-    LyxArrayBase * Copy(int p1 = 0, int p2 = 10000);
+    MathedArray * Copy(int p1 = 0, int p2 = 10000);
    
     /// Delete every object from position p1 to p2
     void Clear();
@@ -134,7 +134,7 @@ class MathedIter {
     ///
     int row, col, ncols;
     ///
-    LyxArrayBase * array;
+    MathedArray * array;
     // one element stack
     struct MIState {
        ///
@@ -229,7 +229,7 @@ class MathedXIter: public MathedIter {
     ///
     void setTab(int, int);
     /// Merge the array at current position
-    void Merge(LyxArrayBase *);
+    void Merge(MathedArray *);
     /// Delete every object from current position to pos2
     void Clean(int pos2);
     ///
@@ -312,14 +312,14 @@ bool MathedIter::IsCR() const
 
 
 inline
-MathedIter::MathedIter(LyxArrayBase * d)
+MathedIter::MathedIter(MathedArray * d)
        : array(d)
 {
     pos = 0;
     row = col = 0;
     fcode = (array && IsFont()) ? (*array)[0]: 0;
 }
-     
+
 
 inline
 void MathedIter::ipush()
@@ -346,11 +346,14 @@ void MathedXIter::GetPos(int & xx, int & yy) const
 { 
     if (p) 
       p->GetXY(xx, yy);
-    else
-      { xx = 0;  yy = 0; }        
+    else {
+           xx = 0;
+           yy = 0;
+    }        
     xx += x;  yy += y;
 }
 
+
 inline 
 int MathedXIter::GetX() const
 { 
@@ -360,6 +363,7 @@ int MathedXIter::GetX() const
     return xx; 
 }
 
+
 inline 
 int MathedXIter::GetY() const
 { 
@@ -373,7 +377,8 @@ int MathedXIter::GetY() const
 inline
 void MathedXIter::GetIncPos(int & xx, int & yy) const
 { 
-    xx = x;  yy = y; 
+    xx = x;
+    yy = y; 
 }
 
 
index 493138c3157b25baf72dfe9fd175bf1a6c989fba..0f227cf615c27471f966157d40eda471b84a6548 100644 (file)
@@ -66,7 +66,7 @@ MathMacro::MathMacro(MathMacroTemplate* t):
          args[i].row = 0;
 /*     int k = tmplate->getMacroPar(i)->GetColumns();
        if (k>0) {
-           args[i].array = new LyxArrayBase;
+           args[i].array = new MathedArray;
            for (int j= 0; j<k-1; ++j) args[i].array->Insert(j, LM_TC_TAB);
        }*/
     }
@@ -375,7 +375,7 @@ void MathMacroTemplate::WriteDef(ostream & os, bool fragile)
 }
 
 
-void MathMacroTemplate::setArgument(LyxArrayBase * a, int i)
+void MathMacroTemplate::setArgument(MathedArray * a, int i)
 {
     args[i].SetData(a);
 }
@@ -449,7 +449,7 @@ void MathMacroTable::builtinMacros()
 {
     MathedIter iter;
     MathParInset * inset;// *arg;
-    LyxArrayBase * array2;
+    MathedArray * array2;
     
     built = true;
     
@@ -458,7 +458,7 @@ void MathMacroTable::builtinMacros()
     // This macro doesn't have arguments
     MathMacroTemplate * m = new MathMacroTemplate("notin");  // this leaks
     addTemplate(m);
-    LyxArrayBase * array = new LyxArrayBase; // this leaks
+    MathedArray * array = new MathedArray; // this leaks
     iter.SetData(array);
     iter.Insert(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not)); // this leaks
     m->SetData(array);
@@ -466,14 +466,14 @@ void MathMacroTable::builtinMacros()
     // These two are only while we are still with LyX 2.x
     m = new MathMacroTemplate("emptyset"); // this leaks
     addTemplate(m);
-    array = new LyxArrayBase; // this leaks
+    array = new MathedArray; // this leaks
     iter.SetData(array);
     iter.Insert(new MathAccentInset('O', LM_TC_RM, LM_not)); // this leaks
     m->SetData(array);
     
     m = new MathMacroTemplate("perp"); // this leaks
     addTemplate(m);
-    array = new LyxArrayBase; // this leaks
+    array = new MathedArray; // this leaks
     iter.SetData(array);
     iter.Insert(LM_bot, LM_TC_BOP);
     m->SetData(array);
@@ -481,18 +481,18 @@ void MathMacroTable::builtinMacros()
     // binom has two arguments
     m = new MathMacroTemplate("binom", 2);
     addTemplate(m);
-    array = new LyxArrayBase
+    array = new MathedArray
     m->SetData(array);
     iter.SetData(array);
     inset = new MathDelimInset('(', ')');
     iter.Insert(inset, LM_TC_ACTIVE_INSET);
-    array = new LyxArrayBase
+    array = new MathedArray
     iter.SetData(array);
     MathFracInset *frac = new MathFracInset(LM_OT_ATOP);
     iter.Insert(frac, LM_TC_ACTIVE_INSET);
     inset->SetData(array);
-    array = new LyxArrayBase;
-    array2 = new LyxArrayBase;  
+    array = new MathedArray;
+    array2 = new MathedArray;  
     iter.SetData(array);
     iter.Insert(m->getMacroPar(0));
     iter.SetData(array2);
@@ -503,7 +503,7 @@ void MathMacroTable::builtinMacros()
     // Cases has 1 argument
     m = new MathMacroTemplate("cases", 1, MMF_Env); // this leaks
     addTemplate(m);
-    array = new LyxArrayBase; // this leaks
+    array = new MathedArray; // this leaks
     iter.SetData(array);
     arg = new MathMatrixInset(2, 1); // this leaks
 
@@ -512,7 +512,7 @@ void MathMacroTable::builtinMacros()
     iter.Insert(arg, LM_TC_ACTIVE_INSET);
     inset = new MathDelimInset('{', '.'); // this leaks
     inset->SetData(array);
-    array = new LyxArrayBase; // this leaks
+    array = new MathedArray; // this leaks
     iter.SetData(array);
     iter.Insert(inset, LM_TC_ACTIVE_INSET);
     m->SetData(array);
@@ -524,7 +524,7 @@ void MathMacroTable::builtinMacros()
     arg = new MathMatrixInset(1, 1); // this leaks
     m->setArgument(arg);
     arg->SetType(LM_OT_MACRO);
-    array = new LyxArrayBase; // this leaks
+    array = new MathedArray; // this leaks
     iter.SetData(array);
     iter.Insert(arg, LM_TC_ACTIVE_INSET);
     m->SetData(array);*/
index a4d14bc49f4ffbf1a48c0743c8cf3be14de6cf8a..fff72b4abc7ea886503e8ce9b71ebe950a72d29a 100644 (file)
@@ -27,7 +27,7 @@
 ///
 typedef MathParInset * MathParInsetP;
 ///
-typedef LyxArrayBase * LyxArrayBaseP;
+typedef MathedArray * MathedArrayP;
 
 class MathMacroTemplate;
 
@@ -65,11 +65,11 @@ public:
     ///
     void SetFocus(int, int);
     ///
-    LyxArrayBase * GetData();
+    MathedArray * GetData();
     ///
     MathedRowSt * getRowSt() const { return args[idx].row; }
     ///
-    void SetData(LyxArrayBase *);
+    void SetData(MathedArray *);
     ///
     MathedTextCodes getTCode() const { return tcode; }
     ///
@@ -85,7 +85,7 @@ private:
        ///
        MathedRowSt * row;
        ///
-       LyxArrayBase * array;
+       MathedArray * array;
        ///
        MacroArgumentBase() { x = y = 0;  array = 0; row = 0; }
     };
@@ -156,7 +156,7 @@ public:
     ///
     MathedTextCodes getTCode() const { return tcode; }
     /// 
-    void setArgument(LyxArrayBase *, int i= 0);
+    void setArgument(MathedArray *, int i= 0);
     /// Number of arguments
     int getNoArgs() const { return nargs; }
     ///
@@ -248,14 +248,14 @@ int MathMacro::getMaxArgumentIdx() const
 
 
 inline
-LyxArrayBase * MathMacro::GetData() 
+MathedArray * MathMacro::GetData() 
 { 
     return args[idx].array; 
 } 
 
 
 inline
-void MathMacro::SetData(LyxArrayBase * a)
+void MathMacro::SetData(MathedArray * a)
 {
    args[idx].array = a;
 }
index 45a0d5db1292d77314ebd95bbdc8499a8eb74fa1..e495782eb74bad1e3bb90fc2b4708b655fc41046 100644 (file)
@@ -384,7 +384,7 @@ MathedInset * doAccent(MathedInset * p)
 }
 
 
-LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * array,
+MathedArray * mathed_parse(unsigned flags, MathedArray * array,
                            MathParInset ** mtx)
 {
    int t = yylex();
@@ -403,7 +403,7 @@ LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * array,
     MathedRowSt * crow = (mt) ? mt->getRowSt() : 0;
 
    ++plevel;
-   if (!array) array = new LyxArrayBase;
+   if (!array) array = new MathedArray;
    MathedIter data(array);
    while (t) {
       if ((flags & FLAG_BRACE) && t != LM_TK_OPEN) {
@@ -538,7 +538,7 @@ LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * array,
     case '^':
       {  
         MathParInset * p = new MathParInset(size, "", LM_OT_SCRIPT);
-        LyxArrayBase * ar = mathed_parse(FLAG_BRACE_OPT|FLAG_BRACE_LAST, 0);
+        MathedArray * ar = mathed_parse(FLAG_BRACE_OPT|FLAG_BRACE_LAST, 0);
         p->SetData(ar);
 //      lyxerr << "UP[" << p->GetStyle() << "]" << endl;
         data.Insert (p, LM_TC_UP);
@@ -547,7 +547,7 @@ LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * array,
     case '_':
       {
         MathParInset * p = new MathParInset(size, "", LM_OT_SCRIPT);
-        LyxArrayBase * ar = mathed_parse(FLAG_BRACE_OPT|FLAG_BRACE_LAST, 0);
+        MathedArray * ar = mathed_parse(FLAG_BRACE_OPT|FLAG_BRACE_LAST, 0);
         p->SetData(ar);
         data.Insert (p, LM_TC_DOWN);
         break;
@@ -645,8 +645,8 @@ LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * array,
     case LM_TK_FRAC:
       {
         MathFracInset * fc = new MathFracInset(fractype);
-        LyxArrayBase * num = mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST);
-        LyxArrayBase * den = mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST);
+        MathedArray * num = mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST);
+        MathedArray * den = mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST);
         fc->SetData(num, den);
         data.Insert(fc, LM_TC_ACTIVE_INSET);
         break;
@@ -677,7 +677,7 @@ LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * array,
         if (lfd == LM_TK_SYM || lfd == LM_TK_STR || lfd == LM_TK_BOP|| lfd == LM_TK_SPECIAL)
           lfd = (lfd == LM_TK_SYM) ? yylval.l->id: yylval.i;
 //      lyxerr << "L[" << lfd << " " << lfd << "]";
-        LyxArrayBase * a = mathed_parse(FLAG_RIGHT);
+        MathedArray * a = mathed_parse(FLAG_RIGHT);
         int rgd = yylex();
 //      lyxerr << "R[" << rgd << "]";
         if (rgd == LM_TK_SYM || rgd == LM_TK_STR || rgd == LM_TK_BOP || rgd == LM_TK_SPECIAL)
index be1853c60f9bfb74ebc6aab02451073f94c584f3..37c5af883b4e0801b7239425151229ca2a677761 100644 (file)
@@ -50,7 +50,7 @@ MathedInset * MathRootInset::Clone()
 }
 
 
-void MathRootInset::SetData(LyxArrayBase * d)
+void MathRootInset::SetData(MathedArray * d)
 {
    if (idx == 1)
      MathParInset::SetData(d);
@@ -79,7 +79,7 @@ void MathRootInset::GetXY(int & x, int & y) const
 }
 
 
-LyxArrayBase * MathRootInset::GetData()
+MathedArray * MathRootInset::GetData()
 {
    if (idx == 1)
      return array;
index cdeae572335d7d5dfce406509ad65e1dce8e362a..fff7d1f547b34bf95047f4172fa888d33d800201 100644 (file)
@@ -45,11 +45,11 @@ public:
     ///
     void SetFocus(int, int);
     ///
-    void SetData(LyxArrayBase *);
+    void SetData(MathedArray *);
     ///
     void GetXY(int & x, int & y) const;
     ///
-    LyxArrayBase * GetData();
+    MathedArray * GetData();
     ///
     bool setArgumentIdx(int i);
     ///