]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/mathml_editor/src/TDictionary.hh
Initial revision
[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       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
49     EntryClass cls;
50     unsigned infix : 8;
51     unsigned prefix : 8;
52     unsigned postfix : 8;
53     unsigned delimiter : 1;
54     unsigned limits : 1;
55     unsigned embellishment : 1;
56     unsigned leftOpen : 1;
57     unsigned rightOpen : 1;
58     unsigned table : 1;
59   };
60
61   void load(const char* uri);
62   const Entry& find(const std::string&) const;
63
64 private:
65   struct StringHash : public std::unary_function< std::string, size_t >
66   { size_t operator()(const std::string& s) const { return hash<char*>()(s.c_str()); } };
67
68 #if 0
69   struct StringEq : public std::binary_function< std::string, std::string, bool >
70   { bool operator()(const std::string&, const class String*) const; };
71 #endif
72
73   typedef std::hash_map< std::string, Entry, StringHash > Dictionary;
74   Dictionary entries;
75 };
76
77 #endif // __TDictionary_hh__
78