]> git.lyx.org Git - lyx.git/blob - src/mathed/math_utils.C
Hopefully fix the problem with stateText() in lyxfont.C
[lyx.git] / src / mathed / math_utils.C
1 /* 
2  *  File:        math_utils.C
3  *  Purpose:     X independent general mathed routines
4  *  Author:      Alejandro Aguilar Sierra <asierra@servidor.unam.mx> 
5  *  Created:     August 1996
6  *  
7  *  Copyright: 1996, 1997 Alejandro Aguilar Sierra
8  *
9  *  License: GNU GPL version 2 or later
10  */
11
12 #include <config.h>
13
14 #include <algorithm>
15
16 #include "math_defs.h"
17 #include "symbol_def.h"
18
19 using std::sort;
20 using std::lower_bound;
21
22 // This table includes all binary operators and relations
23 struct binary_op_pair {
24         short id;
25         short isrel;
26 };
27
28 binary_op_pair binary_op_table[] = {
29       { LM_leq, LMB_RELATION }, { LM_geq, LMB_RELATION }, 
30       { LM_equiv, LMB_RELATION }, { LM_models, LMB_RELATION }, 
31       { LM_prec, LMB_RELATION }, { LM_succ, LMB_RELATION }, 
32       { LM_sim, LMB_RELATION }, { LM_perp, LMB_RELATION }, 
33       { LM_preceq, LMB_RELATION }, { LM_succeq, LMB_RELATION }, 
34       { LM_simeq, LMB_RELATION }, { LM_mid, LMB_RELATION }, 
35       { LM_ll, LMB_RELATION }, { LM_gg, LMB_RELATION }, 
36       { LM_asymp, LMB_RELATION }, { LM_parallel, LMB_RELATION }, 
37       { LM_subset, LMB_RELATION }, { LM_supset, LMB_RELATION }, 
38       { LM_approx, LMB_RELATION }, { LM_smile, LMB_RELATION }, 
39       { LM_subseteq, LMB_RELATION }, { LM_supseteq, LMB_RELATION }, 
40       { LM_cong, LMB_RELATION }, { LM_frown, LMB_RELATION }, 
41       { LM_sqsubseteq, LMB_RELATION }, { LM_sqsupseteq, LMB_RELATION }, 
42       { LM_doteq, LMB_RELATION }, { LM_neq, LMB_RELATION }, 
43       { LM_in, LMB_RELATION }, { LM_ni, LMB_RELATION }, 
44       { LM_propto, LMB_RELATION }, { LM_notin, LMB_RELATION }, 
45       { LM_vdash, LMB_RELATION }, { LM_dashv, LMB_RELATION }, 
46       { LM_bowtie, LMB_RELATION },
47       { LM_pm, LMB_OPERATOR }, { LM_cap, LMB_OPERATOR }, 
48       { LM_diamond, LMB_OPERATOR }, { LM_oplus, LMB_OPERATOR },
49       { LM_mp, LMB_OPERATOR }, { LM_cup, LMB_OPERATOR }, 
50       { LM_bigtriangleup, LMB_OPERATOR }, { LM_ominus, LMB_OPERATOR },
51       { LM_times, LMB_OPERATOR }, { LM_uplus, LMB_OPERATOR }, 
52       { LM_bigtriangledown, LMB_OPERATOR }, { LM_otimes, LMB_OPERATOR },
53       { LM_div, LMB_OPERATOR }, { LM_sqcap, LMB_OPERATOR }, 
54       { LM_triangleright, LMB_OPERATOR }, { LM_oslash, LMB_OPERATOR },
55       { LM_cdot, LMB_OPERATOR }, { LM_sqcup, LMB_OPERATOR }, 
56       { LM_triangleleft, LMB_OPERATOR }, { LM_odot, LMB_OPERATOR },
57       { LM_star, LMB_OPERATOR }, { LM_vee, LMB_OPERATOR }, 
58       { LM_amalg, LMB_OPERATOR }, { LM_bigcirc, LMB_OPERATOR },
59       { LM_setminus, LMB_OPERATOR }, { LM_wedge, LMB_OPERATOR }, 
60       { LM_dagger, LMB_OPERATOR }, { LM_circ, LMB_OPERATOR },
61       { LM_bullet, LMB_OPERATOR }, { LM_wr, LMB_OPERATOR }, 
62       { LM_ddagger, LMB_OPERATOR }
63 };
64
65
66 struct compara {
67         // used by sort
68         inline
69         int operator()(binary_op_pair const & a,
70                        binary_op_pair const & b) const {
71                 return a.id < b.id;
72         }
73         // used by lower_bound
74         inline
75         int operator()(binary_op_pair const & a, short int id) const {
76                 return a.id < id;
77         }
78 };
79
80
81 int MathedLookupBOP(short id)
82 {
83         static int const bopCount =
84                 sizeof(binary_op_table) / sizeof(binary_op_pair);
85         static bool issorted = false;
86         
87         if (!issorted) {
88                 sort(binary_op_table, binary_op_table + bopCount, compara());
89                 issorted = true;
90         }
91         
92         binary_op_pair * res = lower_bound(binary_op_table,
93                                            binary_op_table + bopCount,
94                                            id, compara());
95         if (res != binary_op_table + bopCount && res->id == id)
96                 return res->isrel;
97         else
98                 return LMB_NONE;
99 }