|
k-dot-p 0.1
|
00001 /* 00002 00003 00004 Copyright (C) 2009 Joseph Pingenot 00005 00006 This program is free software: you can redistribute it and/or modify 00007 it under the terms of the GNU Affero General Public License as published by 00008 the Free Software Foundation, either version 3 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU Affero General Public License for more details. 00015 00016 You should have received a copy of the GNU Affero General Public License 00017 along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 00019 */ 00020 00021 #include <glib.h> 00022 #include <gio/gio.h> 00023 00024 #ifndef FUNCTION_SPECIFICTION_HXX__ 00025 #define FUNCTION_SPECIFICTION_HXX__ 00026 00027 #define DOMAIN_FUNCTION_SPECIFICATION 56932 00028 00029 namespace kdotp { 00030 namespace libmodelxx { 00031 namespace postprocessing { 00032 00033 00034 enum function_op { 00035 PLUS, 00036 MINUS, 00037 MUL, 00038 DIV, 00039 EXP, 00040 CONST, 00041 COS, 00042 SIN, 00043 TAN, 00044 LOG, 00045 ACOS, 00046 ASIN, 00047 ATAN, 00048 ABS, 00049 SQRT, 00050 DOT, 00051 CROSS, 00052 NEG, 00053 OR, 00054 AND, 00055 XOR, 00056 NOT, 00057 SYMBOL 00058 }; 00059 00060 /**Note that the data types correspond to 1-(the number of dimensions). This is a feature (take advantage of int conversion)*/ 00061 enum function_datatype { 00062 INVALID=-1, 00063 BINARY, 00064 SCALAR, 00065 VECTOR2, 00066 VECTOR3 00067 }; 00068 00069 struct function_exp { 00070 enum function_op op; 00071 struct function_exp *l; 00072 struct function_exp *r; 00073 }; 00074 00075 struct function_const { 00076 /*op should always be set to CONST*/ 00077 enum function_op op; 00078 enum function_datatype t; 00079 double* value; 00080 }; 00081 00082 struct function_symbol { 00083 /*op should always be set to SYMBOL*/ 00084 enum function_op op; 00085 char* symbol; 00086 }; 00087 00088 enum symbol_type { 00089 CONSTANT_SYMBOL 00090 //USER_FUNCTION 00091 }; 00092 00093 /**describes the symbol being referenced*/ 00094 struct symbol_table_entry { 00095 enum symbol_type st; 00096 enum function_datatype dt; 00097 }; 00098 struct symbol_table_entry_const { 00099 enum symbol_type st; 00100 enum function_datatype dt; 00101 double* value; 00102 }; 00103 00104 struct template_parameter_range { 00105 char* symbol; 00106 double from; 00107 double to; 00108 double stepsize; 00109 /*for use when iterating through*/ 00110 double current_value; 00111 }; 00112 00113 00114 /**get a function 00115 *\param c the builtin function to look up 00116 *\return op corresponding to the function, or NOT if couldn't determine one 00117 */ 00118 enum function_op function_get_op_for_builtin_function(const char* c); 00119 00120 /**Evaluates a function using a set of symbol tables 00121 *\param values array to store the results in 00122 *\param f the function to be evaluated 00123 *\param global_symbols the global symbol table (e.g. constants, built-in template parameters), user-defined template parameters 00124 *\param local_symbols the local symbol table (e.g. x, X) 00125 */ 00126 GError* evaluate_function(double* values, const struct function_exp *f, GHashTable* global_symbols, GHashTable* local_symbols); 00127 /**This gets the data type for the function 00128 *\param global_symbols the global symbol table (e.g. constants, built-in template parameters), user-defined template parameters 00129 *\param local_symbols the local symbol table (e.g. x, X) 00130 *\param exp function 00131 */ 00132 enum function_datatype get_function_datatype(struct function_exp *exp, GHashTable* global_symbols, GHashTable* local_symbols); 00133 00134 /**Pretty prints a function tree to a sring you can print out. 00135 *e the expression to print 00136 *s a GString to which the output will be appended 00137 */ 00138 void function_print_tree(struct function_exp *e, GString **s, int indentation); 00139 00140 enum function_datatype get_function_datatype(struct function_exp* exp, GHashTable* global_symbols, GHashTable* local_symbols); 00141 00142 struct symbol_table_entry* get_symbol_table_entry(const char* symbol, GHashTable *global_symbols, GHashTable* local_symbols, GError **e); 00143 00144 GHashTable* new_symbol_table(); 00145 00146 void add_symbol_table_entry(GHashTable *st, const char* symbol, struct symbol_table_entry* entry); 00147 00148 void parameter_list_init(GList* parameters); 00149 00150 bool update_parameters_plus_check_if_done(GList* parameters); 00151 00152 GFile* get_gfile_directory_for_template_state(const char* prefix, GList* parameters); 00153 00154 char* get_string_for_template_state(GList* parameters); 00155 00156 char* get_header_for_template_state(GList* parameters); 00157 00158 void add_template_parameters_to_symbol_table(GHashTable *st, GList* parms); 00159 00160 void free_function(struct function_exp *e); 00161 00162 } 00163 } 00164 } 00165 #endif