git-svn-id: svn://db.shs.com.ru/pip@647 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2018-10-16 11:36:38 +00:00
parent dd00a36be3
commit 1548cba46e
3 changed files with 86 additions and 27 deletions

View File

@@ -94,6 +94,8 @@ namespace PIEvaluatorTypes {
class PIP_EXPORT PIEvaluatorContent
{
friend class PIEvaluator;
friend inline PIByteArray & operator <<(PIByteArray & s, const PIEvaluatorContent & v);
friend inline PIByteArray & operator >>(PIByteArray & s, PIEvaluatorContent & v);
public:
PIEvaluatorContent();
~PIEvaluatorContent() {;}
@@ -187,11 +189,17 @@ public:
//! Returns last result of \a evaluate()
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;
private:
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);
void convert();
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 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