]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/mathml_editor/src/TDictionary.hh
* temporary fix for handling relative/absolute filenames in
[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&);
63   void load(const std::string&, const std::string&);
64   void load(const DOM::Document&, const std::string& = "");
65   const Entry& find(const std::string&) const;
66
67 private:
68   struct StringHash : public std::unary_function< std::string, size_t >
69   { size_t operator()(const std::string& s) const { return hash<char*>()(s.c_str()); } };
70
71 #if 0
72   struct StringEq : public std::binary_function< std::string, std::string, bool >
73   { bool operator()(const std::string&, const class String*) const; };
74 #endif
75
76   class ALogger& logger;
77 #if defined(HAVE_EXT_HASH_MAP)
78   typedef __gnu_cxx::hash_map< std::string, Entry, StringHash > Dictionary;
79 #elif defined(HAVE_HASH_MAP)
80   typedef std::hash_map< std::string, Entry, StringHash > Dictionary;
81 #else
82 #error "no hash_map could be found"
83 #endif
84   Dictionary entries;
85 };
86
87 #endif // __TDictionary_hh__
88