X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2Fmath_macrotable.C;h=885bd5b3b3738e00df1d4d466397937c7348cea7;hb=7338f3b980d4dc5793ff80be814b7a74e1c72274;hp=9312faa008d1c1c9eff7b1871c0608cb42bd1f96;hpb=aae45c2088d0c6530f589b8c6d0d3ecca8240d35;p=lyx.git diff --git a/src/mathed/math_macrotable.C b/src/mathed/math_macrotable.C index 9312faa008..885bd5b3b3 100644 --- a/src/mathed/math_macrotable.C +++ b/src/mathed/math_macrotable.C @@ -1,109 +1,63 @@ -#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_iter.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; -MathMacroTable MathMacroTable::mathMTable; -bool MathMacroTable::built = false; +MathMacroTable::table_type MathMacroTable::macro_table; -MathMacro * MathMacroTable::createMacro(string const & name) const +void MathMacroTable::dump() { - boost::shared_ptr mt = getTemplate(name); - return (mt.get()) ? new MathMacro(mt) : 0; +/* + lyxerr << "\n------------------------------------------" << endl; + table_type::const_iterator it; + for (it = macro_table.begin(); it != macro_table.end(); ++it) + lyxerr << it->first + << " [" << it->second->asMacroTemplate()->nargs() << "] : " + << it->second->cell(0) << endl; + lyxerr << "------------------------------------------" << endl; +*/ } -boost::shared_ptr const -MathMacroTable::getTemplate(string const & name) const +MathAtom & MathMacroTable::provide(string const & name) { - table_type::const_iterator cit = macro_table.find(name); - if (cit != macro_table.end()) return (*cit).second; - return boost::shared_ptr(); + 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; } -void -MathMacroTable::addTemplate(boost::shared_ptr const & m) +void MathMacroTable::create(MathAtom const & at) { - Assert(m.get()); - macro_table[m->GetName()] = m; + macro_table[at->asMacroTemplate()->name()] = at; } -void MathMacroTable::builtinMacros() +bool MathMacroTable::has(string const & name) { - built = true; - - lyxerr[Debug::MATHED] << "Building macros" << endl; - - // This macro doesn't have arguments - { - boost::shared_ptr m(new MathMacroTemplate("notin", 0)); - addTemplate(m); - MathedArray array; - MathedIter iter(&array); - iter.insertInset(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not), - LM_TC_INSET); - m->setData(array); - } - - // These two are only while we are still with LyX 2.x - { - boost::shared_ptr m(new MathMacroTemplate("emptyset", 0)); - addTemplate(m); - MathedArray array; - MathedIter iter(&array); - iter.insertInset(new MathAccentInset('O', LM_TC_RM, LM_not), - LM_TC_INSET); - m->setData(array); - } - - { - boost::shared_ptr m(new MathMacroTemplate("perp", 0)); - addTemplate(m); - MathedArray array; - MathedIter iter(&array); - iter.insert(LM_bot, LM_TC_BOP); - m->setData(array); - } - - // binom has two arguments - { - boost::shared_ptr m(new MathMacroTemplate("binom", 2)); - addTemplate(m); - MathedArray array; - m->setData(array); - MathedIter iter(&array); - MathParInset * inset = new MathDelimInset('(', ')'); - iter.insertInset(inset, LM_TC_ACTIVE_INSET); - array = MathedArray(); - MathedIter iter2(&array); - MathFracInset * frac = new MathFracInset(LM_OT_ATOP); - iter2.insertInset(frac, LM_TC_ACTIVE_INSET); - inset->setData(array); - array = MathedArray(); - MathedArray array2; - MathedIter iter3(&array); - iter3.insertInset(m->getMacroPar(0), LM_TC_INSET); - MathedIter iter4(&array2); - iter4.insertInset(m->getMacroPar(1), LM_TC_INSET); - frac->SetData(array, array2); - } + return macro_table.find(name) != macro_table.end(); }