]> git.lyx.org Git - lyx.git/blob - src/mathed/math_macrotable.C
small cleanup, doxygen, formatting changes
[lyx.git] / src / mathed / math_macrotable.C
1 #include <config.h>
2
3 #include "math_macrotable.h"
4 #include "math_macro.h"
5 #include "math_macrotemplate.h"
6 #include "math_iter.h"
7 #include "array.h"
8 #include "math_accentinset.h"
9 #include "math_deliminset.h"
10 #include "math_fracinset.h"
11 #include "math_parinset.h"
12 #include "debug.h"
13
14 using std::endl;
15
16 MathMacroTable MathMacroTable::mathMTable;
17
18 bool MathMacroTable::built = false;
19
20
21 MathMacro * MathMacroTable::getMacro(string const & name) const
22 {
23         MathMacroTemplate * mt = getTemplate(name);
24         return (mt) ? new MathMacro(mt): 0;
25 }
26
27
28 // The search is currently linear but will be binary or hash, later.
29 MathMacroTemplate * MathMacroTable::getTemplate(string const & name) const
30 {
31         for (size_type i = 0; i < macro_table.size(); ++i) {
32                 if (name == macro_table[i]->GetName()) 
33                         return macro_table[i];
34         }
35
36         return 0;
37 }
38
39 void MathMacroTable::addTemplate(MathMacroTemplate * m)
40 {
41         macro_table.push_back(m);
42 }
43
44
45 // All this stuff aparently leaks because it's created here and is not 
46 // deleted never, but it have to live all the LyX sesion. OK, would not
47 // so hard to do it in the MacroTable destructor, but this doesn't harm
48 // seriously, so don't bother me with purify results here.   ;-)
49
50 void MathMacroTable::builtinMacros()
51 {
52         MathedIter iter;
53         MathParInset * inset;// *arg;
54         MathedArray * array2;
55     
56         built = true;
57     
58         lyxerr[Debug::MATHED] << "Building macros" << endl;
59     
60         // This macro doesn't have arguments
61         MathMacroTemplate * m = new MathMacroTemplate("notin");  // this leaks
62         addTemplate(m);
63         MathedArray * array = new MathedArray; // this leaks
64         iter.SetData(array);
65         iter.Insert(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not)); // this leaks
66         m->setData(array);
67     
68         // These two are only while we are still with LyX 2.x
69         m = new MathMacroTemplate("emptyset"); // this leaks
70         addTemplate(m);
71         array = new MathedArray; // this leaks
72         iter.SetData(array);
73         iter.Insert(new MathAccentInset('O', LM_TC_RM, LM_not)); // this leaks
74         m->setData(array);
75     
76         m = new MathMacroTemplate("perp"); // this leaks
77         addTemplate(m);
78         array = new MathedArray; // this leaks
79         iter.SetData(array);
80         iter.Insert(LM_bot, LM_TC_BOP);
81         m->setData(array);
82
83         // binom has two arguments
84         m = new MathMacroTemplate("binom", 2);
85         addTemplate(m);
86         array = new MathedArray; 
87         m->setData(array);
88         iter.SetData(array);
89         inset = new MathDelimInset('(', ')');
90         iter.Insert(inset, LM_TC_ACTIVE_INSET);
91         array = new MathedArray; 
92         iter.SetData(array);
93         MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
94         iter.Insert(frac, LM_TC_ACTIVE_INSET);
95         inset->setData(array);
96         array = new MathedArray;
97         array2 = new MathedArray;  
98         iter.SetData(array);
99         iter.Insert(m->getMacroPar(0));
100         iter.SetData(array2);
101         iter.Insert(m->getMacroPar(1));
102         frac->SetData(array, array2);
103
104 /*
105   // Cases has 1 argument
106   m = new MathMacroTemplate("cases", 1, MMF_Env); // this leaks
107   addTemplate(m);
108   array = new MathedArray; // this leaks
109   iter.SetData(array);
110   arg = new MathMatrixInset(2, 1); // this leaks
111
112   m->setArgument(arg);
113   arg->SetAlign('c', "ll");
114   iter.Insert(arg, LM_TC_ACTIVE_INSET);
115   inset = new MathDelimInset('{', '.'); // this leaks
116   inset->SetData(array);
117   array = new MathedArray; // this leaks
118   iter.SetData(array);
119   iter.Insert(inset, LM_TC_ACTIVE_INSET);
120   m->SetData(array);
121   
122
123   // the environment substack has 1 argument
124   m = new MathMacroTemplate("substack", 1, MMF_Env); // this leaks
125   addTemplate(m);     
126   arg = new MathMatrixInset(1, 1); // this leaks
127   m->setArgument(arg);
128   arg->SetType(LM_OT_MACRO);
129   array = new MathedArray; // this leaks
130   iter.SetData(array);
131   iter.Insert(arg, LM_TC_ACTIVE_INSET);
132   m->SetData(array);*/
133 }