Xbase64 Class Library
3.1.2
|
00001 /* xbexp.h 00002 00003 Xbase64 project source code 00004 00005 This file contains a header file for the EXP object, which is 00006 used for expression processing. 00007 00008 Copyright (C) 1997,2003 Gary A Kunkel 00009 00010 This program is free software; you can redistribute it and/or modify 00011 it under the terms of the GNU Lesser General Public License as published by 00012 the Free Software Foundation; either version 2 of the License, or 00013 (at your option) any later version. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU Lesser General Public License for more details. 00019 00020 You should have received a copy of the GNU Lesser General Public License 00021 along with this program; if not, write to the Free Software 00022 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00023 00024 00025 Contact: 00026 00027 Email: 00028 00029 xdb-devel@lists.sourceforge.net 00030 xdb-users@lists.sourceforge.net 00031 00032 00033 Regular Mail: 00034 00035 XBase Support 00036 149C South Main St 00037 Keller Texas, 76248 00038 USA 00039 00040 */ 00041 00042 #ifndef __XB_EXP_H__ 00043 #define __XB_EXP_H__ 00044 00045 #ifdef __GNU_LesserG__ 00046 #pragma interface 00047 #endif 00048 00049 #include <xbase64/xbase64.h> 00050 00051 #ifdef XB_EXPRESSIONS /* compile if expression logic on */ 00052 #include <xbase64/xbtypes.h> 00053 00057 #undef ABS 00058 #undef MIN 00059 #undef MAX 00060 00061 class XBDLLEXPORT xbDbf; 00062 00063 /************************************************************************/ 00065 00068 struct XBDLLEXPORT xbFuncDtl { 00069 const char * FuncName; /* function name */ 00070 xbShort ParmCnt; /* no of parms it needs */ 00071 char ReturnType; /* return type of function */ 00072 void (*ExpFuncPtr)(); /* pointer to function routine */ 00073 }; 00074 00075 /************************************************************************/ 00077 00081 class XBDLLEXPORT xbExpNode { 00082 public: 00083 xbExpNode(); 00084 virtual ~xbExpNode(); 00085 00086 public: 00087 char * NodeText; /* expression text */ 00088 char Type; /* same as TokenType below */ 00089 xbShort Len; /* length of expression text */ 00090 xbShort InTree; /* this node in the tree? 1=yes */ 00091 xbExpNode * Node; /* pointer to parent */ 00092 xbExpNode * Sibling1; /* pointer to sibling 1 */ 00093 xbExpNode * Sibling2; /* pointer to sibling 2 */ 00094 xbExpNode * Sibling3; /* pointe/r to sibling 3 */ 00095 xbShort DataLen; /* length of data in result buffer */ 00096 xbShort ResultLen; /* length of result buffer */ 00097 xbString StringResult; /* string result */ 00098 xbDouble DoubResult; /* Numeric Result */ 00099 xbShort IntResult; /* logical result */ 00100 xbDbf * dbf; /* pointer to datafile */ 00101 xbShort FieldNo; /* field no if DBF field */ 00102 char ExpressionType; /* used in head node C,N,L or D */ 00103 }; 00104 /************************************************************************/ 00106 00109 class XBDLLEXPORT xbStackElement 00110 { 00111 public: 00112 xbStackElement(); 00113 ~xbStackElement(); 00114 00115 friend class xbExpn; 00116 00117 private: 00118 xbStackElement *Previous; 00119 xbStackElement *Next; 00120 xbExpNode *NodePtr; 00121 }; 00122 /************************************************************************/ 00124 00127 /* Expression handler */ 00128 00129 class XBDLLEXPORT xbExpn{ 00130 public: 00131 xbExpn( xbXBase * ); 00132 virtual ~xbExpn(); 00133 00134 xbShort GetNextToken( const char *s, xbShort MaxLen ); 00135 xbShort ProcessExpression( xbExpNode *n, xbShort ); 00136 xbShort ProcessExpression( xbShort opt ) 00137 { return ProcessExpression( Tree, opt ); } 00138 00139 xbExpNode * GetTree() { return Tree; } 00140 void SetTreeToNull() { Tree = NULL; } 00141 xbExpNode * GetFirstTreeNode( xbExpNode * ); 00142 xbExpNode * GetFirstTreeNode() 00143 { return GetFirstTreeNode( Tree ); } 00144 xbShort ProcessExpression( const char *exp, xbDbf * d ); 00145 xbShort ParseExpression( const char *exp, xbDbf * d ); 00146 xbExpNode * GetExpressionHandle(); 00147 char GetExpressionResultType( xbExpNode * ); 00148 char GetExpressionResultType() 00149 { return GetExpressionResultType( Tree ); } 00150 char * GetCharResult(); 00151 xbString & GetStringResult(); 00152 xbDouble GetDoubleResult(); 00153 xbLong GetIntResult(); 00154 xbShort ProcessExpression( xbExpNode * ); 00155 xbShort ProcessExpression() { return ProcessExpression( Tree ); } 00156 xbShort BuildExpressionTree( const char * Expression, xbShort MaxTokenLen, 00157 xbDbf *d ); 00158 00159 /* stack functions */ 00160 void InitStack(); 00161 xbExpNode * Pop(); 00162 xbShort Push(xbExpNode *); 00163 xbShort GetStackDepth() { return StackDepth; } 00164 void DumpStack(); 00165 const char * GetValidFuncName( xbShort funcNo ) 00166 { return XbaseFuncList[funcNo].FuncName; } 00167 00168 #ifdef XBASE_DEBUG 00169 void DumpExpressionTree( xbShort printOption ) 00170 { DumpExpressionTree( Tree, printOption ); } 00171 void DumpExpressionTree( xbExpNode *, xbShort printOption ); 00172 void DumpExpNode( xbExpNode *, xbShort printOption ); 00173 #endif 00174 00175 /* expression methods */ 00176 xbDouble ABS( xbDouble ); 00177 xbLong ASC( const char * ); 00178 xbLong AT( const char *, const char * ); 00179 char * CDOW( const char * ); 00180 char * CHR( xbLong ); 00181 char * CMONTH( const char * ); 00182 char * CTOD( const char * ); 00183 char * DATE(); 00184 xbLong DAY( const char * ); 00185 char * DESCEND( const char * ); 00186 xbLong DESCEND( const xbDate & ); 00187 xbDouble DESCEND( xbDouble ); 00188 xbLong DOW( const char * ); 00189 char * DTOC( const char * ); 00190 char * DTOS( const char * ); 00191 xbDouble EXP( xbDouble ); 00192 char * IIF( xbShort, const char *, const char * ); 00193 xbLong INT( xbDouble ); 00194 xbLong ISALPHA( const char * ); 00195 xbLong ISLOWER( const char * ); 00196 xbLong ISUPPER( const char * ); 00197 char * LEFT( const char *, xbShort ); 00198 xbLong LEN( const char * ); 00199 xbDouble LOG( xbDouble ); 00200 char * LOWER( const char * ); 00201 char * LTRIM( const char * ); 00202 xbDouble MAX( xbDouble, xbDouble ); 00203 xbLong MONTH( const char * ); /* MONTH() */ 00204 xbDouble MIN( xbDouble, xbDouble ); 00205 xbLong RECNO( xbDbf * ); 00206 char * REPLICATE( const char *, xbShort ); 00207 char * RIGHT( const char *, xbShort ); 00208 char * RTRIM( const char * ); 00209 char * SPACE( xbShort ); 00210 xbDouble SQRT( xbDouble ); 00211 char * STR( const char * ); 00212 char * STR( const char *, xbShort ); 00213 char * STR( const char *, xbShort, xbShort ); 00214 char * STR( xbDouble ); 00215 char * STR( xbDouble, xbShort ); 00216 char * STR(xbDouble, xbUShort length, xbShort numDecimals ); 00217 char * STRZERO( const char * ); 00218 char * STRZERO( const char *, xbShort ); 00219 char * STRZERO( const char *, xbShort, xbShort ); 00220 char * STRZERO( xbDouble ); 00221 char * STRZERO( xbDouble, xbShort ); 00222 char * STRZERO( xbDouble, xbShort, xbShort ); 00223 char * SUBSTR( const char *, xbShort, xbShort ); 00224 char * TRIM( const char * ); 00225 char * UPPER( const char * ); 00226 xbLong VAL( const char * ); 00227 xbLong YEAR( const char * ); 00228 00229 protected: 00230 xbShort IsWhiteSpace( char ); 00231 char IsSeparator( char ); 00232 xbExpNode * LoadExpNode( const char * ENodeText, const char EType, 00233 const xbShort ELen, const xbShort BufLen ); 00234 xbShort OperatorWeight( const char *Oper, xbShort len ); 00235 xbShort ReduceComplexExpression( const char * NextToken, xbShort Len, 00236 xbExpNode * cn, xbDbf *d ); 00237 xbShort GetFunctionTokenLen( const char *s ); 00238 xbShort ReduceFunction( const char *NextToken, xbExpNode *cn, xbDbf *d ); 00239 xbExpNode * GetNextTreeNode( xbExpNode * ); 00240 xbShort ProcessOperator( xbShort ); 00241 xbShort ProcessFunction( char * ); 00242 xbShort ValidOperation( char *, char, char ); 00243 char GetOperandType( xbExpNode * ); 00244 xbShort AlphaOperation( char * ); 00245 xbShort NumericOperation( char * ); 00246 xbShort GetFuncInfo( const char *Function, xbShort Option ); 00247 xbDouble GetDoub( xbExpNode * ); 00248 xbLong GetInt( xbExpNode * ); 00249 00250 private: 00251 xbXBase *xbase; 00252 xbFuncDtl *XbaseFuncList; /* pointer to list of Xbase functions */ 00253 xbExpNode *Tree; /* pointer to tree of parsed nodes */ 00254 xbShort LogicalType; /* set to 1 for logical type nodes */ 00255 char TokenType; /* E - Expression, not in simplest form */ 00256 /* C - Constant */ 00257 /* N - Numeric Constant */ 00258 /* O - Operator */ 00259 /* F - Function */ 00260 /* D - Database Field */ 00261 /* s - character string result */ 00262 /* l - logical or short int result */ 00263 /* d - double result */ 00264 char PreviousType; /* used to see if "-" follows operator */ 00265 char * Op1; /* pointer to operand 1 */ 00266 char * Op2; /* pointer to operand 2 */ 00267 xbDouble Opd1; /* double result 1 */ 00268 xbDouble Opd2; /* double result 2 */ 00269 xbShort OpLen1; /* length of memory allocated to operand 1 */ 00270 xbShort OpLen2; /* length of memory allocated to operand 2 */ 00271 xbShort OpDataLen1; /* length of data in op1 */ 00272 xbShort OpDataLen2; /* length of data in op2 */ 00273 char OpType1; /* type of operand 1 */ 00274 char OpType2; /* type of operand 2 */ 00275 xbShort TokenLen; /* length of token */ 00276 00277 // static xbString DefaultDateFormat; /*default date format for DTOC func*/ 00278 enum { WorkBufMaxLen = 200 }; 00279 char WorkBuf[WorkBufMaxLen+1]; 00280 00281 /* stack variables */ 00282 xbShort StackDepth; 00283 xbStackElement *First; 00284 xbStackElement *Last; 00285 }; 00286 00287 #endif // XB_EXPRESSIONS 00288 #endif // __XB_EXP_H__ 00289 00290