git-svn-id: svn://db.shs.com.ru/pip@647 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
48
main.cpp
48
main.cpp
@@ -41,6 +41,30 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
int main() {
|
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();
|
||||||
|
PIByteArray ba = eval.save();
|
||||||
|
us = tm.elapsed_u(); piCout << " save" << us;
|
||||||
|
|
||||||
|
piCout << ba.size();
|
||||||
|
|
||||||
|
tm.reset();
|
||||||
|
eval2.load(ba);
|
||||||
|
us = tm.elapsed_u(); piCout << " load" << us;
|
||||||
|
|
||||||
|
//eval.setVariable("x", complexd(-2, 0));
|
||||||
|
eval2.setVariable("x", complexd(-2, 0));
|
||||||
|
|
||||||
|
piCout << eval.expression() << "=" << eval.evaluate();
|
||||||
|
piCout << eval2.expression() << "=" << eval2.evaluate();
|
||||||
|
|
||||||
/*A a;
|
/*A a;
|
||||||
CONNECTU(PICout::Notifier::object(), finished, &a, pcf);
|
CONNECTU(PICout::Notifier::object(), finished, &a, pcf);
|
||||||
PIString buffer = "my buff:";
|
PIString buffer = "my buff:";
|
||||||
@@ -177,27 +201,3 @@ int main(int argc, char *argv[]) {
|
|||||||
piCout << "server" << st << ba.toHex() << ba.size();*/
|
piCout << "server" << st << ba.toHex() << ba.size();*/
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -699,8 +699,8 @@ void PIEvaluator::convert() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
const PIString & PIEvaluator::preprocess(const PIString & string) {
|
PIString PIEvaluator::preprocess(const PIString & string) {
|
||||||
static PIString ret;
|
PIString ret;
|
||||||
int lind;
|
int lind;
|
||||||
ret = prepare(string);
|
ret = prepare(string);
|
||||||
convert();
|
convert();
|
||||||
@@ -1180,6 +1180,7 @@ inline void PIEvaluator::execFunction(const PIEvaluatorTypes::Instruction & ci)
|
|||||||
|
|
||||||
|
|
||||||
inline bool PIEvaluator::execInstructions() {
|
inline bool PIEvaluator::execInstructions() {
|
||||||
|
kvars = &(content.variables);
|
||||||
PIEvaluatorTypes::Instruction ci;
|
PIEvaluatorTypes::Instruction ci;
|
||||||
int oi;
|
int oi;
|
||||||
complexd tmp;
|
complexd tmp;
|
||||||
@@ -1266,3 +1267,16 @@ complexd PIEvaluator::evaluate() {
|
|||||||
if (fabs(out.imag()) < 1E-300) out = complexd(out.real(), 0.);
|
if (fabs(out.imag()) < 1E-300) out = complexd(out.real(), 0.);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PIByteArray PIEvaluator::save() const {
|
||||||
|
PIByteArray ret;
|
||||||
|
ret << content << elements << currentVariables << unknownVars << variables << 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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -94,6 +94,8 @@ namespace PIEvaluatorTypes {
|
|||||||
class PIP_EXPORT PIEvaluatorContent
|
class PIP_EXPORT PIEvaluatorContent
|
||||||
{
|
{
|
||||||
friend class PIEvaluator;
|
friend class PIEvaluator;
|
||||||
|
friend inline PIByteArray & operator <<(PIByteArray & s, const PIEvaluatorContent & v);
|
||||||
|
friend inline PIByteArray & operator >>(PIByteArray & s, PIEvaluatorContent & v);
|
||||||
public:
|
public:
|
||||||
PIEvaluatorContent();
|
PIEvaluatorContent();
|
||||||
~PIEvaluatorContent() {;}
|
~PIEvaluatorContent() {;}
|
||||||
@@ -187,11 +189,17 @@ public:
|
|||||||
//! Returns last result of \a evaluate()
|
//! Returns last result of \a evaluate()
|
||||||
const complexd & lastResult() const {return out;}
|
const complexd & lastResult() const {return out;}
|
||||||
|
|
||||||
|
//! Save to %PIByteArray evaluator state (expression, variables, errors, compiled instructions)
|
||||||
|
PIByteArray save() const;
|
||||||
|
|
||||||
|
//! Restore from %PIByteArray evaluator state (expression, variables, errors, compiled instructions)
|
||||||
|
void load(PIByteArray ba);
|
||||||
|
|
||||||
PIEvaluatorContent content;
|
PIEvaluatorContent content;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const PIString & prepare(const PIString & string);
|
const PIString & prepare(const PIString & string);
|
||||||
const PIString & preprocess(const PIString & string);
|
PIString preprocess(const PIString & string);
|
||||||
int parse(const PIString & string, int offset = 0);
|
int parse(const PIString & string, int offset = 0);
|
||||||
void convert();
|
void convert();
|
||||||
void checkBrackets();
|
void checkBrackets();
|
||||||
@@ -226,4 +234,41 @@ private:
|
|||||||
inline bool operator ==(PIEvaluatorTypes::Element e1, PIEvaluatorTypes::Element e2) {return (e1.type == e2.type && e1.num == e2.num);}
|
inline bool operator ==(PIEvaluatorTypes::Element e1, PIEvaluatorTypes::Element e2) {return (e1.type == e2.type && e1.num == e2.num);}
|
||||||
inline bool operator !=(PIEvaluatorTypes::Element e1, PIEvaluatorTypes::Element e2) {return (e1.type != e2.type || e1.num != e2.num);}
|
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;
|
||||||
|
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;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
inline PIByteArray & operator <<(PIByteArray & s, const PIEvaluatorTypes::Element & v) {
|
||||||
|
s << ((int)v.type) << v.num << v.var_num;
|
||||||
|
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;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
inline PIByteArray & operator <<(PIByteArray & s, const PIEvaluatorTypes::Variable & v) {
|
||||||
|
s << v.name << v.value;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
inline PIByteArray & operator >>(PIByteArray & s, PIEvaluatorTypes::Variable & v) {
|
||||||
|
s >> v.name >> v.value;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
inline PIByteArray & operator <<(PIByteArray & s, const PIEvaluatorContent & v) {
|
||||||
|
s << v.variables << v.cv_count;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
inline PIByteArray & operator >>(PIByteArray & s, PIEvaluatorContent & v) {
|
||||||
|
s >> v.variables >> v.cv_count;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // PIEVALUATOR_H
|
#endif // PIEVALUATOR_H
|
||||||
|
|||||||
Reference in New Issue
Block a user