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
This commit is contained in:
André Pönitz 2001-08-07 08:40:14 +00:00
parent a8cd821af1
commit d7525e9740
7 changed files with 30 additions and 56 deletions

View File

@ -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 <poenitz@gmx.net>
* math_cursor.C:

View File

@ -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<MathMacroTemplate *>(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;
}

View File

@ -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

View File

@ -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;
}

View File

@ -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<MathMacroTemplate *>(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);
}

View File

@ -4,6 +4,7 @@
#include <map>
#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<string, MathMacroTemplate *> table_type;
typedef std::map<string, MathMacroTemplate> table_type;
//
static table_type macro_table;
public:

View File

@ -36,8 +36,6 @@ public:
private:
///
int numargs_;
/// unimplemented
void operator=(MathMacroTemplate const &);
};
#endif