From d96f7c829cb356d8ba362961e176819c33aecb73 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Mon, 5 Mar 2001 10:18:36 +0000 Subject: [PATCH] small cleanup read ChangeLog git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1663 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/ChangeLog | 14 ++++++++ src/mathed/math_macro.C | 62 ++++++++++++++++++++------------- src/mathed/math_macro.h | 21 ++++------- src/mathed/math_macrotemplate.C | 29 ++++++++------- src/mathed/math_macrotemplate.h | 6 +++- src/mathed/math_parser.C | 9 ++--- 6 files changed, 80 insertions(+), 61 deletions(-) diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index e41d600a59..4c961f4edb 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,5 +1,19 @@ 2001-03-01 Lars Gullik Bjønnes + * math_macrotemplate.C (update): use MathMacro::getArg, and + receive a const reference. + (getMacroPar): add an Assert + + * math_macrotemplate.h: make MathMacro a friend, make update take + a const reference. + + * math_macro.[hC]: get rid of getRowSt, remove MacroArgumentBase + and store a MathMacroArgument in the vector + * math_macro.C: changes because of the above. + (getArg): new method + + * math_parser.C (mathed_parse): plug potential leak + * math_iter.h: add comment on virtual destructor * math_iter.C (Delete): make c const diff --git a/src/mathed/math_macro.C b/src/mathed/math_macro.C index b05140d470..0243be197a 100644 --- a/src/mathed/math_macro.C +++ b/src/mathed/math_macro.C @@ -48,9 +48,19 @@ MathMacro::MathMacro(boost::shared_ptr const & t) : MathParInset(LM_ST_TEXT, "", LM_OT_MACRO), tmplate_(t) { - nargs_ = tmplate_->getNoArgs(); + //nargs_ = tmplate_->getNoArgs(); + int const n = tmplate_->getNoArgs(); + tcode_ = tmplate_->getTCode(); - args_.resize(nargs_); + + for (int i = 0; i < n; ++i) { + args_.push_back(MathMacroArgument(t->args_[i])); + } + //for (int i = 0; i < nargs_; ++i) { + // MathMacroArgument * ma = new MathMacroArgument(*t->args_[i]); + // args_.push_back(boost::shared_ptr(ma)); + //} + idx_ = 0; SetName(tmplate_->GetName()); } @@ -64,8 +74,8 @@ MathedInset * MathMacro::Clone() void MathMacro::Metrics() { - if (nargs_ > 0) - tmplate_->update(this); + if (args_.size() > 0) + tmplate_->update(*this); tmplate_->SetStyle(size()); tmplate_->Metrics(); width = tmplate_->Width(); @@ -86,7 +96,7 @@ void MathMacro::draw(Painter & pain, int x, int y) bool MathMacro::setArgumentIdx(int i) { - if (i >= 0 && i < nargs_) { + if (i >= 0 && i < args_.size()) { idx_ = i; return true; } else @@ -102,19 +112,19 @@ int MathMacro::getArgumentIdx() const int MathMacro::getMaxArgumentIdx() const { - return nargs_ - 1; + return args_.size() - 1; } MathedArray & MathMacro::GetData() { - return args_[idx_].array; + return args_[idx_].GetData(); } MathedArray const & MathMacro::GetData() const { - return args_[idx_].array; + return args_[idx_].GetData(); } @@ -126,19 +136,14 @@ int MathMacro::GetColumns() const void MathMacro::GetXY(int & x, int & y) const { -#if 0 - x = args_[idx_].x_; - y = args_[idx_].y_; -#else const_cast(this)->Metrics(); tmplate_->GetMacroXY(idx_, x, y); -#endif } bool MathMacro::Permit(short f) const { - return (nargs_ > 0) ? + return (args_.size() > 0) ? tmplate_->getMacroPar(idx_)->Permit(f) : MathParInset::Permit(f); } @@ -153,13 +158,7 @@ void MathMacro::SetFocus(int x, int y) void MathMacro::setData(MathedArray const & a) { - args_[idx_].array = a; -} - - -MathedRowSt * MathMacro::getRowSt() const -{ - return args_[idx_].row; + args_[idx_].setData(a); } @@ -173,16 +172,29 @@ void MathMacro::Write(ostream & os, bool fragile) { os << '\\' << name; - if (nargs_ > 0) { + int const n = args_.size(); + + if (n > 0) { os << '{'; - for (int i = 0; i < nargs_; ++i) { - array = args_[i].array; + for (int i = 0; i < n; ++i) { + array = args_[i].GetData(); MathParInset::Write(os, fragile); - if (i < nargs_ - 1) + if (i < n - 1) os << "}{"; } os << '}'; } else os << ' '; } + + +MathMacroArgument const & MathMacro::getArg(int i) const +{ + return args_[i]; +} +//boost::shared_ptr MathMacro::getArg(int i) +//{ +// return args_[i]; +//} + diff --git a/src/mathed/math_macro.h b/src/mathed/math_macro.h index d5d519123b..59c6246760 100644 --- a/src/mathed/math_macro.h +++ b/src/mathed/math_macro.h @@ -25,6 +25,7 @@ #include #include "math_parinset.h" +#include "math_macroarg.h" class MathMacroTemplate; @@ -63,32 +64,24 @@ public: /// MathedArray const & GetData() const; /// - MathedRowSt * getRowSt() const; - /// void setData(MathedArray const &); /// MathedTextCodes getTCode() const; /// bool Permit(short) const; + /// + MathMacroArgument const & getArg(int i) const; + //boost::shared_ptr getArg(int i); private: /// boost::shared_ptr tmplate_; /// - struct MacroArgumentBase { - /// - MathedRowSt * row; - /// - MathedArray array; - /// - MacroArgumentBase() - : row(0) - {} - }; - std::vector args_; + //std::vector > args_; + std::vector args_; /// int idx_; /// - int nargs_; + //int nargs_; /// MathedTextCodes tcode_; }; diff --git a/src/mathed/math_macrotemplate.C b/src/mathed/math_macrotemplate.C index 418fca2b7a..c75df81ad8 100644 --- a/src/mathed/math_macrotemplate.C +++ b/src/mathed/math_macrotemplate.C @@ -23,6 +23,10 @@ MathMacroTemplate::MathMacroTemplate(string const & nm, int na): for (int i = 0; i < nargs_; ++i) { args_.push_back(MathMacroArgument(i + 1)); } + //for (int i = 0; i < nargs_; ++i) { + // MathMacroArgument * ma = new MathMacroArgument(i + 1); + // args_.push_back(boost::shared_ptr(ma)); + //} } else { tcode_ = LM_TC_INSET; // Here is nargs != args_.size() @@ -86,7 +90,6 @@ void MathMacroTemplate::draw(Painter & pain, int x, int y) MathParInset::draw(pain, x, y); xo(x2); yo(y2); - for (int i = 0; i < nargs_; ++i) { args_[i].setExpand(expnd); } @@ -107,24 +110,17 @@ void MathMacroTemplate::Metrics() } } MathParInset::Metrics(); - for (int i = 0; i < nargs_; ++i) { args_[i].setExpand(expnd); } } -void MathMacroTemplate::update(MathMacro * macro) +void MathMacroTemplate::update(MathMacro const & macro) { - Assert(macro); - int const idx = macro->getArgumentIdx(); for (int i = 0; i < nargs_; ++i) { - macro->setArgumentIdx(i); - args_[i].setData(macro->GetData()); - MathedRowSt * row = macro->getRowSt(); - args_[i].setRowSt(row); - } - macro->setArgumentIdx(idx); + args_[i] = macro.getArg(i); + } } @@ -139,7 +135,8 @@ void MathMacroTemplate::WriteDef(ostream & os, bool fragile) for (int i = 0; i < nargs_; ++i) { args_[i].setExpand(false); - } + } + Write(os, fragile); os << "}\n"; } @@ -153,10 +150,12 @@ void MathMacroTemplate::GetMacroXY(int i, int & x, int & y) const MathParInset * MathMacroTemplate::getMacroPar(int i) const { - if (i >= 0 && i < nargs_) - return const_cast + if (i >= 0 && i < nargs_) { + MathParInset * p = const_cast (static_cast(&args_[i])); - else + Assert(p); + return p; + } else return 0; } diff --git a/src/mathed/math_macrotemplate.h b/src/mathed/math_macrotemplate.h index 64a9cf7ce4..bca4647d1a 100644 --- a/src/mathed/math_macrotemplate.h +++ b/src/mathed/math_macrotemplate.h @@ -5,6 +5,7 @@ #include #include +//#include #include "math_parinset.h" #include "math_macroarg.h" @@ -20,6 +21,8 @@ class MathMacro; */ class MathMacroTemplate : public MathParInset, public noncopyable { public: + friend class MathMacro; + /// A template constructor needs all the data explicit MathMacroTemplate(string const &, int na); @@ -45,13 +48,14 @@ public: void setEditMode(bool); /// Replace the appropriate arguments with a specific macro's data - void update(MathMacro * m); + void update(MathMacro const & m); private: /// Are we in edit mode or not? bool edit_; /// MathedTextCodes tcode_; /// + //std::vector > args_; std::vector args_; /// int nargs_; diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index 9886fe7895..1b67bb40e0 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -763,16 +763,13 @@ void mathed_parse(MathedArray & array, unsigned flags = 0, case LM_TK_PMOD: case LM_TK_FUNC: - { -#warning This must leak. (Lgb) - // if (accent) this must leak... (Lgb) - MathedInset * bg = new MathFuncInset(yylval.l->name); if (accent) { data.insert(t, LM_TC_CONST); - } else + } else { + MathedInset * bg = new MathFuncInset(yylval.l->name); data.insertInset(bg, LM_TC_INSET); + } break; - } case LM_TK_FUNCLIM: data.insertInset(new MathFuncInset(yylval.l->name, LM_OT_FUNCLIM), -- 2.39.2