📄 calcformule.h
字号:
// CalcFormula.h: interface for the CCalcFormula class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_CALCFormula_H__37D34E26_07E7_41AE_B4F1_B3373BE39B7C__INCLUDED_)
#define AFX_CALCFormula_H__37D34E26_07E7_41AE_B4F1_B3373BE39B7C__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define TYPE_NUM 1
#define TYPE_STR 2
#define FUNC_AVE 100
#define FUNC_BYTE 101
#define FUNC_CAPITAL 102
#define FUNC_MAX 103
#define FUNC_MIN 104
#define FUNC_SUM 105
#define FUNC_STRCAT 106
#define FUNC_ROUND 107
#define FUNC_IF 108
#define FUNC_PRECISION 109
#define FUNC_SUBSTR 110
#define FUNC_MATCH 111
#define FUNC_COUNT 112
#define FUNC_LN 113
#define FUNC_EXP 114
#define FUNC_SQRT 115
#define FUNC_CASE 116
#define FUNC_LOG 117
#define FUNC_SIN 118
#define FUNC_COS 119
#define FUNC_TAN 120
#define FUNC_CTAN 121
#define FUNC_FIND 122
#define FUNC_FREQUENCE 123
#define FUNC_INT 124
#define FUNC_FRAC 125
#define FUNC_DAY 126
#define FUNC_MONTH 127
#define FUNC_YEAR 128
#define FUNC_DAY_SPAN 129
#define FUNC_MONTH_SPAN 130
#define FUNC_YEAR_SPAN 131
#define FUNC_TODAY 132
#define FUNC_STDDEV 133
#define FUNC_GET_STR 134
#define FUNC_GET_PY 135
#define FUNC_PRINT 136
#define OP_BASE 30 // +
#define OP_ADD 30 // +
#define OP_SUB 31 // -
#define OP_MUL 32 // *
#define OP_DIV 33 // /
#define OP_EQ 34 //==
#define OP_BG 35 //>
#define OP_LT 36 //<
#define OP_EL 37 //<=
#define OP_EB 38 //>=
#define OP_NE 39 //!=
#define OP_BITOR 40 //|
#define OP_BITAND 41 //&
#define OP_NOT 42 //!
#define OP_POWER 43 //^
#define OP_LMOV 44 // >>
#define OP_RMOV 45 // <<
#define OP_LIKE 46 //LIKE
#define OP_IN 47 //IN
#define OP_EVALUATE OP_EQ //=
#define OP_OR OP_BITOR //||
#define OP_AND OP_BITAND //&&
#include <Afxtempl.h>
struct tagFunctionInfo{
LPCTSTR sName;
int nPrmSum;
int nFuncID;
int nRetType;
};
struct tagSysString{
LPCTSTR sName;
LPCTSTR sValue;
};
class CFormulaGetWord{
public:
CFormulaGetWord():m_bIsBack(false){};
virtual ~CFormulaGetWord(){};
protected:
CString m_preWord;
bool m_bIsBack;
public:
inline void SetPreword(LPCTSTR preWord){m_preWord = preWord; m_bIsBack = true;}
virtual CString getAWord() = 0;
};
class CSZGetWord :public CFormulaGetWord
{
public:
CSZGetWord(LPCTSTR szFormula=NULL);
virtual ~CSZGetWord();
private:
LPCTSTR m_sFormula;
int m_nPos;
int m_nSl;
bool m_bAcceptOpt;
public:
inline int GetCurPos(){return m_nPos;}
inline bool IsEnd(){return m_nPos>=m_nSl;}
inline void Reset(){m_nPos=0;}
CString FormatWord(LPCTSTR szWord);
virtual void SetFormula(LPCTSTR szFormula);
virtual CString getAWord();
};
class CSZGetWordWithPrm :public CSZGetWord
{
public:
CSZGetWordWithPrm(LPCTSTR szFormula=NULL,LPCTSTR szParams=NULL);
virtual ~CSZGetWordWithPrm();
public:
struct SParameter{
CString sParamName;
CString sParamValue;
};
private:
int m_nParamSum;
CList<SParameter,SParameter&> paramList;
CString GetParamValue(int nInd);
CString GetParamValue(LPCTSTR sParamName);
public:
void SetParameters(LPCTSTR szParams);
void SetNamedParameters(int nParamSum,...);
void SetUnnamedParameters(int nParamSum,...);
void AddParameter(LPCTSTR szParamName,LPCTSTR szParamValue);
virtual void SetFormula(LPCTSTR szFormula);
virtual CString getAWord();
};
class COptStack{
public:
static int m_OptPri[];
public:
COptStack();
~COptStack();
private:
int m_nLen;
int m_OptStack[10];
public:
int PushOpt(int optID);
int PopOpt();
};
class CCalcFormula
{
public:
static UINT m_uiFunctionSum;
static tagFunctionInfo m_sFunctionList[];
static UINT m_uiSysStrSum;
static tagSysString m_sSysStrList[];
public:
CCalcFormula();
virtual ~CCalcFormula();
private:
CFormulaGetWord * m_lpGetWord;
int GetFuncNo(LPCTSTR sFuncName);
int GetOptID(LPCTSTR sOptName);
BOOL IsKeyWord(LPCTSTR sWord);
void SkipAOperand();
CString Item();
CString OperateFunc(const CStringList & slOperand,int funcID);
CString Operate(const CString & operand,const CString & operand2,int optID);
CString Formula();
CString Func(int nFuncNo);
public:
CString Calculate(LPCTSTR szExpress);
CString Calculate(LPCTSTR szExpress,LPCTSTR szParams);
CString Calculate(CFormulaGetWord * lpGW);
int CheckFormula(LPCTSTR szExpress);
int CheckFormulaEx(LPCTSTR szExpress);
};
#endif // !defined(AFX_CALCFormula_H__37D34E26_07E7_41AE_B4F1_B3373BE39B7C__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -