00001 //DataFunc.h 00002 00003 /*************************************************************/ 00004 // 00005 // CDataFunc 00006 // 00007 // Function parser and evaluator 00008 // 00009 //------------------------------------------------------------- 00010 // 00011 // v 1.7 - 2007/03/27 - Top hat 00012 // v 1.6 - 2007/02/07 - More trig and log functions 00013 // v 1.5 - 2007/02/01 - Heavyside functions 00014 // v 1.4 - 2007/01/13 - Added comma to end of variable list 00015 // v 1.3 - 2006/11/17 - Fixed '-' presidence and ',' argument separator 00016 // v 1.2 - 2006/08/21 - Rewrote Infix -> RPN converter 00017 // v 1.1 - 2006/08/18 - Added plane equation 00018 // v 1.0 - 2006/04/19 - Initial release 00019 // 00020 // See LICENSE.txt for distribution and usage restrictions 00021 // Copyright (c) 2005-2007 Simon Chorley 00022 // www.mylaboratory.co.uk - greylab@mylaboratory.co.uk 00023 // 00024 /*************************************************************/ 00025 00026 00027 ///Function parser and evaluator (Definition) 00028 /** 00029 * Provides CDataFunc function parser and evaluator to process the data. 00030 * @file DataFunc.h 00031 * @version 1.7 - 2007/03/27 00032 */ 00033 00034 00035 #ifndef _DATAFUNC_H_ 00036 #define _DATAFUNC_H_ 00037 00038 00039 #include "Vector.h" 00040 00041 00042 ///GreyLab function parser and evaluator 00043 /** 00044 * Reads, parses and interprets human readable Infix functions into a Reverse Polish Notation for execution 00045 * and performs the operations on data. 00046 */ 00047 class CDataFunc 00048 { 00049 public: 00050 enum status {OK, NONENDING_VAR, UNKNOWN_TAG, UNMATCHED_PARENTHESES, NONENDING_OP, TOO_FEW_VARS, INVALID_SEPARATOR}; ///<Error codes 00051 private: 00052 ///Mathematical operator details 00053 struct op 00054 { 00055 char *tag; ///<Text name of the operator 00056 int precedence; ///<Execution precedence 00057 bool lassociative; ///<Left-associativity 00058 int args; ///<Number of arguments to operator 00059 }; 00060 static op *ops; ///<The list of useable operators 00061 static int nOps; ///<Number of operators 00062 ///RPN token entry 00063 struct token 00064 { 00065 int tagid; ///<Operator ID 00066 double value; ///<Token value (if appropriate) 00067 token *next; ///<Next token 00068 token *prev; ///<Previous token 00069 } *queue; ///<Linked list of tokens 00070 real *values; ///<List of values 00071 int nValues; ///<Number of values 00072 int nQueue; ///<Number of tokens in the list 00073 00074 static int instances; ///<Instances of this class (for cleanup handling) 00075 00076 int FindTagID(char *string); 00077 status TestEvaluate(void); 00078 00079 public: 00080 CDataFunc(); 00081 ~CDataFunc(); 00082 00083 bool valid; ///<Valid function? 00084 00085 status InfixToRPN(char *input); //parse string 00086 double Evaluate(double x, double y, double z, int cols, double coldata[]); //evaluate function 00087 }; 00088 00089 #endif
1.5.3