Xbase64 Class Library 3.1.2
xbexp.h
Go to the documentation of this file.
1/* xbexp.h
2
3 Xbase64 project source code
4
5 This file contains a header file for the EXP object, which is
6 used for expression processing.
7
8 Copyright (C) 1997,2003 Gary A Kunkel
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
24
25 Contact:
26
27 Email:
28
29 xdb-devel@lists.sourceforge.net
30 xdb-users@lists.sourceforge.net
31
32
33 Regular Mail:
34
35 XBase Support
36 149C South Main St
37 Keller Texas, 76248
38 USA
39
40*/
41
42#ifndef __XB_EXP_H__
43#define __XB_EXP_H__
44
45#ifdef __GNU_LesserG__
46#pragma interface
47#endif
48
49#include <xbase64/xbase64.h>
50
51#ifdef XB_EXPRESSIONS /* compile if expression logic on */
52#include <xbase64/xbtypes.h>
53
57#undef ABS
58#undef MIN
59#undef MAX
60
61class XBDLLEXPORT xbDbf;
62
63/************************************************************************/
65
68struct XBDLLEXPORT xbFuncDtl {
69 const char * FuncName; /* function name */
70 xbShort ParmCnt; /* no of parms it needs */
71 char ReturnType; /* return type of function */
72 void (*ExpFuncPtr)(); /* pointer to function routine */
73};
74
75/************************************************************************/
77
81class XBDLLEXPORT xbExpNode {
82 public:
83 xbExpNode();
84 virtual ~xbExpNode();
85
86 public:
87 char * NodeText; /* expression text */
88 char Type; /* same as TokenType below */
89 xbShort Len; /* length of expression text */
90 xbShort InTree; /* this node in the tree? 1=yes */
91 xbExpNode * Node; /* pointer to parent */
92 xbExpNode * Sibling1; /* pointer to sibling 1 */
93 xbExpNode * Sibling2; /* pointer to sibling 2 */
94 xbExpNode * Sibling3; /* pointe/r to sibling 3 */
95 xbShort DataLen; /* length of data in result buffer */
96 xbShort ResultLen; /* length of result buffer */
97 xbString StringResult; /* string result */
98 xbDouble DoubResult; /* Numeric Result */
99 xbShort IntResult; /* logical result */
100 xbDbf * dbf; /* pointer to datafile */
101 xbShort FieldNo; /* field no if DBF field */
102 char ExpressionType; /* used in head node C,N,L or D */
103};
104/************************************************************************/
106
109class XBDLLEXPORT xbStackElement
110{
111 public:
112 xbStackElement();
113 ~xbStackElement();
114
115 friend class xbExpn;
116
117 private:
118 xbStackElement *Previous;
119 xbStackElement *Next;
120 xbExpNode *NodePtr;
121};
122/************************************************************************/
124
127/* Expression handler */
128
129class XBDLLEXPORT xbExpn{
130 public:
131 xbExpn( xbXBase * );
132 virtual ~xbExpn();
133
134 xbShort GetNextToken( const char *s, xbShort MaxLen );
135 xbShort ProcessExpression( xbExpNode *n, xbShort );
136 xbShort ProcessExpression( xbShort opt )
137 { return ProcessExpression( Tree, opt ); }
138
139 xbExpNode * GetTree() { return Tree; }
140 void SetTreeToNull() { Tree = NULL; }
141 xbExpNode * GetFirstTreeNode( xbExpNode * );
142 xbExpNode * GetFirstTreeNode()
143 { return GetFirstTreeNode( Tree ); }
144 xbShort ProcessExpression( const char *exp, xbDbf * d );
145 xbShort ParseExpression( const char *exp, xbDbf * d );
146 xbExpNode * GetExpressionHandle();
147 char GetExpressionResultType( xbExpNode * );
148 char GetExpressionResultType()
149 { return GetExpressionResultType( Tree ); }
150 char * GetCharResult();
151 xbString & GetStringResult();
152 xbDouble GetDoubleResult();
153 xbLong GetIntResult();
154 xbShort ProcessExpression( xbExpNode * );
155 xbShort ProcessExpression() { return ProcessExpression( Tree ); }
156 xbShort BuildExpressionTree( const char * Expression, xbShort MaxTokenLen,
157 xbDbf *d );
158
159 /* stack functions */
160 void InitStack();
161 xbExpNode * Pop();
162 xbShort Push(xbExpNode *);
163 xbShort GetStackDepth() { return StackDepth; }
164 void DumpStack();
165 const char * GetValidFuncName( xbShort funcNo )
166 { return XbaseFuncList[funcNo].FuncName; }
167
168#ifdef XBASE_DEBUG
169 void DumpExpressionTree( xbShort printOption )
170 { DumpExpressionTree( Tree, printOption ); }
171 void DumpExpressionTree( xbExpNode *, xbShort printOption );
172 void DumpExpNode( xbExpNode *, xbShort printOption );
173#endif
174
175 /* expression methods */
176 xbDouble ABS( xbDouble );
177 xbLong ASC( const char * );
178 xbLong AT( const char *, const char * );
179 char * CDOW( const char * );
180 char * CHR( xbLong );
181 char * CMONTH( const char * );
182 char * CTOD( const char * );
183 char * DATE();
184 xbLong DAY( const char * );
185 char * DESCEND( const char * );
186 xbLong DESCEND( const xbDate & );
187 xbDouble DESCEND( xbDouble );
188 xbLong DOW( const char * );
189 char * DTOC( const char * );
190 char * DTOS( const char * );
191 xbDouble EXP( xbDouble );
192 char * IIF( xbShort, const char *, const char * );
193 xbLong INT( xbDouble );
194 xbLong ISALPHA( const char * );
195 xbLong ISLOWER( const char * );
196 xbLong ISUPPER( const char * );
197 char * LEFT( const char *, xbShort );
198 xbLong LEN( const char * );
199 xbDouble LOG( xbDouble );
200 char * LOWER( const char * );
201 char * LTRIM( const char * );
202 xbDouble MAX( xbDouble, xbDouble );
203 xbLong MONTH( const char * ); /* MONTH() */
204 xbDouble MIN( xbDouble, xbDouble );
205 xbLong RECNO( xbDbf * );
206 char * REPLICATE( const char *, xbShort );
207 char * RIGHT( const char *, xbShort );
208 char * RTRIM( const char * );
209 char * SPACE( xbShort );
210 xbDouble SQRT( xbDouble );
211 char * STR( const char * );
212 char * STR( const char *, xbShort );
213 char * STR( const char *, xbShort, xbShort );
214 char * STR( xbDouble );
215 char * STR( xbDouble, xbShort );
216 char * STR(xbDouble, xbUShort length, xbShort numDecimals );
217 char * STRZERO( const char * );
218 char * STRZERO( const char *, xbShort );
219 char * STRZERO( const char *, xbShort, xbShort );
220 char * STRZERO( xbDouble );
221 char * STRZERO( xbDouble, xbShort );
222 char * STRZERO( xbDouble, xbShort, xbShort );
223 char * SUBSTR( const char *, xbShort, xbShort );
224 char * TRIM( const char * );
225 char * UPPER( const char * );
226 xbLong VAL( const char * );
227 xbLong YEAR( const char * );
228
229 protected:
230 xbShort IsWhiteSpace( char );
231 char IsSeparator( char );
232 xbExpNode * LoadExpNode( const char * ENodeText, const char EType,
233 const xbShort ELen, const xbShort BufLen );
234 xbShort OperatorWeight( const char *Oper, xbShort len );
235 xbShort ReduceComplexExpression( const char * NextToken, xbShort Len,
236 xbExpNode * cn, xbDbf *d );
237 xbShort GetFunctionTokenLen( const char *s );
238 xbShort ReduceFunction( const char *NextToken, xbExpNode *cn, xbDbf *d );
239 xbExpNode * GetNextTreeNode( xbExpNode * );
240 xbShort ProcessOperator( xbShort );
241 xbShort ProcessFunction( char * );
242 xbShort ValidOperation( char *, char, char );
243 char GetOperandType( xbExpNode * );
244 xbShort AlphaOperation( char * );
245 xbShort NumericOperation( char * );
246 xbShort GetFuncInfo( const char *Function, xbShort Option );
247 xbDouble GetDoub( xbExpNode * );
248 xbLong GetInt( xbExpNode * );
249
250 private:
251 xbXBase *xbase;
252 xbFuncDtl *XbaseFuncList; /* pointer to list of Xbase functions */
253 xbExpNode *Tree; /* pointer to tree of parsed nodes */
254 xbShort LogicalType; /* set to 1 for logical type nodes */
255 char TokenType; /* E - Expression, not in simplest form */
256 /* C - Constant */
257 /* N - Numeric Constant */
258 /* O - Operator */
259 /* F - Function */
260 /* D - Database Field */
261 /* s - character string result */
262 /* l - logical or short int result */
263 /* d - double result */
264 char PreviousType; /* used to see if "-" follows operator */
265 char * Op1; /* pointer to operand 1 */
266 char * Op2; /* pointer to operand 2 */
267 xbDouble Opd1; /* double result 1 */
268 xbDouble Opd2; /* double result 2 */
269 xbShort OpLen1; /* length of memory allocated to operand 1 */
270 xbShort OpLen2; /* length of memory allocated to operand 2 */
271 xbShort OpDataLen1; /* length of data in op1 */
272 xbShort OpDataLen2; /* length of data in op2 */
273 char OpType1; /* type of operand 1 */
274 char OpType2; /* type of operand 2 */
275 xbShort TokenLen; /* length of token */
276
277// static xbString DefaultDateFormat; /*default date format for DTOC func*/
278 enum { WorkBufMaxLen = 200 };
279 char WorkBuf[WorkBufMaxLen+1];
280
281 /* stack variables */
282 xbShort StackDepth;
283 xbStackElement *First;
284 xbStackElement *Last;
285};
286
287#endif // XB_EXPRESSIONS
288#endif // __XB_EXP_H__
289
290
xbDate class
Definition xbdate.h:68
xbMH struct
Definition xbdbf.h:190
xbString class
Definition xbstring.h:63
xbXBase class
Definition xbase64.h:153
#define XBDLLEXPORT
Definition xbase64.h:87
long xbLong
Definition xbtypes.h:61
short int xbShort
xbShort type
Definition xbtypes.h:60
unsigned short int xbUShort
xbUShort type
Definition xbtypes.h:55
double xbDouble
xbDouble type
Definition xbtypes.h:73