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#define XB_NULL_DATE 21474835648
26
27
28#ifdef XB_FUNCTION_SUPPORT
29#define XB_EXP_CHAR 'C'
30#define XB_EXP_DATE 'D'
31#define XB_EXP_LOGICAL 'L'
32#define XB_EXP_NUMERIC 'N'
33#define XB_EXP_UNKNOWN 'U'
34#endif
35
36#ifdef XB_EXPRESSION_SUPPORT
37
38#define XB_EXP_CONSTANT 'C'
39#define XB_EXP_FUNCTION 'F'
40#define XB_EXP_FIELD 'D'
41#define XB_EXP_OPERATOR 'O'
42#define XB_EXP_NOTROOT 'N' // not root node, needs further parsing
43#define XB_EXP_PRE_OPERATOR 'B' // (B)efore) pre increment, pre decrement
44#define XB_EXP_POST_OPERATOR 'A' // (A)fter) post increment, pre decrement
45
46#define XB_END_OF_EXPRESSION -100
47
48// #define XB_UNBALANCED_PARENS -101
49// #define XB_UNBALANCED_QUOTES -102
50
51
52namespace xb{
53
55struct XBDLLEXPORT xbExpToken {
56 xbString sExpression; // in - expression to pull next token from
57 // out - remainder of the expression after token removed
58 xbString sToken; // next token pulled from the expression
59 char cNodeType; // one of XB_EXP_CONSTANT, XB_EXP_FUNCTION, XB_EXP_FIELD, XB_EXP_OPERATOR, XB_EXP_NOTROOT
60 char cReturnType; // one of XB_EXP_CHAR, XB_EXP_DATE, XB_EXP_LOGICAL, XB_EXP_NUMERIC, XB_EXP_UNKNOWN
61 xbInt16 iSts; // return status after retrieving or attempting next token from expression
62 // 0 = no error
63 // XB_END_OF_EXPRESSION
64 // XB_UNBALANCED_PARENS
65 // XB_UNBALANCED_QUOTES
66 char cPrevNodeType; // previous node type
67 char cPrevReturnType; // previous return type
68
69 // constructor
70 xbExpToken() { cNodeType = 0; cReturnType = 0; iSts = 0; cPrevNodeType = 0; cPrevReturnType = 0; }
71};
73
74
75/************************************************************************/
76
78
133class XBDLLEXPORT xbExp{
134
135 public:
136 xbExp( xbXBase * );
137 xbExp( xbXBase *, xbDbf * );
138 virtual ~xbExp();
139 void ClearTreeHandle();
140
141
142 #ifdef XB_DEBUG_SUPPORT
143 void DumpTree( xbInt16 iOption );
144 void DumpToken( xbExpToken &t, xbInt16 iOption = 0 );
145 #endif
146
147 xbInt16 GetResultLen() const;
148 char GetReturnType() const;
149 xbInt16 GetBoolResult( xbBool &bResult );
150 xbInt16 GetDateResult( xbDate &dtResult );
151 xbInt16 GetNumericResult( xbDouble &dResult );
152 xbInt16 GetStringResult( xbString &sResult );
153 xbInt16 GetStringResult( char * vpResult, xbUInt32 ulLen );
154 xbExpNode *GetTreeHandle();
155 xbInt16 ParseExpression( const xbString &sExpression );
156 xbInt16 ParseExpression( xbDbf *dbf, const xbString &sExpression );
157 xbInt16 ProcessExpression();
158 xbInt16 ProcessExpression( xbInt16 iRecBufSw );
159
160
161 protected:
162 xbInt16 GetNextToken( xbExpToken &t );
163 xbInt16 OperatorWeight( const xbString &sOperator );
164 xbExpNode *GetNextNode( xbExpNode * n ) const; // traverses the tree from bottom left node, right, then up
165
166 private: // methods
167
168 // xbInt16 CalcExpressionResultLen();
169 xbInt16 CalcFunctionResultLen( xbExpNode *n ) const;
170 xbInt16 CalcCharNodeLen( xbExpNode *n );
171 xbInt16 CheckParensAndQuotes( const xbString &sExpression );
172 xbInt16 GetExpressionResultLen() const;
173
174 xbInt16 GetTokenCharConstant ( xbExpToken &t );
175 xbInt16 GetTokenDatabaseField ( xbExpToken &t );
176 xbInt16 GetTokenDateConstant ( xbExpToken &t );
177 xbInt16 GetTokenFunction ( xbExpToken &t );
178 xbInt16 GetTokenLogicalConstant( xbExpToken &t );
179 xbInt16 GetTokenNumericConstant( xbExpToken &t );
180 xbInt16 GetTokenOperator ( xbExpToken &t );
181 xbInt16 GetTokenParen ( xbExpToken &t );
182
183 xbBool IsFunction ( const xbString &sExp, char &cReturnType );
184 xbBool IsLogicalConstant ( const xbString &sExp );
185 xbBool IsNumericConstant ( const xbString &sExp, char cPrevNodeType );
186 xbBool IsOperator ( const xbString &sExp );
187 char IsTokenSeparator ( char c );
188 xbBool IsWhiteSpace ( char c );
189
190 xbInt16 ParseExpression ( const xbString &sExpression, xbInt16 iWeight );
191 xbInt16 ParseExpressionConstant( xbExpToken &t, xbExpNode *n );
192 xbInt16 ParseExpressionFunction( xbExpToken &t, xbExpNode *n, xbInt16 iWeight );
193 xbInt16 ParseExpressionFunctionParms( const xbString &sParms, xbLinkList<xbString> &llParms );
194 xbInt16 ParseExpressionField ( xbExpToken &t, xbExpNode *n );
195 xbInt16 ParseExpressionOperator( xbExpToken &t, xbExpNode *n, xbInt16 iWeight );
196
197 xbInt16 ProcessExpressionFunction( xbExpNode *n, xbInt16 iRecBufSw = 0 );
198 xbInt16 ProcessExpressionOperator( xbExpNode *n );
199
200 private: // fields
201 xbXBase *xbase;
202 xbDbf *dbf;
203 xbExpNode *nTree; // pointer to tree of expNodes
204 // xbInt16 iExpLen; // size of expression result
205
206
207};
208
209/* Expression handler */
210
211
212};
213#endif // XB_EXPRESSION_SUPPORT
214#endif // __XB_EXP_H__
215
216
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