FormulaParserInterface Class Reference Math Library

#include <formulaparser.h>

详细描述

公式 Parser that calculates the value of a string expression.

the following metric units are supported: km, m, cm, mm, um (also micron-sign-character + m), nm, mi (mile), yd (yard), ft (foot), in (inch)

the following functions are supported: sin(x), cos(x), acos(x), asin(x), tan(x), atan(x), cosh(x), sinh(x), tanh(x), floor(x), ceil(x), round(x), abs(x), sqr(x), sqrt(x), exp(x), log(x), log10(x), trunc(x) (converts a floating point number to an integer), rnd(x) (random value between 0 and x), rnd(x;y) (y is a seed value), pow(x;y), mod(a;b), clamp(x;lower;upper) (clamps x between interval [lower..upper]), min(x;y), max(x;y), a<<b, (x)shl(y) (bitwise shift), a>>b, (x)shr(y) (bitwise shift), len(a;b;...) (vector length of two or more components)

the following operators are supported: +, -, *, /, (, ), =, ==, >, >=, <, <=, !=, ! (bitwise not), ||, or, &&, and, & (bitwise and), | (bitwise or), ^ (bitwise xor), ~ (bitwise not), cond?(x;y) (conditional statement), if (cond;x;y) (conditional statement)

the following constants are supported: e, pi

also: any ',' characters will be interpreted like '.' as a decimal comma

Typical return errors of this interface are FormulaBadStringError, FormulaBadExecutionError, FormulaNumberError and OutOfMemoryError.

公共成员函数

MAXON_METHOD Result < void >  AddFloatVariable (const String &name, Float64 *val, Bool caseSensitive)
MAXON_METHOD Result < void >  AddIntVariable (const String &name, Int64 *val, Bool caseSensitive)
MAXON_METHOD Result < void >  AddStringVariable (const String &name, String *val, Bool caseSensitive)
MAXON_METHOD Result < void >  RemoveVariable (const String &name, Bool caseSensitive)
MAXON_METHOD Result < void >  CalculateParserCache (FormulaParserCacheRef &cache, const String &formula, METRICUNIT unit, ANGLEUNIT angleUnit, Int base, Bool integerMode)
MAXON_METHOD Result < void >  CalculateFloat (FormulaParserCacheRef &cache, Float32 &result)
MAXON_METHOD Result < void >  CalculateFloat (FormulaParserCacheRef &cache, Float64 &result)
MAXON_METHOD Result < void >  CalculateInt (FormulaParserCacheRef &cache, Int64 &result)
MAXON_METHOD Result < void >  EvaluateFloat (const String &formula, Float64 &result, METRICUNIT unit= METRICUNIT::NONE , ANGLEUNIT angleUnit= ANGLEUNIT::RADIANS , Int base=10)
MAXON_METHOD Result < void >  EvaluateInt (const String &formula, Int64 &result, METRICUNIT unit= METRICUNIT::NONE , ANGLEUNIT angleUnit= ANGLEUNIT::RADIANS , Int base=10)
MAXON_METHOD Result < void >  AddDataVariable (const String &name, 数据 *val, Bool caseSensitive)

静态公共成员函数

static MAXON_METHOD FormulaParserInterface Alloc ( MAXON_SOURCE_LOCATION_DECLARATION )

私有成员函数

  MAXON_INTERFACE_NONVIRTUAL ( FormulaParserInterface , MAXON_REFERENCE_NORMAL , "net.maxon.interface.formulaparser")

成员函数文档编制

◆  MAXON_INTERFACE_NONVIRTUAL()

MAXON_INTERFACE_NONVIRTUAL ( FormulaParserInterface   ,
MAXON_REFERENCE_NORMAL   ,
"net.maxon.interface.formulaparser"   
)
private

◆  Alloc()

static MAXON_METHOD FormulaParserInterface * Alloc ( MAXON_SOURCE_LOCATION_DECLARATION   )
static

allocator for common use.

◆  AddFloatVariable()

MAXON_METHOD Result <void> AddFloatVariable ( const String name ,
Float64 val ,
Bool   caseSensitive  
)

Adds a floating point variable to the formula parser.

参数
[in] name Name of the variable.
[in] val Pointer to the variable. Note that the pointer must always be valid when Calculate or Evaluate are called.
[in] caseSensitive If false, then the user can write the letters of the variable using any lower/uppercase combinations.
返回
OK on success. IllegalArgumentError is returned if a variable was already present.

◆  AddIntVariable()

MAXON_METHOD Result <void> AddIntVariable ( const String name ,
Int64 val ,
Bool   caseSensitive  
)

Adds an integer variable to the formula parser.

参数
[in] name Name of the variable.
[in] val Pointer to the variable. Note that the pointer must always be valid when Calculate or Evaluate are called.
[in] caseSensitive If false, then the user can write the letters of the variable using any lower/uppercase combinations.
返回
OK on success. IllegalArgumentError is returned if a variable was already present.

◆  AddStringVariable()

