MCPcopy Create free account
hub / github.com/Kitware/VTK / GetMathFunctionNumberByCheckingParenthesis

Method GetMathFunctionNumberByCheckingParenthesis

Common/Misc/vtkFunctionParser.cxx:1573–1615  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

1571
1572//------------------------------------------------------------------------------
1573int vtkFunctionParser::GetMathFunctionNumberByCheckingParenthesis(int currentIndex)
1574{
1575 // This function assumes that RemoveSpaces() has been called and
1576 // hence involves the check on the '(' that immediately follows a
1577 // valid function. Addressing '(' here instead of in CheckSyntax()
1578 // allows for early detection of grammar errors, i.e., lack of '(',
1579 // and hence simplifies the parsing process.
1580
1581 // For addition of any new math function, please update NUMBFUNCS
1582 // and add an entry to each of the three arrays below.
1583
1584 constexpr int NUMBFUNCS = 24;
1585
1586 static const int charsLens[NUMBFUNCS] = { 4, 4, 5, 6, 3, 6, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 4, 4,
1587 6, 5, 4, 5, 3 };
1588
1589 static const int funcNumbs[NUMBFUNCS] = { VTK_PARSER_ABSOLUTE_VALUE, VTK_PARSER_EXPONENT,
1590 VTK_PARSER_CEILING, VTK_PARSER_FLOOR,
1591
1592 VTK_PARSER_LOGARITHME, VTK_PARSER_LOGARITHM10, VTK_PARSER_LOGARITHM, VTK_PARSER_SQUARE_ROOT,
1593
1594 VTK_PARSER_SINE, VTK_PARSER_HYPERBOLIC_SINE, VTK_PARSER_COSINE, VTK_PARSER_HYPERBOLIC_COSINE,
1595
1596 VTK_PARSER_TANGENT, VTK_PARSER_HYPERBOLIC_TANGENT, VTK_PARSER_ARCSINE, VTK_PARSER_ARCCOSINE,
1597
1598 VTK_PARSER_ARCTANGENT, VTK_PARSER_MIN, VTK_PARSER_MAX, VTK_PARSER_CROSS,
1599
1600 VTK_PARSER_SIGN, VTK_PARSER_MAGNITUDE, VTK_PARSER_NORMALIZE, VTK_PARSER_IF };
1601
1602 static char funcNames[NUMBFUNCS][10] = { "abs(", "exp(", "ceil(", "floor(", "ln(", "log10(",
1603 "log(", "sqrt(", "sin(", "sinh(", "cos(", "cosh(", "tan(", "tanh(", "asin(", "acos(", "atan(",
1604 "min(", "max(", "cross(", "sign(", "mag(", "norm(", "if(" };
1605
1606 int isMatched = 0;
1607 int retNumber = 0;
1608 for (int i = 0; i < NUMBFUNCS && isMatched == 0; i++)
1609 {
1610 isMatched = (strncmp(this->Function + currentIndex, funcNames[i], charsLens[i]) == 0) ? 1 : 0;
1611 retNumber = isMatched * funcNumbs[i];
1612 }
1613
1614 return retNumber;
1615}
1616
1617//------------------------------------------------------------------------------
1618int vtkFunctionParser::GetMathFunctionStringLength(int mathFunctionNumber)

Callers 1

CheckExpressionMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected