00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
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
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;
00070 xbShort ParmCnt;
00071 char ReturnType;
00072 void (*ExpFuncPtr)();
00073 };
00074
00075
00077
00081 class XBDLLEXPORT xbExpNode {
00082 public:
00083 xbExpNode();
00084 virtual ~xbExpNode();
00085
00086 public:
00087 char * NodeText;
00088 char Type;
00089 xbShort Len;
00090 xbShort InTree;
00091 xbExpNode * Node;
00092 xbExpNode * Sibling1;
00093 xbExpNode * Sibling2;
00094 xbExpNode * Sibling3;
00095 xbShort DataLen;
00096 xbShort ResultLen;
00097 xbString StringResult;
00098 xbDouble DoubResult;
00099 xbShort IntResult;
00100 xbDbf * dbf;
00101 xbShort FieldNo;
00102 char ExpressionType;
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
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
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
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 * );
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;
00253 xbExpNode *Tree;
00254 xbShort LogicalType;
00255 char TokenType;
00256
00257
00258
00259
00260
00261
00262
00263
00264 char PreviousType;
00265 char * Op1;
00266 char * Op2;
00267 xbDouble Opd1;
00268 xbDouble Opd2;
00269 xbShort OpLen1;
00270 xbShort OpLen2;
00271 xbShort OpDataLen1;
00272 xbShort OpDataLen2;
00273 char OpType1;
00274 char OpType2;
00275 xbShort TokenLen;
00276
00277
00278 enum { WorkBufMaxLen = 200 };
00279 char WorkBuf[WorkBufMaxLen+1];
00280
00281
00282 xbShort StackDepth;
00283 xbStackElement *First;
00284 xbStackElement *Last;
00285 };
00286
00287 #endif // XB_EXPRESSIONS
00288 #endif // __XB_EXP_H__
00289
00290