X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2Fmath_macrotable.C;h=885bd5b3b3738e00df1d4d466397937c7348cea7;hb=7338f3b980d4dc5793ff80be814b7a74e1c72274;hp=4f3368fa07fdf23a658a86c3932a4da122f9b7ec;hpb=88b5d739b5f25ff9012be11620256e98ba3789bb;p=lyx.git diff --git a/src/mathed/math_macrotable.C b/src/mathed/math_macrotable.C index 4f3368fa07..885bd5b3b3 100644 --- a/src/mathed/math_macrotable.C +++ b/src/mathed/math_macrotable.C @@ -1,179 +1,63 @@ -#include - -#include +/** + * \file math_macrotable.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author André Pönitz + * + * Full author contact details are available in file CREDITS. + */ -#ifdef __GNUG__ -#pragma implementation -#endif +#include #include "math_macrotable.h" #include "math_macro.h" #include "math_macrotemplate.h" #include "math_parser.h" -#include "array.h" -#include "math_accentinset.h" -#include "math_deliminset.h" -#include "math_fracinset.h" -#include "math_inset.h" +#include "math_mathmlstream.h" #include "debug.h" -#include "support/LAssert.h" +#include "math_support.h" // math_font_available + +#include using std::endl; + MathMacroTable::table_type MathMacroTable::macro_table; void MathMacroTable::dump() { - lyxerr << "\n------------------------------------------\n"; +/* + lyxerr << "\n------------------------------------------" << endl; table_type::const_iterator it; for (it = macro_table.begin(); it != macro_table.end(); ++it) - lyxerr << it->first << " [" << it->second->nargs() << "] : " - << it->second << endl; - lyxerr << "------------------------------------------" << endl;; -} - - -void MathMacroTable::updateTemplate(MathMacroTemplate * par) -{ - table_type::iterator pos = macro_table.find(par->name()); - - if (pos == macro_table.end()) - lyxerr << "MathMacroTable::updateTemplate: no template with name '" - << par->name() << "' available." << endl; - else - pos->second = par; -} - - -void MathMacroTable::insertTemplate(MathMacroTemplate * p) -{ - macro_table[p->name()] = p; + lyxerr << it->first + << " [" << it->second->asMacroTemplate()->nargs() << "] : " + << it->second->cell(0) << endl; + lyxerr << "------------------------------------------" << endl; +*/ } -MathMacroTemplate & MathMacroTable::provideTemplate(string const & name) +MathAtom & MathMacroTable::provide(string const & name) { - builtinMacros(); - table_type::iterator pos = macro_table.find(name); - if (pos == macro_table.end()) { lyxerr << "MathMacroTable::provideTemplate: no template with name '" << name << "' available." << endl; } - - return *pos->second; + return pos->second; } -bool MathMacroTable::hasTemplate(string const & name) +void MathMacroTable::create(MathAtom const & at) { - builtinMacros(); - return macro_table.find(name) != macro_table.end(); + macro_table[at->asMacroTemplate()->name()] = at; } -MathMacro * MathMacroTable::cloneTemplate(string const & name) +bool MathMacroTable::has(string const & name) { - return new MathMacro(provideTemplate(name)); -} - - -void MathMacroTable::builtinMacros() -{ - static bool built = false; - - if (built) - return; - - built = true; - - lyxerr[Debug::MATHED] << "Building macros" << endl; - - // This macro doesn't have arguments - { - MathMacroTemplate * t = new MathMacroTemplate("notin", 0); - MathAccentInset * p = new MathAccentInset(LM_not); - p->cell(0).push_back(LM_in, LM_TC_BOPS); - t->push_back(p); - insertTemplate(t); - } - -/* - // This macro doesn't have arguments - { - MathMacroTemplate & m = createTemplate("silentmult", 0); - istringstream is("\\cdot\0"); - mathed_parser_file(is, 0); - MathMatrixInset * p = &m; - mathed_parse(m.array, p, 0); - } -*/ - - { - MathMacroTemplate * t = new MathMacroTemplate("emptyset", 0); - MathAccentInset * p = new MathAccentInset(LM_not); - p->cell(0).push_back('0', LM_TC_VAR); - t->push_back(p); - insertTemplate(t); - } - - { - MathMacroTemplate * t = new MathMacroTemplate("to", 0); - t->push_back(LM_rightarrow, LM_TC_SYMB); - insertTemplate(t); - } - - { - MathMacroTemplate * t = new MathMacroTemplate("perp", 0); - t->push_back(LM_bot, LM_TC_BOP); - insertTemplate(t); - } -/* - { - MathMacroTemplate & m = createTemplate("lint", 4); - istringstream is("\\int_{#1}^{#2}#3 d#4\0"); - mathed_parser_file(is, 0); - MathMatrixInset * p = &m; - mathed_parse(m.array, p, 0); - } -*/ -/* - { - MathMacroTemplate * t = new MathMacroTemplate("binomii", 2); - istringstream is("\\left(\\frac{#1}{#2}\\right)\0"); - mathed_parser_file(is, 0); - mathed_parse(t->array, t, 0); - insertTemplate(t); - } -*/ - - // binom has two arguments - { - MathFracInset * frac = new MathFracInset("atop"); - frac->cell(0).push_back(new MathMacroArgument(1)); - frac->cell(1).push_back(new MathMacroArgument(2)); - - MathInset * inset = new MathDelimInset('(', ')'); - inset->push_back(frac); - - MathMacroTemplate * t = new MathMacroTemplate("binom", 2); - t->push_back(inset); - - insertTemplate(t); - } - -/* - { - MathFracInset * frac = new MathFracInset(LM_OT_ATOP); - frac->cell(0)->push_back(new MathMacroArgument(1)); - frac->cell(1)->push_back(new MathMacroArgument(2)); - - MathMacroTemplate * t = new MathMacroTemplate("choose", 2); - t->push_back(frac); - - insertTemplate(t); - } -*/ + return macro_table.find(name) != macro_table.end(); }