MAXON_METHOD Result <void> AddStringVariable ( const String name ,
String val ,
Bool   caseSensitive  
)

Adds a string variable to the formula parser.

参数
[in] name Name of the variable.
[in] val Pointer to the variable. Note that the pointer must always be valid when Calculate or Evaluate are called.
[in] caseSensitive If false, then the user can write the letters of the variable using any lower/uppercase combinations.
返回
OK on success. IllegalArgumentError is returned if a variable was already present.

◆  RemoveVariable()

MAXON_METHOD Result <void> RemoveVariable ( const String name ,
Bool   caseSensitive  
)

Removes variable from the formula parser.

参数
[in] name Name of the variable.
[in] caseSensitive If false, then any variable that matches any possible lower/uppercase combination will be picked.
返回
OK on success. IllegalArgumentError is returned if a variable was not present.

◆  CalculateParserCache()

MAXON_METHOD Result <void> CalculateParserCache ( FormulaParserCacheRef &  cache ,
const String formula ,
METRICUNIT   unit ,
ANGLEUNIT   angleUnit ,
Int   base ,
Bool   integerMode  
)

Translates a formula expression string into a pre-parsed cache.

参数
[out] cache Cache that will be created.
[in] formula Formula to be parsed.
[in] unit The metric unit format for the result value. If set to METRICUNIT::NONE all metric units will be ignored as if they were not present.
[in] angleUnit The angular unit that trigonometric functions expect as input / produce as output.
[in] base The numerical base for numbers in the range of [2..36], by default 10. If the base is != 10 then any number will be parsed as an integer value.
[in] integerMode Calculate expressions with integer numbers (floating point values cannot accurately represent most of the Int64 values)
返回
OK on success.

◆  CalculateFloat() [1/2]

MAXON_METHOD Result <void> CalculateFloat ( FormulaParserCacheRef &  cache ,
Float32 result  
)

Executes a floating point formula calculation using a pre-parsed cache for better performance.

参数
[in,out] cache Pre-parsed cache generated by CalculateParserCache. The cache might be modified during this call.
[out] result Will be filled with the result of the formula (even if a neglectable error occured) or 0.0.
返回
OK on success.

◆  CalculateFloat() [2/2]

MAXON_METHOD Result <void> CalculateFloat ( FormulaParserCacheRef &  cache ,
Float64 result  
)

◆  CalculateInt()

MAXON_METHOD Result <void> CalculateInt ( FormulaParserCacheRef &  cache ,
Int64 result  
)

Executes an integer formula calculation using a pre-parsed cache for better performance.

参数
[in,out] cache Pre-parsed cache generated by CalculateParserCache. The cache might be modified during this call.
[out] result Will be filled with the result of the formula (even if a neglectable error occured) or 0.
返回
OK on success.

◆  EvaluateFloat()

MAXON_METHOD Result <void> EvaluateFloat ( const String formula ,
Float64 result ,
METRICUNIT   unit = METRICUNIT::NONE ,
ANGLEUNIT   angleUnit = ANGLEUNIT::RADIANS ,
Int   base = 10  
)

Evaluates a floating point formula. If you need multiple calls to the same formula (e.g. when variables are used) use CalculateParserCache and CalculateFloat for better performance.

参数
[in] formula Formula to be parsed.
[out] result Will be filled with the result of the formula (might even be the case if a neglectable error occured) or 0.0.
[in] unit The metric unit format for the result value. If set to METRICUNIT::NONE all metric units will be ignored as if they were not present.
[in] angleUnit The angular unit that trigonometric functions expect as input / produce as output.
[in] base The numerical base for numbers in the range of [2..36], by default 10. If the base is != 10 then any number will be parsed as an integer value.
返回
OK on success.

◆  EvaluateInt()

MAXON_METHOD Result <void> EvaluateInt ( const String formula ,
Int64 result ,
METRICUNIT   unit = METRICUNIT::NONE ,
ANGLEUNIT   angleUnit = ANGLEUNIT::RADIANS ,
Int   base = 10  
)

Evaluates an integer formula. If you need multiple calls to the same formula (e.g. when variables are used) use CalculateParserCache and CalculateInt for better performance.

参数
[in] formula Formula to be parsed.
[out] result Will be filled with the result of the formula (might even be the case if a neglectable error occured) or 0.
[in] unit The metric unit format for the result value. If set to METRICUNIT::NONE all metric units will be ignored as if they were not present.
[in] angleUnit The angular unit that trigonometric functions expect as input / produce as output.
[in] base The numerical base for numbers in the range of [2..36], by default 10.
返回
OK on success.

◆  AddDataVariable()

MAXON_METHOD Result <void> AddDataVariable ( const String name ,
数据 val ,
Bool   caseSensitive  
)

Adds a 数据 variable to the formula parser.

参数
[in] name Name of the variable.
[in] val Pointer to the variable. Note that the pointer must always be valid when Calculate or Evaluate are called.
[in] caseSensitive If false, then the user can write the letters of the variable using any lower/uppercase combinations.
返回
OK on success. IllegalArgumentError is returned if a variable was already present.