Newer
Older

Michal Kravcenko
committed
/**
* DESCRIPTION OF THE FILE
*
* @author Michal Kravčenko
* @date 4.9.18 -
*/
#include "ExprtkWrapper.h"
Martin Beseda
committed
#include "exprtk.hpp"

Michal Kravcenko
committed
Martin Beseda
committed
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
typedef exprtk::symbol_table<double> symbol_table_t;
typedef exprtk::expression<double> expression_t;
typedef exprtk::parser<double> parser_t;
class ExprtkWrapper :: ExprtkWrapperImpl {
public:
/**
*
*/
expression_t *expression = nullptr;
/**
*
*/
symbol_table_t *symbol_table = nullptr;
/**
*
*/
parser_t * parser = nullptr;
/**
* variables
*/
double x, y, z, t, f;
/**
* referential expression string
*/
std::string expression_str;
};

Michal Kravcenko
committed
ExprtkWrapper::ExprtkWrapper( std::string expression_string ) {
this->p_impl->expression_str = expression_string;
this->p_impl->symbol_table = new symbol_table_t( );

Michal Kravcenko
committed
this->p_impl->symbol_table->add_variable("x", this->p_impl->x);
this->p_impl->symbol_table->add_variable("y", this->p_impl->y);
this->p_impl->symbol_table->add_variable("z", this->p_impl->z);
this->p_impl->symbol_table->add_variable("t", this->p_impl->t);
this->p_impl->symbol_table->add_variable("f", this->p_impl->z);

Michal Kravcenko
committed
this->p_impl->expression = new expression_t( );
this->p_impl->expression->register_symbol_table( *this->p_impl->symbol_table );

Michal Kravcenko
committed
this->p_impl->parser = new parser_t( );
this->p_impl->parser->compile(this->p_impl->expression_str, *this->p_impl->expression );

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

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

Michal Kravcenko
committed
}
double ExprtkWrapper::eval(double x1, double x2, double x3, double x4) {
this->p_impl->x = x1;
this->p_impl->y = x2;
this->p_impl->z = x3;
this->p_impl->t = x4;

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

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

Michal Kravcenko
committed
}
if(p.size() > 1){

Michal Kravcenko
committed
}
if(p.size() > 2){

Michal Kravcenko
committed
}
if(p.size() > 3){

Michal Kravcenko
committed
}
double result = this->p_impl->expression->value();
return result;