void CMenu::error(const wstringEx &msg) { s32 padsState; WPADData *wd; WPAD_Rumble(WPAD_CHAN_0, 0); _hideAbout(); _hideCode(); _hideConfig(); _hideConfig2(); _hideConfigAdv(); _hideDownload(); _hideGame(); _hideMain(); _hideWBFS(); _hideGameSettings(); m_btnMgr.setText(m_errorLblMessage, msg, true); _showError(); do { WPAD_ScanPads(); padsState = WPAD_ButtonsDown(0); wd = WPAD_Data(0); _mainLoopCommon(wd); } while ((padsState & (WPAD_BUTTON_HOME | WPAD_BUTTON_A | WPAD_BUTTON_B)) == 0); WPAD_Rumble(WPAD_CHAN_0, 0); _hideError(false); }
double Func::getValue() const { double value = 0.0; if (!_valid){ cout << "Error: Func::getValue() - invalid state" << endl; return value; } try{ value = _parser.Eval(); } catch (mu::Parser::exception_type &e){ _showError(e); } return value; }
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); } }
double Func::getDerivative() const { double value = 0.0; if (!_valid){ cout << "Error: Func::getDerivative() - invalid state" << endl; return value; } if (_x != NULL){ try{ value = _parser.Diff(_x, *_x); } catch (mu::Parser::exception_type &e){ _showError(e); } } return value; }
double Function::getDerivative() const { double value = 0.0; if (!_valid){ cout << "Error: Function::getDerivative() - invalid state" << endl; return value; } mu::varmap_type variables = _parser.GetVar(); mu::varmap_type::const_iterator item = variables.find(_independent); if (item != variables.end()){ try{ value = _parser.Diff(item->second, *(item->second)); } catch (mu::Parser::exception_type &e){ _showError(e); } } return value; }
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; }
vector<string> Func::getVars() const { vector< string > ret; if (!_valid){ cout << "Error: Func::getVars() - invalid parser state" << endl; return ret; } mu::varmap_type vars; try{ vars = _parser.GetVar(); for (mu::varmap_type::iterator ii = vars.begin(); ii != vars.end(); ++ii){ ret.push_back(ii->first); } } catch (mu::Parser::exception_type &e){ _showError(e); } return ret; }
/** Get value of variable `name` */ double Func::getVar(string name) const { if (!_valid){ cout << "Error: Func::getVar() - invalid parser state" << endl; return 0.0; } try{ const mu::varmap_type &vars = _parser.GetVar(); mu::varmap_type::const_iterator v = vars.find(name); if (v != vars.end()){ return *v->second; } else { cout << "Error: no such variable " << name << endl; return 0.0; } } catch (mu::Parser::exception_type &e) { _showError(e); return 0.0; } }
/** Set value of variable `name` */ void Func::setVar(string name, double value) { if (!_valid){ cout << "Error: Func::setVar() - invalid parser state" << endl; return; } mu::varmap_type vars; try{ vars = _parser.GetVar(); } catch (mu::Parser::exception_type &e) { _valid = false; _showError(e); return; } mu::varmap_type::iterator v = vars.find(name); if (v != vars.end()){ *v->second = value; } else { cout << "Error: no such variable " << name << endl; } }
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; }