1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- #ifndef _COMPUTER_H_
- #define _COMPUTER_H_
- #include <stack>
- using namespace std;
- #define LEVELS 6
- #define DERROR 0
- #define BIGNUMBER 0 //计算出错时,赋零
- #define UNARY 0
- #define BINARY 1
- /* 运算符类 */
- class COperator
- {
- public:
- COperator();
- ~COperator();
- // 运行符;
- CString m_strOperator;
- WORD m_nLevel;
- WORD m_nType;
- WORD m_nStartIndex;
- };
- typedef stack<COperator*> OperatorStack;
- /* 运算数类 */
- class COperand
- {
- public:
- COperand();
- ~COperand();
- BOOL operator ==(const COperand&od);
- CString m_strName;
- BOOL m_bIsConst;
- WORD m_nStartIndex;
- };
- typedef stack<COperand*> OperandStack;
- /* 计算基类 */
- class CComputer : public CObject
- {
- public:
- void Destroy();
- BOOL ExpressionIsError();
- CString GetDigitalString(double* variantValue=0,int num=-1);
- int GetErrorNumber();
- CString GetErrorInformation();
- double computer(double variantValue[],int num);
- void SetFormula(CString strFormula);
- CComputer(char *pszFormula=NULL);
- int GetVariantTableSize(){return m_nOprandANum;}
- const COperand* GetVariantTable();
- ~CComputer();
- public:
- int m_nOprandNum;
- int m_nOprandANum;
- int m_nOperatorNum;
- CString m_strFormula;
- COperator *m_pOperator;
- COperand *m_pOprand;
- COperand *m_pOprandA;
- int IsFormula();
- BOOL GetStack(OperatorStack &Op, OperandStack &Od);
- BOOL Initialize();
- double Computer(OperatorStack &Operator, OperandStack &Oprand);
- BOOL EmptyStack(OperatorStack st);
- BOOL EmptyStack(OperandStack st);
- BOOL GetOperandStack(OperandStack&Oprand,CString&string);
- virtual BOOL GetOperatorStack(OperatorStack&Operator,CString &string);
- virtual double computing(const COperator*op,const COperand*oprand);
- virtual double computing(const COperator*op,const COperand*Loprand,const COperand*Roprand);
- };
- /* 实时计算类 */
- class CRealComputer :public CComputer
- {
- public:
- CString m_strExpression;
- virtual BOOL GetOperatorStack(OperatorStack&Operator,CString &string);
- virtual double computing(const COperator*op,const COperand*oprand);
- virtual double computing(const COperator*op,const COperand*Loprand,const COperand*Roprand);
- virtual int IsFormula();
- double GetResult();
- };
- #endif //_COMPUTER_H_
|