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
00043
00044
00045
00046
00047
00048
00049
00050 #ifndef __XB_EXP_H__
00051 #define __XB_EXP_H__
00052
00053 #ifdef __GNUG__
00054 #pragma interface
00055 #endif
00056
00057 #include <xbase/xbase.h>
00058
00059 #ifdef XB_EXPRESSIONS
00060
00061 #define XB_EXPRESSION xbExpNode
00062
00063 #include <xbase/xtypes.h>
00064 #include <xbase/xstack.h>
00065
00069 #undef ABS
00070 #undef MIN
00071 #undef MAX
00072
00073 class XBDLLEXPORT xbDbf;
00074
00076
00079 struct XBDLLEXPORT xbFuncDtl {
00080 const char * FuncName;
00081 xbShort ParmCnt;
00082 char ReturnType;
00083 void (*ExpFuncPtr)();
00084 };
00085
00087
00090 class XBDLLEXPORT xbExpNode {
00091 public:
00092 char * NodeText;
00093 char Type;
00094 xbShort Len;
00095 xbShort InTree;
00096 xbExpNode * Node;
00097 xbExpNode * Sibling1;
00098 xbExpNode * Sibling2;
00099 xbExpNode * Sibling3;
00100
00101 xbShort DataLen;
00102 xbShort ResultLen;
00103
00104 xbString StringResult;
00105 xbDouble DoubResult;
00106 xbShort IntResult;
00107
00108 xbDbf * dbf;
00109 xbShort FieldNo;
00110 char ExpressionType;
00111
00112
00113 public:
00114 xbExpNode() :
00115 NodeText(0),
00116 Type(0),
00117 Len(0),
00118 InTree(0),
00119 Node(0),
00120 Sibling1(0),
00121 Sibling2(0),
00122 Sibling3(0),
00123 DataLen(0),
00124 ResultLen(0),
00125 DoubResult(0),
00126 IntResult(0),
00127 dbf(0),
00128 FieldNo(-1),
00129 ExpressionType(0)
00130 {}
00131 ~xbExpNode(){
00132 if( Sibling1 ) delete Sibling1;
00133 if( Sibling2 ) delete Sibling2;
00134 if( Sibling3 ) delete Sibling3;
00135 }
00136 };
00137
00139
00142
00143
00144 class XBDLLEXPORT xbExpn : public xbStack, public xbDate {
00145 public:
00146 xbShort ProcessExpression( xbExpNode *, xbShort );
00147 xbExpNode * GetTree( void ) { return Tree; }
00148 void SetTreeToNull( void ) { Tree = NULL; }
00149 xbExpNode * GetFirstTreeNode( xbExpNode * );
00150
00151 xbExpn( void );
00152 xbShort GetNextToken( const char *s, xbShort MaxLen);
00153
00154
00155 xbDouble ABS( xbDouble );
00156 xbLong ASC( const char * );
00157 xbLong AT( const char *, const char * );
00158 char * CDOW( const char * );
00159 char * CHR( xbLong );
00160 char * CMONTH( const char * );
00161 char * DATE();
00162 xbLong DAY( const char * );
00163 xbLong DESCEND( const char * );
00164 xbLong DOW( const char * );
00165 char * DTOC( const char * );
00166 char * DTOS( const char * );
00167 xbDouble EXP( xbDouble );
00168 xbLong INT( xbDouble );
00169 xbLong ISALPHA( const char * );
00170 xbLong ISLOWER( const char * );
00171 xbLong ISUPPER( const char * );
00172 char * LEFT( const char *, xbShort );
00173 xbLong LEN( const char * );
00174 xbDouble LOG( xbDouble );
00175 char * LOWER( const char * );
00176 char * LTRIM( const char * );
00177 xbDouble MAX( xbDouble, xbDouble );
00178 xbLong MONTH( const char * );
00179 xbDouble MIN( xbDouble, xbDouble );
00180 char * RECNO( xbULong );
00181 xbLong RECNO( xbDbf * );
00182 char * REPLICATE( const char *, xbShort );
00183 char * RIGHT( const char *, xbShort );
00184 char * RTRIM( const char * );
00185 char * SPACE( xbShort );
00186 xbDouble SQRT( xbDouble );
00187 char * STR( const char * );
00188 char * STR( const char *, xbShort );
00189 char * STR( const char *, xbShort, xbShort );
00190 char * STR( xbDouble );
00191 char * STR( xbDouble, xbShort );
00192 char * STR(xbDouble, xbUShort length, xbShort numDecimals );
00193 char * STRZERO( const char * );
00194 char * STRZERO( const char *, xbShort );
00195 char * STRZERO( const char *, xbShort, xbShort );
00196 char * STRZERO( xbDouble );
00197 char * STRZERO( xbDouble, xbShort );
00198 char * STRZERO( xbDouble, xbShort, xbShort );
00199 char * SUBSTR( const char *, xbShort, xbShort );
00200 char * TRIM( const char * );
00201 char * UPPER( const char * );
00202 xbLong VAL( const char * );
00203 xbLong YEAR( const char * );
00205
00208 void SetDefaultDateFormat(const xbString f){ DefaultDateFormat = f; }
00209
00210 xbString GetDefaultDateFormat() const { return DefaultDateFormat; }
00211 xbShort ProcessExpression( const char *exp, xbDbf * d );
00212 xbShort ParseExpression( const char *exp, xbDbf * d );
00213 XB_EXPRESSION * GetExpressionHandle();
00214 char GetExpressionResultType(XB_EXPRESSION * );
00215 char * GetCharResult();
00216 xbString & GetStringResult();
00217 xbDouble GetDoubleResult();
00218 xbLong GetIntResult();
00219 xbShort ProcessExpression( xbExpNode * );
00220 xbShort BuildExpressionTree( const char * Expression, xbShort MaxTokenLen,
00221 xbDbf *d );
00222
00223 #ifdef XBASE_DEBUG
00224 void DumpExpressionTree( xbExpNode * );
00225 void DumpExpNode( xbExpNode * );
00226 #endif
00227
00228 protected:
00229 xbFuncDtl *XbaseFuncList;
00230
00231 xbExpNode *Tree;
00232 xbShort LogicalType;
00233
00234 char TokenType;
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244 char PreviousType;
00245 char * Op1;
00246 char * Op2;
00247 xbDouble Opd1;
00248 xbDouble Opd2;
00249 xbShort OpLen1;
00250 xbShort OpLen2;
00251 xbShort OpDataLen1;
00252 xbShort OpDataLen2;
00253
00254 char OpType1;
00255 char OpType2;
00256 xbShort TokenLen;
00257
00258 static xbString DefaultDateFormat;
00259
00260 enum { WorkBufMaxLen = 200 };
00261 char WorkBuf[WorkBufMaxLen+1];
00262
00263 xbShort IsWhiteSpace( char );
00264 char IsSeparator( char );
00265 xbExpNode * LoadExpNode( const char * ENodeText, const char EType,
00266 const xbShort ELen, const xbShort BufLen );
00267 xbShort OperatorWeight( const char *Oper, xbShort len );
00268 xbShort ReduceComplexExpression( const char * NextToken, xbShort Len,
00269 xbExpNode * cn, xbDbf *d );
00270 xbShort GetFunctionTokenLen( const char *s );
00271 xbShort ReduceFunction( const char *NextToken, xbExpNode *cn, xbDbf *d );
00272 xbExpNode * GetNextTreeNode( xbExpNode * );
00273 xbShort ProcessOperator( xbShort );
00274 xbShort ProcessFunction( char * );
00275 xbShort ValidOperation( char *, char, char );
00276 char GetOperandType( xbExpNode * );
00277 xbShort AlphaOperation( char * );
00278 xbShort NumericOperation( char * );
00279 xbExpNode * GetExpNode( xbShort );
00280 xbShort GetFuncInfo( const char *Function, xbShort Option );
00281 xbDouble GetDoub( xbExpNode * );
00282 xbLong GetInt( xbExpNode * );
00283 };
00284 #endif // XB_EXPRESSIONS
00285 #endif // __XB_EXP_H__