bcParser.NET
Math Parser for .NET
Public Member Functions | List of all members
Bestcode.MathParser.IParameter Interface Reference

IParameter is used to supply a parameter value for a user defined function. The actual value may be calculated from a complicated sub expression. The value is not computed until you call the IParamater.GetValue() function(s). If you are going to use the value more than once, it is best to cache it in a local variable. The value can be numeric (DOUBLE_PARSER) or a String. If the string can be parsed as a double, then you can still call GetValueAsDouble on it and an automatic conversion will take place. All functions take an array of IParameter[] that enables them to query the current value of the parameters using the GetValue(), GetValueAsDouble() or GetValueAsString() functions.

For most functions such as sin(x), cos(x) etc the length of IParameter[] p is 1. For some functions such as min(x,y), the length of IParameter[] p is 2. The built in IF(a, b,c) function has IParameter[] p length 3. The build in RDN() function has IParameter[] p length 0. For functions such as SUM(...) or CONCAT(...) the p.length (number of parameters that the function is taking) is determined at runtime. It can be 0 or more. See IFunction interface to learn more about defining functions and their parameter lengths. Example:

public IConvertible Run(IParameter[] p) {
double x__ = p[0].GetValueAsDouble();
return (Math.Exp(x__)+Math.Exp(-x__))*0.5;
}
br /> /summary> More...

Inheritance diagram for Bestcode.MathParser.IParameter:
Bestcode.MathParser.Node

Public Member Functions

IConvertible GetValue ()
 Returns the value of the Parameter. In some cases, this may require lengthy calculations. Therefore, in your user defined function implementations, try not to call this method repeated times. Instead call it once and cache the returned value within your method implementation. In some cases, you may skip calculation of the value. For example, lets say you want to implement a divide(x,y) function, if y is 0, result is infinity. So it is best to do y.GetValue() first and if it is zero return infinity or throw exception without ever doing x.GetValue(). This is a basic example to describe you what you could do. Otherwise, it is very unlikely that you will ever define your own divide(x,y) function. The type of the result is Double for numeric functions, and it is String for Strings. More...
 
String GetValueAsString ()
 Returns the value as a String. More...
 

Detailed Description

IParameter is used to supply a parameter value for a user defined function. The actual value may be calculated from a complicated sub expression. The value is not computed until you call the IParamater.GetValue() function(s). If you are going to use the value more than once, it is best to cache it in a local variable. The value can be numeric (DOUBLE_PARSER) or a String. If the string can be parsed as a double, then you can still call GetValueAsDouble on it and an automatic conversion will take place. All functions take an array of IParameter[] that enables them to query the current value of the parameters using the GetValue(), GetValueAsDouble() or GetValueAsString() functions.

For most functions such as sin(x), cos(x) etc the length of IParameter[] p is 1. For some functions such as min(x,y), the length of IParameter[] p is 2. The built in IF(a, b,c) function has IParameter[] p length 3. The build in RDN() function has IParameter[] p length 0. For functions such as SUM(...) or CONCAT(...) the p.length (number of parameters that the function is taking) is determined at runtime. It can be 0 or more. See IFunction interface to learn more about defining functions and their parameter lengths. Example:

public IConvertible Run(IParameter[] p) {
double x__ = p[0].GetValueAsDouble();
return (Math.Exp(x__)+Math.Exp(-x__))*0.5;
}
br /> /summary>

Member Function Documentation

IConvertible Bestcode.MathParser.IParameter.GetValue ( )

Returns the value of the Parameter. In some cases, this may require lengthy calculations. Therefore, in your user defined function implementations, try not to call this method repeated times. Instead call it once and cache the returned value within your method implementation. In some cases, you may skip calculation of the value. For example, lets say you want to implement a divide(x,y) function, if y is 0, result is infinity. So it is best to do y.GetValue() first and if it is zero return infinity or throw exception without ever doing x.GetValue(). This is a basic example to describe you what you could do. Otherwise, it is very unlikely that you will ever define your own divide(x,y) function. The type of the result is Double for numeric functions, and it is String for Strings.

Returns
Returns the value of the parameter.

Implemented in Bestcode.MathParser.Node.

String Bestcode.MathParser.IParameter.GetValueAsString ( )

Returns the value as a String.

Returns
The value as a String object.

Implemented in Bestcode.MathParser.Node.