Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

exp.h

Go to the documentation of this file.
00001 /*  $Id: exp.h,v 1.10 2003/08/20 01:53:27 gkunkel Exp $
00002 
00003     Xbase project source code 
00004 
00005     This file contains a header file for the EXP object, which is
00006     used for expression processing.
00007 
00008     Copyright (C) 1997  Gary A. Kunkel   
00009 
00010     This library is free software; you can redistribute it and/or
00011     modify it under the terms of the GNU Lesser General Public
00012     License as published by the Free Software Foundation; either
00013     version 2.1 of the License, or (at your option) any later version.
00014 
00015     This library is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018     Lesser General Public License for more details.
00019 
00020     You should have received a copy of the GNU Lesser General Public
00021     License along with this library; if not, write to the Free Software
00022     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 
00024     Contact:
00025 
00026       Mail:
00027 
00028         Technology Associates, Inc.
00029         XBase Project
00030         1455 Deming Way #11
00031         Sparks, NV 89434
00032         USA
00033 
00034       Email:
00035 
00036         xbase@techass.com
00037         xdb-devel@lists.sourceforge.net
00038         xdb-users@lists.sourceforge.net
00039 
00040       See our website at:
00041 
00042         xdb.sourceforge.net
00043 
00044 */
00045 
00046 #ifndef __XB_EXP_H__
00047 #define __XB_EXP_H__
00048 
00049 #ifdef __GNUG__
00050 #pragma interface
00051 #endif
00052 
00053 #include <xbase/xbase.h>
00054 
00055 #ifdef XB_EXPRESSIONS             /* compile if expression logic on */
00056 
00057 #define XB_EXPRESSION xbExpNode
00058 
00059 #include <xbase/xtypes.h>
00060 #include <xbase/xstack.h>
00061 
00065 #undef ABS
00066 #undef MIN
00067 #undef MAX
00068 
00069 class XBDLLEXPORT xbDbf;
00070 
00072 
00075 struct XBDLLEXPORT xbFuncDtl {
00076    const char * FuncName;     /* function name               */
00077    xbShort ParmCnt;                  /* no of parms it needs        */
00078    char    ReturnType;               /* return type of function     */
00079    void    (*ExpFuncPtr)();          /* pointer to function routine */
00080 };
00081 
00083 
00086 class XBDLLEXPORT xbExpNode {
00087 public:
00088    char * NodeText;           /* expression text                 */
00089    char Type;                 /* same as TokenType below         */
00090    xbShort Len;                 /* length of expression text       */
00091    xbShort InTree;              /* this node in the tree? 1=yes    */
00092    xbExpNode * Node;            /* pointer to parent               */
00093    xbExpNode * Sibling1;        /* pointer to sibling 1            */
00094    xbExpNode * Sibling2;        /* pointer to sibling 2            */
00095    xbExpNode * Sibling3;        /* pointer to sibling 3            */
00096 
00097    xbShort  DataLen;            /* length of data in result buffer */
00098    xbShort  ResultLen;          /* length of result buffer         */
00099 //   char * Result;             /* result buffer - ptr to result   */
00100    xbString StringResult;
00101    xbDouble DoubResult;         /* Numeric Result                  */
00102    xbShort  IntResult;          /* logical result                  */
00103 
00104    xbDbf *  dbf;                /* pointer to datafile             */
00105    xbShort  FieldNo;            /* field no if DBF field           */
00106    char   ExpressionType;     /* used in head node C,N,L or D    */
00107 
00108 
00109   public:
00110    xbExpNode();
00111    virtual ~xbExpNode();
00112 };
00113 
00115 
00118 /* Expression handler */
00119 
00120 class XBDLLEXPORT xbExpn : public xbStack, public xbDate {
00121 public:
00122    xbShort ProcessExpression( xbExpNode *, xbShort );
00123    xbExpNode * GetTree( void ) { return Tree; }
00124    void SetTreeToNull( void ) { Tree = NULL; }
00125    xbExpNode * GetFirstTreeNode( xbExpNode * );
00126 
00127    xbExpn( void );
00128    virtual ~xbExpn();
00129 
00130    xbShort  GetNextToken( const char *s, xbShort MaxLen);
00131 
00132    /* expression methods */
00133    xbDouble ABS( xbDouble );
00134    xbLong   ASC( const char * );
00135    xbLong   AT( const char *, const char * );
00136    char *   CDOW( const char * );
00137    char *   CHR( xbLong );
00138    char *   CMONTH( const char * );
00139    char *   DATE();
00140    xbLong   DAY( const char * );
00141    xbLong   DESCEND( const char * );
00142    xbLong   DOW( const char * );
00143    char *   DTOC( const char * );
00144    char *   DTOS( const char * );
00145    xbDouble EXP( xbDouble );
00146    xbLong   INT( xbDouble );
00147    xbLong   ISALPHA( const char * );
00148    xbLong   ISLOWER( const char * );
00149    xbLong   ISUPPER( const char * );
00150    char *   LEFT( const char *, xbShort );
00151    xbLong   LEN( const char * );
00152    xbDouble LOG( xbDouble );
00153    char *   LOWER( const char * );
00154    char *   LTRIM( const char * );
00155    xbDouble MAX( xbDouble, xbDouble );
00156    xbLong   MONTH( const char * );         /* MONTH() */
00157    xbDouble MIN( xbDouble, xbDouble );
00158    char *   RECNO( xbULong );
00159    xbLong   RECNO( xbDbf * );
00160    char *   REPLICATE( const char *, xbShort );
00161    char *   RIGHT( const char *, xbShort );
00162    char *   RTRIM( const char * );
00163    char *   SPACE( xbShort );   
00164    xbDouble SQRT( xbDouble );
00165    char *   STR( const char * );
00166    char *   STR( const char *, xbShort );
00167    char *   STR( const char *, xbShort, xbShort );
00168    char *   STR( xbDouble );
00169    char *   STR( xbDouble, xbShort );
00170    char *   STR(xbDouble, xbUShort length, xbShort numDecimals );
00171    char *   STRZERO( const char * );
00172    char *   STRZERO( const char *, xbShort );
00173    char *   STRZERO( const char *, xbShort, xbShort );
00174    char *   STRZERO( xbDouble );
00175    char *   STRZERO( xbDouble, xbShort );
00176    char *   STRZERO( xbDouble, xbShort, xbShort );
00177    char *   SUBSTR( const char *, xbShort, xbShort );
00178    char *   TRIM( const char * );
00179    char *   UPPER( const char * );
00180    xbLong   VAL( const char * );
00181    xbLong   YEAR( const char * );  
00183 
00186    void     SetDefaultDateFormat(const xbString & f){ DefaultDateFormat = f; }
00187 
00188    xbString GetDefaultDateFormat() const { return DefaultDateFormat; }
00189    xbShort  ProcessExpression( const char *exp, xbDbf * d );
00190    xbShort  ParseExpression( const char *exp, xbDbf * d );
00191    XB_EXPRESSION * GetExpressionHandle();
00192    char     GetExpressionResultType(XB_EXPRESSION * );
00193    char *   GetCharResult();
00194    xbString & GetStringResult();
00195    xbDouble GetDoubleResult();
00196    xbLong   GetIntResult();
00197    xbShort  ProcessExpression( xbExpNode * );
00198    xbShort  BuildExpressionTree( const char * Expression, xbShort MaxTokenLen,
00199             xbDbf *d );
00200 
00201 #ifdef XBASE_DEBUG
00202    void DumpExpressionTree( xbExpNode * );
00203    void DumpExpNode( xbExpNode * );
00204 #endif
00205 
00206 protected:
00207    xbFuncDtl *XbaseFuncList;    /* pointer to list of Xbase functions    */
00208 //   xbExpNode *NextFreeExpNode;  /* pointer to chain of free nodes        */
00209    xbExpNode *Tree;
00210    xbShort LogicalType;         /* set to 1 for logical type nodes       */
00211 
00212    char TokenType;            /* E - Expression, not in simplest form  */
00213                               /* C - Constant                          */
00214                               /* N - Numeric Constant                  */
00215                               /* O - Operator                          */
00216                               /* F - Function                          */
00217                               /* D - Database Field                    */
00218                               /* s - character string result           */
00219                               /* l - logical or short int result       */
00220                               /* d - double result                     */
00221 
00222    char  PreviousType;         /* used to see if "-" follows operator     */
00223    char  *  Op1;               /* pointer to operand 1                    */
00224    char  *  Op2;               /* pointer to operand 2                    */
00225    xbDouble Opd1;              /* double result 1                         */
00226    xbDouble Opd2;              /* double result 2                         */
00227    xbShort OpLen1;             /* length of memory allocated to operand 1 */
00228    xbShort OpLen2;             /* length of memory allocated to operand 2 */
00229    xbShort OpDataLen1;         /* length of data in op1                   */
00230    xbShort OpDataLen2;         /* length of data in op2                   */
00231 
00232    char    OpType1;            /* type of operand 1                       */
00233    char    OpType2;            /* type of operand 2                       */
00234    xbShort TokenLen;           /* length of token                         */
00235 
00236    static xbString DefaultDateFormat;  /*default date format for DTOC func*/
00237 
00238    enum { WorkBufMaxLen = 200 };
00239    char  WorkBuf[WorkBufMaxLen+1];
00240 
00241    xbShort  IsWhiteSpace( char );
00242    char     IsSeparator( char );
00243    xbExpNode * LoadExpNode( const char * ENodeText, const char EType,
00244             const xbShort ELen, const xbShort BufLen );
00245    xbShort  OperatorWeight( const char *Oper, xbShort len );
00246    xbShort  ReduceComplexExpression( const char * NextToken, xbShort Len,
00247             xbExpNode * cn, xbDbf *d );
00248    xbShort  GetFunctionTokenLen( const char *s );
00249    xbShort  ReduceFunction( const char *NextToken, xbExpNode *cn, xbDbf *d );
00250    xbExpNode * GetNextTreeNode( xbExpNode * );
00251    xbShort  ProcessOperator( xbShort );
00252    xbShort  ProcessFunction( char * );
00253    xbShort  ValidOperation( char *, char, char );
00254    char     GetOperandType( xbExpNode * );
00255    xbShort  AlphaOperation( char * );
00256    xbShort  NumericOperation( char * );
00257    xbExpNode * GetExpNode( xbShort );
00258    xbShort  GetFuncInfo( const char *Function, xbShort Option );
00259    xbDouble GetDoub( xbExpNode * );
00260    xbLong   GetInt( xbExpNode * );
00261 };
00262 #endif               // XB_EXPRESSIONS
00263 #endif               // __XB_EXP_H__

Generated on Wed Jan 26 11:45:09 2005 for Xbase Class Library by  doxygen 1.4.1