]> git.lyx.org Git - lyx.git/blob - src/mathed/math_factory.C
Use references instead of pointers where possible
[lyx.git] / src / mathed / math_factory.C
1 #include <config.h>
2
3 #include "math_parser.h"
4 #include "math_binominset.h"
5 #include "math_decorationinset.h"
6 #include "math_dotsinset.h"
7 #include "math_funcinset.h"
8 #include "math_funcliminset.h"
9 #include "math_fracinset.h"
10 #include "math_kerninset.h"
11 #include "math_macro.h"
12 #include "math_macrotable.h"
13 #include "math_macroarg.h"
14 #include "math_notinset.h"
15 #include "math_rootinset.h"
16 #include "math_spaceinset.h"
17 #include "math_specialcharinset.h"
18 #include "math_sqrtinset.h"
19 #include "math_symbolinset.h"
20 #include "math_stackrelinset.h"
21
22
23 MathAtom createMathInset(latexkeys const * l)
24 {
25         switch (l->token) {
26         case LM_TK_FUNCLIM:
27                 return MathAtom(new MathFuncLimInset(l));
28         case LM_TK_SPECIAL:
29                 return MathAtom(new MathSpecialCharInset(l->id));
30         case LM_TK_SYM:
31         case LM_TK_CMR:
32         case LM_TK_CMSY:
33         case LM_TK_CMM:
34         case LM_TK_CMEX:
35         case LM_TK_MSA:
36         case LM_TK_MSB:
37                 return MathAtom(new MathSymbolInset(l));
38         case LM_TK_STACK:
39                 return MathAtom(new MathStackrelInset);
40         case LM_TK_KERN: 
41                 return MathAtom(new MathKernInset);
42         case LM_TK_BINOM:
43         case LM_TK_CHOOSE:
44                 return MathAtom(new MathBinomInset);
45         case LM_TK_OVER:
46         case LM_TK_FRAC:
47                 return MathAtom(new MathFracInset);
48         case LM_TK_ATOP:
49                 return MathAtom(new MathFracInset(true));
50         case LM_TK_NOT:
51                 return MathAtom(new MathNotInset);
52         case LM_TK_SQRT:
53                 return MathAtom(new MathSqrtInset);
54         case LM_TK_ROOT:
55                 return MathAtom(new MathRootInset);
56         case LM_TK_DECORATION:
57                 return MathAtom(new MathDecorationInset(l->name));
58         case LM_TK_SPACE:
59                 return MathAtom(new MathSpaceInset(l->id));
60         case LM_TK_DOTS:
61                 return MathAtom(new MathDotsInset(l->name));
62         }
63         return MathAtom(new MathFuncInset(l->name));
64 }
65
66
67 MathAtom createMathInset(string const & s)
68 {
69         //cerr << "creating inset with name: '" << s << "'\n";
70         if (s.size() == 2 && s[0] == '#' && s[1] >= '1' && s[1] <= '9')
71                 return MathAtom(new MathMacroArgument(s[1] - '0'));
72
73         if (s.size() == 3 && s[0] == '\\' && s[1] == '#' && s[2] >= '1' && s[2] <= '9')
74                 return MathAtom(new MathMacroArgument(s[2] - '0'));
75
76         latexkeys const * l = in_word_set(s);
77         if (l)
78                 return createMathInset(l);
79
80         if (MathMacroTable::has(s)) 
81                 return MathAtom(new MathMacro(s));
82
83         return MathAtom(new MathFuncInset(s));
84 }