Parser Class Reference

#include <c4d_general.h>

详细描述

A class to evaluate mathematical expressions.

注意
Has to be created with Alloc() and destroyed with Free() 。使用 AutoAlloc to automate the allocation and destruction based on scope.

公共成员函数

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   重置 ( ParserCache *p=nullptr)

静态公共成员函数

static Parser Alloc (void)
static void  Free ( Parser *&pr)

私有成员函数

  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)

构造函数 & 析构函数文档编制

◆  Parser()

Parser () private

◆  ~Parser()

~ Parser () private

成员函数文档编制

◆  Alloc()

static Parser * Alloc ( void  )
static

Allocates a parser. Destroy the allocated parser with Free() 。使用 AutoAlloc to automate the allocation and destruction based on scope.

返回
The allocated parser, or nullptr if the allocation failed.

◆  Free()

static void Free ( Parser *&  pr )
static

Destructs parsers allocated with Alloc() 。使用 AutoAlloc to automate the allocation and destruction based on scope.

参数
[in,out] pr The parser to destruct. If the pointer is nullptr nothing happens. The pointer is assigned nullptr afterwards.

◆  Eval()

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.)

注意
Calls internally Init() and Calculate() , or if the string has not changed ReEval() .
参数
[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.
返回
true if successful, otherwise false .

◆  EvalLong()

Bool EvalLong ( const maxon::String str ,
Int32 error ,
Int32 res ,
Int32   unit ,
Int32   basis  
)

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.)

注意
Calls internally Init() and CalculateLong() , or if the string has not changed ReEvalLong() .
参数
[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.
返回
true if successful, otherwise false .

◆  AddVar()

Bool AddVar ( const maxon::String str ,
Float value ,
Bool   case_sensitive = false  
)

Adds a variable to the parser to be evaluated.
范例:

Float vu; for (i=0; i<1000; i++) { vu = i*0.2; parser->AddVar( "u" ,&vu, true ); parser->Eval( "Sin(u)" ,...); }
参数
[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 .
返回
true if successful, otherwise false .

◆  RemoveVar()

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 .
返回
true if successful, otherwise false .

◆  RemoveAllVars()

Bool RemoveAllVars ( void  )

Remove all variables from the parser evaluation.

返回
true if successful, otherwise false .

◆  GetParserData()

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.

◆  Init()

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.
返回
true if successful, otherwise false .

◆  ReEval()

Bool ReEval ( Float result ,
Int32 error  
)

Re-evaluates the expression.

警告
The expression string must not change prior to using this method.
参数
[out] result Assigned the result of the expression.
[out] error Assigned an error values if failed: NEWPARSERERROR
返回
true if successful, otherwise false .

◆  Calculate()

Bool Calculate ( const ParserCache pdat ,
Float result ,
Int32 error  
)

Calculates the result for an expression in an existing parser cache.

另请参阅
GetParserData()
参数
[in] pdat A parser cache.
[out] result Assigned the result of the expression.
[out] error Assigned an error values if failed: NEWPARSERERROR
返回
true if successful, otherwise false .

◆  AddVarLong()

Bool AddVarLong ( const maxon::String str ,
Int32 value ,
Bool   case_sensitive = false  
)

Adds an integer variable to the parser to be evaluated. 范例:

for (i=0; i<1000; i++) { parser->AddVar( "i" ,&i, true ); parser->EvalLong( "2*i" ,...); }
参数
[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 .
返回
true if successful, otherwise false .

◆  ReEvalLong()

Bool ReEvalLong ( Int32 result ,
Int32 error  
)

Re-evaluates the expression.

警告
The expression string must not change prior to using this method.
参数
[out] result Assigned the result of the expression.
[out] error Assigned an error values if failed: NEWPARSERERROR
返回
true if successful, otherwise false .

◆  CalculateLong()

Bool CalculateLong ( const ParserCache pdat ,
Int32 result ,
Int32 error  
)

Calculates the result for an expression in an existing parser cache.

另请参阅
GetParserData()
参数
[in] pdat A parser cache.
[out] result Assigned the result of the expression.
[out] error Assigned an error values if failed: NEWPARSERERROR
返回
true if successful, otherwise false .

◆  Reset()

Bool 重置 ( 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.
返回
true if successful, otherwise false .

◆  GenerateShaderCode()

Bool GenerateShaderCode ( const maxon::String resultVariableName ,
maxon::String result  
)

Returns an OpenGL Shading Language representation of the parsed expression.

由于
R17.032
警告
Init() must be called before using this function, as it uses internally-cached data. Knowledge of the OpenGL Shading Language is required for correct use of this function.
注意
The generated OpenGL shader code assigns the result of the expression to a float variable with the given name (it must be a valid GLSL identifier).
Each expression variable name is converted to upper case before being inserted into the shader code.
Variable names with spaces are not supported and must be valid GLSL identifiers.
Declarations of these expression variables (such as those defined with AddVar() ) must be added by the caller to the start of the code string and initialized with default values.
It is advisable to add braces around these declarations and the generated code so as to avoid naming conflicts.
参数
[in] resultVariableName The name of the variable in the shade code to which the result will be assigned.
[out] result The generated shader code.
返回
true if successful, otherwise false .

◆  GenerateShaderCodeFromCache()

Bool GenerateShaderCodeFromCache ( const ParserCache pdat ,
const maxon::String resultVariableName ,
maxon::String result  
)

Returns an OpenGL Shading Language representation of the parsed expression.

由于
R17.032
警告
Knowledge of the OpenGL Shading Language is required for correct use of this function.
注意
The generated OpenGL shader code assigns the result of the expression to a float variable with the given name (it must be a valid GLSL identifier).
Each expression variable name is converted to upper case before being inserted into the shader code.
Variable names with spaces are not supported and must be valid GLSL identifiers.
Declarations of these expression variables (such as those defined with AddVar() ) must be added by the caller to the start of the code string and initialized with default values.
It is advisable to add braces around these declarations and the generated code so as to avoid naming conflicts.
参数
[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.
返回
true if successful, otherwise false .
Float
maxon::Float Float
定义: ge_sys_math.h:64