]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/mathml_editor/src/TDictionary.hh
Now it's possible to insert and delete control sequence with arguments
[helm.git] / helm / DEVEL / mathml_editor / src / TDictionary.hh
1
2 #ifndef __TDictionary_hh__
3 #define __TDictionary_hh__
4
5 #include <string>
6 #include <vector>
7 #include <hash_map>
8
9 #include "TToken.hh"
10
11 class TDictionary
12 {
13 public:
14   TDictionary(void) { };
15   ~TDictionary() { };
16
17   enum Form
18     {
19       INFIX,
20       PREFIX,
21       POSTFIX
22     };
23
24   enum EntryClass
25     {
26       UNDEFINED,
27       MACRO,
28       OPERATOR,
29       IDENTIFIER,
30       NUMBER
31     };
32
33   struct Entry
34   {
35     Entry(void)
36     { 
37       cls = UNDEFINED;
38       infix = prefix = postfix = 0;
39       table = delimiter = limits = embellishment = leftOpen = rightOpen = 0;
40     };
41
42     std::vector<TToken> pattern;
43     std::string value;
44
45     bool defined(void) const { return cls != UNDEFINED; };
46     bool hasArguments(void) const { return !pattern.empty(); };
47     bool paramDelimited(unsigned) const;
48     bool lastDelimiter(unsigned) const;
49     unsigned previousParam(unsigned) const;
50
51     EntryClass cls;
52     unsigned infix : 8;
53     unsigned prefix : 8;
54     unsigned postfix : 8;
55     unsigned delimiter : 1;
56     unsigned limits : 1;
57     unsigned embellishment : 1;
58     unsigned leftOpen : 1;
59     unsigned rightOpen : 1;
60     unsigned table : 1;
61   };
62
63   void load(const char* uri);
64   const Entry& find(const std::string&) const;
65
66 private:
67   struct StringHash : public std::unary_function< std::string, size_t >
68   { size_t operator()(const std::string& s) const { return hash<char*>()(s.c_str()); } };
69
70 #if 0
71   struct StringEq : public std::binary_function< std::string, std::string, bool >
72   { bool operator()(const std::string&, const class String*) const; };
73 #endif
74
75   typedef std::hash_map< std::string, Entry, StringHash > Dictionary;
76   Dictionary entries;
77 };
78
79 #endif // __TDictionary_hh__
80