00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef SYMBOLTABLE_H
00023 #define SYMBOLTABLE_H
00024
00025 #include <stddef.h>
00026 #include "NameList.h"
00027 #include "Command.h"
00028
00029 class ParseTree;
00030
00032 class CmdAddAtomSelMacro : public Command {
00033 public:
00034 CmdAddAtomSelMacro(const char *theName, const char *theMacro)
00035 : Command(ATOMSEL_ADDMACRO) {}
00036 };
00037
00038
00040 class CmdDelAtomSelMacro : public Command {
00041 public:
00042 CmdDelAtomSelMacro(const char *theName)
00043 : Command(ATOMSEL_DELMACRO) {}
00044 };
00045
00046
00048 extern "C" {
00049 typedef double (*c_ddfunc)(double);
00050 }
00051
00052
00054 class SymbolTableElement {
00055 public:
00056 typedef int (*int_fctn)(void *, int, int *, int *);
00057 typedef int (*double_fctn)(void *, int, double *, int *);
00058 typedef int (*string_fctn)(void *, int, const char **, int *);
00059 typedef int (*single_fctn)(void *, int, int *);
00060 typedef int (*stringfctn_fctn)(void *, int, const char **, int *, int, int *);
00061
00062 typedef void (*void_fctn)(void);
00063 typedef int (*set_int_fctn)(void *, int, int *, int *);
00064 typedef int (*set_double_fctn)(void *, int, double *, int *);
00065 typedef int (*set_string_fctn)(void *, int, const char **, int *);
00066 typedef int (*set_single_fctn)(void *, int, int *, int *);
00067
00068 enum symtype {IS_INT, IS_FLOAT, IS_STRING};
00069 enum symdesc {NOTHING, KEYWORD, FUNCTION, SINGLEWORD, STRINGFCTN};
00070
00071 symdesc is_a;
00072 symtype returns_a;
00073
00075 union {
00076 c_ddfunc fctn;
00077 int_fctn keyword_int;
00078 double_fctn keyword_double;
00079 string_fctn keyword_string;
00080 single_fctn keyword_single;
00081 stringfctn_fctn keyword_stringfctn;
00082 };
00083
00085 union {
00086 void_fctn set_fctn;
00087 set_int_fctn set_keyword_int;
00088 set_double_fctn set_keyword_double;
00089 set_string_fctn set_keyword_string;
00090 set_single_fctn set_keyword_single;
00091 };
00092
00093 SymbolTableElement()
00094 : is_a(NOTHING), fctn(NULL), set_fctn(NULL) {}
00095
00096 SymbolTableElement(c_ddfunc get)
00097 : is_a(FUNCTION), returns_a(IS_FLOAT),
00098 fctn(get), set_fctn(NULL) {}
00099
00100 SymbolTableElement(int_fctn get, set_int_fctn set)
00101 : is_a(KEYWORD), returns_a(IS_INT),
00102 keyword_int(get), set_keyword_int(set) {}
00103
00104 SymbolTableElement(double_fctn get, set_double_fctn set)
00105 : is_a(KEYWORD), returns_a(IS_FLOAT),
00106 keyword_double(get), set_keyword_double(set) {}
00107
00108 SymbolTableElement(string_fctn get, set_string_fctn set)
00109 : is_a(KEYWORD), returns_a(IS_STRING),
00110 keyword_string(get), set_keyword_string(set) {}
00111
00112 SymbolTableElement(stringfctn_fctn get)
00113 : is_a(STRINGFCTN), returns_a(IS_STRING),
00114 keyword_stringfctn(get), set_fctn(NULL) {}
00115
00116 SymbolTableElement(single_fctn get, set_single_fctn set)
00117 : is_a(SINGLEWORD), returns_a(IS_INT),
00118 keyword_single(get), set_keyword_single(set) {}
00119 };
00120
00121
00123 class SymbolTable {
00124 private:
00126 NameList<char *> custom_singlewords;
00127
00128 public:
00129 NameList<SymbolTableElement *> fctns;
00130
00131 SymbolTable(void) {};
00132 ~SymbolTable(void);
00133
00135 ParseTree *parse(const char *seltext);
00136
00137
00138
00139
00140 void add_keyword(const char *visible,
00141 SymbolTableElement::int_fctn get,
00142 SymbolTableElement::set_int_fctn set) {
00143 fctns.add_name(visible, new SymbolTableElement(get, set));
00144 }
00145 void add_keyword(const char *visible,
00146 SymbolTableElement::double_fctn get,
00147 SymbolTableElement::set_double_fctn set) {
00148 fctns.add_name(visible, new SymbolTableElement(get, set));
00149 }
00150 void add_keyword(const char *visible,
00151 SymbolTableElement::string_fctn get,
00152 SymbolTableElement::set_string_fctn set) {
00153 fctns.add_name(visible, new SymbolTableElement(get, set));
00154 }
00155 void add_singleword(const char *visible,
00156 SymbolTableElement::single_fctn get,
00157 SymbolTableElement::set_single_fctn set) {
00158 fctns.add_name(visible, new SymbolTableElement(get, set));
00159 }
00160 void add_stringfctn(const char *visible,
00161 SymbolTableElement::stringfctn_fctn get) {
00162 fctns.add_name(visible, new SymbolTableElement(get));
00163 }
00164
00170 void add_cfunction(const char *visible, c_ddfunc fctn) {
00171 fctns.add_name(visible, new SymbolTableElement(fctn));
00172 }
00173
00175 int find_attribute(const char *attrib) {
00176 return fctns.typecode(attrib);
00177 }
00178
00180 int is_changeable(int fctnidx);
00181
00186 int num_custom_singleword();
00187
00189 const char *custom_singleword_name(int);
00190
00192 int add_custom_singleword(const char *name, const char *macro);
00193
00195 const char *get_custom_singleword(const char *name);
00196
00198 int remove_custom_singleword(const char *name);
00199 };
00200
00201 #endif
00202