X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2Fmath_macrotable.C;h=885bd5b3b3738e00df1d4d466397937c7348cea7;hb=7338f3b980d4dc5793ff80be814b7a74e1c72274;hp=e4a41c05ccf882adcd635b40abfd3c429b80df58;hpb=b9d25422e0e54b298a6706918e03765c10bd4c7a;p=lyx.git diff --git a/src/mathed/math_macrotable.C b/src/mathed/math_macrotable.C index e4a41c05cc..885bd5b3b3 100644 --- a/src/mathed/math_macrotable.C +++ b/src/mathed/math_macrotable.C @@ -1,129 +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 "array.h" -#include "math_accentinset.h" -#include "math_deliminset.h" -#include "math_fracinset.h" -#include "math_parinset.h" +#include "math_parser.h" +#include "math_mathmlstream.h" #include "debug.h" -#include "support/LAssert.h" +#include "math_support.h" // math_font_available + +#include using std::endl; -using std::make_pair; -MathMacroTable::table_type MathMacroTable::macro_table; -bool MathMacroTable::built = false; +MathMacroTable::table_type MathMacroTable::macro_table; void MathMacroTable::dump() { - using std::cerr; - - cerr << "\n------------------------------------------\n"; +/* + lyxerr << "\n------------------------------------------" << endl; table_type::const_iterator it; for (it = macro_table.begin(); it != macro_table.end(); ++it) - cerr << it->first << ": " << it->second->GetData() << endl; - cerr << "------------------------------------------\n"; + lyxerr << it->first + << " [" << it->second->asMacroTemplate()->nargs() << "] : " + << it->second->cell(0) << endl; + lyxerr << "------------------------------------------" << endl; +*/ } -MathMacroTemplate & -MathMacroTable::provideTemplate(string const & name, int na) +MathAtom & MathMacroTable::provide(string const & name) { - if (!built) - builtinMacros(); - - if (macro_table.find(name) == macro_table.end()) - macro_table.insert(make_pair(name, new MathMacroTemplate(name, na))); - - return *(macro_table.find(name)->second); + 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; } -MathMacroTemplate & -MathMacroTable::provideTemplate(string const & name) +void MathMacroTable::create(MathAtom const & at) { - if (!built) - builtinMacros(); - - return *macro_table[name]; + macro_table[at->asMacroTemplate()->name()] = at; } -bool MathMacroTable::hasTemplate(string const & name) +bool MathMacroTable::has(string const & name) { - if (!built) - builtinMacros(); - return macro_table.find(name) != macro_table.end(); } - - -MathMacro * MathMacroTable::cloneTemplate(string const & name) -{ - return new MathMacro(provideTemplate(name)); -} - - -void MathMacroTable::builtinMacros() -{ - built = true; - - lyxerr[Debug::MATHED] << "Building macros" << endl; - - // This macro doesn't have arguments - { - MathMacroTemplate & m = provideTemplate("notin", 0); - m.push_back(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not), LM_TC_INSET); - } - - // This macro doesn't have arguments - { - MathMacroTemplate & m = provideTemplate("silentmult", 0); - istringstream is("\\cdot\0"); - mathed_parser_file(is, 0); - MathParInset * p = &m; - mathed_parse(m.array, p, 0); - } - - { - MathMacroTemplate & m = provideTemplate("emptyset", 0); - m.push_back(new MathAccentInset('0', LM_TC_RM, LM_not), LM_TC_INSET); - } - - { - MathMacroTemplate & m = provideTemplate("perp", 0); - m.GetData().push_back(LM_bot, LM_TC_BOP); - } - - { - MathMacroTemplate & m = provideTemplate("lint", 4); - istringstream is("\\int_{#1}^{#2}#3 d#4\0"); - mathed_parser_file(is, 0); - MathParInset * p = &m; - mathed_parse(m.array, p, 0); - } - - // binom has two arguments - { - MathFracInset * frac = new MathFracInset(LM_OT_ATOP); - frac->push_back(new MathMacroArgument(1), LM_TC_INSET); - frac->denom()->push_back(new MathMacroArgument(2), LM_TC_INSET); - - MathParInset * inset = new MathDelimInset('(', ')'); - inset->push_back(frac, LM_TC_ACTIVE_INSET); - - MathMacroTemplate & m = provideTemplate("binom", 2); - m.push_back(inset, LM_TC_ACTIVE_INSET); - } -}