#include <c4d_general.h>
A class to evaluate mathematical expressions.
Public Member Functions | |
Bool | Eval (const maxon::String &str, Int32 *error, Float *res, Int32 unit=0, Int32 angletype=0, Int32 basis=10) |
Bool | EvalLong (const maxon::String &str, Int32 *error, Int32 *res, Int32 unit, Int32 basis) |
Bool | AddVar (const maxon::String &str, Float *value, Bool case_sensitive=false) |
Bool | RemoveVar (const maxon::String &s, Bool case_sensitive=false) |
Bool | RemoveAllVars (void) |
void | GetParserData (ParserCache *p) |
Bool | Init (const maxon::String &s, Int32 *error, Int32 unit=0, Int32 angle_unit=0, Int32 base=10) |
Bool | ReEval (Float *result, Int32 *error) |
Bool | Calculate (const ParserCache *pdat, Float *result, Int32 *error) |
Bool | AddVarLong (const maxon::String &str, Int32 *value, Bool case_sensitive=false) |
Bool | ReEvalLong (Int32 *result, Int32 *error) |
Bool | CalculateLong (const ParserCache *pdat, Int32 *result, Int32 *error) |
Bool | Reset (ParserCache *p=nullptr) |
Static Public Member Functions | |
static Parser * | Alloc (void) |
static void | Free (Parser *&pr) |
Private Member Functions | |
Parser () | |
~Parser () | |
Shader Code Generation | |
Bool | GenerateShaderCode (const maxon::String &resultVariableName, maxon::String *result) |
Bool | GenerateShaderCodeFromCache (const ParserCache *pdat, const maxon::String &resultVariableName, maxon::String *result) |
|
private |
|
private |
|
static |
|
static |
Bool Eval | ( | const maxon::String & | str, |
Int32 * | error, | ||
Float * | res, | ||
Int32 | unit = 0 , |
||
Int32 | angletype = 0 , |
||
Int32 | basis = 10 |
||
) |
Evaluates a string using the variables added with AddVar() and the built-in expressions supported by Cinema 4D. (See the Formula object in the manual.)
[in] | str | The expression to evaluate. |
[out] | error | Assigned an error value if failed: NEWPARSERERROR |
[out] | res | Assigned the result of the expression. |
[in] | unit | The unit used in the expression: UNIT |
[in] | angletype | The angle unit used in the expression: ANGLE |
[in] | basis | The base of the number system used in the expression. |
Evaluates a string using the integer variables added with AddVarLong() and the built-in expressions supported by Cinema 4D. (See the Formula object in the manual.)
[in] | str | The expression to evaluate. |
[out] | error | Assigned an error values if failed: NEWPARSERERROR |
[out] | res | Assigned the result of the expression. |
[in] | unit | The unit used in the expression: UNIT |
[in] | basis | The base of the number system used in the expression. |
Bool AddVar | ( | const maxon::String & | str, |
Float * | value, | ||
Bool | case_sensitive = false |
||
) |
Adds a variable to the parser to be evaluated.
Example:
[in] | str | The name of the variable to add, this is the name that will be used in the expression string. |
[in] | value | Assigned the evaluated value for the variable. |
[in] | case_sensitive | true if the variable string is case sensitive, otherwise false. |
Bool RemoveVar | ( | const maxon::String & | s, |
Bool | case_sensitive = false |
||
) |
Removes a variable from the parser evaluation.
[in] | s | The name of the variable to be removed. |
[in] | case_sensitive | true if the variable string is case sensitive, otherwise false. |
Bool RemoveAllVars | ( | void | ) |
Remove all variables from the parser evaluation.
void GetParserData | ( | ParserCache * | p | ) |
Retrieves the cached parser data.
[out] | p | Assigned the parser cache. The caller owns the pointed parser cache. This is used for instance by the Calculate() method. It makes possible to use multiple caches with one parser. |
Bool Init | ( | const maxon::String & | s, |
Int32 * | error, | ||
Int32 | unit = 0 , |
||
Int32 | angle_unit = 0 , |
||
Int32 | base = 10 |
||
) |
Initializes the parser with an expression string.
[in] | s | The expression string for the initialization. |
[out] | error | Assigned an error value if failed: NEWPARSERERROR |
[in] | unit | The unit used in the expression: UNIT |
[in] | angle_unit | The angle unit used in the expression: ANGLE |
[in] | base | The base of the number system used in the expression. |
Re-evaluates the expression.
[out] | result | Assigned the result of the expression. |
[out] | error | Assigned an error values if failed: NEWPARSERERROR |
Bool Calculate | ( | const ParserCache * | pdat, |
Float * | result, | ||
Int32 * | error | ||
) |
Calculates the result for an expression in an existing parser cache.
[in] | pdat | A parser cache. |
[out] | result | Assigned the result of the expression. |
[out] | error | Assigned an error values if failed: NEWPARSERERROR |
Bool AddVarLong | ( | const maxon::String & | str, |
Int32 * | value, | ||
Bool | case_sensitive = false |
||
) |
Adds an integer variable to the parser to be evaluated. Example:
[in] | str | The name of the variable to add, this is the name that will be used in the string. |
[in] | value | Assigned the evaluated value for the variable. |
[in] | case_sensitive | true if the variable string is case sensitive, otherwise false. |
Re-evaluates the expression.
[out] | result | Assigned the result of the expression. |
[out] | error | Assigned an error values if failed: NEWPARSERERROR |
Bool CalculateLong | ( | const ParserCache * | pdat, |
Int32 * | result, | ||
Int32 * | error | ||
) |
Calculates the result for an expression in an existing parser cache.
[in] | pdat | A parser cache. |
[out] | result | Assigned the result of the expression. |
[out] | error | Assigned an error values if failed: NEWPARSERERROR |
Bool Reset | ( | ParserCache * | p = nullptr | ) |
Resets certain functions used by the parser (Random etc.).
This is necessary in animated situations, otherwise results will not be consistent for the same frame.
[in] | p | The parser cache to reset. |
Bool GenerateShaderCode | ( | const maxon::String & | resultVariableName, |
maxon::String * | result | ||
) |
Returns an OpenGL Shading Language representation of the parsed expression.
[in] | resultVariableName | The name of the variable in the shade code to which the result will be assigned. |
[out] | result | The generated shader code. |
Bool GenerateShaderCodeFromCache | ( | const ParserCache * | pdat, |
const maxon::String & | resultVariableName, | ||
maxon::String * | result | ||
) |
Returns an OpenGL Shading Language representation of the parsed expression.
[in] | pdat | A parser cache. |
[in] | resultVariableName | The name of the variable in the shade code to which the result will be assigned. |
[out] | result | The generated shader code. |