[muparser] Remove OnDetectVar and Diff

These are unused and useless.
This commit is contained in:
ridiculousfish 2017-12-18 12:02:47 -08:00
parent 2c317a2585
commit 873ea0f0df
5 changed files with 0 additions and 71 deletions

View file

@ -54,9 +54,6 @@ namespace mu {
virtual void InitFun();
virtual void InitConst();
virtual void InitOprt();
virtual void OnDetectVar(string_type *pExpr, int &nStart, int &nEnd);
ValueOrError Diff(value_type *a_Var, value_type a_fPos, value_type a_fEpsilon = 0) const;
protected:
// Trigonometric functions

View file

@ -155,8 +155,6 @@ class ParserBase {
virtual void InitConst() = 0;
virtual void InitOprt() = 0;
virtual void OnDetectVar(string_type *pExpr, int &nStart, int &nEnd);
static const char_type *c_DefaultOprt[];
static std::locale s_locale; ///< The locale used by the parser
static bool g_DbgDumpCmdCode;

View file

@ -302,65 +302,4 @@ void Parser::InitOprt() {
assertNoError(DefineInfixOprt(_T("+"), UnaryPlus));
}
//---------------------------------------------------------------------------
void Parser::OnDetectVar(string_type * /*pExpr*/, int & /*nStart*/, int & /*nEnd*/) {
// this is just sample code to illustrate modifying variable names on the fly.
// I'm not sure anyone really needs such a feature...
/*
string sVar(pExpr->begin()+nStart, pExpr->begin()+nEnd);
string sRepl = std::string("_") + sVar + "_";
int nOrigVarEnd = nEnd;
cout << "variable detected!\n";
cout << " Expr: " << *pExpr << "\n";
cout << " Start: " << nStart << "\n";
cout << " End: " << nEnd << "\n";
cout << " Var: \"" << sVar << "\"\n";
cout << " Repl: \"" << sRepl << "\"\n";
nEnd = nStart + sRepl.length();
cout << " End: " << nEnd << "\n";
pExpr->replace(pExpr->begin()+nStart, pExpr->begin()+nOrigVarEnd, sRepl);
cout << " New expr: " << *pExpr << "\n";
*/
}
//---------------------------------------------------------------------------
/** \brief Numerically differentiate with regard to a variable.
\param [in] a_Var Pointer to the differentiation variable.
\param [in] a_fPos Position at which the differentiation should take place.
\param [in] a_fEpsilon Epsilon used for the numerical differentiation.
Numerical differentiation uses a 5 point operator yielding a 4th order
formula. The default value for epsilon is 0.00074 which is
numeric_limits<double>::epsilon() ^ (1/5) as suggested in the muparser
forum:
http://sourceforge.net/forum/forum.php?thread_id=1994611&forum_id=462843
*/
ValueOrError Parser::Diff(value_type *a_Var, value_type a_fPos, value_type a_fEpsilon) const {
value_type fRes(0), fBuf(*a_Var), fEpsilon(a_fEpsilon);
ValueOrError f[4] = {0, 0, 0, 0};
// Backwards compatible calculation of epsilon in case the user doesn't provide
// his own epsilon
if (fEpsilon == 0) fEpsilon = (a_fPos == 0) ? (value_type)1e-10 : (value_type)1e-7 * a_fPos;
*a_Var = a_fPos + 2 * fEpsilon;
f[0] = Eval();
*a_Var = a_fPos + 1 * fEpsilon;
f[1] = Eval();
*a_Var = a_fPos - 1 * fEpsilon;
f[2] = Eval();
*a_Var = a_fPos - 2 * fEpsilon;
f[3] = Eval();
*a_Var = fBuf; // restore variable
for (ValueOrError &v : f) {
if (!v) return std::move(v);
}
fRes = (-*f[0] + 8 * *f[1] - 8 * *f[2] + *f[3]) / (12 * fEpsilon);
return fRes;
}
} // namespace mu

View file

@ -116,9 +116,6 @@ void ParserBase::ReInit() const {
m_pTokenReader->ReInit();
}
//---------------------------------------------------------------------------
void ParserBase::OnDetectVar(string_type * /*pExpr*/, int & /*nStart*/, int & /*nEnd*/) {}
//---------------------------------------------------------------------------
/** \brief Add a value parsing function.

View file

@ -615,8 +615,6 @@ bool ParserTokenReader::IsVarTok(token_type &a_Tok) {
if (m_iSynFlags & noVAR) return Error(ecUNEXPECTED_VAR, m_iPos, strTok);
m_pParser->OnDetectVar(&m_strFormula, m_iPos, iEnd);
m_iPos = iEnd;
a_Tok.SetVar(item->second, strTok);
m_UsedVar[item->first] = item->second; // Add variable to used-var-list