This one is a bit fishy. It changes pointers to references all over the
place but it is "unfinished" on "both ends": MathIter still works with a
MathedArray * and mathed_parse returns MathedArray *.

I tried to do it in one big sweep but failed. This should be as nice as
an intermediate version could get (it's stable, but leaks)...

Andre' 

-- 
André Pönitz ........................................ [EMAIL PROTECTED]
Index: formula.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/formula.C,v
retrieving revision 1.86
diff -u -p -u -r1.86 formula.C
--- formula.C   2001/02/20 13:16:07     1.86
+++ formula.C   2001/02/20 15:34:41
@@ -1224,7 +1224,7 @@ InsetFormula::LocalDispatch(BufferView *
 static
 void mathedValidate(LaTeXFeatures & features, MathParInset * par)
 {
-       MathedIter it(par->GetData());
+       MathedIter it(&par->GetData());
 
        while (it.OK() && !(features.binom && features.boldsymbol)) {
                if (it.IsInset()) {
Index: formulamacro.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/formulamacro.C,v
retrieving revision 1.47
diff -u -p -u -r1.47 formulamacro.C
--- formulamacro.C      2001/02/17 18:52:52     1.47
+++ formulamacro.C      2001/02/20 15:34:41
@@ -195,9 +195,6 @@ void InsetFormulaMacro::Edit(BufferView 
 void InsetFormulaMacro::InsetUnlock(BufferView * bv)
 {
        opened = false;
-       MathedArray * tarray = tmacro->GetData();
-       MathedIter it(tarray);
-       it.Clear();
        tmacro->setData(par->GetData());
        tmacro->setEditMode(false);
        InsetFormula::InsetUnlock(bv);
Index: math_cursor.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_cursor.C,v
retrieving revision 1.37
diff -u -p -u -r1.37 math_cursor.C
--- math_cursor.C       2001/02/20 14:00:34     1.37
+++ math_cursor.C       2001/02/20 15:34:41
@@ -452,7 +452,6 @@ void MathedCursor::Insert(byte c, Mathed
                        mt->SetStyle(LM_ST_DISPLAY);
                        mt->SetType(type);
                        mt->setData(p->GetData());
-                       p->setData(0);                          // BUG duda
                        delete p;
                        par = mt;
                        p = mt;
@@ -509,7 +508,7 @@ void MathedCursor::insertInset(MathedIns
        if (selection) {
                if (MathIsActive(t)) {
                        SelCut();
-                       static_cast<MathParInset*>(p)->setData(&selarray);
+                       static_cast<MathParInset*>(p)->setData(selarray);
                } else
                        SelDel();
        }
@@ -841,11 +840,11 @@ bool MathedCursor::pullArg()
                if (!p) 
                        return false;
                
-               MathedArray * a = p->GetData();
+               MathedArray a = p->GetData();
                p->clear();
                Delete();
-               if (!a->empty()) {
-                       cursor->Merge(a);
+               if (!a.empty()) {
+                       cursor->Merge(&a);
                        cursor->Adjust();
                }
 
Index: math_fracinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_fracinset.C,v
retrieving revision 1.6
diff -u -p -u -r1.6 math_fracinset.C
--- math_fracinset.C    2001/02/20 14:00:34     1.6
+++ math_fracinset.C    2001/02/20 15:34:41
@@ -59,14 +59,14 @@ void MathFracInset::SetStyle(short st)
 }
 
 
-void MathFracInset::SetData(MathedArray * n, MathedArray * d)
+void MathFracInset::SetData(MathedArray const & n, MathedArray const & d)
 {
        den_->setData(d);
        MathParInset::setData(n);
 }
 
 
-void MathFracInset::setData(MathedArray * d)
+void MathFracInset::setData(MathedArray const & d)
 {
        if (idx_ == 0)
                MathParInset::setData(d);
@@ -85,10 +85,10 @@ void MathFracInset::GetXY(int & x, int &
 }
 
 
-MathedArray * MathFracInset::GetData()
+MathedArray & MathFracInset::GetData()
 {
        if (idx_ == 0)
-               return &array;
+               return array;
        else
                return den_->GetData();
 }
Index: math_fracinset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_fracinset.h,v
retrieving revision 1.2
diff -u -p -u -r1.2 math_fracinset.h
--- math_fracinset.h    2001/02/16 09:25:43     1.2
+++ math_fracinset.h    2001/02/20 15:34:41
@@ -22,12 +22,12 @@ public:
        ///
        void Metrics();
        
-       /** This does the same that SetData(MathedArray*) but for both
+       /** This does the same that SetData(MathedArray const &) but for both
            numerator and denominator at once.
        */
-       void SetData(MathedArray *, MathedArray *);
+       void SetData(MathedArray const &, MathedArray const &);
        ///
-       void setData(MathedArray *);
+       void setData(MathedArray const &);
        ///
        void GetXY(int & x, int & y) const;
        ///
@@ -35,7 +35,7 @@ public:
        ///
        bool Inside(int, int);
        ///
-       MathedArray * GetData();
+       MathedArray & GetData();
        ///
        bool setArgumentIdx(int i); // was bool Up/down(void);
        ///
Index: math_macro.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_macro.C,v
retrieving revision 1.40
diff -u -p -u -r1.40 math_macro.C
--- math_macro.C        2001/02/20 10:49:48     1.40
+++ math_macro.C        2001/02/20 15:34:41
@@ -70,7 +70,7 @@ MathMacro::MathMacro(MathMacro * m): 
        for (int i = 0; i < tmplate_->getNoArgs(); ++i) {
                m->setArgumentIdx(i);
                args_[i].row   = m->args_[i].row;
-               args_[i].array = *(m->GetData());
+               args_[i].array = m->GetData();
        }
 }
 
@@ -134,9 +134,9 @@ int MathMacro::getMaxArgumentIdx() const
 } 
 
 
-MathedArray * MathMacro::GetData() 
+MathedArray & MathMacro::GetData() 
 { 
-       return &args_[idx_].array; 
+       return args_[idx_].array; 
 } 
 
 
@@ -167,9 +167,9 @@ void MathMacro::SetFocus(int x, int y)
 }
 
 
-void MathMacro::setData(MathedArray * a)
+void MathMacro::setData(MathedArray const & a)
 {
-       args_[idx_].array = *a;
+       args_[idx_].array = a;
 }
 
 
Index: math_macro.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_macro.h,v
retrieving revision 1.31
diff -u -p -u -r1.31 math_macro.h
--- math_macro.h        2001/02/20 10:49:48     1.31
+++ math_macro.h        2001/02/20 15:34:41
@@ -63,11 +63,11 @@ public:
        ///
        void SetFocus(int, int);
        ///
-       MathedArray * GetData();
+       MathedArray & GetData();
        ///
        MathedRowSt * getRowSt() const;
        ///
-       void setData(MathedArray *);
+       void setData(MathedArray const &);
        ///
        MathedTextCodes getTCode() const;
        ///
Index: math_macrotable.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_macrotable.C,v
retrieving revision 1.6
diff -u -p -u -r1.6 math_macrotable.C
--- math_macrotable.C   2001/02/19 18:29:10     1.6
+++ math_macrotable.C   2001/02/20 15:34:41
@@ -59,8 +59,8 @@ void MathMacroTable::builtinMacros()
        MathMacroTemplate * m = new MathMacroTemplate("notin");  // this leaks
        addTemplate(m);
        {
-               MathedArray * array = new MathedArray; // this leaks
-               MathedIter iter(array);
+               MathedArray array;
+               MathedIter iter(&array);
                iter.insertInset(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not),
                                 LM_TC_INSET); // this leaks
                m->setData(array);
@@ -70,8 +70,8 @@ void MathMacroTable::builtinMacros()
        m = new MathMacroTemplate("emptyset"); // this leaks
        addTemplate(m); 
        {
-               MathedArray * array = new MathedArray; // this leaks
-               MathedIter iter(array);
+               MathedArray array;
+               MathedIter iter(&array);
                iter.insertInset(new MathAccentInset('O', LM_TC_RM, LM_not),
                                 LM_TC_INSET); // this leaks
                m->setData(array);
@@ -80,8 +80,8 @@ void MathMacroTable::builtinMacros()
        m = new MathMacroTemplate("perp"); // this leaks
        addTemplate(m);
        {
-               MathedArray * array = new MathedArray; // this leaks
-               MathedIter iter(array);
+               MathedArray array;
+               MathedIter iter(&array);
                iter.insert(LM_bot, LM_TC_BOP);
                m->setData(array);
        }
@@ -90,21 +90,21 @@ void MathMacroTable::builtinMacros()
        m = new MathMacroTemplate("binom", 2);
        addTemplate(m);
        {
-               MathedArray * array = new MathedArray; 
+               MathedArray array;
                m->setData(array);
-               MathedIter iter(array);
+               MathedIter iter(&array);
                inset = new MathDelimInset('(', ')');
                iter.insertInset(inset, LM_TC_ACTIVE_INSET);
-               array = new MathedArray; 
-               MathedIter iter2(array);
+               array = MathedArray();
+               MathedIter iter2(&array);
                MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
                iter2.insertInset(frac, LM_TC_ACTIVE_INSET);
                inset->setData(array);
-               array = new MathedArray;
-               MathedArray * array2 = new MathedArray;  
-               MathedIter iter3(array);
+               array = MathedArray();
+               MathedArray array2;
+               MathedIter iter3(&array);
                iter3.insertInset(m->getMacroPar(0), LM_TC_INSET);
-               MathedIter iter4(array2);
+               MathedIter iter4(&array2);
                iter4.insertInset(m->getMacroPar(1), LM_TC_INSET);
                frac->SetData(array, array2);
        }
Index: math_macrotemplate.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_macrotemplate.C,v
retrieving revision 1.4
diff -u -p -u -r1.4 math_macrotemplate.C
--- math_macrotemplate.C        2001/02/16 09:25:43     1.4
+++ math_macrotemplate.C        2001/02/20 15:34:41
@@ -45,12 +45,7 @@ MathMacroTemplate::MathMacroTemplate(str
 
 
 MathMacroTemplate::~MathMacroTemplate()
-{
-       // prevent to delete already deleted objects
-       for (int i = 0; i < nargs_; ++i) {
-               args_[i].setData(0);
-       }
-}
+{}
 
 
 void MathMacroTemplate::setEditMode(bool ed)
@@ -154,7 +149,7 @@ void MathMacroTemplate::WriteDef(ostream
 
 void MathMacroTemplate::setArgument(MathedArray * a, int i)
 {
-       args_[i].setData(a);
+       args_[i].setData(*a);
 }
 
 
Index: math_matrixinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_matrixinset.C,v
retrieving revision 1.6
diff -u -p -u -r1.6 math_matrixinset.C
--- math_matrixinset.C  2001/02/20 10:49:48     1.6
+++ math_matrixinset.C  2001/02/20 15:34:41
@@ -35,7 +35,7 @@ MathMatrixInset::MathMatrixInset(MathMat
          nc_(mt->nc_), nr_(0), ws_(mt->nc_),
          v_align_(mt->v_align_), h_align_(mt->h_align_)
 {
-       array = *(mt->GetData());
+       array = mt->GetData();
        if (mt->row_ != 0) {
                MathedRowSt * ro = 0;
                MathedRowSt * mrow = mt->row_;
@@ -84,10 +84,11 @@ void MathMatrixInset::SetAlign(char vv, 
 
 
 // Check the number of tabs and crs
-void MathMatrixInset::setData(MathedArray * a)
+void MathMatrixInset::setData(MathedArray const & a)
 {
-       if (!a) return;
-       MathedIter it(a);
+       array = a;
+
+       MathedIter it(&array);
        int nn = nc_ - 1;
        nr_ = 1;
        // count tabs per row
@@ -115,7 +116,6 @@ void MathMatrixInset::setData(MathedArra
        
        // Automatically inserts tabs around bops
        // DISABLED because it's very easy to insert tabs 
-       array = *a;
 }
 
 
Index: math_matrixinset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_matrixinset.h,v
retrieving revision 1.2
diff -u -p -u -r1.2 math_matrixinset.h
--- math_matrixinset.h  2001/02/16 09:25:43     1.2
+++ math_matrixinset.h  2001/02/20 15:34:41
@@ -30,7 +30,7 @@ public: 
        ///
        void Metrics();
        ///
-       void setData(MathedArray *);
+       void setData(MathedArray const &);
        ///
        void SetAlign(char, string const &);
        ///
Index: math_parinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_parinset.C,v
retrieving revision 1.8
diff -u -p -u -r1.8 math_parinset.C
--- math_parinset.C     2001/02/20 13:16:07     1.8
+++ math_parinset.C     2001/02/20 15:34:41
@@ -46,15 +46,9 @@ MathedInset * MathParInset::Clone()
 }
 
 
-void MathParInset::setData(MathedArray * a)
+void MathParInset::setData(MathedArray const & a)
 {
-       if (!a) {
-               lyxerr << "can't set Data from NULL pointer" << endl;
-               array = MathedArray();
-               return;
-       }
-
-       array = *a;
+       array = a;
        
        // A standard paragraph shouldn't have any tabs nor CRs.
        MathedIter it(&array);
@@ -430,9 +424,9 @@ bool MathParInset::Permit(short f) const
 }
 
 
-MathedArray * MathParInset::GetData()
+MathedArray & MathParInset::GetData()
 {
-       return &array;
+       return array;
 }
 
 
Index: math_parinset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_parinset.h,v
retrieving revision 1.6
diff -u -p -u -r1.6 math_parinset.h
--- math_parinset.h     2001/02/20 13:16:07     1.6
+++ math_parinset.h     2001/02/20 15:34:41
@@ -31,9 +31,9 @@ public: 
        ///
        virtual void UserSetSize(short);
        /// Data is stored in a LyXArray
-       virtual void setData(MathedArray *);
+       virtual void setData(MathedArray const &);
        ///
-       virtual MathedArray * GetData();
+       virtual MathedArray & GetData();
        /// Paragraph position
        virtual void GetXY(int &, int &) const;
        ///
Index: math_parser.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_parser.C,v
retrieving revision 1.31
diff -u -p -u -r1.31 math_parser.C
--- math_parser.C       2001/02/17 18:52:53     1.31
+++ math_parser.C       2001/02/20 15:34:41
@@ -469,7 +469,7 @@ MathedArray * mathed_parse(unsigned flag
          macro = new MathMacroTemplate(name, na);
          flags = FLAG_BRACE|FLAG_BRACE_LAST;
          *mtx = macro;
-         macro->setData(array);
+         macro->setData(*array);
          break;
       }
     case LM_TK_SPECIAL:
@@ -560,7 +560,7 @@ MathedArray * mathed_parse(unsigned flag
       {  
         MathParInset * p = new MathParInset(size, "", LM_OT_SCRIPT);
         MathedArray * ar = mathed_parse(FLAG_BRACE_OPT|FLAG_BRACE_LAST, 0);
-        p->setData(ar);
+        p->setData(*ar);
 //      lyxerr << "UP[" << p->GetStyle() << "]" << endl;
         data.insertInset(p, LM_TC_UP);
         break;
@@ -569,7 +569,7 @@ MathedArray * mathed_parse(unsigned flag
       {
         MathParInset * p = new MathParInset(size, "", LM_OT_SCRIPT);
         MathedArray * ar = mathed_parse(FLAG_BRACE_OPT|FLAG_BRACE_LAST, 0);
-        p->setData(ar);
+        p->setData(*ar);
         data.insertInset(p, LM_TC_DOWN);
         break;
       }
@@ -672,7 +672,7 @@ MathedArray * mathed_parse(unsigned flag
         MathFracInset * fc = new MathFracInset(fractype);
         MathedArray * num = mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST);
         MathedArray * den = mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST);
-        fc->SetData(num, den);
+        fc->SetData(*num, *den);
         data.insertInset(fc, LM_TC_ACTIVE_INSET);
         break;
       }
@@ -685,13 +685,13 @@ MathedArray * mathed_parse(unsigned flag
         if (c == '[') {
             rt = new MathRootInset(size);
             rt->setArgumentIdx(0);
-            rt->setData(mathed_parse(FLAG_BRACK_END, 0, &rt));
+            rt->setData(*mathed_parse(FLAG_BRACK_END, 0, &rt));
             rt->setArgumentIdx(1);
         } else {
                 yyis->putback(c);
             rt = new MathSqrtInset(size);
         }
-        rt->setData(mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST, 0, &rt));
+        rt->setData(*mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST, 0, &rt));
         data.insertInset(rt, LM_TC_ACTIVE_INSET);
         break;
       }
@@ -708,7 +708,7 @@ MathedArray * mathed_parse(unsigned flag
         if (rgd == LM_TK_SYM || rgd == LM_TK_STR || rgd == LM_TK_BOP || rgd == 
LM_TK_SPECIAL)
           rgd = (rgd == LM_TK_SYM) ? yylval.l->id: yylval.i;    
         MathDelimInset * dl = new MathDelimInset(lfd, rgd);
-        dl->setData(a);
+        dl->setData(*a);
         data.insertInset(dl, LM_TC_ACTIVE_INSET);
 //      lyxerr << "RL[" << lfd << " " << rgd << "]";
         break;
@@ -736,7 +736,7 @@ MathedArray * mathed_parse(unsigned flag
       {  
         MathDecorationInset * sq = new MathDecorationInset(yylval.l->id,
                                                            size);
-        sq->setData(mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST));
+        sq->setData(*mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST));
         data.insertInset(sq, LM_TC_ACTIVE_INSET);
         break;
       }
@@ -781,7 +781,7 @@ MathedArray * mathed_parse(unsigned flag
           else
             data.insertInset(p, p->getTCode());
           for (int i = 0; p->setArgumentIdx(i); ++i)
-            p->setData(mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST));
+            p->setData(*mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST));
        }
        else {
           MathedInset * q = new MathFuncInset(yylval.s, LM_OT_UNDEF);
@@ -802,7 +802,7 @@ MathedArray * mathed_parse(unsigned flag
                 lyxerr << "[" << yylval.i << "]" << endl;
         --plevel;
         if (mt) { // && (flags & FLAG_END)) {
-           mt->setData(array);
+           mt->setData(*array);
            array = 0;
         }
         return array;
@@ -822,7 +822,7 @@ MathedArray * mathed_parse(unsigned flag
            MathParInset * mm = new MathMatrixInset(nc, 0);
            mm->SetAlign(ar2[0], ar);
                    data.insertInset(mm, LM_TC_ACTIVE_INSET);
-            mathed_parse(FLAG_END, mm->GetData(), &mm);
+            mathed_parse(FLAG_END, &mm->GetData(), &mm);
         } else if (is_eqn_type(yylval.i)) {
             if (plevel!= 0) {
                 mathPrintError("Misplaced environment");
@@ -873,7 +873,7 @@ MathedArray * mathed_parse(unsigned flag
             if (p) {
                 data.insertInset(p, p->getTCode());
                 p->setArgumentIdx(0);
-                mathed_parse(FLAG_END, p->GetData(), 
reinterpret_cast<MathParInset**>(&p));
+                mathed_parse(FLAG_END, &p->GetData(), 
+reinterpret_cast<MathParInset**>(&p));
 //              for (int i = 0; p->setArgumentIdx(i); ++i)
 //                p->SetData(mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST));
             } else 
Index: math_root.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_root.C,v
retrieving revision 1.20
diff -u -p -u -r1.20 math_root.C
--- math_root.C 2001/02/20 14:00:34     1.20
+++ math_root.C 2001/02/20 15:34:41
@@ -48,7 +48,7 @@ MathedInset * MathRootInset::Clone()
 }
 
 
-void MathRootInset::setData(MathedArray * d)
+void MathRootInset::setData(MathedArray const & d)
 {
        if (idx_ == 1)
                MathParInset::setData(d);
@@ -77,10 +77,10 @@ void MathRootInset::GetXY(int & x, int &
 }
 
 
-MathedArray * MathRootInset::GetData()
+MathedArray & MathRootInset::GetData()
 {
        if (idx_ == 1)
-               return &array;
+               return array;
        else
                return uroot_->GetData();
 }
Index: math_root.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_root.h,v
retrieving revision 1.23
diff -u -p -u -r1.23 math_root.h
--- math_root.h 2001/02/16 09:25:43     1.23
+++ math_root.h 2001/02/20 15:34:41
@@ -47,11 +47,11 @@ public:
        ///
        void SetFocus(int, int);
        ///
-       void setData(MathedArray *);
+       void setData(MathedArray const &);
        ///
        void GetXY(int & x, int & y) const;
        ///
-       MathedArray * GetData();
+       MathedArray & GetData();
        ///
        bool setArgumentIdx(int i);
        ///
Index: math_xiter.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_xiter.C,v
retrieving revision 1.10
diff -u -p -u -r1.10 math_xiter.C
--- math_xiter.C        2001/02/20 13:16:07     1.10
+++ math_xiter.C        2001/02/20 15:34:41
@@ -195,7 +195,7 @@ void MathedXIter::SetData(MathParInset *
 {
        p_ = pp;
        x_ = y_ = 0;
-       array = p_->GetData();
+       array = &p_->GetData();
        ncols = p_->GetColumns();
        crow_ = p_->getRowSt();
        if (p_->Permit(LMPF_ALLOW_CR))
@@ -209,7 +209,7 @@ void MathedXIter::SetData(MathParInset *
        } 
        if (!array) {
                array = new MathedArray; // this leaks
-               p_->setData(array);
+               p_->setData(*array);
        }
        size_ = p_->GetStyle();
        Reset();

Reply via email to