Newer
Older

Michal Kravcenko
committed
/**
* DESCRIPTION OF THE FILE
*
* @author Michal Kravčenko
* @date 4.9.18 -
*/
Martin Beseda
committed
#include <boost/serialization/export.hpp>
Martin Beseda
committed
Martin Beseda
committed
#include "exprtk.hpp"
#include "ExprtkWrapper.h"
#include "ExprtkWrapperSerialization.h"
Martin Beseda
committed
Martin Beseda
committed
//BOOST_CLASS_EXPORT_IMPLEMENT(ExprtkWrapper);
Martin Beseda
committed
ExprtkWrapper::ExprtkWrapper(std::string expression_string) {

Michal Kravcenko
committed
Martin Beseda
committed
// this = new ExprtkWrapperImpl();
Martin Beseda
committed
this->expression_str = expression_string;
Martin Beseda
committed
this->symbol_table = new symbol_table_t();
Martin Beseda
committed
this->symbol_table->add_variable("x",
this->x);
this->symbol_table->add_variable("y",
this->y);
this->symbol_table->add_variable("z",
this->z);
this->symbol_table->add_variable("t",
this->t);
this->symbol_table->add_variable("f",
this->z);
Martin Beseda
committed
this->expression = new expression_t();
this->expression->register_symbol_table(*this->symbol_table);
Martin Beseda
committed
this->parser = new parser_t();
this->parser->compile(this->expression_str,
*this->expression);

Michal Kravcenko
committed
}
ExprtkWrapper::~ExprtkWrapper() {

Michal Kravcenko
committed
Martin Beseda
committed
if (this->expression) {
delete this->expression;
this->expression = nullptr;
Martin Beseda
committed
if (this->symbol_table) {
delete this->symbol_table;
this->symbol_table = nullptr;
Martin Beseda
committed
if (this->parser) {
delete this->parser;
this->parser = nullptr;

Michal Kravcenko
committed
Martin Beseda
committed
delete this;
// this = nullptr;

Michal Kravcenko
committed
}
double ExprtkWrapper::eval(double x1,
double x2,
double x3,
double x4) {

Michal Kravcenko
committed
Martin Beseda
committed
this->x = x1;
this->y = x2;
this->z = x3;
this->t = x4;

Michal Kravcenko
committed
Martin Beseda
committed
return this->expression->value();

Michal Kravcenko
committed
}
double ExprtkWrapper::eval(std::vector<double>& p) {

Michal Kravcenko
committed
Martin Beseda
committed
this->x = p[0];

Michal Kravcenko
committed
}
Martin Beseda
committed
this->y = p[1];

Michal Kravcenko
committed
}
Martin Beseda
committed
this->z = p[2];

Michal Kravcenko
committed
}
Martin Beseda
committed
this->t = p[3];

Michal Kravcenko
committed
}
Martin Beseda
committed
double result = this->expression->value();
return result;
Martin Beseda
committed
}
ExprtkWrapper::ExprtkWrapper(expression_t* expression,
symbol_table_t* symbol_table,
parser_t* parser,
double x,
double y,
double z,
double t,
double f,
std::string expression_str) {
this->expression = expression;
this->symbol_table = symbol_table;
this->parser = parser;
this->x = x;
this->y = y;
this->z = z;
this->t = t;
this->f = f;
this->expression_str = expression_str;
}