git-svn-id: svn://db.shs.com.ru/pip@648 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
35
main.cpp
35
main.cpp
@@ -42,28 +42,29 @@ public:
|
||||
};
|
||||
int main() {
|
||||
PIEvaluator eval, eval2;
|
||||
piCout << "start";
|
||||
|
||||
eval.setVariable("x", complexd(1, 2));
|
||||
PITimeMeasurer tm;
|
||||
eval.check("e2eelg(10ex");
|
||||
double us = tm.elapsed_u(); piCout << "check" << us;
|
||||
|
||||
tm.reset();
|
||||
eval.setVariable("t", complexd(1, 2));
|
||||
eval.check("(t*t*(t<8))+(72*(t>8)-8*(9-t)*(9-t)*(t>8)*(t<8.8))+(3*(t-8.8)*(t>8.8))");
|
||||
PIByteArray ba = eval.save();
|
||||
us = tm.elapsed_u(); piCout << " save" << us;
|
||||
|
||||
piCout << ba.size();
|
||||
PITimeMeasurer tm; double us = 0.;
|
||||
|
||||
tm.reset();
|
||||
eval2.load(ba);
|
||||
us = tm.elapsed_u(); piCout << " load" << us;
|
||||
PIEvaluator e1;
|
||||
piForTimes(100) {
|
||||
e1.setVariable("t", complexd(1, 2));
|
||||
e1.check("(t*t*(t<8))+(72*(t>8)-8*(9-t)*(9-t)*(t>8)*(t<8.8))+(3*(t-8.8)*(t>8.8))");
|
||||
complexd ret = e1.evaluate();
|
||||
}
|
||||
us = tm.elapsed_u(); piCout << "check" << us / 100.;
|
||||
|
||||
//eval.setVariable("x", complexd(-2, 0));
|
||||
eval2.setVariable("x", complexd(-2, 0));
|
||||
|
||||
piCout << eval.expression() << "=" << eval.evaluate();
|
||||
piCout << eval2.expression() << "=" << eval2.evaluate();
|
||||
tm.reset();
|
||||
PIEvaluator e2;
|
||||
piForTimes(100) {
|
||||
e2.load(ba);
|
||||
e2.setVariable("t", complexd(1, 2));
|
||||
complexd ret = e2.evaluate();
|
||||
}
|
||||
us = tm.elapsed_u(); piCout << " save" << us / 100.;
|
||||
|
||||
/*A a;
|
||||
CONNECTU(PICout::Notifier::object(), finished, &a, pcf);
|
||||
|
||||
@@ -710,7 +710,7 @@ PIString PIEvaluator::preprocess(const PIString & string) {
|
||||
lind = parse(currentString);
|
||||
if (instructions.size() == 0) {
|
||||
variables.push_back(PIEvaluatorTypes::Variable());
|
||||
instructions.push_back(PIEvaluatorTypes::Instruction(PIEvaluatorTypes::oNone, PIVector<int>(1, lind), -variables.size_s()));
|
||||
instructions.push_back(PIEvaluatorTypes::Instruction(PIEvaluatorTypes::oNone, PIVector<short>(1, lind), -variables.size_s()));
|
||||
}
|
||||
kvars = &(content.variables);
|
||||
/*
|
||||
@@ -762,7 +762,7 @@ int PIEvaluator::parse(const PIString & string, int offset) {
|
||||
PIEvaluatorTypes::Function cfunc;
|
||||
PIEvaluatorTypes::Operation coper;
|
||||
PIString sbrackets, carg;
|
||||
PIVector<int> args, atmp;
|
||||
PIVector<short> args, atmp;
|
||||
PIVector<PIEvaluatorTypes::Operation> opers;
|
||||
|
||||
///qDebug() << "to parse :" + string;
|
||||
@@ -1271,12 +1271,13 @@ complexd PIEvaluator::evaluate() {
|
||||
|
||||
PIByteArray PIEvaluator::save() const {
|
||||
PIByteArray ret;
|
||||
ret << content << elements << currentVariables << unknownVars << variables << instructions << currentString << lastError << out << correct;
|
||||
ret << content << currentVariables << unknownVars << instructions << currentString << lastError << out << correct;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void PIEvaluator::load(PIByteArray ba) {
|
||||
if (ba.size() <= 4) return;
|
||||
ba >> content >> elements >> currentVariables >> unknownVars >> variables >> instructions >> currentString >> lastError >> out >> correct;
|
||||
ba >> content >> currentVariables >> unknownVars >> instructions >> currentString >> lastError >> out >> correct;
|
||||
variables = currentVariables;
|
||||
}
|
||||
|
||||
@@ -52,29 +52,29 @@ namespace PIEvaluatorTypes {
|
||||
|
||||
struct PIP_EXPORT Instruction {
|
||||
Instruction() {out = -1; function = -1; operation = oNone;}
|
||||
Instruction(Operation oper, PIVector<int> opers, int out_ind, int func = -1) {
|
||||
Instruction(Operation oper, PIVector<short> opers, short out_ind, short func = -1) {
|
||||
operation = oper; operators = opers; out = out_ind; function = func;}
|
||||
Operation operation;
|
||||
PIVector<int> operators;
|
||||
int out;
|
||||
int function;
|
||||
short out;
|
||||
short function;
|
||||
PIVector<short> operators;
|
||||
};
|
||||
struct PIP_EXPORT Element {
|
||||
Element() {num = 0; var_num = -1; type = etNumber;}
|
||||
Element(eType new_type, int new_num, int new_var_num = -1) {set(new_type, new_num, new_var_num);}
|
||||
void set(eType new_type, int new_num, int new_var_num = -1) {type = new_type; num = new_num; var_num = new_var_num;}
|
||||
Element(eType new_type, short new_num, short new_var_num = -1) {set(new_type, new_num, new_var_num);}
|
||||
void set(eType new_type, short new_num, short new_var_num = -1) {type = new_type; num = new_num; var_num = new_var_num;}
|
||||
eType type;
|
||||
int num;
|
||||
int var_num;
|
||||
short num;
|
||||
short var_num;
|
||||
};
|
||||
struct PIP_EXPORT Function {
|
||||
Function() {arguments = 0; type = bfUnknown; handler = 0;}
|
||||
Function(const PIString & name, int args, BaseFunctions ftype) {identifier = name; arguments = args; type = ftype; handler = 0;}
|
||||
Function(const PIString & name, int args, FuncFunc h) {identifier = name; arguments = args; type = bfCustom; handler = h;}
|
||||
Function(const PIString & name, short args, BaseFunctions ftype) {identifier = name; arguments = args; type = ftype; handler = 0;}
|
||||
Function(const PIString & name, short args, FuncFunc h) {identifier = name; arguments = args; type = bfCustom; handler = h;}
|
||||
PIString identifier;
|
||||
BaseFunctions type;
|
||||
FuncFunc handler;
|
||||
int arguments;
|
||||
short arguments;
|
||||
};
|
||||
struct PIP_EXPORT Variable {
|
||||
Variable() {value = 0.;}
|
||||
@@ -235,23 +235,19 @@ inline bool operator ==(PIEvaluatorTypes::Element e1, PIEvaluatorTypes::Element
|
||||
inline bool operator !=(PIEvaluatorTypes::Element e1, PIEvaluatorTypes::Element e2) {return (e1.type != e2.type || e1.num != e2.num);}
|
||||
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const PIEvaluatorTypes::Instruction & v) {
|
||||
s << ((int)v.operation) << v.operators << v.out << v.function;
|
||||
s << PIByteArray::RawData(&v, sizeof(v) - sizeof(v.operators)) << v.operators;
|
||||
return s;
|
||||
}
|
||||
inline PIByteArray & operator >>(PIByteArray & s, PIEvaluatorTypes::Instruction & v) {
|
||||
int i(0);
|
||||
s >> i >> v.operators >> v.out >> v.function;
|
||||
v.operation = (PIEvaluatorTypes::Operation)i;
|
||||
s >> PIByteArray::RawData(&v, sizeof(v) - sizeof(v.operators)) >> v.operators;
|
||||
return s;
|
||||
}
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const PIEvaluatorTypes::Element & v) {
|
||||
s << ((int)v.type) << v.num << v.var_num;
|
||||
s << PIByteArray::RawData(&v, sizeof(v));
|
||||
return s;
|
||||
}
|
||||
inline PIByteArray & operator >>(PIByteArray & s, PIEvaluatorTypes::Element & v) {
|
||||
int i(0);
|
||||
s >> i >> v.num >> v.var_num;
|
||||
v.type = (PIEvaluatorTypes::eType)i;
|
||||
s >> PIByteArray::RawData(&v, sizeof(v));
|
||||
return s;
|
||||
}
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const PIEvaluatorTypes::Variable & v) {
|
||||
|
||||
Reference in New Issue
Block a user