]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/mathml_editor/src/TDictionary.hh
* this is a large commit
[helm.git] / helm / DEVEL / mathml_editor / src / TDictionary.hh
1
2 #ifndef __TDictionary_hh__
3 #define __TDictionary_hh__
4
5 #include <config.h>
6
7 #include <string>
8 #include <vector>
9 #include <hash_map>
10
11 #include "dom.hh"
12 #include "TToken.hh"
13
14 class TDictionary
15 {
16 public:
17   TDictionary(class ALogger& l) : logger(l) { };
18   ~TDictionary() { };
19
20   enum Form
21     {
22       INFIX,
23       PREFIX,
24       POSTFIX
25     };
26
27   enum EntryClass
28     {
29       UNDEFINED,
30       MACRO,
31       OPERATOR,
32       IDENTIFIER,
33       NUMBER
34     };
35
36   struct Entry
37   {
38     Entry(void)
39     { 
40       cls = UNDEFINED;
41       table = delimiter = limits = embellishment = leftOpen = rightOpen = 0;
42     };
43
44     std::vector<TToken> pattern;
45     std::string value;
46
47     bool defined(void) const { return cls != UNDEFINED; };
48     bool hasArguments(void) const { return !pattern.empty(); };
49     bool paramDelimited(unsigned) const;
50     bool lastDelimiter(unsigned) const;
51     unsigned previousParam(unsigned) const;
52
53     EntryClass cls;
54     unsigned delimiter : 1;
55     unsigned limits : 1;
56     unsigned embellishment : 1;
57     unsigned leftOpen : 1;
58     unsigned rightOpen : 1;
59     unsigned table : 1;
60   };
61
62   void load(const std::string& uri);
63   void load(const DOM::Document& doc);
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   class ALogger& logger;
76 #if defined(HAVE_EXT_HASH_MAP)
77   typedef __gnu_cxx::hash_map< std::string, Entry, StringHash > Dictionary;
78 #elif defined(HAVE_HASH_MAP)
79   typedef std::hash_map< std::string, Entry, StringHash > Dictionary;
80 #else
81 #error "no hash_map could be found"
82 #endif
83   Dictionary entries;
84 };
85
86 #endif // __TDictionary_hh__
87