From d7525e974053df6bf1345a2cd772473b3042c27b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Tue, 7 Aug 2001 08:40:14 +0000 Subject: [PATCH] move ownership of the templates from the formulamacro inset to the mcaro table git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2437 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/ChangeLog | 3 +++ src/mathed/formulamacro.C | 42 ++++++++++----------------------- src/mathed/formulamacro.h | 8 ------- src/mathed/math_inset.C | 2 +- src/mathed/math_macrotable.C | 22 ++++++++--------- src/mathed/math_macrotable.h | 7 +++--- src/mathed/math_macrotemplate.h | 2 -- 7 files changed, 30 insertions(+), 56 deletions(-) diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 3fb6a4fe47..7457bdc80d 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -13,6 +13,9 @@ * math_funcinset.[Ch]: bring red color back + * math_macro*.[Ch]: move ownership of the templates from the formulamacro + inset to the mcaro table + 2001-08-01 André Pönitz * math_cursor.C: diff --git a/src/mathed/formulamacro.C b/src/mathed/formulamacro.C index d7e4b460c4..c32946ffad 100644 --- a/src/mathed/formulamacro.C +++ b/src/mathed/formulamacro.C @@ -43,38 +43,20 @@ using std::ostream; extern MathCursor * mathcursor; InsetFormulaMacro::InsetFormulaMacro() - : tmacro_(new MathMacroTemplate("unknown", 0)) -{} - - -InsetFormulaMacro::InsetFormulaMacro(InsetFormulaMacro const & m) - : InsetFormulaBase(m), - tmacro_(static_cast(m.tmacro_->clone())) -{} - - -InsetFormulaMacro::InsetFormulaMacro(string nm, int na) - : tmacro_(new MathMacroTemplate(nm, na)) { - MathMacroTable::insertTemplate(tmacro_); + setInsetName("unknown"); } -InsetFormulaMacro::~InsetFormulaMacro() +InsetFormulaMacro::InsetFormulaMacro(string nm, int na) { -#ifdef WITH_WARNINGS -#warning Need to unregister from MathMacroTable. -#endif - // Instead of unregister an delete leak this until it gets fixed - //delete tmacro_; + setInsetName(nm); + MathMacroTable::createTemplate(nm, na, string()); } Inset * InsetFormulaMacro::clone(Buffer const &, bool) const { -#ifdef WITH_WARNINGS -#warning This should not be needed in reality... -#endif return new InsetFormulaMacro(*this); } @@ -114,10 +96,10 @@ int InsetFormulaMacro::docBook(ostream & os) const void InsetFormulaMacro::read(LyXLex & lex) { - // Awful hack... - delete tmacro_; - tmacro_ = mathed_parse_macro(lex); - MathMacroTable::insertTemplate(tmacro_); + MathMacroTemplate * t = mathed_parse_macro(lex); + MathMacroTable::insertTemplate(*t); + setInsetName(t->name()); + delete t; metrics(); } @@ -175,7 +157,7 @@ InsetFormulaMacro::localDispatch(BufferView * bv, MathMacroTemplate const & InsetFormulaMacro::tmacro() const { - return *tmacro_; + return MathMacroTable::provideTemplate(getInsetName()); } @@ -193,13 +175,13 @@ MathInsetTypes InsetFormulaMacro::getType() const MathInset const * InsetFormulaMacro::par() const { - return tmacro_; + return &tmacro(); } void InsetFormulaMacro::metrics() const { - tmacro_->metrics(LM_ST_TEXT); + tmacro().metrics(LM_ST_TEXT); } @@ -229,7 +211,7 @@ void InsetFormulaMacro::draw(BufferView * bv, LyXFont const & f, // formula float t = tmacro().width() + 5; x -= t; - tmacro_->draw(pain, int(x), baseline); + tmacro().draw(pain, int(x), baseline); x += t; } diff --git a/src/mathed/formulamacro.h b/src/mathed/formulamacro.h index 3ae2f5ce1a..baf7acff5e 100644 --- a/src/mathed/formulamacro.h +++ b/src/mathed/formulamacro.h @@ -35,14 +35,8 @@ public: /// InsetFormulaMacro(); /// - InsetFormulaMacro(InsetFormulaMacro const &); - /// explicit InsetFormulaMacro(string name, int na); /// - ~InsetFormulaMacro(); - /// - void operator=(InsetFormulaMacro const &); - /// int ascent(BufferView *, LyXFont const &) const; /// int descent(BufferView *, LyXFont const &) const; @@ -81,8 +75,6 @@ private: MathMacroTemplate const & tmacro() const; /// prefix in inset string prefix() const; - /// - MathMacroTemplate const * tmacro_; }; #endif diff --git a/src/mathed/math_inset.C b/src/mathed/math_inset.C index 12774e37ba..31dd692391 100644 --- a/src/mathed/math_inset.C +++ b/src/mathed/math_inset.C @@ -309,7 +309,7 @@ void MathInset::code(MathTextCodes t) void MathInset::metrics(MathStyles st) const { - lyxerr[Debug::MATHED] << "MathInset::metrics() called directly!\n"; + lyxerr << "MathInset::metrics() called directly!\n"; size_ = st; } diff --git a/src/mathed/math_macrotable.C b/src/mathed/math_macrotable.C index e054d218f9..27fb617a51 100644 --- a/src/mathed/math_macrotable.C +++ b/src/mathed/math_macrotable.C @@ -26,15 +26,17 @@ void MathMacroTable::dump() lyxerr << "\n------------------------------------------\n"; table_type::const_iterator it; for (it = macro_table.begin(); it != macro_table.end(); ++it) - lyxerr << it->first << " [" << it->second->nargs() << "] : " + lyxerr << it->first << " [" << it->second.nargs() << "] : " << it->second << "\n"; lyxerr << "------------------------------------------\n"; } -void MathMacroTable::insertTemplate(MathMacroTemplate const * p) +void MathMacroTable::insertTemplate(MathMacroTemplate const & p) { - macro_table[p->name()] = const_cast(p); + if (macro_table.find(p.name()) != macro_table.end()) + lyxerr << "macro '" << p.name() << "' not new\n"; + macro_table[p.name()] = p; } @@ -49,19 +51,16 @@ MathMacroTemplate & MathMacroTable::provideTemplate(string const & name) << name << "' available.\n"; } - return *pos->second; + return pos->second; } void MathMacroTable::createTemplate (string const & name, int na, string const & text) { - MathMacroTemplate * t = new MathMacroTemplate(name, na); - t->cell(0) = mathed_parse_cell(text); + MathMacroTemplate t(name, na); + t.cell(0) = mathed_parse_cell(text); insertTemplate(t); -#ifdef WITH_WARNINGS -#warning who frees this? -#endif } @@ -110,9 +109,8 @@ void MathMacroTable::builtinMacros() MathInset * inset = new MathDelimInset('(', ')'); inset->push_back(frac); - MathMacroTemplate * t = new MathMacroTemplate("binom", 2); - t->push_back(inset); - + MathMacroTemplate t("binom", 2); + t.push_back(inset); insertTemplate(t); } diff --git a/src/mathed/math_macrotable.h b/src/mathed/math_macrotable.h index 8c8ff4618a..2feaa00d5f 100644 --- a/src/mathed/math_macrotable.h +++ b/src/mathed/math_macrotable.h @@ -4,6 +4,7 @@ #include #include "LString.h" +#include "math_macrotemplate.h" #ifdef __GNUG__ #pragma interface @@ -11,13 +12,13 @@ class MathMacro; -class MathMacroTemplate; + /// struct MathMacroTable { public: /// - static void insertTemplate(MathMacroTemplate const *); + static void insertTemplate(MathMacroTemplate const &); /// static MathMacroTemplate & provideTemplate(string const &); /// @@ -30,7 +31,7 @@ public: static void builtinMacros(); private: /// - typedef std::map table_type; + typedef std::map table_type; // static table_type macro_table; public: diff --git a/src/mathed/math_macrotemplate.h b/src/mathed/math_macrotemplate.h index e00164d0f9..7e64b1e2db 100644 --- a/src/mathed/math_macrotemplate.h +++ b/src/mathed/math_macrotemplate.h @@ -36,8 +36,6 @@ public: private: /// int numargs_; - /// unimplemented - void operator=(MathMacroTemplate const &); }; #endif -- 2.39.2