Esempio n. 1
0
/** \brief Return the number of constants defined in a parser. */
API_EXPORT(int) mupGetConstNum(muParserHandle_t a_hParser)
{
  MU_TRY
    muParser_t* const p(AsParser(a_hParser));
    const mu::valmap_type ValMap = p->GetConst();
    return (int)ValMap.size();
  MU_CATCH

  return 0; // never reached
}
Esempio n. 2
0
/** \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
    */
API_EXPORT(void) mupGetConst(muParserHandle_t a_hParser,
    unsigned a_iVar,
    const muChar_t **a_pszName,
    muFloat_t *a_fVal)
{
    // A static buffer is needed for the name since i cant return the
    // pointer from the map.
    static muChar_t szName[1024];

    MU_TRY
        muParser_t* const p(AsParser(a_hParser));
    const mu::valmap_type ValMap = p->GetConst();

    if (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;

#ifndef _UNICODE
    strncpy(szName, item->first.c_str(), sizeof(szName));
#else
    wcsncpy(szName, item->first.c_str(), sizeof(szName));
#endif

    szName[sizeof(szName)-1] = 0;

    *a_pszName = &szName[0];
    *a_fVal = item->second;
    return;

    MU_CATCH

        *a_pszName = 0;
    *a_fVal = 0;
}