Beispiel #1
0
Function& Function::operator=(const Function rhs)
{
	static Eref er;
    _clearBuffer();
    _mode = rhs._mode;
    _lastValue = rhs._lastValue;
    _value = rhs._value;
    _rate = rhs._rate;
    _independent = rhs._independent;
    // Adding pi and e, the defaults are `_pi` and `_e`
    _parser.DefineConst(_T("pi"), (mu::value_type)M_PI);
    _parser.DefineConst(_T("e"), (mu::value_type)M_E);
    // Copy the constants
    mu::valmap_type cmap = rhs._parser.GetConst();
    if (cmap.size()){
        mu::valmap_type::const_iterator item = cmap.begin();
        for (; item!=cmap.end(); ++item){
            _parser.DefineConst(item->first, item->second);
        }
    }
    // Copy the values from the var pointers in rhs
    setExpr(er, rhs.getExpr( er ));
    assert(_varbuf.size() == rhs._varbuf.size());
    for (unsigned int ii = 0; ii < rhs._varbuf.size(); ++ii){
        _varbuf[ii]->value = rhs._varbuf[ii]->value;
    }
    assert(_pullbuf.size() == rhs._pullbuf.size());
    for (unsigned int ii = 0; ii < rhs._pullbuf.size(); ++ii){
        *_pullbuf[ii] = *(rhs._pullbuf[ii]);
    }
    return *this;
}
Beispiel #2
0
void Function::setNumVar(const unsigned int num)
{
    _clearBuffer();
    for (unsigned int ii = 0; ii < num; ++ii){
        stringstream name;
        name << "x" << ii;
        _functionAddVar(name.str().c_str(), this);
    }
}
Beispiel #3
0
Func& Func::operator=(const Func rhs)
{
    _clearBuffer();
    _mode = rhs._mode;
    // Adding pi and e, the defaults are `_pi` and `_e`
    _parser.DefineConst(_T("pi"), (mu::value_type)M_PI);
    _parser.DefineConst(_T("e"), (mu::value_type)M_E);
    setExpr(rhs.getExpr());
    vector <string> vars = rhs.getVars();
    for (unsigned int ii = 0; ii < vars.size(); ++ii){
        setVar(vars[ii], rhs.getVar(vars[ii]));
    }
    return *this;
}
Beispiel #4
0
void Function::setExpr(const Eref& eref, string expr)
{
    _valid = false;
    _clearBuffer();
    _varbuf.resize(_numVar);
    // _pullbuf.resize(_num
    mu::varmap_type vars;
    try{
        _parser.SetExpr(expr);
    } catch (mu::Parser::exception_type &e) {
        cerr << "Error setting expression on: " << eref.objId().path() << endl;
        _showError(e);
        _clearBuffer();
        return;
    }
    // Force variable creation right away. Otherwise numVar does not
    // get set properly
    try{
        _parser.Eval();
        _valid = true;
    } catch (mu::Parser::exception_type &e){
        _showError(e);
    }
}
Beispiel #5
0
Function::Function(): _valid(false), _numVar(0), _lastValue(0.0),
                      _value(0.0), _rate(0.0), _mode(1), _stoich(0)
{
    _parser.SetVarFactory(_functionAddVar, this);
    // Adding pi and e, the defaults are `_pi` and `_e`
    _parser.DefineConst(_T("pi"), (mu::value_type)M_PI);
    _parser.DefineConst(_T("e"), (mu::value_type)M_E);
    _independent = "x0";
    // Adding this default expression by default to avoid complains from GUI
    try{
        _parser.SetExpr("0");
    } catch (mu::Parser::exception_type &e) {
        _showError(e);
        _clearBuffer();
        return;
    }
    _valid = true;
}
Beispiel #6
0
void Func::setExpr(string expr)
{
    _valid = false;
    _x = NULL;
    _y = NULL;
    _z = NULL;
    mu::varmap_type vars;
    try{
        _parser.SetExpr(expr);
        vars = _parser.GetUsedVar();
    } catch (mu::Parser::exception_type &e) {
        _showError(e);
        _clearBuffer();
        return;
    }
    mu::varmap_type::iterator v = vars.find("x");
    if (v != vars.end()){
        _x = v->second;
    } else if (vars.size() >= 1){
        v = vars.begin();
        _x = v->second;
    }
    v = vars.find("y");
    if (v != vars.end()){
        _y = v->second;
    } else if (vars.size() >= 2){
        v = vars.begin();
        ++v;
        _y = v->second;
    }
    v = vars.find("z");
    if (v != vars.end()){
        _z = v->second;
    } else if (vars.size() >= 3){
        v = vars.begin();
        v++; v++;
        _z = v->second;
    }
    _valid = true;
}
Beispiel #7
0
Func::~Func()
{

    _clearBuffer();
}
Beispiel #8
0
Function::~Function()
{
        _clearBuffer();
 }