]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/DEVEL/mathml_editor/src/TDictionary.hh
Initial revision
[helm.git] / helm / DEVEL / mathml_editor / src / TDictionary.hh
diff --git a/helm/DEVEL/mathml_editor/src/TDictionary.hh b/helm/DEVEL/mathml_editor/src/TDictionary.hh
new file mode 100644 (file)
index 0000000..44c020c
--- /dev/null
@@ -0,0 +1,78 @@
+
+#ifndef __TDictionary_hh__
+#define __TDictionary_hh__
+
+#include <string>
+#include <vector>
+#include <hash_map>
+
+#include "TToken.hh"
+
+class TDictionary
+{
+public:
+  TDictionary(void) { };
+  ~TDictionary() { };
+
+  enum Form
+    {
+      INFIX,
+      PREFIX,
+      POSTFIX
+    };
+
+  enum EntryClass
+    {
+      UNDEFINED,
+      MACRO,
+      OPERATOR,
+      IDENTIFIER,
+      NUMBER
+    };
+
+  struct Entry
+  {
+    Entry(void)
+    { 
+      cls = UNDEFINED;
+      infix = prefix = postfix = 0;
+      delimiter = limits = embellishment = leftOpen = rightOpen = 0;
+    };
+
+    std::vector<TToken> pattern;
+    std::string value;
+
+    bool defined(void) const { return cls != UNDEFINED; };
+    bool hasArguments(void) const { return !pattern.empty(); };
+    bool paramDelimited(unsigned) const;
+
+    EntryClass cls;
+    unsigned infix : 8;
+    unsigned prefix : 8;
+    unsigned postfix : 8;
+    unsigned delimiter : 1;
+    unsigned limits : 1;
+    unsigned embellishment : 1;
+    unsigned leftOpen : 1;
+    unsigned rightOpen : 1;
+    unsigned table : 1;
+  };
+
+  void load(const char* uri);
+  const Entry& find(const std::string&) const;
+
+private:
+  struct StringHash : public std::unary_function< std::string, size_t >
+  { size_t operator()(const std::string& s) const { return hash<char*>()(s.c_str()); } };
+
+#if 0
+  struct StringEq : public std::binary_function< std::string, std::string, bool >
+  { bool operator()(const std::string&, const class String*) const; };
+#endif
+
+  typedef std::hash_map< std::string, Entry, StringHash > Dictionary;
+  Dictionary entries;
+};
+
+#endif // __TDictionary_hh__
+