Skip to content
Snippets Groups Projects
ExprtkWrapper.cpp 1.17 KiB
Newer Older
  • Learn to ignore specific revisions
  • /**
     * DESCRIPTION OF THE FILE
     *
     * @author Michal Kravčenko
     * @date 4.9.18 -
     */
    
    #include "ExprtkWrapper.h"
    
    
    ExprtkWrapper::ExprtkWrapper( std::string expression_string ) {
    
        this->symbol_table = new symbol_table_t( );
    
        symbol_table->add_variable("x", this->t);
        symbol_table->add_variable("y", this->y);
        symbol_table->add_variable("z", this->z);
        symbol_table->add_variable("t", this->t);
    
        this->expression = new expression_t( );
        this->expression->register_symbol_table( *this->symbol_table );
    
        this->parser = new parser_t( );
        parser->compile(expression_string, *this->expression );
    }
    
    ExprtkWrapper::ExprtkWrapper( ) {
    
    
    }
    
    ExprtkWrapper::~ExprtkWrapper() {
    }
    
    double ExprtkWrapper::eval(double x1, double x2, double x3, double x4) {
    
        this->x = x1;
        this->y = x2;
        this->z = x3;
        this->t = x4;
    
        return this->expression->value();
    }
    
    double ExprtkWrapper::eval(std::vector<double> &p) {
    
    
        if(p.size() > 0){
            this->x = p[0];
        }
        if(p.size() > 1){
            this->y = p[1];
        }
        if(p.size() > 2){
            this->z = p[2];
        }
        if(p.size() > 3){
            this->t = p[3];
        }
    
        return this->expression->value();
    }