12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- #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_operator;
- WORD m_level;
- WORD m_type;
- WORD m_startIndex;
- };
- typedef stack<COperator*> OperatorStack;
- /* 运算数类 */
- class COperand
- {
- public:
- COperand();
- ~COperand();
- BOOL operator ==(const COperand&od);
- CString m_name;
- BOOL m_IsConst;
- WORD m_startIndex;
- };
- 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 formula);
- CComputer(char*formula=0);
- int GetVariantTableSize(){return m_oprandANum;}
- const COperand* GetVariantTable();
- ~CComputer();
- public:
- int m_oprandNum;
- int m_oprandANum;
- int m_operatorNum;
- CString m_formula;
- COperator*m_operator;
- COperand*m_oprand;
- COperand*m_oprandA;
- 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_
|