📄 test.cpp
字号:
// Includes
#include <iostream>
#include <ctime>
//#include "../expreval.h"
#include "ExprEval.h"
//using namespace std;
using namespace ExprEval;
/*
class TestNode : public FunctionNode
{
public:
TestNode(Expression *expr) : FunctionNode(expr)
{
SetArgumentCount(0, 0, 0, 0);
}
double DoEvaluate()
{
return 123.456;
}
};
class TestFactory : public FunctionFactory
{
public:
string GetName() const
{
return "test";
}
FunctionNode *DoCreate(Expression *expr)
{
return new TestNode(expr);
}
};
*/
void HandleException(CException &e)
{
switch(e.GetType())
{
case CException::Type_SyntaxException:
::std::cout << "Syntax Error\n";
break;
case CException::Type_EmptyExpressionException:
::std::cout << "Empty Expression\n";
break;
default:
::std::cout << "Other Error\n";
break;
}
}
int main()
{
//std::cout<<"succ"<<std::endl;
::std::string expr;
long pos, count;
::std::cout << "Enter expression: ";
::std::cin >> expr;
::std::cout << "Enter count: ";
::std::cin >> count;
try
{
CValueList v;
CFunctionList f;
CExpression e;
v.AddDefaultValues();
f.AddDefaultFunctions();
//f.Add(new TestFactory());
e.SetValueList(&v);
e.SetFunctionList(&f);
e.Parse(expr);
double result;
// Start a timer
time_t start = time(NULL);
//for(pos = 0; pos < count; pos++)
//{
result = e.Evaluate();
//}
std::cout<<result<<std::endl;
// Determine total time
double total = difftime(time(NULL), start);
::std::cout << "Total time: " << total << ::std::endl;
if(total != 0.0)
{
::std::cout << "Average/sec: " << (double)count / total << ::std::endl;
}
// Variable dump
::std::cout << "Value dump" << ::std::endl;
::std::cout << "-------------------------" << ::std::endl;
/*
ValueList::size_type i, c;
c = v.Count();
for(i = 0; i < c; i++)
{
string name;
double value;
v.Item(i, &name, &value);
cout << name.c_str() << " = " << value << endl;
}
*/
::std::cout << ::std::endl;
}
catch(CException &e)
{
HandleException(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -