📄 muparserdll.cpp
字号:
bool a_bAllowOpt)
{
MU_PARSER_TRY
parser_type p(GetPtr(a_hParser));
p->DefinePostfixOprt(a_szName, a_pOprt, a_bAllowOpt);
MU_PARSER_CATCH
}
//---------------------------------------------------------------------------
MU_PARSER_API void mupDefineInfixOprt(parser_handle a_hParser,
const char *a_szName,
fun_type1 a_pOprt,
bool a_bAllowOpt)
{
MU_PARSER_TRY
parser_type p(GetPtr(a_hParser));
p->DefineInfixOprt(a_szName, a_pOprt, a_bAllowOpt);
MU_PARSER_CATCH
}
// Define character sets for identifiers
//---------------------------------------------------------------------------
MU_PARSER_API void mupDefineNameChars(parser_handle a_hParser, const char *a_szCharset)
{
parser_type p(GetPtr(a_hParser));
p->DefineNameChars(a_szCharset);
}
//---------------------------------------------------------------------------
MU_PARSER_API void mupDefineOprtChars(parser_handle a_hParser, const char *a_szCharset)
{
parser_type p(GetPtr(a_hParser));
p->DefineOprtChars(a_szCharset);
}
//---------------------------------------------------------------------------
MU_PARSER_API void mupDefineInfixOprtChars(parser_handle a_hParser, const char *a_szCharset)
{
parser_type p(GetPtr(a_hParser));
p->DefineInfixOprtChars(a_szCharset);
}
//---------------------------------------------------------------------------
/** \brief Get the number of variables defined in the parser.
\param a_hParser [in] Must be a valid parser handle.
\return The number of used variables.
\sa mupGetExprVar
*/
MU_PARSER_API int mupGetVarNum(parser_handle a_hParser)
{
MU_PARSER_TRY
parser_type p(GetPtr(a_hParser));
const mu::varmap_type VarMap = p->GetVar();
return (int)VarMap.size();
MU_PARSER_CATCH
return 0; // never reached
}
//---------------------------------------------------------------------------
/** \brief Return a variable that is used in an expression.
Prior to calling this function call mupGetExprVarNum in order to get the
number of variables in the expression. If the parameter a_iVar is greater
than the number of variables both a_szName and a_pVar will be set to zero.
As a side effect this function will trigger an internal calculation of the
expression undefined variables will be set to zero during this calculation.
During the calculation user defined callback functions present in the expression
will be called, this is unavoidable.
\param a_hParser [in] A valid parser handle.
\param a_iVar [in] The index of the variable to return.
\param a_szName [out] Pointer to the variable name.
\param a_pVar [out] Pointer to the variable.
\throw nothrow
*/
MU_PARSER_API void mupGetVar(parser_handle a_hParser, unsigned a_iVar, const char **a_szName, double **a_pVar)
{
// A static buffer is needed for the name since i cant return the
// pointer from the map.
static char szName[1024];
MU_PARSER_TRY
parser_type p(GetPtr(a_hParser));
const mu::varmap_type VarMap = p->GetVar();
if (a_iVar<0 || a_iVar>=VarMap.size())
{
*a_szName = 0;
*a_pVar = 0;
return;
}
mu::varmap_type::const_iterator item;
item = VarMap.begin();
for (unsigned i=0; i<a_iVar; ++i)
item++;
strncpy(szName, item->first.c_str(), sizeof(szName));
szName[sizeof(szName)-1] = 0;
*a_szName = &szName[0];
*a_pVar = item->second;
return;
MU_PARSER_CATCH
*a_szName = 0;
*a_pVar = 0;
}
//---------------------------------------------------------------------------
/** \brief Get the number of variables used in the expression currently set in the parser.
\param a_hParser [in] Must be a valid parser handle.
\return The number of used variables.
\sa mupGetExprVar
*/
MU_PARSER_API int mupGetExprVarNum(parser_handle a_hParser)
{
MU_PARSER_TRY
parser_type p(GetPtr(a_hParser));
const mu::varmap_type VarMap = p->GetUsedVar();
return (int)VarMap.size();
MU_PARSER_CATCH
return 0; // never reached
}
//---------------------------------------------------------------------------
/** \brief Return a variable that is used in an expression.
Prior to calling this function call mupGetExprVarNum in order to get the
number of variables in the expression. If the parameter a_iVar is greater
than the number of variables both a_szName and a_pVar will be set to zero.
As a side effect this function will trigger an internal calculation of the
expression undefined variables will be set to zero during this calculation.
During the calculation user defined callback functions present in the expression
will be called, this is unavoidable.
\param a_hParser [in] A valid parser handle.
\param a_iVar [in] The index of the variable to return.
\param a_szName [out] Pointer to the variable name.
\param a_pVar [out] Pointer to the variable.
\throw nothrow
*/
MU_PARSER_API void mupGetExprVar(parser_handle a_hParser, unsigned a_iVar, const char **a_szName, double **a_pVar)
{
// A static buffer is needed for the name since i cant return the
// pointer from the map.
static char szName[1024];
MU_PARSER_TRY
parser_type p(GetPtr(a_hParser));
const mu::varmap_type VarMap = p->GetUsedVar();
if (a_iVar<0 || a_iVar>=VarMap.size())
{
*a_szName = 0;
*a_pVar = 0;
return;
}
mu::varmap_type::const_iterator item;
item = VarMap.begin();
for (unsigned i=0; i<a_iVar; ++i)
item++;
strncpy(szName, item->first.c_str(), sizeof(szName));
szName[sizeof(szName)-1] = 0;
*a_szName = &szName[0];
*a_pVar = item->second;
return;
MU_PARSER_CATCH
*a_szName = 0;
*a_pVar = 0;
}
//---------------------------------------------------------------------------
/** \brief Return the number of constants defined in a parser. */
MU_PARSER_API int mupGetConstNum(parser_handle a_hParser)
{
MU_PARSER_TRY
parser_type p(GetPtr(a_hParser));
const mu::valmap_type ValMap = p->GetConst();
return (int)ValMap.size();
MU_PARSER_CATCH
return 0; // never reached
}
//---------------------------------------------------------------------------
/** \brief Retrieve name and value of a single parser constant.
\param a_hParser [in] a valid parser handle
\param a_iVar [in] Index of the constant to query
\param a_pszName [out] pointer to a null terminated string with the constant name
\param [out] The constant value
*/
MU_PARSER_API void mupGetConst(parser_handle a_hParser, unsigned a_iVar,
const char **a_pszName, double &a_fVal)
{
// A static buffer is needed for the name since i cant return the
// pointer from the map.
static char szName[1024];
MU_PARSER_TRY
parser_type p(GetPtr(a_hParser));
const mu::valmap_type ValMap = p->GetConst();
if (a_iVar<0 || a_iVar>=ValMap.size())
{
*a_pszName = 0;
a_fVal = 0;
return;
}
mu::valmap_type::const_iterator item;
item = ValMap.begin();
for (unsigned i=0; i<a_iVar; ++i)
item++;
strncpy(szName, item->first.c_str(), sizeof(szName));
szName[sizeof(szName)-1] = 0;
*a_pszName = &szName[0];
a_fVal = item->second;
return;
MU_PARSER_CATCH
*a_pszName = 0;
a_fVal = 0;
}
//---------------------------------------------------------------------------
/** \brief Add a custom value regognition function.
*/
MU_PARSER_API void mupAddValIdent(parser_handle a_hParser, identfun_type a_pFun)
{
MU_PARSER_TRY
parser_type p(GetPtr(a_hParser));
p->AddValIdent(a_pFun);
MU_PARSER_CATCH
}
//---------------------------------------------------------------------------
/** \brief Query if an error occured.
After querying the internal error bit will be reset. So a consecutive call
will return false.
*/
MU_PARSER_API bool mupError()
{
bool bError(g_bError);
g_bError = false;
return bError;
}
//---------------------------------------------------------------------------
/** \brief Reset the internal error flag.
*/
MU_PARSER_API void mupErrorReset()
{
g_bError = false;
}
//---------------------------------------------------------------------------
/** \brief Return the message associated with the last error.
*/
MU_PARSER_API const char* mupGetErrorMsg()
{
return g_ParserError.GetMsg().c_str();
}
//---------------------------------------------------------------------------
/** \brief Return the message associated with the last error.
*/
MU_PARSER_API const char* mupGetErrorToken()
{
return g_ParserError.GetToken().c_str();
}
//---------------------------------------------------------------------------
/** \brief Return the code associated with the last error.
*/
MU_PARSER_API int mupGetErrorCode()
{
return g_ParserError.GetCode();
}
//---------------------------------------------------------------------------
/** \brief Return the postion associated with the last error. */
MU_PARSER_API int mupGetErrorPos()
{
return (int)g_ParserError.GetPos();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -