Xbase64 4.0.1
C++ Library for handling Xbase (DBF) format type files
xbexp.h
Go to the documentation of this file.
1/* xbexp.h
2
3XBase64 Software Library
4
5Copyright (c) 1997,2003,2014,2022 Gary A Kunkel
6
7The xb64 software library is covered under the terms of the GPL Version 3, 2007 license.
8
9Email Contact:
10
11 XDB-devel@lists.sourceforge.net
12 XDB-users@lists.sourceforge.net
13
14*/
15
16
17#ifndef __XB_EXP_H__
18#define __XB_EXP_H__
19
20
21// #ifdef CMAKE_COMPILER_IS_GNUCC
22// #pragma interface
23// #endif
24
25
26
27#ifdef XB_FUNCTION_SUPPORT
28#define XB_EXP_CHAR 'C'
29#define XB_EXP_DATE 'D'
30#define XB_EXP_LOGICAL 'L'
31#define XB_EXP_NUMERIC 'N'
32#define XB_EXP_UNKNOWN 'U'
33#endif
34
35#ifdef XB_EXPRESSION_SUPPORT
36
37#define XB_EXP_CONSTANT 'C'
38#define XB_EXP_FUNCTION 'F'
39#define XB_EXP_FIELD 'D'
40#define XB_EXP_OPERATOR 'O'
41#define XB_EXP_NOTROOT 'N' // not root node, needs further parsing
42#define XB_EXP_PRE_OPERATOR 'B' // (B)efore) pre increment, pre decrement
43#define XB_EXP_POST_OPERATOR 'A' // (A)fter) post increment, pre decrement
44
45#define XB_END_OF_EXPRESSION -100
46
47// #define XB_UNBALANCED_PARENS -101
48// #define XB_UNBALANCED_QUOTES -102
49
50
51namespace xb{
52
54struct XBDLLEXPORT xbExpToken {
55 xbString sExpression; // in - expression to pull next token from
56 // out - remainder of the expression after token removed
57 xbString sToken; // next token pulled from the expression
58 char cNodeType; // one of XB_EXP_CONSTANT, XB_EXP_FUNCTION, XB_EXP_FIELD, XB_EXP_OPERATOR, XB_EXP_NOTROOT
59 char cReturnType; // one of XB_EXP_CHAR, XB_EXP_DATE, XB_EXP_LOGICAL, XB_EXP_NUMERIC, XB_EXP_UNKNOWN
60 xbInt16 iSts; // return status after retrieving or attempting next token from expression
61 // 0 = no error
62 // XB_END_OF_EXPRESSION
63 // XB_UNBALANCED_PARENS
64 // XB_UNBALANCED_QUOTES
65 char cPrevNodeType; // previous node type
66 char cPrevReturnType; // previous return type
67
68 // constructor
69 xbExpToken() { cNodeType = 0; cReturnType = 0; iSts = 0; cPrevNodeType = 0; cPrevReturnType = 0; }
70};
72
73
74/************************************************************************/
75
77
132class XBDLLEXPORT xbExp{
133
134 public:
135 xbExp( xbXBase * );
136 xbExp( xbXBase *, xbDbf * );
137 virtual ~xbExp();
138 void ClearTreeHandle();
139
140
141 #ifdef XB_DEBUG_SUPPORT
142 void DumpTree( xbInt16 iOption );
143 void DumpToken( xbExpToken &t, xbInt16 iOption = 0 );
144 #endif
145
146 xbInt16 GetResultLen() const;
147 char GetReturnType() const;
148 xbInt16 GetBoolResult( xbBool &bResult );
149 xbInt16 GetDateResult( xbDate &dtResult );
150 xbInt16 GetNumericResult( xbDouble &dResult );
151 xbInt16 GetStringResult( xbString &sResult );
152 xbInt16 GetStringResult( char * vpResult, xbUInt32 ulLen );
153 xbExpNode *GetTreeHandle();
154 xbInt16 ParseExpression( const xbString &sExpression );
155 xbInt16 ParseExpression( xbDbf *dbf, const xbString &sExpression );
156 xbInt16 ProcessExpression();
157 xbInt16 ProcessExpression( xbInt16 iRecBufSw );
158
159
160 protected:
161 xbInt16 GetNextToken( xbExpToken &t );
162 xbInt16 OperatorWeight( const xbString &sOperator );
163 xbExpNode *GetNextNode( xbExpNode * n ) const; // traverses the tree from bottom left node, right, then up
164
165 private: // methods
166
167 // xbInt16 CalcExpressionResultLen();
168 xbInt16 CalcFunctionResultLen( xbExpNode *n ) const;
169 xbInt16 CalcCharNodeLen( xbExpNode *n );
170 xbInt16 CheckParensAndQuotes( const xbString &sExpression );
171 xbInt16 GetExpressionResultLen() const;
172
173 xbInt16 GetTokenCharConstant ( xbExpToken &t );
174 xbInt16 GetTokenDatabaseField ( xbExpToken &t );
175 xbInt16 GetTokenDateConstant ( xbExpToken &t );
176 xbInt16 GetTokenFunction ( xbExpToken &t );
177 xbInt16 GetTokenLogicalConstant( xbExpToken &t );
178 xbInt16 GetTokenNumericConstant( xbExpToken &t );
179 xbInt16 GetTokenOperator ( xbExpToken &t );
180 xbInt16 GetTokenParen ( xbExpToken &t );
181
182 xbBool IsFunction ( const xbString &sExp, char &cReturnType );
183 xbBool IsLogicalConstant ( const xbString &sExp );
184 xbBool IsNumericConstant ( const xbString &sExp, char cPrevNodeType );
185 xbBool IsOperator ( const xbString &sExp );
186 char IsTokenSeparator ( char c );
187 xbBool IsWhiteSpace ( char c );
188
189 xbInt16 ParseExpression ( const xbString &sExpression, xbInt16 iWeight );
190 xbInt16 ParseExpressionConstant( xbExpToken &t, xbExpNode *n );
191 xbInt16 ParseExpressionFunction( xbExpToken &t, xbExpNode *n, xbInt16 iWeight );
192 xbInt16 ParseExpressionFunctionParms( const xbString &sParms, xbLinkList<xbString> &llParms );
193 xbInt16 ParseExpressionField ( xbExpToken &t, xbExpNode *n );
194 xbInt16 ParseExpressionOperator( xbExpToken &t, xbExpNode *n, xbInt16 iWeight );
195
196 xbInt16 ProcessExpressionFunction( xbExpNode *n, xbInt16 iRecBufSw = 0 );
197 xbInt16 ProcessExpressionOperator( xbExpNode *n );
198
199 private: // fields
200 xbXBase *xbase;
201 xbDbf *dbf;
202 xbExpNode *nTree; // pointer to tree of expNodes
203 // xbInt16 iExpLen; // size of expression result
204
205
206};
207
208/* Expression handler */
209
210
211};
212#endif // XB_EXPRESSION_SUPPORT
213#endif // __XB_EXP_H__
214
215
Definition: xbdate.cpp:19
double xbDouble
Definition: xbtypes.h:23
class XBDLLEXPORT xbXBase
Definition: xbssv.h:27
short int xbBool
Definition: xbtypes.h:24
class XBDLLEXPORT xbDbf
Definition: xbtblmgr.h:28