1 /* 2 * Copyright (c) 2001 Graham Short. <grahshrt@netscape.net> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 */ 18 19 #ifndef QPRO_FORMULA_H 20 #define QPRO_FORMULA_H 21 22 #include <qpro/tablenames.h> 23 #include <qpro/stream.h> 24 #include <qpro/record.h> 25 26 class QpFormula; 27 28 // -------------------------------------------------------------------- 29 30 class QpFormulaStack 31 { 32 public: 33 QpFormulaStack(); 34 ~QpFormulaStack(); 35 36 void bracket(const char* pBefore = "(", const char* pAfter = ")"); 37 void push(const char* pString); 38 void pop(int pCnt = 1); 39 void join(int pCnt, const char* pSeparator = ","); 40 const char* top(); 41 42 const char* operator [](int pIdx); 43 44 protected: 45 int cIdx; 46 int cMax; 47 48 char** cStack; 49 }; 50 51 52 // -------------------------------------------------------------------- 53 54 struct QpFormulaConv { 55 QP_UINT8 cOperand; 56 void (*cFunc)(QpFormula& pThis, const char* pArg); 57 const char* cArg; 58 }; 59 60 // -------------------------------------------------------------------- 61 62 class QpFormula 63 { 64 public: 65 QpFormula(QpRecFormulaCell& pCell, QpTableNames& pTable); 66 ~QpFormula(); 67 68 void argSeparator(const char* pArg); 69 70 char* formula(); 71 72 binaryOperand(QpFormula & pThis,const char * pOper)73 static void binaryOperand(QpFormula& pThis, const char* pOper) { 74 pThis.binaryOperandReal(pOper); 75 } 76 floatFunc(QpFormula & pThis,const char * pFunc)77 static void floatFunc(QpFormula& pThis, const char* pFunc) { 78 pThis.floatFuncReal(pFunc); 79 } 80 81 void formulaStart(const char* pFirstChar); 82 absKludge(QpFormula & pThis,const char * pFunc)83 static void absKludge(QpFormula& pThis, const char* pFunc) { 84 pThis.absKludgeReal(pFunc); 85 } 86 func0(QpFormula & pThis,const char * pFunc)87 static void func0(QpFormula& pThis, const char* pFunc) { 88 pThis.func0Real(pFunc); 89 } 90 func1(QpFormula & pThis,const char * pFunc)91 static void func1(QpFormula& pThis, const char* pFunc) { 92 pThis.func1Real(pFunc); 93 } 94 func2(QpFormula & pThis,const char * pFunc)95 static void func2(QpFormula& pThis, const char* pFunc) { 96 pThis.func2Real(pFunc); 97 } 98 func3(QpFormula & pThis,const char * pFunc)99 static void func3(QpFormula& pThis, const char* pFunc) { 100 pThis.func3Real(pFunc); 101 } 102 func4(QpFormula & pThis,const char * pFunc)103 static void func4(QpFormula& pThis, const char* pFunc) { 104 pThis.func4Real(pFunc); 105 } 106 funcV(QpFormula & pThis,const char * pFunc)107 static void funcV(QpFormula& pThis, const char* pFunc) { 108 pThis.funcVReal(pFunc); 109 } 110 intFunc(QpFormula & pThis,const char * pFunc)111 static void intFunc(QpFormula& pThis, const char* pFunc) { 112 pThis.intFuncReal(pFunc); 113 } 114 115 void dropLeadingAt(int pBool = -1); 116 ref(QpFormula & pThis,const char * pFunc)117 static void ref(QpFormula& pThis, const char* pFunc) { 118 pThis.refReal(pFunc); 119 } 120 121 void replaceFunc(QpFormulaConv* pFuncEntry); 122 stringFunc(QpFormula & pThis,const char * pFunc)123 static void stringFunc(QpFormula& pThis, const char* pFunc) { 124 pThis.stringFuncReal(pFunc); 125 } 126 unaryOperand(QpFormula & pThis,const char * pOper)127 static void unaryOperand(QpFormula& pThis, const char* pOper) { 128 pThis.unaryOperandReal(pOper); 129 } 130 131 protected: 132 char* cArgSeparator; 133 QpRecFormulaCell& cCell; 134 QpIStream cFormula; 135 QpIStream cFormulaRefs; 136 QpFormulaConv* cReplaceFunc; 137 char* cFormulaStart; 138 int cIdx; 139 QpFormulaStack cStack; 140 int cDropLeadingAt; 141 QpTableNames& cTable; 142 143 void absKludgeReal(const char* pOper); 144 void binaryOperandReal(const char* pOper); 145 void floatFuncReal(const char* pFunc); 146 void func0Real(const char* pFunc); 147 void func1Real(const char* pFunc); 148 void func2Real(const char* pFunc); 149 void func3Real(const char* pFunc); 150 void func4Real(const char* pFunc); 151 void funcVReal(const char* pFunc); 152 void intFuncReal(const char* pFunc); 153 void refReal(const char* pFunc); 154 void stringFuncReal(const char* pFunc); 155 void unaryOperandReal(const char* pOper); 156 }; 157 158 #endif // QPRO_FORMULA_H 159