?? expression.cpp
字號:
/******************************************************************************
文件名 :Expression.cpp
版本號 : 1.0
作者 : Amos Peng
生成日期 :2008-07-08
最近修改 :
功能描述 :表達式類
函數列表 :
*******************************************************************************/
#include "Expression.h"
//using namespace std;
using namespace ExprEval;
// Expression object
//------------------------------------------------------------------------------
// Constructor
CExpression::CExpression() : m_vlist(0), m_flist(0), m_expr(0)
{
m_abortcount = 200000;
m_abortreset = 200000;
}
// Destructor
CExpression::~CExpression()
{
// Delete expression nodes
delete m_expr;
}
// Set value list
void CExpression::SetValueList(CValueList *vlist)
{
m_vlist = vlist;
}
// Get value list
CValueList* CExpression::GetValueList() const
{
return m_vlist;
}
// Set function list
void CExpression::SetFunctionList(CFunctionList *flist)
{
m_flist = flist;
}
// Get function list
CFunctionList* CExpression::GetFunctionList() const
{
return m_flist;
}
// Test for an abort
bool CExpression::DoTestAbort()
{
// Derive a class to test abort
return false;
}
// Test for an abort
void CExpression::TestAbort(bool force)
{
if(force)
{
// Test for an abort now
if(DoTestAbort())
{
throw(CAbortException());
}
}
else
{
// Test only if abort count is 0
if(m_abortcount == 0)
{
// Reset count
m_abortcount = m_abortreset;
// Test abort
if(DoTestAbort())
{
throw(CAbortException());
}
}
else
{
// Decrease abort count
m_abortcount--;
}
}
}
// Set test abort count
void CExpression::SetTestAbortCount(unsigned long count)
{
m_abortreset = count;
if(m_abortcount > count)
{
m_abortcount = count;
}
}
// Parse expression
void CExpression::Parse(const ::std::string& exstr)
{
// Clear the expression if needed
if(m_expr)
{
Clear();
}
// Create parser
auto_ptr<CParser> p(new CParser(this));
// Parse the expression
m_expr = p->Parse(exstr);
}
// Clear the expression
void CExpression::Clear()
{
delete m_expr;
m_expr = 0;
}
// Evaluate an expression
double CExpression::Evaluate()
{
if(m_expr)
{
return m_expr->Evaluate();
}
else
{
throw(CEmptyExpressionException());
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -