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