]> git.lyx.org Git - lyx.git/blob - src/mathed/math_macrotable.C
some fixes for compaq cxx
[lyx.git] / src / mathed / math_macrotable.C
1 #include <config.h>
2
3 #include <iostream>
4
5 #ifdef __GNUG__
6 #pragma implementation
7 #endif
8
9 #include "math_macrotable.h"
10 #include "math_macro.h"
11 #include "math_macrotemplate.h"
12 #include "math_parser.h"
13 #include "array.h"
14 #include "math_accentinset.h"
15 #include "math_deliminset.h"
16 #include "math_fracinset.h"
17 #include "math_inset.h"
18 #include "debug.h"
19 #include "support/LAssert.h"
20
21 using std::endl;
22
23 MathMacroTable::table_type MathMacroTable::macro_table;
24
25
26 void MathMacroTable::dump()
27 {
28         lyxerr << "\n------------------------------------------\n";
29         table_type::const_iterator it;
30         for (it = macro_table.begin(); it != macro_table.end(); ++it)
31                 lyxerr << it->first << " [" << it->second->nargs() << "] : "
32                         << it->second << endl;
33         lyxerr << "------------------------------------------" << endl;;
34 }
35
36
37 void MathMacroTable::updateTemplate(MathMacroTemplate * par)
38 {
39         table_type::iterator pos = macro_table.find(par->name());
40
41         if (pos == macro_table.end())
42                 lyxerr << "MathMacroTable::updateTemplate: no template with name '"
43                        << par->name() << "' available." << endl;
44         else
45                 pos->second = par;
46 }
47
48
49 void MathMacroTable::insertTemplate(MathMacroTemplate * p)
50 {
51         macro_table[p->name()] = p;
52 }
53
54
55 MathMacroTemplate & MathMacroTable::provideTemplate(string const & name)
56 {
57         builtinMacros();
58         
59         table_type::iterator pos = macro_table.find(name);
60
61         if (pos == macro_table.end()) {
62                 lyxerr << "MathMacroTable::provideTemplate: no template with name '"
63                        << name << "' available." << endl;
64         }
65                 
66         return *pos->second;
67 }
68
69
70 bool MathMacroTable::hasTemplate(string const & name)
71 {
72         builtinMacros();
73         return macro_table.find(name) != macro_table.end();
74 }
75
76
77 MathMacro * MathMacroTable::cloneTemplate(string const & name)
78 {
79         return new MathMacro(provideTemplate(name));
80 }
81
82
83 void MathMacroTable::builtinMacros()
84 {
85         static bool built = false;
86         
87         if (built)
88                 return; 
89
90         built = true;
91     
92         lyxerr[Debug::MATHED] << "Building macros" << endl;
93     
94         // This macro doesn't have arguments
95         {
96                 MathMacroTemplate * t = new MathMacroTemplate("notin", 0);
97                 t->push_back(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not));
98                 insertTemplate(t);
99         }
100
101 /*
102         // This macro doesn't have arguments
103         {
104                 MathMacroTemplate & m = createTemplate("silentmult", 0);
105                 istringstream is("\\cdot\0");
106                 mathed_parser_file(is, 0);
107                 MathMatrixInset * p = &m;
108         mathed_parse(m.array, p, 0);
109         }
110 */
111
112         {
113                 MathMacroTemplate * t = new MathMacroTemplate("emptyset", 0);
114                 t->push_back(new MathAccentInset('0', LM_TC_RM, LM_not));
115                 insertTemplate(t);
116         }
117
118         {
119                 MathMacroTemplate * t = new MathMacroTemplate("to", 0);
120                 t->push_back(LM_rightarrow, LM_TC_SYMB);
121                 insertTemplate(t);
122         }
123
124         {
125                 MathMacroTemplate * t = new MathMacroTemplate("perp", 0);
126                 t->push_back(LM_bot, LM_TC_BOP);
127                 insertTemplate(t);
128         }
129 /*
130         {
131                 MathMacroTemplate & m = createTemplate("lint", 4);
132                 istringstream is("\\int_{#1}^{#2}#3 d#4\0");
133                 mathed_parser_file(is, 0);
134                 MathMatrixInset * p = &m;
135         mathed_parse(m.array, p, 0);
136         }
137 */
138 /*
139         {
140                 MathMacroTemplate * t = new MathMacroTemplate("binomii", 2);
141                 istringstream is("\\left(\\frac{#1}{#2}\\right)\0");
142                 mathed_parser_file(is, 0);
143         mathed_parse(t->array, t, 0);
144                 insertTemplate(t);
145         }
146 */
147
148         // binom has two arguments
149         {
150                 MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
151                 frac->cell(0).push_back(new MathMacroArgument(1));
152                 frac->cell(1).push_back(new MathMacroArgument(2));
153
154                 MathInset * inset = new MathDelimInset('(', ')');
155                 inset->push_back(frac);
156
157                 MathMacroTemplate * t = new MathMacroTemplate("binom", 2);
158                 t->push_back(inset);
159
160                 insertTemplate(t);
161         }
162
163 /*
164         {
165                 MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
166                 frac->cell(0)->push_back(new MathMacroArgument(1));
167                 frac->cell(1)->push_back(new MathMacroArgument(2));
168
169                 MathMacroTemplate * t = new MathMacroTemplate("choose", 2);
170                 t->push_back(frac);
171
172                 insertTemplate(t);
173         }
174 */
175 }